Skip to content

Commit

Permalink
fix: support blank MAIL FROM
Browse files Browse the repository at this point in the history
  • Loading branch information
titanism committed Dec 7, 2024
1 parent e94b41e commit b6b3476
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions helpers/on-mail-from.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b6b3476

Please sign in to comment.