From 22e5bf85715d2911da456c4cc84821726eff9c2d Mon Sep 17 00:00:00 2001 From: link2xt Date: Thu, 3 Oct 2024 17:01:33 +0000 Subject: [PATCH] fix(download_msg): do not fail if the message does not exist anymore Without this fix IMAP loop may get stuck trying to download non-existing message over and over like this: ``` src/imap.rs:372: Logging into IMAP server with LOGIN. src/imap.rs:388: Successfully logged into IMAP server src/scheduler.rs:361: Failed to download message Msg#3467: Message Msg#3467 does not exist. src/scheduler.rs:418: Failed fetch_idle: Failed to download messages: Message Msg#3467 does not exist ``` The whole download operation fails due to attempt to set the state of non-existing message to "failed". Now download of the message will "succeed" if the message does not exist and we don't try to set its state. --- src/download.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/download.rs b/src/download.rs index eb763eed8..849de01de 100644 --- a/src/download.rs +++ b/src/download.rs @@ -135,7 +135,17 @@ pub(crate) async fn download_msg( msg_id: MsgId, session: &mut Session, ) -> Result<()> { - let msg = Message::load_from_db(context, msg_id).await?; + let Some(msg) = Message::load_from_db_optional(context, msg_id).await? else { + // If partially downloaded message was already deleted + // we do not know its Message-ID anymore + // so cannot download it. + // + // Probably the message expired due to `delete_device_after` + // setting or was otherwise removed from the device, + // so we don't want it to reappear anyway. + return Ok(()); + }; + let row = context .sql .query_row_optional(