diff options
author | Quentin <quentin@dufour.io> | 2024-01-19 14:04:03 +0000 |
---|---|---|
committer | Quentin <quentin@dufour.io> | 2024-01-19 14:04:03 +0000 |
commit | 0f227e44e4996e54d2e55ed5c7a07f5458c4db4f (patch) | |
tree | 7f6c4fec623d0d99d3f09e752a360ca0f806429e /src/imap/search.rs | |
parent | 55e26d24a08519ded6a6898453dcd6db287f45c8 (diff) | |
parent | 23aa313e11f344da07143d60ce446b5f23d5f362 (diff) | |
download | aerogramme-0f227e44e4996e54d2e55ed5c7a07f5458c4db4f.tar.gz aerogramme-0f227e44e4996e54d2e55ed5c7a07f5458c4db4f.zip |
Merge pull request 'Implement IDLE' (#72) from feat/idle into main
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/aerogramme/pulls/72
Diffstat (limited to 'src/imap/search.rs')
-rw-r--r-- | src/imap/search.rs | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/src/imap/search.rs b/src/imap/search.rs index 61cbad5..d06c3bd 100644 --- a/src/imap/search.rs +++ b/src/imap/search.rs @@ -2,7 +2,7 @@ use std::num::{NonZeroU32, NonZeroU64}; use anyhow::Result; use imap_codec::imap_types::core::NonEmptyVec; -use imap_codec::imap_types::search::{SearchKey, MetadataItemSearch}; +use imap_codec::imap_types::search::{MetadataItemSearch, SearchKey}; use imap_codec::imap_types::sequence::{SeqOrUid, Sequence, SequenceSet}; use crate::imap::index::MailIndex; @@ -115,12 +115,15 @@ 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()), + 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 @@ -187,7 +190,10 @@ impl<'a> Criteria<'a> { // Sequence logic maybe_seq if is_sk_seq(maybe_seq) => is_keep_seq(maybe_seq, midx).into(), maybe_flag if is_sk_flag(maybe_flag) => is_keep_flag(maybe_flag, midx).into(), - ModSeq { metadata_item , modseq } => is_keep_modseq(metadata_item, modseq, midx).into(), + ModSeq { + metadata_item, + modseq, + } => is_keep_modseq(metadata_item, modseq, midx).into(), // All the stuff we can't evaluate yet Bcc(_) | Cc(_) | From(_) | Header(..) | SentBefore(_) | SentOn(_) | SentSince(_) @@ -225,7 +231,10 @@ impl<'a> Criteria<'a> { //@FIXME Reevaluating our previous logic... maybe_seq if is_sk_seq(maybe_seq) => is_keep_seq(maybe_seq, &mail_view.in_idx), maybe_flag if is_sk_flag(maybe_flag) => is_keep_flag(maybe_flag, &mail_view.in_idx), - ModSeq { metadata_item , modseq } => is_keep_modseq(metadata_item, modseq, &mail_view.in_idx).into(), + ModSeq { + metadata_item, + modseq, + } => is_keep_modseq(metadata_item, modseq, &mail_view.in_idx).into(), // Filter on mail meta Before(search_naive) => match mail_view.stored_naive_date() { @@ -331,7 +340,7 @@ fn approx_sequence_set_size(seq_set: &SequenceSet) -> u64 { } // This is wrong as sequence UID can have holes, -// as we don't know the number of messages in the mailbox also +// as we don't know the number of messages in the mailbox also // we gave to guess fn approx_sequence_size(seq: &Sequence) -> u64 { match seq { @@ -473,9 +482,13 @@ fn is_keep_seq(sk: &SearchKey, midx: &MailIndex) -> bool { } } -fn is_keep_modseq(filter: &Option<MetadataItemSearch>, modseq: &NonZeroU64, midx: &MailIndex) -> bool { +fn is_keep_modseq( + filter: &Option<MetadataItemSearch>, + modseq: &NonZeroU64, + midx: &MailIndex, +) -> bool { if filter.is_some() { tracing::warn!(filter=?filter, "Ignoring search metadata filter as it's not supported yet"); } - modseq <= &midx.modseq + modseq <= &midx.modseq } |