Skip to content

Commit

Permalink
v3.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Jun 25, 2020
1 parent 427cb7a commit 17fd809
Show file tree
Hide file tree
Showing 9 changed files with 236 additions and 297 deletions.
5 changes: 4 additions & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module.exports = {
printWidth: 160,
tabWidth: 4,
singleQuote: true
singleQuote: true,
endOfLine: 'lf',
trailingComma: 'none',
arrowParens: 'avoid'
};
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v3.7.0 2020-06-25

- Bump dependencies to latest

## v3.6.0 2020-03-15

- Add remote address to any errors
Expand Down
15 changes: 3 additions & 12 deletions lib/sasl.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ const SASL = (module.exports = {
return callback();
}

let data = Buffer.from(token, 'base64')
.toString()
.split('\x00');
let data = Buffer.from(token, 'base64').toString().split('\x00');

if (data.length !== 3) {
this.send(500, 'Error: invalid userdata');
Expand Down Expand Up @@ -354,9 +352,7 @@ const SASL = (module.exports = {
return callback();
}

let tokenParts = Buffer.from(token, 'base64')
.toString()
.split(' ');
let tokenParts = Buffer.from(token, 'base64').toString().split(' ');
let username = tokenParts.shift();
let challengeResponse = (tokenParts.shift() || '').toLowerCase();

Expand All @@ -366,12 +362,7 @@ const SASL = (module.exports = {
username,
validatePassword(password) {
let hmac = crypto.createHmac('md5', password);
return (
hmac
.update(challenge)
.digest('hex')
.toLowerCase() === challengeResponse
);
return hmac.update(challenge).digest('hex').toLowerCase() === challengeResponse;
}
},
this.session,
Expand Down
60 changes: 13 additions & 47 deletions lib/smtp-connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class SMTPConnection extends EventEmitter {
}

if (code >= 400) {
this.session.error = payload;
this.session.error = payload;
}

if (this._socket && this._socket.writable) {
Expand Down Expand Up @@ -350,7 +350,7 @@ class SMTPConnection extends EventEmitter {
return;
}

err.remote = this.remoteAddress
err.remote = this.remoteAddress;
this._server.logger.error(
{
err,
Expand Down Expand Up @@ -379,11 +379,7 @@ class SMTPConnection extends EventEmitter {
* @param {Function} callback Callback to run once the command is processed
*/
_onCommand(command, callback) {
let commandName = (command || '')
.toString()
.split(' ')
.shift()
.toUpperCase();
let commandName = (command || '').toString().split(' ').shift().toUpperCase();
this._server.logger.debug(
{
tnx: 'command',
Expand Down Expand Up @@ -483,10 +479,7 @@ class SMTPConnection extends EventEmitter {
* @returns {Boolean} Returns true if the command can be used
*/
_isSupported(command) {
command = (command || '')
.toString()
.trim()
.toUpperCase();
command = (command || '').toString().trim().toUpperCase();
return !this._server.options.disabledCommands.includes(command) && typeof this['handler_' + command] === 'function';
}

Expand All @@ -499,20 +492,11 @@ class SMTPConnection extends EventEmitter {
*/
_parseAddressCommand(name, command) {
command = (command || '').toString();
name = (name || '')
.toString()
.trim()
.toUpperCase();
name = (name || '').toString().trim().toUpperCase();

let parts = command.split(':');
command = parts
.shift()
.trim()
.toUpperCase();
parts = parts
.join(':')
.trim()
.split(/\s+/);
command = parts.shift().trim().toUpperCase();
parts = parts.join(':').trim().split(/\s+/);

let address = parts.shift();
let args = false;
Expand Down Expand Up @@ -653,10 +637,7 @@ class SMTPConnection extends EventEmitter {
* Processes EHLO. Requires valid hostname as the single argument.
*/
handler_EHLO(command, callback) {
let parts = command
.toString()
.trim()
.split(/\s+/);
let parts = command.toString().trim().split(/\s+/);
let hostname = parts[1] || '';

if (parts.length !== 2) {
Expand Down Expand Up @@ -700,10 +681,7 @@ class SMTPConnection extends EventEmitter {
* Processes HELO. Requires valid hostname as the single argument.
*/
handler_HELO(command, callback) {
let parts = command
.toString()
.trim()
.split(/\s+/);
let parts = command.toString().trim().split(/\s+/);
let hostname = parts[1] || '';

if (parts.length !== 2) {
Expand Down Expand Up @@ -782,10 +760,7 @@ class SMTPConnection extends EventEmitter {
}

let allowedKeys = ['NAME', 'ADDR', 'PORT', 'PROTO', 'HELO', 'LOGIN'];
let parts = command
.toString()
.trim()
.split(/\s+/);
let parts = command.toString().trim().split(/\s+/);
let key, value;
let data = new Map();
parts.shift(); // remove XCLIENT prefix
Expand Down Expand Up @@ -977,10 +952,7 @@ class SMTPConnection extends EventEmitter {
}

let allowedKeys = ['NAME', 'ADDR', 'PORT', 'PROTO', 'HELO', 'IDENT', 'SOURCE'];
let parts = command
.toString()
.trim()
.split(/\s+/);
let parts = command.toString().trim().split(/\s+/);
let key, value;
let data = new Map();
let hasAddr = false;
Expand Down Expand Up @@ -1129,10 +1101,7 @@ class SMTPConnection extends EventEmitter {
* Check if selected authentication is available and delegate auth data to SASL
*/
handler_AUTH(command, callback) {
let args = command
.toString()
.trim()
.split(/\s+/);
let args = command.toString().trim().split(/\s+/);
let method;
let handler;

Expand Down Expand Up @@ -1330,10 +1299,7 @@ class SMTPConnection extends EventEmitter {
* Processes sendmail WIZ command, upgrades to "wizard mode"
*/
handler_WIZ(command, callback) {
let args = command
.toString()
.trim()
.split(/\s+/);
let args = command.toString().trim().split(/\s+/);
let password;

args.shift(); // remove WIZ
Expand Down
39 changes: 9 additions & 30 deletions lib/smtp-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,10 @@ class SMTPServer extends EventEmitter {
this.updateSecureContext();

// setup disabled commands list
this.options.disabledCommands = [].concat(this.options.disabledCommands || []).map(command =>
(command || '')
.toString()
.toUpperCase()
.trim()
);
this.options.disabledCommands = [].concat(this.options.disabledCommands || []).map(command => (command || '').toString().toUpperCase().trim());

// setup allowed auth methods
this.options.authMethods = [].concat(this.options.authMethods || []).map(method =>
(method || '')
.toString()
.toUpperCase()
.trim()
);
this.options.authMethods = [].concat(this.options.authMethods || []).map(method => (method || '').toString().toUpperCase().trim());

if (!this.options.authMethods.length) {
this.options.authMethods = ['LOGIN', 'PLAIN'];
Expand Down Expand Up @@ -75,19 +65,13 @@ class SMTPServer extends EventEmitter {
// ignore, should not happen
}
if (this.options.secured) {
return this.connect(
socket,
socketOptions
);
return this.connect(socket, socketOptions);
}
this._upgrade(socket, (err, tlsSocket) => {
if (err) {
return this._onError(err);
}
this.connect(
tlsSocket,
socketOptions
);
this.connect(tlsSocket, socketOptions);
});
});
});
Expand All @@ -97,10 +81,7 @@ class SMTPServer extends EventEmitter {
if (err) {
// ignore, should not happen
}
this.connect(
socket,
socketOptions
);
this.connect(socket, socketOptions);
})
);
}
Expand Down Expand Up @@ -171,9 +152,9 @@ class SMTPServer extends EventEmitter {
});
}
if (typeof callback === 'function') {
const realCallback = callback;
callback = null;
return realCallback();
const realCallback = callback;
callback = null;
return realCallback();
}
}, timeout);
}
Expand Down Expand Up @@ -380,9 +361,7 @@ class SMTPServer extends EventEmitter {
socket.unshift(remainder);
}

let header = Buffer.concat(chunks, chunklen)
.toString()
.trim();
let header = Buffer.concat(chunks, chunklen).toString().trim();

let params = (header || '').toString().split(' ');
let commandName = params.shift().toUpperCase();
Expand Down
6 changes: 1 addition & 5 deletions lib/tls-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ const tlsDefaults = {
'-----END CERTIFICATE-----',
honorCipherOrder: true,
requestOCSP: false,
sessionIdContext: crypto
.createHash('sha1')
.update(process.argv.join(' '))
.digest('hex')
.slice(0, 32)
sessionIdContext: crypto.createHash('sha1').update(process.argv.join(' ')).digest('hex').slice(0, 32)
};

/**
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "smtp-server",
"version": "3.6.0",
"version": "3.7.0",
"description": "Create custom SMTP servers on the fly",
"main": "lib/smtp-server.js",
"scripts": {
Expand All @@ -11,17 +11,17 @@
"dependencies": {
"base32.js": "0.1.0",
"ipv6-normalize": "1.0.1",
"nodemailer": "6.4.5"
"nodemailer": "6.4.10"
},
"devDependencies": {
"chai": "4.2.0",
"eslint-config-nodemailer": "1.2.0",
"eslint-config-prettier": "6.10.0",
"grunt": "1.0.4",
"eslint-config-prettier": "6.11.0",
"grunt": "1.1.0",
"grunt-cli": "1.3.2",
"grunt-eslint": "22.0.0",
"grunt-eslint": "23.0.0",
"grunt-mocha-test": "0.13.3",
"mocha": "7.1.0",
"mocha": "8.0.1",
"pem": "1.14.4"
},
"repository": {
Expand Down
Loading

0 comments on commit 17fd809

Please sign in to comment.