From 0034f195e3e948c193c3e851a4b660a6b78f34ba Mon Sep 17 00:00:00 2001 From: Zisu Andrei Date: Thu, 24 Dec 2020 11:46:15 +0000 Subject: [PATCH] melib/imap: Lazy evaluate idle capability With the eager evaluation, you run the risk of checking the capabilities store before any connection to the server may have been opened. Therefore, the capabilities uid_store will be empty and it will fall back to poll_with_examine even if the server might have support for idle. --- melib/src/backends/imap.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/melib/src/backends/imap.rs b/melib/src/backends/imap.rs index 8a8d8b4b..061c9b00 100644 --- a/melib/src/backends/imap.rs +++ b/melib/src/backends/imap.rs @@ -453,20 +453,20 @@ impl MailBackend for ImapType { let server_conf = self.server_conf.clone(); let main_conn = self.connection.clone(); let uid_store = self.uid_store.clone(); - let has_idle: bool = match self.server_conf.protocol { - ImapProtocol::IMAP { - extension_use: ImapExtensionUse { idle, .. }, - } => { - idle && uid_store - .capabilities - .lock() - .unwrap() - .iter() - .any(|cap| cap.eq_ignore_ascii_case(b"IDLE")) - } - _ => false, - }; Ok(Box::pin(async move { + let has_idle: bool = match server_conf.protocol { + ImapProtocol::IMAP { + extension_use: ImapExtensionUse { idle, .. }, + } => { + idle && uid_store + .capabilities + .lock() + .unwrap() + .iter() + .any(|cap| cap.eq_ignore_ascii_case(b"IDLE")) + } + _ => false, + }; while let Err(err) = if has_idle { idle(ImapWatchKit { conn: ImapConnection::new_connection(&server_conf, uid_store.clone()),