From e1161cab0e71ec604e376d2d87f7d1226f3f0244 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 17 Jan 2024 16:56:05 +0100 Subject: idle sync --- src/mail/mailbox.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/mail') diff --git a/src/mail/mailbox.rs b/src/mail/mailbox.rs index 5e95f32..4310a73 100644 --- a/src/mail/mailbox.rs +++ b/src/mail/mailbox.rs @@ -67,6 +67,11 @@ impl Mailbox { self.mbox.write().await.opportunistic_sync().await } + /// Block until a sync has been done (due to changes in the event log) + pub async fn idle_sync(&self) -> Result<()> { + self.mbox.write().await.idle_sync().await + } + // ---- Functions for reading the mailbox ---- /// Get a clone of the current UID Index of this mailbox @@ -199,6 +204,11 @@ impl MailboxInternal { Ok(()) } + async fn idle_sync(&mut self) -> Result<()> { + self.uid_index.idle_sync().await?; + Ok(()) + } + // ---- Functions for reading the mailbox ---- async fn fetch_meta(&self, ids: &[UniqueIdent]) -> Result> { -- cgit v1.2.3 From 185033c462b92854117bc57258bf33b3579a7ca5 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Thu, 18 Jan 2024 17:33:57 +0100 Subject: idling works!!! --- src/mail/mailbox.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/mail') diff --git a/src/mail/mailbox.rs b/src/mail/mailbox.rs index 4310a73..c20d815 100644 --- a/src/mail/mailbox.rs +++ b/src/mail/mailbox.rs @@ -68,8 +68,8 @@ impl Mailbox { } /// Block until a sync has been done (due to changes in the event log) - pub async fn idle_sync(&self) -> Result<()> { - self.mbox.write().await.idle_sync().await + pub async fn notify(&self) -> std::sync::Weak { + self.mbox.read().await.notifier() } // ---- Functions for reading the mailbox ---- @@ -204,9 +204,8 @@ impl MailboxInternal { Ok(()) } - async fn idle_sync(&mut self) -> Result<()> { - self.uid_index.idle_sync().await?; - Ok(()) + fn notifier(&self) -> std::sync::Weak { + self.uid_index.notifier() } // ---- Functions for reading the mailbox ---- -- cgit v1.2.3 From 2c5adc8f166c6117ece353376b9071f5e30857b1 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Thu, 18 Jan 2024 18:03:21 +0100 Subject: reformat code --- src/mail/uidindex.rs | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'src/mail') diff --git a/src/mail/uidindex.rs b/src/mail/uidindex.rs index 248aab1..5a06670 100644 --- a/src/mail/uidindex.rs +++ b/src/mail/uidindex.rs @@ -140,8 +140,7 @@ impl BayouState for UidIndex { let bump_uid = new.internalseq.get() - uid.get(); let bump_modseq = (new.internalmodseq.get() - modseq.get()) as u32; new.uidvalidity = - NonZeroU32::new(new.uidvalidity.get() + bump_uid + bump_modseq) - .unwrap(); + NonZeroU32::new(new.uidvalidity.get() + bump_uid + bump_modseq).unwrap(); } // Assign the real uid of the email @@ -179,10 +178,10 @@ impl BayouState for UidIndex { if let Some((uid, email_modseq, existing_flags)) = new.table.get_mut(ident) { // Bump UIDValidity if required if *candidate_modseq < new.internalmodseq { - let bump_modseq = (new.internalmodseq.get() - candidate_modseq.get()) as u32; + let bump_modseq = + (new.internalmodseq.get() - candidate_modseq.get()) as u32; new.uidvalidity = - NonZeroU32::new(new.uidvalidity.get() + bump_modseq) - .unwrap(); + NonZeroU32::new(new.uidvalidity.get() + bump_modseq).unwrap(); } // Add flags to the source of trust and the cache @@ -205,10 +204,10 @@ impl BayouState for UidIndex { if let Some((uid, email_modseq, existing_flags)) = new.table.get_mut(ident) { // Bump UIDValidity if required if *candidate_modseq < new.internalmodseq { - let bump_modseq = (new.internalmodseq.get() - candidate_modseq.get()) as u32; + let bump_modseq = + (new.internalmodseq.get() - candidate_modseq.get()) as u32; new.uidvalidity = - NonZeroU32::new(new.uidvalidity.get() + bump_modseq) - .unwrap(); + NonZeroU32::new(new.uidvalidity.get() + bump_modseq).unwrap(); } // Remove flags from the source of trust and the cache @@ -228,10 +227,10 @@ impl BayouState for UidIndex { if let Some((uid, email_modseq, existing_flags)) = new.table.get_mut(ident) { // Bump UIDValidity if required if *candidate_modseq < new.internalmodseq { - let bump_modseq = (new.internalmodseq.get() - candidate_modseq.get()) as u32; + let bump_modseq = + (new.internalmodseq.get() - candidate_modseq.get()) as u32; new.uidvalidity = - NonZeroU32::new(new.uidvalidity.get() + bump_modseq) - .unwrap(); + NonZeroU32::new(new.uidvalidity.get() + bump_modseq).unwrap(); } // Remove flags from the source of trust and the cache @@ -248,7 +247,7 @@ impl BayouState for UidIndex { existing_flags.append(&mut to_add); new.idx_by_flag.remove(*uid, &rm_flags); new.idx_by_flag.insert(*uid, &to_add); - + // Register that email has been modified new.idx_by_modseq.insert(new.internalmodseq, *ident); *email_modseq = new.internalmodseq; @@ -448,7 +447,12 @@ mod tests { { let m = UniqueIdent([0x03; 24]); let f = vec!["\\Archive".to_string(), "\\Recent".to_string()]; - let ev = UidIndexOp::MailAdd(m, NonZeroU32::new(1).unwrap(), NonZeroU64::new(1).unwrap(), f); + let ev = UidIndexOp::MailAdd( + m, + NonZeroU32::new(1).unwrap(), + NonZeroU64::new(1).unwrap(), + f, + ); state = state.apply(&ev); } -- cgit v1.2.3