From ca9d4fde588c4c8b58560a638674eb06e61b1098 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Tue, 9 Jun 2020 15:38:13 +0300 Subject: [PATCH] Discard EnvelopeRename event if envelope is missing from Collection --- melib/src/collection.rs | 7 ++++--- src/conf/accounts.rs | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/melib/src/collection.rs b/melib/src/collection.rs index 308412970..a677c5de2 100644 --- a/melib/src/collection.rs +++ b/melib/src/collection.rs @@ -147,9 +147,9 @@ impl Collection { old_hash: EnvelopeHash, new_hash: EnvelopeHash, mailbox_hash: MailboxHash, - ) { + ) -> bool { if !self.envelopes.write().unwrap().contains_key(&old_hash) { - return; + return false; } let mut envelope = self.envelopes.write().unwrap().remove(&old_hash).unwrap(); self.mailboxes.entry(mailbox_hash).and_modify(|m| { @@ -168,7 +168,7 @@ impl Collection { .update_envelope(&self.envelopes, old_hash, new_hash) .is_ok() { - return; + return true; } } /* envelope is not in threads, so insert it */ @@ -184,6 +184,7 @@ impl Collection { .ok() .take(); } + true } /// Merge new mailbox to collection and update threads. diff --git a/src/conf/accounts.rs b/src/conf/accounts.rs index 6da91cc14..a5b76053d 100644 --- a/src/conf/accounts.rs +++ b/src/conf/accounts.rs @@ -535,7 +535,9 @@ impl Account { } RefreshEventKind::Rename(old_hash, new_hash) => { debug!("rename {} to {}", old_hash, new_hash); - self.collection.rename(old_hash, new_hash, mailbox_hash); + if !self.collection.rename(old_hash, new_hash, mailbox_hash) { + return Some(EnvelopeRename(old_hash, new_hash)); + } #[cfg(feature = "sqlite3")] { let envelopes = self.collection.envelopes.read();