Skip to content

Commit

Permalink
fix: fixed SRS rewrite for @forwardemail.net messages (it should not …
Browse files Browse the repository at this point in the history
…rewrite)
  • Loading branch information
titanism committed Jan 8, 2025
1 parent 449fcd5 commit 98243ef
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
31 changes: 26 additions & 5 deletions helpers/on-data-mx.js
Original file line number Diff line number Diff line change
Expand Up @@ -1100,12 +1100,33 @@ async function forward(recipient, headers, session, body) {
};
}

//
// TODO: check DSN issues (e.g. specify `recipient` field)
// <https://www.nodemailer.com/smtp/dsn/>
//
// > The DSN MUST be addressed (in both the message header and the
// transport envelope) to the return address from the transport envelope
// which accompanied the original message for which the DSN was
// generated. (For a message that arrived via SMTP, the envelope return
// address appears in the MAIL FROM command.)
//
// <https://datatracker.ietf.org/doc/html/rfc3464#:~:text=The%20DSN%20MUST%20be,the%20MAIL%20FROM%20command.)>
//
let from;
if (isSANB(session.envelope.mailFrom.address))
from = srs.forward(
checkSRS(session.envelope.mailFrom.address),
env.WEB_HOST
);
if (isSANB(session.envelope.mailFrom.address)) {
if (
session.envelope.mailFrom.address
.toLowerCase()
.endsWith(`@${env.WEB_HOST}`)
) {
from = session.envelope.mailFrom.address;
} else {
from = srs.forward(
checkSRS(session.envelope.mailFrom.address),
env.WEB_HOST
);
}
}

// NOTE: only webhooks use array for `to`, send email uses a string (we convert it)
if (!_.isArray(recipient.to) || recipient.to.length > 1)
Expand Down
4 changes: 3 additions & 1 deletion helpers/process-email.js
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,9 @@ async function processEmail({ email, port = 25, resolver, client }) {
// rewrite envelope From with SRS using CNAME
// (custom Return-Path but we don't add this header since IMAP does)
const envelope = {
from: srs.forward(email.envelope.from, srsDomain),
from: email.envelope.from.toLowerCase().endsWith(`@${env.WEB_HOST}`)
? email.envelope.from
: srs.forward(email.envelope.from, srsDomain),
to: [...email.envelope.to]
};

Expand Down

0 comments on commit 98243ef

Please sign in to comment.