From cd59be3a007822637a8b48efe988fb052d58a756 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Wed, 13 Jul 2022 14:21:14 +0200 Subject: Implement opportunistic sync based on watch value, and use it --- src/imap/command/examined.rs | 4 +++- src/imap/mailbox_view.rs | 18 ++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src/imap') diff --git a/src/imap/command/examined.rs b/src/imap/command/examined.rs index 94e8e88..8da68f8 100644 --- a/src/imap/command/examined.rs +++ b/src/imap/command/examined.rs @@ -87,7 +87,9 @@ impl<'a> ExaminedContext<'a> { } pub async fn noop(self) -> Result<(Response, flow::Transition)> { - let updates = self.mailbox.sync_update().await?; + self.mailbox.mailbox.force_sync().await?; + + let updates = self.mailbox.update().await?; Ok(( Response::ok("NOOP completed.")?.with_body(updates), flow::Transition::None, diff --git a/src/imap/mailbox_view.rs b/src/imap/mailbox_view.rs index 5debcb9..9941428 100644 --- a/src/imap/mailbox_view.rs +++ b/src/imap/mailbox_view.rs @@ -68,16 +68,10 @@ impl MailboxView { Ok((new_view, data)) } - /// Looks up state changes in the mailbox and produces a set of IMAP - /// responses describing the changes. - pub async fn sync_update(&mut self) -> Result> { - self.mailbox.sync().await?; - - self.update().await - } - /// Produces a set of IMAP responses describing the change between /// what the client knows and what is actually in the mailbox. + /// This does NOT trigger a sync, it bases itself on what is currently + /// loaded in RAM by Bayou. pub async fn update(&mut self) -> Result> { let new_view = MailboxView { mailbox: self.mailbox.clone(), @@ -156,6 +150,8 @@ impl MailboxView { flags: &[Flag], uid: &bool, ) -> Result> { + self.mailbox.opportunistic_sync().await?; + if *uid { bail!("UID STORE not implemented"); } @@ -181,9 +177,11 @@ impl MailboxView { } pub async fn expunge(&mut self) -> Result> { + self.mailbox.opportunistic_sync().await?; + let deleted_flag = Flag::Deleted.to_string(); - let msgs = self - .known_state + let state = self.mailbox.current_uid_index().await; + let msgs = state .table .iter() .filter(|(_uuid, (_uid, flags))| flags.iter().any(|x| *x == deleted_flag)) -- cgit v1.2.3