diff options
author | Quentin Dufour <quentin@deuxfleurs.fr> | 2024-01-06 11:33:56 +0100 |
---|---|---|
committer | Quentin Dufour <quentin@deuxfleurs.fr> | 2024-01-06 11:33:56 +0100 |
commit | 53dbf82cbce3cb17cbcffd09558677faf8702f54 (patch) | |
tree | b78cca747e5c2bc004cb93b93536623f7abb6ef5 /src/imap | |
parent | 1ca6cd5de0656910213425e1d8f05256af820f21 (diff) | |
download | aerogramme-53dbf82cbce3cb17cbcffd09558677faf8702f54.tar.gz aerogramme-53dbf82cbce3cb17cbcffd09558677faf8702f54.zip |
Format code again
Diffstat (limited to 'src/imap')
-rw-r--r-- | src/imap/index.rs | 25 | ||||
-rw-r--r-- | src/imap/mail_view.rs | 40 | ||||
-rw-r--r-- | src/imap/mailbox_view.rs | 32 | ||||
-rw-r--r-- | src/imap/search.rs | 3 |
4 files changed, 72 insertions, 28 deletions
diff --git a/src/imap/index.rs b/src/imap/index.rs index 347222c..01dd2ef 100644 --- a/src/imap/index.rs +++ b/src/imap/index.rs @@ -8,7 +8,11 @@ use crate::mail::unique_ident::UniqueIdent; pub struct Index<'a>(pub &'a UidIndex); impl<'a> Index<'a> { - pub fn fetch(self: &Index<'a>, sequence_set: &SequenceSet, by_uid: bool) -> Result<Vec<MailIndex<'a>>> { + pub fn fetch( + self: &Index<'a>, + sequence_set: &SequenceSet, + by_uid: bool, + ) -> Result<Vec<MailIndex<'a>>> { let mail_vec = self .0 .idx_by_uid @@ -37,7 +41,13 @@ impl<'a> Index<'a> { i: NonZeroU32::try_from(i as u32 + 1).unwrap(), uid: mail.0, uuid: mail.1, - flags: self.0.table.get(&mail.1).ok_or(anyhow!("mail is missing from index"))?.1.as_ref(), + flags: self + .0 + .table + .get(&mail.1) + .ok_or(anyhow!("mail is missing from index"))? + .1 + .as_ref(), }); } } else { @@ -59,7 +69,13 @@ impl<'a> Index<'a> { i, uid: mail.0, uuid: mail.1, - flags: self.0.table.get(&mail.1).ok_or(anyhow!("mail is missing from index"))?.1.as_ref(), + flags: self + .0 + .table + .get(&mail.1) + .ok_or(anyhow!("mail is missing from index"))? + .1 + .as_ref(), }); } else { bail!("No such mail: {}", i); @@ -68,7 +84,6 @@ impl<'a> Index<'a> { } Ok(mails) - } } @@ -76,5 +91,5 @@ pub struct MailIndex<'a> { pub i: NonZeroU32, pub uid: ImapUid, pub uuid: UniqueIdent, - pub flags: &'a Vec<String> + pub flags: &'a Vec<String>, } diff --git a/src/imap/mail_view.rs b/src/imap/mail_view.rs index 1f87f02..de9bfe3 100644 --- a/src/imap/mail_view.rs +++ b/src/imap/mail_view.rs @@ -16,15 +16,14 @@ use eml_codec::{ part::{composite::Message, AnyPart}, }; - use crate::mail::query::QueryResult; use crate::imap::attributes::AttributesProxy; use crate::imap::flags; use crate::imap::imf_view::message_envelope; +use crate::imap::index::MailIndex; use crate::imap::mime_view; use crate::imap::response::Body; -use crate::imap::index::MailIndex; pub struct MailView<'a> { pub in_idx: MailIndex<'a>, @@ -39,18 +38,20 @@ impl<'a> MailView<'a> { query_result, content: match query_result { QueryResult::FullResult { content, .. } => { - let (_, parsed) = eml_codec::parse_message(&content).or(Err(anyhow!("Invalid mail body")))?; + let (_, parsed) = + eml_codec::parse_message(&content).or(Err(anyhow!("Invalid mail body")))?; FetchedMail::new_from_message(parsed) - }, + } QueryResult::PartialResult { metadata, .. } => { - let (_, parsed) = eml_codec::parse_imf(&metadata.headers).or(Err(anyhow!("unable to parse email headers")))?; + let (_, parsed) = eml_codec::parse_imf(&metadata.headers) + .or(Err(anyhow!("unable to parse email headers")))?; FetchedMail::Partial(parsed) } QueryResult::IndexResult { .. } => FetchedMail::IndexOnly, - } + }, }) } - + fn uid(&self) -> MessageDataItem<'static> { MessageDataItem::Uid(self.in_idx.uid.clone()) } @@ -66,12 +67,22 @@ impl<'a> MailView<'a> { } fn rfc_822_size(&self) -> Result<MessageDataItem<'static>> { - let sz = self.query_result.metadata().ok_or(anyhow!("mail metadata are required"))?.rfc822_size; + let sz = self + .query_result + .metadata() + .ok_or(anyhow!("mail metadata are required"))? + .rfc822_size; Ok(MessageDataItem::Rfc822Size(sz as u32)) } fn rfc_822_header(&self) -> Result<MessageDataItem<'static>> { - let hdrs: NString = self.query_result.metadata().ok_or(anyhow!("mail metadata are required"))?.headers.to_vec().try_into()?; + let hdrs: NString = self + .query_result + .metadata() + .ok_or(anyhow!("mail metadata are required"))? + .headers + .to_vec() + .try_into()?; Ok(MessageDataItem::Rfc822Header(hdrs)) } @@ -142,7 +153,16 @@ impl<'a> MailView<'a> { fn internal_date(&self) -> Result<MessageDataItem<'static>> { let dt = Utc .fix() - .timestamp_opt(i64::try_from(self.query_result.metadata().ok_or(anyhow!("mail metadata were not fetched"))?.internaldate / 1000)?, 0) + .timestamp_opt( + i64::try_from( + self.query_result + .metadata() + .ok_or(anyhow!("mail metadata were not fetched"))? + .internaldate + / 1000, + )?, + 0, + ) .earliest() .ok_or(anyhow!("Unable to parse internal date"))?; Ok(MessageDataItem::InternalDate(DateTime::unvalidated(dt))) diff --git a/src/imap/mailbox_view.rs b/src/imap/mailbox_view.rs index 6a4724d..e4ffdcd 100644 --- a/src/imap/mailbox_view.rs +++ b/src/imap/mailbox_view.rs @@ -13,17 +13,16 @@ use imap_codec::imap_types::search::SearchKey; use imap_codec::imap_types::sequence::SequenceSet; use crate::mail::mailbox::Mailbox; -use crate::mail::snapshot::FrozenMailbox; use crate::mail::query::QueryScope; +use crate::mail::snapshot::FrozenMailbox; use crate::mail::uidindex::{ImapUid, ImapUidvalidity}; use crate::imap::attributes::AttributesProxy; use crate::imap::flags; +use crate::imap::index::Index; use crate::imap::mail_view::{MailView, SeenFlag}; use crate::imap::response::Body; use crate::imap::search; -use crate::imap::index::Index; - const DEFAULT_FLAGS: [Flag; 5] = [ Flag::Seen, @@ -40,7 +39,7 @@ const DEFAULT_FLAGS: [Flag; 5] = [ /// To do this, it keeps a variable `known_state` that corresponds to /// what the client knows, and produces IMAP messages to be sent to the /// client that go along updates to `known_state`. -pub struct MailboxView (pub FrozenMailbox); +pub struct MailboxView(pub FrozenMailbox); impl MailboxView { /// Creates a new IMAP view into a mailbox. @@ -258,11 +257,15 @@ impl MailboxView { let mail_idx_list = self.index().fetch(sequence_set, *is_uid_fetch)?; // [2/6] Fetch the emails - let uuids = mail_idx_list.iter().map(|midx| midx.uuid).collect::<Vec<_>>(); + let uuids = mail_idx_list + .iter() + .map(|midx| midx.uuid) + .collect::<Vec<_>>(); let query_result = self.0.query(&uuids, query_scope).fetch().await?; - + // [3/6] Derive an IMAP-specific view from the results, apply the filters - let views = query_result.iter() + let views = query_result + .iter() .zip(mail_idx_list.into_iter()) .map(|(qr, midx)| MailView::new(qr, midx)) .collect::<Result<Vec<_>, _>>()?; @@ -284,7 +287,10 @@ impl MailboxView { .filter(|(_mv, seen)| matches!(seen, SeenFlag::MustAdd)) .map(|(mv, _seen)| async move { let seen_flag = Flag::Seen.to_string(); - self.0.mailbox.add_flags(*mv.query_result.uuid(), &[seen_flag]).await?; + self.0 + .mailbox + .add_flags(*mv.query_result.uuid(), &[seen_flag]) + .await?; Ok::<_, anyhow::Error>(()) }) .collect::<FuturesOrdered<_>>() @@ -399,7 +405,8 @@ impl MailboxView { // 1. Collecting all the possible flags in the mailbox // 1.a Fetch them from our index - let mut known_flags: Vec<Flag> = self.0 + let mut known_flags: Vec<Flag> = self + .0 .snapshot .idx_by_flag .flags() @@ -440,7 +447,8 @@ impl MailboxView { pub(crate) fn unseen_count(&self) -> usize { let total = self.0.snapshot.table.len(); - let seen = self.0 + let seen = self + .0 .snapshot .idx_by_flag .get(&Flag::Seen.to_string()) @@ -462,12 +470,12 @@ mod tests { use std::fs; use crate::cryptoblob; + use crate::imap::index::MailIndex; use crate::imap::mail_view::MailView; use crate::imap::mime_view; - use crate::imap::index::MailIndex; use crate::mail::mailbox::MailMeta; - use crate::mail::unique_ident; use crate::mail::query::QueryResult; + use crate::mail::unique_ident; #[test] fn mailview_body_ext() -> Result<()> { diff --git a/src/imap/search.rs b/src/imap/search.rs index ef89288..b3c6b05 100644 --- a/src/imap/search.rs +++ b/src/imap/search.rs @@ -76,7 +76,8 @@ impl<'a> Criteria<'a> { use SearchKey::*; match self.0 { // IMF Headers - Bcc(_) | Cc(_) | From(_) | Header(..) | SentBefore(_) | SentOn(_) | SentSince(_) | Subject(_) | To(_) => true, + Bcc(_) | Cc(_) | From(_) | Header(..) | SentBefore(_) | SentOn(_) | SentSince(_) + | Subject(_) | To(_) => true, // Internal Date is also stored in MailMeta Before(_) | On(_) | Since(_) => true, // Message size is also stored in MailMeta |