From e86b17096975951e6c532e27b605de7715aeada6 Mon Sep 17 00:00:00 2001 From: Hocuri Date: Mon, 23 Mar 2026 18:29:49 +0100 Subject: [PATCH] fix: Don't fall into infinite loop if the folder is missing (#8021) Previously, if the mvbox_move folder is missing, then core will loop infinitely, because `new_mail` is never set to false. The fix is to first set `new_mail` to false, then return if the folder is missing. This is the bug @hpk42 experienced when commenting in https://github.com/chatmail/core/issues/7989 --------- Co-authored-by: holger krekel --- src/imap.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/imap.rs b/src/imap.rs index 6492cae56..35d20d869 100644 --- a/src/imap.rs +++ b/src/imap.rs @@ -561,16 +561,19 @@ impl Imap { .select_with_uidvalidity(context, folder) .await .with_context(|| format!("Failed to select folder {folder:?}"))?; - if !folder_exists { - return Ok(false); - } if !session.new_mail { info!(context, "No new emails in folder {folder:?}."); return Ok(false); } + // Make sure not to return before setting new_mail to false + // Otherwise, we will skip IDLE and go into an infinite loop session.new_mail = false; + if !folder_exists { + return Ok(false); + } + let mut read_cnt = 0; loop { let (n, fetch_more) = self @@ -1237,6 +1240,7 @@ impl Session { // have been modified while our request was in progress. // We may or may not have these new flags as a part of the response, // so better skip next IDLE and do another round of flag synchronization. + info!(context, "Got unsolicited fetch, will skip idle"); self.new_mail = true; }