Skip to content

Commit 6a8ea8a

Browse files
committed
fix: set message download state to Failure on IMAP errors
Previously the message was removed from `download` table, but message bubble was stuck in InProgress state. Now download state is updated by the caller, so it cannot be accidentally skipped.
1 parent e0e56cd commit 6a8ea8a

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

src/download.rs

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -146,29 +146,19 @@ pub(crate) async fn download_msg(context: &Context, msg_id: MsgId, imap: &mut Im
146146
)
147147
.await?;
148148

149-
if let Some((server_uid, server_folder)) = row {
150-
match imap
151-
.fetch_single_msg(context, &server_folder, server_uid, msg.rfc724_mid.clone())
152-
.await
153-
{
154-
ImapActionResult::RetryLater | ImapActionResult::Failed => {
155-
msg.id
156-
.update_download_state(context, DownloadState::Failure)
157-
.await?;
158-
Err(anyhow!("Call download_full() again to try over."))
159-
}
160-
ImapActionResult::Success => {
161-
// update_download_state() not needed as receive_imf() already
162-
// set the state and emitted the event.
163-
Ok(())
164-
}
165-
}
166-
} else {
149+
let Some((server_uid, server_folder)) = row else {
167150
// No IMAP record found, we don't know the UID and folder.
168-
msg.id
169-
.update_download_state(context, DownloadState::Failure)
170-
.await?;
171-
Err(anyhow!("Call download_full() again to try over."))
151+
return Err(anyhow!("Call download_full() again to try over."));
152+
};
153+
154+
match imap
155+
.fetch_single_msg(context, &server_folder, server_uid, msg.rfc724_mid.clone())
156+
.await
157+
{
158+
ImapActionResult::RetryLater | ImapActionResult::Failed => {
159+
Err(anyhow!("Call download_full() again to try over."))
160+
}
161+
ImapActionResult::Success => Ok(()),
172162
}
173163
}
174164

src/scheduler.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use self::connectivity::ConnectivityStore;
1515
use crate::config::Config;
1616
use crate::contact::{ContactId, RecentlySeenLoop};
1717
use crate::context::Context;
18-
use crate::download::download_msg;
18+
use crate::download::{download_msg, DownloadState};
1919
use crate::ephemeral::{self, delete_expired_imap_messages};
2020
use crate::events::EventType;
2121
use crate::imap::{FolderMeaning, Imap};
@@ -350,6 +350,16 @@ async fn download_msgs(context: &Context, imap: &mut Imap) -> Result<()> {
350350
for msg_id in msg_ids {
351351
if let Err(err) = download_msg(context, msg_id, imap).await {
352352
warn!(context, "Failed to download message {msg_id}: {:#}.", err);
353+
354+
// Update download state to failure
355+
// so it can be retried.
356+
//
357+
// On success update_download_state() is not needed
358+
// as receive_imf() already
359+
// set the state and emitted the event.
360+
msg_id
361+
.update_download_state(context, DownloadState::Failure)
362+
.await?;
353363
}
354364
context
355365
.sql

0 commit comments

Comments
 (0)