diff --git a/app/models/emails.js b/app/models/emails.js index 8bbb320233..220ab931f6 100644 --- a/app/models/emails.js +++ b/app/models/emails.js @@ -373,7 +373,7 @@ Emails.pre('validate', function (next) { if (!Array.isArray(this.rejectedErrors)) this.rejectedErrors = []; // ensure accepted is lowercased and unique - this.accepted = _.uniq(this.accepted).sort(); + this.accepted = _.uniq(this.accepted.map((a) => a.toLowerCase())).sort(); // ensure that all `rejectedErrors` are Objects not Errors this.rejectedErrors = this.rejectedErrors.map((err) => { @@ -397,7 +397,7 @@ Emails.pre('validate', function (next) { // filter out any `accepted` from `rejectedErrors` this.rejectedErrors = this.rejectedErrors.filter( - (err) => !this.accepted.includes(err.recipient) + (err) => !this.accepted.includes(err.recipient.toLowerCase()) ); // ensure that `rejectedErrors` are unique (by most recent/last added) diff --git a/helpers/process-email.js b/helpers/process-email.js index 99be2d1de7..ebee89346e 100644 --- a/helpers/process-email.js +++ b/helpers/process-email.js @@ -699,7 +699,6 @@ async function processEmail({ email, port = 25, resolver, client }) { // // accepted [String] - // rejected [String] // rejectedErrors [Object] (an Array of Objects which were parsed Errors via `parse-err`) // // - [x] filter out recipients already accepted @@ -714,7 +713,10 @@ async function processEmail({ email, port = 25, resolver, client }) { const map = new Map(); for (const to of envelope.to) { // filter out recipients already accepted - if (Array.isArray(email.accepted) && email.accepted.includes(to)) + if ( + Array.isArray(email.accepted) && + email.accepted.includes(to.toLowerCase()) + ) continue; // filter out recipients that have 5xx errors and were already rejected @@ -746,7 +748,11 @@ async function processEmail({ email, port = 25, resolver, client }) { // is already accepted it will mark the email as being sent // if ( - email.accepted.sort().join(',') === email.envelope.to.sort().join(',') + email.accepted.sort().join(',') === + email.envelope.to + .map((s) => s.toLowerCase()) + .sort() + .join(',') ) { await Emails.findByIdAndUpdate(email._id, { $set: { @@ -797,7 +803,7 @@ async function processEmail({ email, port = 25, resolver, client }) { addresses, // eslint-disable-next-line complexity async (address) => { - const to = [address]; + const to = [address.toLowerCase()]; const target = address.split('@')[1]; // // check if exists for domain being blocked