diff options
Diffstat (limited to 'src/imap/mailbox_view.rs')
-rw-r--r-- | src/imap/mailbox_view.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/imap/mailbox_view.rs b/src/imap/mailbox_view.rs index 77fe7f7..3f8389b 100644 --- a/src/imap/mailbox_view.rs +++ b/src/imap/mailbox_view.rs @@ -1,7 +1,7 @@ use std::num::NonZeroU32; use std::sync::Arc; -use anyhow::{anyhow, Error, Result}; +use anyhow::{anyhow, Error, Context, Result}; use futures::stream::{FuturesOrdered, StreamExt}; @@ -130,6 +130,7 @@ impl MailboxView { data.extend(self.flags_status()?.into_iter()); data.push(self.uidvalidity_status()?); data.push(self.uidnext_status()?); + self.unseen_first_status()?.map(|unseen_status| data.push(unseen_status)); Ok(data) } @@ -400,6 +401,22 @@ impl MailboxView { Ok(Body::Data(Data::Recent(self.recent()?))) } + fn unseen_first_status(&self) -> Result<Option<Body<'static>>> { + Ok(self.unseen_first()?.map(|unseen_id| { + Status::ok(None, Some(Code::Unseen(unseen_id)), "First unseen.").map(Body::Status) + }).transpose()?) + } + + fn unseen_first(&self) -> Result<Option<NonZeroU32>> { + Ok(self.0.snapshot.table + .values() + .enumerate() + .find(|(_i, (_imap_uid, flags))| { + !flags.contains(&"\\Seen".to_string()) + }).map(|(i, _)| NonZeroU32::try_from(i as u32 + 1)) + .transpose()?) + } + pub(crate) fn recent(&self) -> Result<u32> { let recent = self .0 |