From 64e5d4af4f07b2debd0899b32a2a2bed2ae3ca09 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Tue, 23 Jun 2020 19:23:06 +0300 Subject: [PATCH] imap/untagged.rs: properly queue refresh events RefreshEvents where added in self.uid_store.refresh_events queue though ImapConnection has a method add_refresh_event() that drains the queue if possible --- melib/src/backends/imap/untagged.rs | 53 ++++++++++++----------------- 1 file changed, 21 insertions(+), 32 deletions(-) diff --git a/melib/src/backends/imap/untagged.rs b/melib/src/backends/imap/untagged.rs index ae74697a..08cf752c 100644 --- a/melib/src/backends/imap/untagged.rs +++ b/melib/src/backends/imap/untagged.rs @@ -42,7 +42,7 @@ impl ImapConnection { Err(err.clone()), ); debug!("failure: {}", err.to_string()); - self.uid_store.refresh_events.lock().unwrap().push(RefreshEvent { + self.add_refresh_event(RefreshEvent { account_hash: self.uid_store.account_hash, mailbox_hash: $mailbox_hash, kind: RefreshEventKind::Failure(err.clone()), @@ -167,13 +167,11 @@ impl ImapConnection { if !env.is_seen() { *mailbox.unseen.lock().unwrap() += 1; } - self.uid_store.refresh_events.lock().unwrap().push( - RefreshEvent { - account_hash: self.uid_store.account_hash, - mailbox_hash, - kind: Create(Box::new(env)), - }, - ); + self.add_refresh_event(RefreshEvent { + account_hash: self.uid_store.account_hash, + mailbox_hash, + kind: Create(Box::new(env)), + }); } } } @@ -258,13 +256,11 @@ impl ImapConnection { *mailbox.unseen.lock().unwrap() += 1; } - self.uid_store.refresh_events.lock().unwrap().push( - RefreshEvent { - account_hash: self.uid_store.account_hash, - mailbox_hash, - kind: Create(Box::new(env)), - }, - ); + self.add_refresh_event(RefreshEvent { + account_hash: self.uid_store.account_hash, + mailbox_hash, + kind: Create(Box::new(env)), + }); } } } @@ -307,23 +303,16 @@ impl ImapConnection { { Ok(mut v) => { if let Some(uid) = v.pop() { - if let Some(env_hash) = self - .uid_store - .uid_index - .lock() - .unwrap() - .get(&(mailbox_hash, uid)) - { - self.uid_store - .refresh_events - .lock() - .unwrap() - .push(RefreshEvent { - account_hash: self.uid_store.account_hash, - mailbox_hash, - kind: NewFlags(*env_hash, flags), - }); - } + let lck = self.uid_store.uid_index.lock().unwrap(); + let env_hash = lck.get(&(mailbox_hash, uid)).map(|&h| h); + drop(lck); + if let Some(env_hash) = env_hash { + self.add_refresh_event(RefreshEvent { + account_hash: self.uid_store.account_hash, + mailbox_hash, + kind: NewFlags(env_hash, flags), + }); + }; } } Err(e) => {