diff --git a/src/message.rs b/src/message.rs index d72344465..594fab07e 100644 --- a/src/message.rs +++ b/src/message.rs @@ -114,23 +114,15 @@ WHERE id=?; /// Deletes a message, corresponding MDNs and unsent SMTP messages from the database. pub(crate) async fn delete_from_db(self, context: &Context) -> Result<()> { - // We don't use transactions yet, so remove MDNs first to make - // sure they are not left while the message is deleted. context .sql - .execute("DELETE FROM smtp WHERE msg_id=?", (self,)) - .await?; - context - .sql - .execute("DELETE FROM msgs_mdns WHERE msg_id=?;", (self,)) - .await?; - context - .sql - .execute("DELETE FROM msgs_status_updates WHERE msg_id=?;", (self,)) - .await?; - context - .sql - .execute("DELETE FROM msgs WHERE id=?;", (self,)) + .transaction(move |transaction| { + transaction.execute("DELETE FROM smtp WHERE msg_id=?", (self,))?; + transaction.execute("DELETE FROM msgs_mdns WHERE msg_id=?", (self,))?; + transaction.execute("DELETE FROM msgs_status_updates WHERE msg_id=?", (self,))?; + transaction.execute("DELETE FROM msgs WHERE id=?", (self,))?; + Ok(()) + }) .await?; Ok(()) }