From d708f386a1ef700284e1676f1b433758f01ce34b Mon Sep 17 00:00:00 2001 From: link2xt Date: Sun, 13 Feb 2022 08:58:45 +0000 Subject: [PATCH] smtp: set message state to failed when retry limit is exceeded --- CHANGELOG.md | 1 + src/smtp.rs | 26 +++++++++++++++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31519b11b..c29bce7dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - Fix a bug where messages in the Spam folder created contact requests #3015 - Fix a bug where drafts disappeared after some days #3067 - do not retry message sending infinitely in case of permanent SMTP failure #3070 +- set message state to failed when retry limit is exceeded #3072 ## 1.75.0 diff --git a/src/smtp.rs b/src/smtp.rs index 19442cbfa..925da08ef 100644 --- a/src/smtp.rs +++ b/src/smtp.rs @@ -356,19 +356,35 @@ pub(crate) async fn send_msg_to_smtp( .await .context("failed to update retries count")?; - let (body, recipients, msg_id) = context + let (body, recipients, msg_id, retries) = context .sql .query_row( - "SELECT mime, recipients, msg_id FROM smtp WHERE id=?", + "SELECT mime, recipients, msg_id, retries FROM smtp WHERE id=?", paramsv![rowid], |row| { let mime: String = row.get(0)?; let recipients: String = row.get(1)?; let msg_id: MsgId = row.get(2)?; - Ok((mime, recipients, msg_id)) + let retries: i64 = row.get(3)?; + Ok((mime, recipients, msg_id, retries)) }, ) .await?; + if retries > 6 { + message::set_msg_failed( + context, + msg_id, + Some("Number of retries exceeded the limit."), + ) + .await; + context + .sql + .execute("DELETE FROM smtp WHERE id=?", paramsv![rowid]) + .await + .context("failed to remove message with exceeded retry limit from smtp table")?; + bail!("Number of retries exceeded the limit"); + } + let recipients_list = recipients .split(' ') .filter_map( @@ -456,10 +472,6 @@ pub(crate) async fn send_smtp_messages( connection: &mut Smtp, ) -> anyhow::Result<()> { context.send_sync_msg().await?; // Add sync message to the end of the queue if needed. - context - .sql - .execute("DELETE FROM smtp WHERE retries > 5", paramsv![]) - .await?; let rowids = context .sql .query_map(