aboutsummaryrefslogtreecommitdiff
path: root/src/mail/uidindex.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-07-13 11:00:35 +0200
committerAlex Auvolat <alex@adnab.me>2022-07-13 11:00:35 +0200
commita1ca6d9defc844fee52d966951701a57727050c7 (patch)
treefaccf61f4f882dc05f3812655bb6f58bde79b725 /src/mail/uidindex.rs
parent7959adb8e970c9006ea9799b5ddd6b2c9aac217a (diff)
downloadaerogramme-a1ca6d9defc844fee52d966951701a57727050c7.tar.gz
aerogramme-a1ca6d9defc844fee52d966951701a57727050c7.zip
"set flags" as a bayou op
Diffstat (limited to 'src/mail/uidindex.rs')
-rw-r--r--src/mail/uidindex.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/mail/uidindex.rs b/src/mail/uidindex.rs
index 6da08c1..3a3e252 100644
--- a/src/mail/uidindex.rs
+++ b/src/mail/uidindex.rs
@@ -36,6 +36,7 @@ pub enum UidIndexOp {
MailDel(UniqueIdent),
FlagAdd(UniqueIdent, Vec<Flag>),
FlagDel(UniqueIdent, Vec<Flag>),
+ FlagSet(UniqueIdent, Vec<Flag>),
BumpUidvalidity(u32),
}
@@ -61,6 +62,11 @@ impl UidIndex {
}
#[must_use]
+ pub fn op_flag_set(&self, ident: UniqueIdent, flags: Vec<Flag>) -> UidIndexOp {
+ UidIndexOp::FlagSet(ident, flags)
+ }
+
+ #[must_use]
pub fn op_bump_uidvalidity(&self, count: u32) -> UidIndexOp {
UidIndexOp::BumpUidvalidity(count)
}
@@ -162,6 +168,24 @@ impl BayouState for UidIndex {
new.idx_by_flag.remove(*uid, rm_flags);
}
}
+ UidIndexOp::FlagSet(ident, new_flags) => {
+ if let Some((uid, existing_flags)) = new.table.get_mut(ident) {
+ // Remove flags from the source of trust and the cache
+ let (keep_flags, rm_flags): (Vec<String>, Vec<String>) = existing_flags
+ .iter()
+ .cloned()
+ .partition(|x| new_flags.contains(x));
+ *existing_flags = keep_flags;
+ let mut to_add: Vec<Flag> = new_flags
+ .iter()
+ .filter(|f| !existing_flags.contains(f))
+ .cloned()
+ .collect();
+ existing_flags.append(&mut to_add);
+ new.idx_by_flag.remove(*uid, &rm_flags);
+ new.idx_by_flag.insert(*uid, &to_add);
+ }
+ }
UidIndexOp::BumpUidvalidity(count) => {
new.uidvalidity = ImapUidvalidity::new(new.uidvalidity.get() + *count)
.unwrap_or(ImapUidvalidity::new(u32::MAX).unwrap());