diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2020-10-13 21:18:26 +0300 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2020-10-13 21:18:26 +0300 |
commit | 2944fc992bf4b87821129a2275fc67f35093368b (patch) | |
tree | c4beb3d956b420ba322f1e3a30f855b843942609 /melib/src/backends | |
parent | 535d04f4f0a5fb48a20551eedca555445c5b8e94 (diff) |
melib/imap/untagged: handle EXPUNGE if our MSNs invalid
Diffstat (limited to 'melib/src/backends')
-rw-r--r-- | melib/src/backends/imap/untagged.rs | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/melib/src/backends/imap/untagged.rs b/melib/src/backends/imap/untagged.rs index 60b29cc2..a64a0c1c 100644 --- a/melib/src/backends/imap/untagged.rs +++ b/melib/src/backends/imap/untagged.rs @@ -78,7 +78,7 @@ impl ImapConnection { .lock() .unwrap() .get(&mailbox_hash) - .map(|i| i.len() < n.try_into().unwrap()) + .map(|i| i.len() < TryInto::<usize>::try_into(n).unwrap()) .unwrap_or(true) { debug!( @@ -86,6 +86,64 @@ impl ImapConnection { n, self.uid_store.msn_index.lock().unwrap().get(&mailbox_hash) ); + self.send_command("UID SEARCH 1:*".as_bytes()).await?; + self.read_response(&mut response, RequiredResponses::SEARCH) + .await?; + let results = super::protocol_parser::search_results(&response)? + .1 + .into_iter() + .collect::<std::collections::BTreeSet<UID>>(); + { + let mut lck = self.uid_store.msn_index.lock().unwrap(); + let msn_index = lck.entry(mailbox_hash).or_default(); + msn_index.clear(); + msn_index.extend( + super::protocol_parser::search_results(&response)? + .1 + .into_iter(), + ); + } + let mut events = vec![]; + for (deleted_uid, deleted_hash) in self + .uid_store + .uid_index + .lock() + .unwrap() + .iter() + .filter(|((mailbox_hash_, u), _)| { + *mailbox_hash_ == mailbox_hash && !results.contains(u) + }) + .map(|((_, uid), hash)| (*uid, *hash)) + .collect::<Vec<(UID, crate::email::EnvelopeHash)>>() + { + mailbox.exists.lock().unwrap().remove(deleted_hash); + mailbox.unseen.lock().unwrap().remove(deleted_hash); + self.uid_store + .uid_index + .lock() + .unwrap() + .remove(&(mailbox_hash, deleted_uid)); + self.uid_store + .hash_index + .lock() + .unwrap() + .remove(&deleted_hash); + events.push(( + deleted_uid, + RefreshEvent { + account_hash: self.uid_store.account_hash, + mailbox_hash, + kind: Remove(deleted_hash), + }, + )); + } + if self.uid_store.keep_offline_cache { + cache_handle.update(mailbox_hash, &events)?; + } + for (_, event) in events { + self.add_refresh_event(event); + } + return Ok(true); } let deleted_uid = self |