diff options
author | Quentin Dufour <quentin@deuxfleurs.fr> | 2024-01-05 15:26:57 +0100 |
---|---|---|
committer | Quentin Dufour <quentin@deuxfleurs.fr> | 2024-01-05 15:26:57 +0100 |
commit | d3c156a087f3c767fc0d2376abd7c1d304161d47 (patch) | |
tree | 0c95d813be4fad70c839b81794889b327142f2a7 /src/imap | |
parent | 35591ff0608096b32d7bab22d719a6ceb8574c2c (diff) | |
download | aerogramme-d3c156a087f3c767fc0d2376abd7c1d304161d47.tar.gz aerogramme-d3c156a087f3c767fc0d2376abd7c1d304161d47.zip |
Select what to fecth for search
Diffstat (limited to 'src/imap')
-rw-r--r-- | src/imap/mailbox_view.rs | 9 | ||||
-rw-r--r-- | src/imap/search.rs | 30 |
2 files changed, 34 insertions, 5 deletions
diff --git a/src/imap/mailbox_view.rs b/src/imap/mailbox_view.rs index 5311635..4d0858f 100644 --- a/src/imap/mailbox_view.rs +++ b/src/imap/mailbox_view.rs @@ -344,12 +344,19 @@ impl MailboxView { search_key: &SearchKey<'a>, uid: bool, ) -> Result<Vec<Body<'static>>> { - let (seq_set, seq_type) = search::Criteria(search_key).to_sequence_set(); + // 1. Compute the subset of sequence identifiers we need to fetch + let query = search::Criteria(search_key); + let (seq_set, seq_type) = query.to_sequence_set(); let mailids = MailIdentifiersList(self.get_mail_ids(&seq_set, seq_type.is_uid())?); let mail_u32 = match uid { true => mailids.uids(), _ => mailids.ids(), }; + + // 2. Compute wether we will need to fetch the mail meta and/or the body + let _need_meta = query.need_meta(); + let _need_body = query.need_body(); + Ok(vec![Body::Data(Data::Search(mail_u32))]) } diff --git a/src/imap/search.rs b/src/imap/search.rs index bf1d30e..ef89288 100644 --- a/src/imap/search.rs +++ b/src/imap/search.rs @@ -69,12 +69,34 @@ impl<'a> Criteria<'a> { } } - fn need_meta(&self) { - unimplemented!(); + /// Not really clever as we can have cases where we filter out + /// the email before needing to inspect its meta. + /// But for now we are seeking the most basic/stupid algorithm. + pub fn need_meta(&self) -> bool { + use SearchKey::*; + match self.0 { + // IMF Headers + 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 + Larger(_) | Smaller(_) => true, + And(and_list) => and_list.as_ref().iter().any(|sk| Criteria(sk).need_meta()), + Not(inner) => Criteria(inner).need_meta(), + Or(left, right) => Criteria(left).need_meta() || Criteria(right).need_meta(), + _ => false, + } } - fn need_body(&self) { - unimplemented!(); + pub fn need_body(&self) -> bool { + use SearchKey::*; + match self.0 { + Text(_) | Body(_) => true, + And(and_list) => and_list.as_ref().iter().any(|sk| Criteria(sk).need_body()), + Not(inner) => Criteria(inner).need_body(), + Or(left, right) => Criteria(left).need_body() || Criteria(right).need_body(), + _ => false, + } } } |