diff options
author | Alex Auvolat <alex@adnab.me> | 2022-07-13 15:39:52 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-07-13 15:39:52 +0200 |
commit | 3b256de3dc1347bf449905de714ac5486935264a (patch) | |
tree | 55fbeb68d510ed62f02566870a62907d1e37520d /src/imap/mailbox_view.rs | |
parent | 956a92377ea46e730f9fe5dcfee8b49be65e78ec (diff) | |
download | aerogramme-3b256de3dc1347bf449905de714ac5486935264a.tar.gz aerogramme-3b256de3dc1347bf449905de714ac5486935264a.zip |
Remove OK [UNSEEN x] responses to SELECT and EXAMINE, and fix STATUS UNSEEN
Diffstat (limited to 'src/imap/mailbox_view.rs')
-rw-r--r-- | src/imap/mailbox_view.rs | 36 |
1 files changed, 11 insertions, 25 deletions
diff --git a/src/imap/mailbox_view.rs b/src/imap/mailbox_view.rs index f9485e4..25b3f3e 100644 --- a/src/imap/mailbox_view.rs +++ b/src/imap/mailbox_view.rs @@ -61,9 +61,6 @@ impl MailboxView { data.extend(new_view.flags_status()?.into_iter()); data.push(new_view.uidvalidity_status()?); data.push(new_view.uidnext_status()?); - if let Some(unseen) = new_view.unseen_status()? { - data.push(unseen); - } Ok((new_view, data)) } @@ -432,27 +429,6 @@ impl MailboxView { self.known_state.uidnext } - /// Produces an UNSEEN message (if relevant) corresponding to the - /// first unseen message id in `known_state` - fn unseen_status(&self) -> Result<Option<Body>> { - if let Some(unseen) = self.unseen() { - let status_unseen = - Status::ok(None, Some(Code::Unseen(unseen.clone())), "First unseen UID") - .map_err(Error::msg)?; - Ok(Some(Body::Status(status_unseen))) - } else { - Ok(None) - } - } - - pub(crate) fn unseen(&self) -> Option<ImapUid> { - self.known_state - .idx_by_flag - .get(&"$unseen".to_string()) - .and_then(|os| os.get_min()) - .cloned() - } - /// Produce an EXISTS message corresponding to the number of mails /// in `known_state` fn exists_status(&self) -> Result<Body> { @@ -504,6 +480,17 @@ impl MailboxView { Ok(ret) } + + pub(crate) fn unseen_count(&self) -> usize { + let total = self.known_state.table.len(); + let seen = self + .known_state + .idx_by_flag + .get(&Flag::Seen.to_string()) + .map(|x| x.len()) + .unwrap_or(0); + total - seen + } } fn string_to_flag(f: &str) -> Option<Flag> { @@ -523,7 +510,6 @@ fn string_to_flag(f: &str) -> Option<Flag> { Ok(a) => Some(Flag::Extension(a)), }, }, - Some('$') if f == "$unseen" => None, Some(_) => match Atom::try_from(f.clone()) { Err(_) => { tracing::error!(flag=%f, "Unable to encode flag as IMAP atom"); |