fix: Delete received outgoing messages from SMTP queue (#5115)

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:
https://github.com/deltachat/deltachat-core-rust/issues/1383. This is largely fixed by
https://github.com/async-email/async-smtp/pull/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.
This commit is contained in:
iequidoo
2023-12-21 01:31:56 -03:00
committed by iequidoo
parent b83bd26325
commit a27e84ad89

View File

@@ -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.
@@ -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,