Skip to content

Commit

Permalink
fix: Delete received outgoing messages from SMTP queue (#5115)
Browse files Browse the repository at this point in the history
Some SMTP servers are running slow before-queue filters, most commonly Postfix with `rspamd` filter
which is implemented as a [before-queue Milter](https://www.postfix.org/MILTER_README.html). Some of
`rspamd` plugin filters are slow on large mails.

We previously had problems with timing out during waiting for SMTP response:
#1383. This is largely fixed by
async-email/async-smtp#29 and currently we have 60-second timeout just for
reading a response but apparently it is not sufficient -- maybe connection gets killed by NAT while
we are waiting for response or `rspamd` takes more than 60 seconds for large messages.

As a result a message is resent multiple times and eventually fails with "too many retries" while
multiple BCC-self messages are received.

We should remove the message from the SMTP queue as soon as we receive it via IMAP as it is clear
the message was sent even if we did not manage to get actual SMTP server response.
  • Loading branch information
iequidoo committed Dec 21, 2023
1 parent b83bd26 commit a27e84a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/receive_imf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,15 @@ pub(crate) async fn receive_imf_inner(
context,
"Receiving message {rfc724_mid_orig:?}, seen={seen}...",
);
let incoming = !context.is_self_addr(&mime_parser.from.addr).await?;

// For the case if we missed a successful SMTP response.
if !incoming {
context
.sql
.execute("DELETE FROM smtp WHERE rfc724_mid=?", (rfc724_mid_orig,))
.await?;
}

// check, if the mail is already in our database.
// make sure, this check is done eg. before securejoin-processing.
Expand Down Expand Up @@ -251,8 +260,6 @@ pub(crate) async fn receive_imf_inner(
}
};

let incoming = from_id != ContactId::SELF;

let to_ids = add_or_lookup_contacts_by_address_list(
context,
&mime_parser.recipients,
Expand Down

0 comments on commit a27e84a

Please sign in to comment.