diff options
author | Alex Auvolat <alex@adnab.me> | 2022-05-18 12:42:25 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-05-18 12:42:25 +0200 |
commit | cfc02ba3685c481ebb71ffeddc970998af987de9 (patch) | |
tree | 04a2631f295b9a0a0e5764655dbab22fb61b8c6a /src/uidindex.rs | |
parent | 7a3ce9f81963cc374271272bfe4e0e204e9b7012 (diff) | |
download | aerogramme-cfc02ba3685c481ebb71ffeddc970998af987de9.tar.gz aerogramme-cfc02ba3685c481ebb71ffeddc970998af987de9.zip |
more stuff
Diffstat (limited to 'src/uidindex.rs')
-rw-r--r-- | src/uidindex.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/uidindex.rs b/src/uidindex.rs index 7c5500f..600cf6a 100644 --- a/src/uidindex.rs +++ b/src/uidindex.rs @@ -28,6 +28,30 @@ pub struct UidIndex { pub enum UidIndexOp { MailAdd(MailUuid, ImapUid, Vec<String>), MailDel(MailUuid), + FlagAdd(MailUuid, Vec<String>), + FlagDel(MailUuid, Vec<String>), +} + +impl UidIndex { + #[must_use] + pub fn op_mail_add(&self, uuid: MailUuid, flags: Vec<String>) -> UidIndexOp { + UidIndexOp::MailAdd(uuid, self.internalseq, flags) + } + + #[must_use] + pub fn op_mail_del(&self, uuid: MailUuid) -> UidIndexOp { + UidIndexOp::MailDel(uuid) + } + + #[must_use] + pub fn op_flag_add(&self, uuid: MailUuid, flags: Vec<String>) -> UidIndexOp { + UidIndexOp::FlagAdd(uuid, flags) + } + + #[must_use] + pub fn op_flag_del(&self, uuid: MailUuid, flags: Vec<String>) -> UidIndexOp { + UidIndexOp::FlagDel(uuid, flags) + } } impl Default for UidIndex { @@ -74,6 +98,19 @@ impl BayouState for UidIndex { } new.internalseq += 1; } + UidIndexOp::FlagAdd(uuid, new_flags) => { + let mail_flags = new.mail_flags.entry(*uuid).or_insert(vec![]); + for flag in new_flags { + if !mail_flags.contains(flag) { + mail_flags.push(flag.to_string()); + } + } + } + UidIndexOp::FlagDel(uuid, rm_flags) => { + if let Some(mail_flags) = new.mail_flags.get_mut(uuid) { + mail_flags.retain(|x| !rm_flags.contains(x)); + } + } } new } |