aboutsummaryrefslogtreecommitdiff
path: root/src/imap/mailbox_view.rs
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2024-01-19 17:39:55 +0100
committerQuentin Dufour <quentin@deuxfleurs.fr>2024-01-19 17:39:55 +0100
commitc2a518a997fa12f6e82b2a9eb1ba8cd6059fdf41 (patch)
treeb183720d2a048b1c6641260431258f6332739db3 /src/imap/mailbox_view.rs
parent0cc38571f494a40170dc9913eddad5012337574a (diff)
downloadaerogramme-c2a518a997fa12f6e82b2a9eb1ba8cd6059fdf41.tar.gz
aerogramme-c2a518a997fa12f6e82b2a9eb1ba8cd6059fdf41.zip
filter expunge
Diffstat (limited to 'src/imap/mailbox_view.rs')
-rw-r--r--src/imap/mailbox_view.rs22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/imap/mailbox_view.rs b/src/imap/mailbox_view.rs
index 0efa987..f632df1 100644
--- a/src/imap/mailbox_view.rs
+++ b/src/imap/mailbox_view.rs
@@ -237,16 +237,26 @@ impl MailboxView {
self.update(UpdateParameters::default()).await
}
- pub async fn expunge(&mut self) -> Result<Vec<Body<'static>>> {
+ pub async fn expunge(&mut self, maybe_seq_set: &Option<SequenceSet>) -> Result<Vec<Body<'static>>> {
+ // Get a recent view to apply our change
self.internal.sync().await?;
let state = self.internal.peek().await;
+ let idx = Index::new(&state)?;
+
+ // Build a default sequence set for the default case
+ use imap_codec::imap_types::sequence::{Sequence, SeqOrUid};
+ let seq = match maybe_seq_set {
+ Some(s) => s.clone(),
+ None => SequenceSet(vec![Sequence::Range(SeqOrUid::Value(NonZeroU32::MIN), SeqOrUid::Asterisk)].try_into().unwrap()),
+ };
+
let deleted_flag = Flag::Deleted.to_string();
- let msgs = state
- .table
- .iter()
- .filter(|(_uuid, (_uid, _modseq, flags))| flags.iter().any(|x| *x == deleted_flag))
- .map(|(uuid, _)| *uuid);
+ let msgs = idx
+ .fetch_on_uid(&seq)
+ .into_iter()
+ .filter(|midx| midx.flags.iter().any(|x| *x == deleted_flag))
+ .map(|midx| midx.uuid);
for msg in msgs {
self.internal.mailbox.delete(msg).await?;