smtp-server
Advanced tools
Comparing version 1.1.0 to 1.1.1
# Changelog | ||
## v1.1.1 2015-03-11 | ||
* Fixed an issue with parsing MAIL FROM and RCPT TO commands, if there was a space before or after the first colon | ||
## v1.1.0 2015-03-09 | ||
@@ -4,0 +8,0 @@ |
@@ -279,3 +279,3 @@ 'use strict'; | ||
* | ||
* @param {[type]} name Address type, eg 'from' or 'to' | ||
* @param {[type]} name Address type, eg 'mail from' or 'rcpt to' | ||
* @param {[type]} command Data payload to parse | ||
@@ -286,20 +286,14 @@ * @returns {Object|Boolean} Parsed address in the form of {address:, args: {}} or false if parsing failed | ||
command = (command || '').toString(); | ||
name = (name || '').toString().trim().toLowerCase(); | ||
name = (name || '').toString().trim().toUpperCase(); | ||
var parts = command.split(/\s+/); | ||
var address = false; | ||
var parts = command.split(':'); | ||
command = parts.shift().trim().toUpperCase(); | ||
parts = parts.join(':').trim().split(/\s+/); | ||
var address = parts.shift(); | ||
var args = false; | ||
var invalid = false; | ||
parts.shift(); // remove command | ||
address = parts.shift() || ''; | ||
if (new RegExp('^' + name + '$', 'i').test(address)) { | ||
address = parts.shift() || ''; | ||
} else { | ||
address = address.split(':'); | ||
if (!new RegExp('^' + name, 'i').test(address.shift())) { | ||
invalid = true; | ||
} | ||
address = address.join(':').trim(); | ||
if (name !== command) { | ||
return false; | ||
} | ||
@@ -546,3 +540,3 @@ | ||
SMTPConnection.prototype.handler_MAIL = function(command, callback) { | ||
var parsed = this._parseAddressCommand('from', command); | ||
var parsed = this._parseAddressCommand('mail from', command); | ||
@@ -578,3 +572,3 @@ // sender address can be empty, so we only check if parsing failed or not | ||
SMTPConnection.prototype.handler_RCPT = function(command, callback) { | ||
var parsed = this._parseAddressCommand('to', command); | ||
var parsed = this._parseAddressCommand('rcpt to', command); | ||
@@ -581,0 +575,0 @@ // recipient address can not be empty |
{ | ||
"name": "smtp-server", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Create custom SMTP servers on the fly", | ||
@@ -5,0 +5,0 @@ "main": "lib/smtp-server.js", |
'use strict'; | ||
var chai = require('chai'); | ||
var SMTPConnection = require('smtp-connection'); | ||
var Client = require('smtp-connection'); | ||
var SMTPServer = require('../lib/smtp-server').SMTPServer; | ||
var SMTPConnection = require('../lib/smtp-connection').SMTPConnection; | ||
var expect = chai.expect; | ||
@@ -14,2 +16,31 @@ var fs = require('fs'); | ||
describe('Unit tests', function() { | ||
describe('#_parseAddressCommand', function() { | ||
it('should parse MAIL FROM/RCPT TO', function() { | ||
expect(SMTPConnection.prototype._parseAddressCommand('MAIL FROM', 'MAIL FROM:<test@example.com>')).to.deep.equal({ | ||
address: 'test@example.com', | ||
args: false | ||
}); | ||
expect(SMTPConnection.prototype._parseAddressCommand('MAIL FROM', 'MAIL FROM:<sender@example.com> SIZE=12345 RET=HDRS ')).to.deep.equal({ | ||
address: 'sender@example.com', | ||
args: { | ||
SIZE: '12345', | ||
RET: 'HDRS' | ||
} | ||
}); | ||
expect(SMTPConnection.prototype._parseAddressCommand('MAIL FROM', 'MAIL FROM : <test@example.com>')).to.deep.equal({ | ||
address: 'test@example.com', | ||
args: false | ||
}); | ||
expect(SMTPConnection.prototype._parseAddressCommand('MAIL TO', 'MAIL FROM:<test@example.com>')).to.be.false; | ||
}); | ||
}); | ||
}); | ||
describe('Plaintext server', function() { | ||
@@ -33,3 +64,3 @@ var PORT = 1336; | ||
it('should connect without TLS', function(done) { | ||
var connection = new SMTPConnection({ | ||
var connection = new Client({ | ||
port: PORT, | ||
@@ -48,3 +79,3 @@ host: '127.0.0.1', | ||
it('should connect with TLS', function(done) { | ||
var connection = new SMTPConnection({ | ||
var connection = new Client({ | ||
port: PORT, | ||
@@ -71,3 +102,3 @@ host: '127.0.0.1', | ||
var createConnection = function(callback) { | ||
var connection = new SMTPConnection({ | ||
var connection = new Client({ | ||
port: PORT, | ||
@@ -124,3 +155,3 @@ host: '127.0.0.1', | ||
var createConnection = function(callback) { | ||
var connection = new SMTPConnection({ | ||
var connection = new Client({ | ||
port: PORT, | ||
@@ -174,3 +205,3 @@ host: '127.0.0.1', | ||
it('should close on timeout', function(done) { | ||
var connection = new SMTPConnection({ | ||
var connection = new Client({ | ||
port: PORT, | ||
@@ -193,3 +224,3 @@ host: '127.0.0.1', | ||
it('should close on timeout using secure socket', function(done) { | ||
var connection = new SMTPConnection({ | ||
var connection = new Client({ | ||
port: PORT, | ||
@@ -234,3 +265,3 @@ host: '127.0.0.1', | ||
it('should connect without TLS', function(done) { | ||
var connection = new SMTPConnection({ | ||
var connection = new Client({ | ||
port: PORT, | ||
@@ -249,3 +280,3 @@ host: '127.0.0.1' | ||
it('should connect with TLS', function(done) { | ||
var connection = new SMTPConnection({ | ||
var connection = new Client({ | ||
port: PORT, | ||
@@ -274,3 +305,3 @@ host: '127.0.0.1', | ||
disabledCommands: ['STARTTLS'], | ||
loggers: false, | ||
logger: false, | ||
socketTimeout: 2 * 1000 | ||
@@ -288,3 +319,3 @@ }); | ||
it('should connect without TLS', function(done) { | ||
var connection = new SMTPConnection({ | ||
var connection = new Client({ | ||
port: PORT, | ||
@@ -303,3 +334,3 @@ host: '127.0.0.1' | ||
it('should not connect with TLS', function(done) { | ||
var connection = new SMTPConnection({ | ||
var connection = new Client({ | ||
port: PORT, | ||
@@ -351,3 +382,3 @@ host: '127.0.0.1', | ||
it('should connect to secure server', function(done) { | ||
var connection = new SMTPConnection({ | ||
var connection = new Client({ | ||
port: PORT, | ||
@@ -415,3 +446,3 @@ host: '127.0.0.1', | ||
it('should authenticate', function(done) { | ||
var connection = new SMTPConnection({ | ||
var connection = new Client({ | ||
port: PORT, | ||
@@ -439,3 +470,3 @@ host: '127.0.0.1', | ||
it('should fail', function(done) { | ||
var connection = new SMTPConnection({ | ||
var connection = new Client({ | ||
port: PORT, | ||
@@ -466,3 +497,3 @@ host: '127.0.0.1', | ||
it('should authenticate', function(done) { | ||
var connection = new SMTPConnection({ | ||
var connection = new Client({ | ||
port: PORT, | ||
@@ -490,3 +521,3 @@ host: '127.0.0.1', | ||
it('should fail', function(done) { | ||
var connection = new SMTPConnection({ | ||
var connection = new Client({ | ||
port: PORT, | ||
@@ -517,3 +548,3 @@ host: '127.0.0.1', | ||
it('should authenticate', function(done) { | ||
var connection = new SMTPConnection({ | ||
var connection = new Client({ | ||
port: PORT, | ||
@@ -541,3 +572,3 @@ host: '127.0.0.1', | ||
it('should fail', function(done) { | ||
var connection = new SMTPConnection({ | ||
var connection = new Client({ | ||
port: PORT, | ||
@@ -625,3 +656,3 @@ host: '127.0.0.1', | ||
server.listen(PORT, '127.0.0.1', function() { | ||
connection = new SMTPConnection({ | ||
connection = new Client({ | ||
port: PORT, | ||
@@ -763,3 +794,3 @@ host: '127.0.0.1', | ||
server.listen(PORT, '127.0.0.1', function() { | ||
connection = new SMTPConnection({ | ||
connection = new Client({ | ||
port: PORT, | ||
@@ -805,3 +836,3 @@ host: '127.0.0.1' | ||
server.listen(PORT, '127.0.0.1', function() { | ||
connection = new SMTPConnection({ | ||
connection = new Client({ | ||
port: PORT, | ||
@@ -808,0 +839,0 @@ host: '127.0.0.1' |
90113
1967