diff --git a/src/receive_imf.rs b/src/receive_imf.rs index f7ba9bc2f..4aadc0f1e 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -45,6 +45,7 @@ use crate::securejoin::{ self, get_secure_join_step, handle_securejoin_handshake, observe_securejoin_on_other_device, }; use crate::simplify; +use crate::smtp::msg_has_pending_smtp_job; use crate::stats::STATISTICS_BOT_EMAIL; use crate::stock_str; use crate::sync::Sync::*; @@ -582,14 +583,7 @@ pub(crate) async fn receive_imf_inner( (rfc724_mid_orig, &self_addr), ) .await?; - if !context - .sql - .exists( - "SELECT COUNT(*) FROM smtp WHERE rfc724_mid=?", - (rfc724_mid_orig,), - ) - .await? - { + if !msg_has_pending_smtp_job(context, msg_id).await? { msg_id.set_delivered(context).await?; } return Ok(None); diff --git a/src/smtp.rs b/src/smtp.rs index aca1f46ea..02f277410 100644 --- a/src/smtp.rs +++ b/src/smtp.rs @@ -465,11 +465,7 @@ pub(crate) async fn send_msg_to_smtp( match status { SendResult::Retry => Err(format_err!("Retry")), SendResult::Success => { - if !context - .sql - .exists("SELECT COUNT(*) FROM smtp WHERE msg_id=?", (msg_id,)) - .await? - { + if !msg_has_pending_smtp_job(context, msg_id).await? { msg_id.set_delivered(context).await?; } Ok(()) @@ -478,6 +474,16 @@ pub(crate) async fn send_msg_to_smtp( } } +pub(crate) async fn msg_has_pending_smtp_job( + context: &Context, + msg_id: MsgId, +) -> Result { + context + .sql + .exists("SELECT COUNT(*) FROM smtp WHERE msg_id=?", (msg_id,)) + .await +} + /// Attempts to send queued MDNs. async fn send_mdns(context: &Context, connection: &mut Smtp) -> Result<()> { loop { diff --git a/src/test_utils.rs b/src/test_utils.rs index 8491dda86..ea1434a59 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -40,6 +40,7 @@ use crate::message::{Message, MessageState, MsgId, update_msg_state}; use crate::mimeparser::{MimeMessage, SystemMessage}; use crate::receive_imf::receive_imf; use crate::securejoin::{get_securejoin_qr, join_securejoin}; +use crate::smtp::msg_has_pending_smtp_job; use crate::stock_str::StockStrings; use crate::tools::time; @@ -658,10 +659,7 @@ impl TestContext { .execute("DELETE FROM smtp WHERE id=?;", (rowid,)) .await .expect("failed to remove job"); - if !self - .ctx - .sql - .exists("SELECT COUNT(*) FROM smtp WHERE msg_id=?", (msg_id,)) + if !msg_has_pending_smtp_job(self, msg_id) .await .expect("Failed to check for more jobs") {