diff --git a/src/receive_imf.rs b/src/receive_imf.rs index ccb30d73e3..7d2c463958 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -98,6 +98,22 @@ pub async fn receive_imf( receive_imf_inner(context, &rfc724_mid, imf_raw, seen, None, false).await } +/// Inserts a tombstone into `msgs` table +/// to prevent downloading the same message in the future. +/// +/// Returns tombstone database row ID. +async fn insert_tombstone(context: &Context, rfc724_mid: &str) -> Result { + let row_id = context + .sql + .insert( + "INSERT INTO msgs(rfc724_mid, chat_id) VALUES (?,?)", + (rfc724_mid, DC_CHAT_ID_TRASH), + ) + .await?; + let msg_id = MsgId::new(u32::try_from(row_id)?); + Ok(msg_id) +} + /// Receive a message and add it to the database. /// /// Returns an error on database failure or if the message is broken, @@ -137,14 +153,7 @@ pub(crate) async fn receive_imf_inner( return Ok(None); } - let row_id = context - .sql - .insert( - "INSERT INTO msgs(rfc724_mid, chat_id) VALUES (?,?)", - (rfc724_mid, DC_CHAT_ID_TRASH), - ) - .await?; - let msg_ids = vec![MsgId::new(u32::try_from(row_id)?)]; + let msg_ids = vec![insert_tombstone(context, rfc724_mid).await?]; return Ok(Some(ReceivedMsg { chat_id: DC_CHAT_ID_TRASH,