diff --git a/debian/changelog b/debian/changelog index 861260bfc..c19baa4a7 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,11 @@ +dovecot (1:2.3.21+dfsg1-3+chatmail3) UNRELEASED; urgency=medium + + * lmtp: retry delivery from the raw message when the first saved mail + was expunged before it could be copied for the remaining recipients + (chatmail/relay#1064). + + -- mrgluek Fri, 23 Oct 2026 08:25:47 +0100 + dovecot (1:2.3.21+dfsg1-3+chatmail2) UNRELEASED; urgency=medium * Backport 14 Debian security fixes from bookworm-security (2.3.19.1 diff --git a/debian/patches/lmtp-retry-expunged-first-saved-mail.patch b/debian/patches/lmtp-retry-expunged-first-saved-mail.patch new file mode 100644 index 000000000..375dd864c --- /dev/null +++ b/debian/patches/lmtp-retry-expunged-first-saved-mail.patch @@ -0,0 +1,74 @@ +Description: lmtp: retry delivery from raw mail if first saved mail was expunged + For multi-recipient deliveries LMTP saves the message for the first recipient + and then copies that saved mail for all remaining recipients, so that maildir + files can be hardlinked. If a client of the first recipient expunges the + message before LMTP is done (Delta Chat deletes messages right after fetching + them, and IDLE notifications are instant with remove-500ms-idle-debounce.patch), + every remaining recipient fails with + "451 4.2.0 Message was expunged (received-date)" and Postfix retries them later. + . + When a copy from first_saved_mail fails because it was expunged, retry the + delivery once from the raw message received over LMTP and use the raw message + for the remaining recipients. +Author: mrgluek +Bug: https://github.com/chatmail/relay/issues/1064 +Forwarded: no +Last-Update: 2026-10-22 +--- +diff --git a/src/lmtp/lmtp-local.c b/src/lmtp/lmtp-local.c +index c20b6194..69b6cb78 100644 +--- a/src/lmtp/lmtp-local.c ++++ b/src/lmtp/lmtp-local.c +@@ -532,6 +532,12 @@ lmtp_local_default_do_deliver(struct lmtp_local *local, + return 0; + } + ++ if (error_code == MAIL_DELIVER_ERROR_TEMPORARY && ++ dctx->src_mail != local->raw_mail && dctx->src_mail->expunged) { ++ /* Don't reply yet, the caller retries from raw_mail. */ ++ return -2; ++ } ++ + switch (error_code) { + case MAIL_DELIVER_ERROR_NONE: + i_unreached(); +@@ -609,6 +615,20 @@ int lmtp_local_default_deliver(struct client *client, + mail_deliver_init(&dctx, &dinput); + ret = lmtp_local_default_do_deliver(local, llrcpt, lldctx, &dctx); + mail_deliver_deinit(&dctx); ++ if (ret == -2) { ++ /* The first recipient's copy was expunged (e.g. by a client ++ that deletes messages right after fetching them) before it ++ could be copied for this recipient. Save it again from the ++ raw message received over LMTP. */ ++ e_info(event, "Source mail was expunged, " ++ "retrying delivery from the raw message"); ++ lldctx->src_mail = local->raw_mail; ++ dinput.src_mail = local->raw_mail; ++ mail_deliver_init(&dctx, &dinput); ++ ret = lmtp_local_default_do_deliver(local, llrcpt, lldctx, ++ &dctx); ++ mail_deliver_deinit(&dctx); ++ } + event_unref(&event); + + return ret; +@@ -646,10 +666,17 @@ lmtp_local_deliver_to_rcpts(struct lmtp_local *local, + trans, llrcpt, src_mail, session); + client_update_data_state(client, NULL); + ++ /* first_saved_mail was expunged, the delivery fell back to ++ raw_mail. Use raw_mail for the remaining recipients too. */ ++ if (src_mail == local->first_saved_mail && ++ src_mail->expunged) ++ src_mail = local->raw_mail; ++ + /* succeeded and mail_user is not saved in first_saved_mail */ + if ((ret == 0 && + (local->first_saved_mail == NULL || +- local->first_saved_mail == src_mail)) || ++ local->first_saved_mail == src_mail || ++ first_uid != (uid_t)-1)) || + /* failed. try the next one. */ + (ret != 0 && local->rcpt_user != NULL)) { + if (i == (count - 1)) diff --git a/debian/patches/series b/debian/patches/series index 96704a8e1..6ed55050f 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -51,3 +51,4 @@ CVE-2026-27857-3.patch CVE-2026-27857-4.patch CVE-2026-27857-5.patch CVE-2026-42006.patch +lmtp-retry-expunged-first-saved-mail.patch