Skip to content

Commit a27e84a

Browse files
committed
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: #1383. This is largely fixed by chatmail/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.
1 parent b83bd26 commit a27e84a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/receive_imf.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,15 @@ pub(crate) async fn receive_imf_inner(
191191
context,
192192
"Receiving message {rfc724_mid_orig:?}, seen={seen}...",
193193
);
194+
let incoming = !context.is_self_addr(&mime_parser.from.addr).await?;
195+
196+
// For the case if we missed a successful SMTP response.
197+
if !incoming {
198+
context
199+
.sql
200+
.execute("DELETE FROM smtp WHERE rfc724_mid=?", (rfc724_mid_orig,))
201+
.await?;
202+
}
194203

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

254-
let incoming = from_id != ContactId::SELF;
255-
256263
let to_ids = add_or_lookup_contacts_by_address_list(
257264
context,
258265
&mime_parser.recipients,

0 commit comments

Comments
 (0)