Select what to fecth for search

This commit is contained in:
Quentin 2024-01-05 15:26:57 +01:00
parent 35591ff060
commit d3c156a087
Signed by: quentin
GPG key ID: E9602264D639FF68
4 changed files with 36 additions and 7 deletions

2
Cargo.lock generated
View file

@ -1723,7 +1723,7 @@ dependencies = [
"httpdate", "httpdate",
"itoa", "itoa",
"pin-project-lite 0.2.13", "pin-project-lite 0.2.13",
"socket2 0.5.5", "socket2 0.4.10",
"tokio", "tokio",
"tower-service", "tower-service",
"tracing", "tracing",

View file

@ -58,7 +58,7 @@ aws-sdk-s3 = "1.9.0"
eml-codec = { git = "https://git.deuxfleurs.fr/Deuxfleurs/eml-codec.git", branch = "main" } eml-codec = { git = "https://git.deuxfleurs.fr/Deuxfleurs/eml-codec.git", branch = "main" }
smtp-message = { git = "http://github.com/Alexis211/kannader", branch = "feature/lmtp" } smtp-message = { git = "http://github.com/Alexis211/kannader", branch = "feature/lmtp" }
smtp-server = { git = "http://github.com/Alexis211/kannader", branch = "feature/lmtp" } smtp-server = { git = "http://github.com/Alexis211/kannader", branch = "feature/lmtp" }
imap-codec = { version = "1.0.0", features = ["quirk_crlf_relaxed", "bounded-static", "ext_condstore_qresync"] } imap-codec = { version = "1.0.0", features = ["bounded-static", "ext_condstore_qresync"] }
imap-flow = { git = "https://github.com/duesee/imap-flow.git", rev = "e45ce7bb6ab6bda3c71a0c7b05e9b558a5902e90" } imap-flow = { git = "https://github.com/duesee/imap-flow.git", rev = "e45ce7bb6ab6bda3c71a0c7b05e9b558a5902e90" }
[dev-dependencies] [dev-dependencies]

View file

@ -344,12 +344,19 @@ impl MailboxView {
search_key: &SearchKey<'a>, search_key: &SearchKey<'a>,
uid: bool, uid: bool,
) -> Result<Vec<Body<'static>>> { ) -> 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 mailids = MailIdentifiersList(self.get_mail_ids(&seq_set, seq_type.is_uid())?);
let mail_u32 = match uid { let mail_u32 = match uid {
true => mailids.uids(), true => mailids.uids(),
_ => mailids.ids(), _ => 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))]) Ok(vec![Body::Data(Data::Search(mail_u32))])
} }

View file

@ -69,12 +69,34 @@ impl<'a> Criteria<'a> {
} }
} }
fn need_meta(&self) { /// Not really clever as we can have cases where we filter out
unimplemented!(); /// 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) { pub fn need_body(&self) -> bool {
unimplemented!(); 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,
}
} }
} }