diff options
author | Quentin Dufour <quentin@deuxfleurs.fr> | 2022-06-23 14:41:10 +0200 |
---|---|---|
committer | Quentin Dufour <quentin@deuxfleurs.fr> | 2022-06-23 14:41:10 +0200 |
commit | 8a0df56cde2bfed40514b7a43405cf25848b7568 (patch) | |
tree | d6443697de48a134ddd11282530650d6bad37e89 /src/uidindex.rs | |
parent | cea27474f9dfed289be4e7be017913d7165342f3 (diff) | |
download | aerogramme-8a0df56cde2bfed40514b7a43405cf25848b7568.tar.gz aerogramme-8a0df56cde2bfed40514b7a43405cf25848b7568.zip |
Return UID validity
Diffstat (limited to 'src/uidindex.rs')
-rw-r--r-- | src/uidindex.rs | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/uidindex.rs b/src/uidindex.rs index 8e4a189..f53d770 100644 --- a/src/uidindex.rs +++ b/src/uidindex.rs @@ -1,11 +1,13 @@ +use std::num::NonZeroU32; + use im::{HashMap, HashSet, OrdMap, OrdSet}; use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer}; use crate::bayou::*; use crate::mail_ident::MailIdent; -pub type ImapUid = u32; -pub type ImapUidvalidity = u32; +pub type ImapUid = NonZeroU32; +pub type ImapUidvalidity = NonZeroU32; pub type Flag = String; #[derive(Clone)] @@ -90,9 +92,9 @@ impl Default for UidIndex { table: OrdMap::new(), idx_by_uid: OrdMap::new(), idx_by_flag: FlagIndex::new(), - uidvalidity: 1, - uidnext: 1, - internalseq: 1, + uidvalidity: NonZeroU32::new(1).unwrap(), + uidnext: NonZeroU32::new(1).unwrap(), + internalseq: NonZeroU32::new(1).unwrap(), } } } @@ -106,7 +108,9 @@ impl BayouState for UidIndex { UidIndexOp::MailAdd(ident, uid, flags) => { // Change UIDValidity if there is a conflict if *uid < new.internalseq { - new.uidvalidity += new.internalseq - *uid; + new.uidvalidity = + NonZeroU32::new(new.uidvalidity.get() + new.internalseq.get() - uid.get()) + .unwrap(); } // Assign the real uid of the email @@ -123,7 +127,7 @@ impl BayouState for UidIndex { new.reg_email(*ident, new_uid, flags); // Update counters - new.internalseq += 1; + new.internalseq = NonZeroU32::new(new.internalseq.get() + 1).unwrap(); new.uidnext = new.internalseq; } UidIndexOp::MailDel(ident) => { @@ -131,7 +135,7 @@ impl BayouState for UidIndex { new.unreg_email(ident); // We update the counter - new.internalseq += 1; + new.internalseq = NonZeroU32::new(new.internalseq.get() + 1).unwrap(); } UidIndexOp::FlagAdd(ident, new_flags) => { if let Some((uid, existing_flags)) = new.table.get_mut(ident) { |