Skip to content

Commit

Permalink
fix: fixed inbox flood issue on outbound mail retries due to case sen…
Browse files Browse the repository at this point in the history
…sitivity
  • Loading branch information
titanism committed Nov 26, 2024
1 parent 97b5638 commit 8228996
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/models/emails.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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)
Expand Down
14 changes: 10 additions & 4 deletions helpers/process-email.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8228996

Please sign in to comment.