From 1751509739a6e6aaa986759a315b937e832c94d3 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Fri, 11 Sep 2020 00:12:34 +0300 Subject: [PATCH] melib/imap: prevent false IDLE wakeups Prevent IDLE loop waking up when receiving continuation "+ " lines --- melib/src/backends/imap/watch.rs | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/melib/src/backends/imap/watch.rs b/melib/src/backends/imap/watch.rs index fa2bd9f4..1a28e8b0 100644 --- a/melib/src/backends/imap/watch.rs +++ b/melib/src/backends/imap/watch.rs @@ -145,14 +145,40 @@ pub async fn idle(kit: ImapWatchKit) -> Result<()> { } watch = now; } + if to_str!(&line) + .split_rn() + .filter(|l| { + !l.starts_with("+ ") + && !l.starts_with("* ok") + && !l.starts_with("* ok") + && !l.starts_with("* Ok") + && !l.starts_with("* OK") + }) + .count() + == 0 { - let mut conn = timeout(Duration::from_secs(10), main_conn.lock()).await?; - conn.examine_mailbox(mailbox_hash, &mut response, false) + continue; + } + { + blockn.conn.send_raw(b"DONE").await?; + blockn + .conn + .read_response(&mut response, RequiredResponses::empty()) .await?; for l in to_str!(&line).split_rn() { debug!("process_untagged {:?}", &l); - conn.process_untagged(l).await?; + if l.starts_with("+ ") + || l.starts_with("* ok") + || l.starts_with("* ok") + || l.starts_with("* Ok") + || l.starts_with("* OK") + { + debug!("ignore continuation mark"); + continue; + } + blockn.conn.process_untagged(l).await?; } + blockn.conn.send_command(b"IDLE").await?; } *uid_store.is_online.lock().unwrap() = (Instant::now(), Ok(())); }