From 28c4ad92661f9df9f96d9fa64a9de6b161c74b5a Mon Sep 17 00:00:00 2001 From: Cliff Stanford Date: Sun, 7 May 2017 12:34:14 +0300 Subject: [PATCH 1/6] Add the latest message to the session. This allows an external logger to see what the last thing sent was before closing the session using onClose. --- lib/smtp-connection.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/smtp-connection.js b/lib/smtp-connection.js index 9ff0cd8..24d23bc 100644 --- a/lib/smtp-connection.js +++ b/lib/smtp-connection.js @@ -192,6 +192,8 @@ class SMTPConnection extends EventEmitter { payload = [].concat(code || []).concat(data || []).join(' '); } + this.session.response = payload; + if (this._socket && this._socket.writable) { this._socket.write(payload + '\r\n'); this._server.logger.debug({ From 240466c61200fcd535d062641f169d1b1cec775c Mon Sep 17 00:00:00 2001 From: Cliff Stanford Date: Sun, 7 May 2017 14:38:49 +0300 Subject: [PATCH 2/6] Only save the result if it's an error. Otherwise we end up with the 221 from the QUIT. --- lib/smtp-connection.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/smtp-connection.js b/lib/smtp-connection.js index 24d23bc..632e99f 100644 --- a/lib/smtp-connection.js +++ b/lib/smtp-connection.js @@ -192,7 +192,9 @@ class SMTPConnection extends EventEmitter { payload = [].concat(code || []).concat(data || []).join(' '); } - this.session.response = payload; + if (code >= 400) { + this.session.error = payload; + } if (this._socket && this._socket.writable) { this._socket.write(payload + '\r\n'); From 40cfd20cf74d36d9c851abb1637eed78b008dfc2 Mon Sep 17 00:00:00 2001 From: Cliff Stanford Date: Wed, 23 Aug 2017 14:40:40 +0300 Subject: [PATCH 3/6] Perform a callback after forcing connections closed. --- lib/smtp-server.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/smtp-server.js b/lib/smtp-server.js index 3068674..91f00ce 100644 --- a/lib/smtp-server.js +++ b/lib/smtp-server.js @@ -145,6 +145,9 @@ class SMTPServer extends EventEmitter { connection.close(); }); } + if (typeof callback === 'function') { + return callback(); + } }, timeout); } From 6b4263301d1d490af90bede62e4a4a7a94362567 Mon Sep 17 00:00:00 2001 From: Cliff Stanford Date: Sat, 14 Mar 2020 12:25:25 +0200 Subject: [PATCH 4/6] Add remote address to any errors. --- lib/smtp-connection.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/smtp-connection.js b/lib/smtp-connection.js index 4b28753..4c243b1 100644 --- a/lib/smtp-connection.js +++ b/lib/smtp-connection.js @@ -350,6 +350,7 @@ class SMTPConnection extends EventEmitter { return; } + err.remote = this.remoteAddress this._server.logger.error( { err, From 0c5f9d10ed19bf0010031a1de9112f50fdbe71e0 Mon Sep 17 00:00:00 2001 From: Cliff Stanford Date: Sat, 14 Mar 2020 14:10:34 +0200 Subject: [PATCH 5/6] Fix global issue with eslint. --- test/smtp-stream-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/smtp-stream-test.js b/test/smtp-stream-test.js index af941c8..69a6021 100644 --- a/test/smtp-stream-test.js +++ b/test/smtp-stream-test.js @@ -1,5 +1,5 @@ /* eslint no-unused-expressions:0, prefer-arrow-callback: 0 */ -/* globals beforeEach, describe, it */ +/* globals describe, it */ 'use strict'; From b87cbf70d9944fc83b70f2f670ae1c0eeefcc98f Mon Sep 17 00:00:00 2001 From: Cliff Stanford Date: Sun, 15 Mar 2020 13:58:03 +0200 Subject: [PATCH 6/6] Prevent server.close from calling the callback again. --- lib/smtp-server.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/smtp-server.js b/lib/smtp-server.js index abf0f57..c5ba56b 100644 --- a/lib/smtp-server.js +++ b/lib/smtp-server.js @@ -171,7 +171,9 @@ class SMTPServer extends EventEmitter { }); } if (typeof callback === 'function') { - return callback(); + const realCallback = callback; + callback = null; + return realCallback(); } }, timeout); }