diff --git a/src/imap/attributes.rs b/src/imap/attributes.rs index 7a55632..8ab891e 100644 --- a/src/imap/attributes.rs +++ b/src/imap/attributes.rs @@ -1,4 +1,4 @@ -use imap_codec::imap_types::fetch::{MacroOrMessageDataItemNames, MessageDataItemName}; +use imap_codec::imap_types::fetch::{MacroOrMessageDataItemNames, MessageDataItemName, Section}; /// Internal decisions based on fetched attributes /// passed by the client @@ -36,14 +36,26 @@ impl AttributesProxy { pub fn need_body(&self) -> bool { self.attrs.iter().any(|x| { - matches!( - x, + println!("item is: {:?}", x); + match x { MessageDataItemName::Body - | MessageDataItemName::BodyExt { .. } - | MessageDataItemName::Rfc822 - | MessageDataItemName::Rfc822Text - | MessageDataItemName::BodyStructure - ) + | MessageDataItemName::Rfc822 + | MessageDataItemName::Rfc822Text + | MessageDataItemName::BodyStructure => true, + + MessageDataItemName::BodyExt { + section: Some(section), + partial: _, + peek: _, + } => match section { + Section::Header(None) + | Section::HeaderFields(None, _) + | Section::HeaderFieldsNot(None, _) => false, + _ => true, + }, + MessageDataItemName::BodyExt { .. } => true, + _ => false, + } }) } } diff --git a/src/imap/mail_view.rs b/src/imap/mail_view.rs index a593b1a..eeb6b4b 100644 --- a/src/imap/mail_view.rs +++ b/src/imap/mail_view.rs @@ -32,10 +32,7 @@ pub struct MailView<'a> { } impl<'a> MailView<'a> { - pub fn new( - query_result: &'a QueryResult, - in_idx: &'a MailIndex<'a>, - ) -> Result> { + pub fn new(query_result: &'a QueryResult, in_idx: &'a MailIndex<'a>) -> Result> { Ok(Self { in_idx, query_result, diff --git a/src/mail/query.rs b/src/mail/query.rs index a8a23b2..0838800 100644 --- a/src/mail/query.rs +++ b/src/mail/query.rs @@ -31,8 +31,12 @@ impl QueryScope { impl<'a, 'b> Query<'a, 'b> { pub async fn fetch(&self) -> Result> { match self.scope { - QueryScope::Index => Ok(self.emails.iter().map(|&uuid| QueryResult::IndexResult { uuid }).collect()), - QueryScope::Partial =>self.partial().await, + QueryScope::Index => Ok(self + .emails + .iter() + .map(|&uuid| QueryResult::IndexResult { uuid }) + .collect()), + QueryScope::Partial => self.partial().await, QueryScope::Full => self.full().await, } } @@ -44,9 +48,7 @@ impl<'a, 'b> Query<'a, 'b> { let result = meta .into_iter() .zip(self.emails.iter()) - .map(|(metadata, &uuid)| { - QueryResult::PartialResult { uuid, metadata } - }) + .map(|(metadata, &uuid)| QueryResult::PartialResult { uuid, metadata }) .collect::>(); Ok(result) @@ -125,20 +127,14 @@ impl QueryResult { fn into_partial(self, metadata: MailMeta) -> Option { match self { - Self::IndexResult { uuid } => Some(Self::PartialResult { - uuid, - metadata, - }), + Self::IndexResult { uuid } => Some(Self::PartialResult { uuid, metadata }), _ => None, } } fn into_full(self, content: Vec) -> Option { match self { - Self::PartialResult { - uuid, - metadata, - } => Some(Self::FullResult { + Self::PartialResult { uuid, metadata } => Some(Self::FullResult { uuid, metadata, content,