Enable CONDSTORE if SEARCH MODSEQ is queried

This commit is contained in:
Quentin 2024-01-11 11:48:02 +01:00
parent 917c32ae0b
commit fbf2e9aa96
Signed by: quentin
GPG key ID: E9602264D639FF68
4 changed files with 24 additions and 4 deletions

View file

@ -120,7 +120,10 @@ impl<'a> ExaminedContext<'a> {
criteria: &SearchKey<'a>, criteria: &SearchKey<'a>,
uid: &bool, uid: &bool,
) -> Result<(Response<'static>, flow::Transition)> { ) -> Result<(Response<'static>, flow::Transition)> {
let found = self.mailbox.search(charset, criteria, *uid).await?; let (found, enable_condstore) = self.mailbox.search(charset, criteria, *uid).await?;
if enable_condstore {
self.client_capabilities.enable_condstore();
}
Ok(( Ok((
Response::build() Response::build()
.to_req(self.req) .to_req(self.req)

View file

@ -146,7 +146,10 @@ impl<'a> SelectedContext<'a> {
criteria: &SearchKey<'a>, criteria: &SearchKey<'a>,
uid: &bool, uid: &bool,
) -> Result<(Response<'static>, flow::Transition)> { ) -> Result<(Response<'static>, flow::Transition)> {
let found = self.mailbox.search(charset, criteria, *uid).await?; let (found, enable_condstore) = self.mailbox.search(charset, criteria, *uid).await?;
if enable_condstore {
self.client_capabilities.enable_condstore();
}
Ok(( Ok((
Response::build() Response::build()
.to_req(self.req) .to_req(self.req)

View file

@ -325,7 +325,7 @@ impl MailboxView {
_charset: &Option<Charset<'a>>, _charset: &Option<Charset<'a>>,
search_key: &SearchKey<'a>, search_key: &SearchKey<'a>,
uid: bool, uid: bool,
) -> Result<Vec<Body<'static>>> { ) -> Result<(Vec<Body<'static>>, bool)> {
// 1. Compute the subset of sequence identifiers we need to fetch // 1. Compute the subset of sequence identifiers we need to fetch
// based on the search query // based on the search query
let crit = search::Criteria(search_key); let crit = search::Criteria(search_key);
@ -354,7 +354,10 @@ impl MailboxView {
_ => final_selection.map(|in_idx| in_idx.i).collect(), _ => final_selection.map(|in_idx| in_idx.i).collect(),
}; };
Ok(vec![Body::Data(Data::Search(selection_fmt))]) // 7. Add the modseq entry if needed
let is_modseq = crit.is_modseq();
Ok((vec![Body::Data(Data::Search(selection_fmt))], is_modseq))
} }
// ---- // ----

View file

@ -112,6 +112,17 @@ impl<'a> Criteria<'a> {
} }
} }
pub fn is_modseq(&self) -> bool {
use SearchKey::*;
match self.0 {
And(and_list) => and_list.as_ref().iter().any(|child| Criteria(child).is_modseq()),
Or(left, right) => Criteria(left).is_modseq() || Criteria(right).is_modseq(),
Not(child) => Criteria(child).is_modseq(),
ModSeq { .. } => true,
_ => false,
}
}
/// Returns emails that we now for sure we want to keep /// Returns emails that we now for sure we want to keep
/// but also a second list of emails we need to investigate further by /// but also a second list of emails we need to investigate further by
/// fetching some remote data /// fetching some remote data