From 13ed1b3890ce1bddf89d5397998ead191c6815ec Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Tue, 14 Jun 2022 10:35:12 +0200 Subject: [PATCH] Alias Flag to String --- src/uidindex.rs | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/uidindex.rs b/src/uidindex.rs index 99647bc..bcc5ecd 100644 --- a/src/uidindex.rs +++ b/src/uidindex.rs @@ -5,6 +5,7 @@ use crate::bayou::*; pub type ImapUid = u32; pub type ImapUidvalidity = u32; +pub type Flag = String; /// A Mail UUID is composed of two components: /// - a process identifier, 128 bits @@ -20,9 +21,9 @@ pub struct MailUuid(pub [u8; 24]); /// that are optimized for cloning (they clone underlying values only if they are modified) pub struct UidIndex { pub mail_uid: OrdMap, - pub mail_flags: OrdMap>, + pub mail_flags: OrdMap>, pub mails_by_uid: OrdMap, - pub flags: HashMap>, + pub flags: HashMap>, pub uidvalidity: ImapUidvalidity, pub uidnext: ImapUid, @@ -31,15 +32,15 @@ pub struct UidIndex { #[derive(Clone, Serialize, Deserialize, Debug)] pub enum UidIndexOp { - MailAdd(MailUuid, ImapUid, Vec), + MailAdd(MailUuid, ImapUid, Vec), MailDel(MailUuid), - FlagAdd(MailUuid, Vec), - FlagDel(MailUuid, Vec), + FlagAdd(MailUuid, Vec), + FlagDel(MailUuid, Vec), } impl UidIndex { #[must_use] - pub fn op_mail_add(&self, uuid: MailUuid, flags: Vec) -> UidIndexOp { + pub fn op_mail_add(&self, uuid: MailUuid, flags: Vec) -> UidIndexOp { UidIndexOp::MailAdd(uuid, self.internalseq, flags) } @@ -49,12 +50,12 @@ impl UidIndex { } #[must_use] - pub fn op_flag_add(&self, uuid: MailUuid, flags: Vec) -> UidIndexOp { + pub fn op_flag_add(&self, uuid: MailUuid, flags: Vec) -> UidIndexOp { UidIndexOp::FlagAdd(uuid, flags) } #[must_use] - pub fn op_flag_del(&self, uuid: MailUuid, flags: Vec) -> UidIndexOp { + pub fn op_flag_del(&self, uuid: MailUuid, flags: Vec) -> UidIndexOp { UidIndexOp::FlagDel(uuid, flags) } } @@ -122,9 +123,17 @@ impl BayouState for UidIndex { }); } UidIndexOp::FlagDel(uuid, rm_flags) => { + // Upate mapping Email -> Flag if let Some(mail_flags) = new.mail_flags.get_mut(uuid) { mail_flags.retain(|x| !rm_flags.contains(x)); } + + // Update mapping Flag -> Email + rm_flags.iter().for_each(|flag| { + new.flags + .entry(flag.clone()) + .and_modify(|hs| { hs.remove(uuid); }); + }); } } new @@ -135,7 +144,7 @@ impl BayouState for UidIndex { #[derive(Serialize, Deserialize)] struct UidIndexSerializedRepr { - mails: Vec<(ImapUid, MailUuid, Vec)>, + mails: Vec<(ImapUid, MailUuid, Vec)>, uidvalidity: ImapUidvalidity, uidnext: ImapUid, internalseq: ImapUid,