From b6b3476a2963d3abcdb9a4f1a48950ce3bd4ae7c Mon Sep 17 00:00:00 2001 From: titanism <101466223+titanism@users.noreply.github.com> Date: Sat, 7 Dec 2024 01:05:29 -0600 Subject: [PATCH] fix: support blank MAIL FROM --- helpers/on-mail-from.js | 53 +++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/helpers/on-mail-from.js b/helpers/on-mail-from.js index 7c517a2830..6cb4b1d601 100644 --- a/helpers/on-mail-from.js +++ b/helpers/on-mail-from.js @@ -19,33 +19,34 @@ function onMailFrom(address, session, fn) { if (this.isClosing) return setImmediate(() => fn(new ServerShutdownError())); // validate email address - if ( - typeof address === 'object' && - isSANB(address.address) && - !isEmail(address.address, { ignore_max_length: true }) - ) - return setImmediate(() => - fn( - refineAndLogError( - new SMTPError('Address is not a valid RFC 5321 email address', { - responseCode: 553, - ignoreHook: true - }), - session, - false, - this + if (typeof address === 'object' && isSANB(address.address)) { + if (!isEmail(address.address, { ignore_max_length: true })) + return setImmediate(() => + fn( + refineAndLogError( + new SMTPError('Address is not a valid RFC 5321 email address', { + responseCode: 553, + ignoreHook: true + }), + session, + false, + this + ) ) - ) - ); - - // - // check if it was invalid SRS (pass `shouldThrow` as `true`) - // - try { - if (parseHostFromDomainOrAddress(address.address) === env.WEB_HOST) - checkSRS(address.address, true, true); - } catch (err) { - return setImmediate(() => fn(refineAndLogError(err, session, false, this))); + ); + + // + // check if it was invalid SRS (pass `shouldThrow` as `true`) + // (we need to support blank MAIL FROM, e.g. "MAIL FROM: <>") + // + try { + if (parseHostFromDomainOrAddress(address.address) === env.WEB_HOST) + checkSRS(address.address, true, true); + } catch (err) { + return setImmediate(() => + fn(refineAndLogError(err, session, false, this)) + ); + } } setImmediate(fn);