From 3277fb16a84d1b7335a4590d69a3c65229204370 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Thu, 30 Jun 2022 16:04:38 +0200 Subject: update uid in mailbox list when opening mailbox --- src/mail/user.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/mail/user.rs b/src/mail/user.rs index 0be3801..ea22d5b 100644 --- a/src/mail/user.rs +++ b/src/mail/user.rs @@ -69,12 +69,22 @@ impl User { /// Opens an existing mailbox given its IMAP name. pub async fn open_mailbox(&self, name: &str) -> Result>> { - let (list, _ct) = self.load_mailbox_list().await?; - match list.get(name) { + let (mut list, ct) = self.load_mailbox_list().await?; + match list.get_mut(name) { Some(MailboxListEntry { id_lww: (_, Some(mbid)), uidvalidity, - }) => self.open_mailbox_by_id(*mbid, *uidvalidity).await, + }) => { + let mb_opt = self.open_mailbox_by_id(*mbid, *uidvalidity).await?; + if let Some(mb) = &mb_opt { + let mb_uidvalidity = mb.current_uid_index().await.uidvalidity; + if mb_uidvalidity > *uidvalidity { + *uidvalidity = mb_uidvalidity; + self.save_mailbox_list(&list, ct).await?; + } + } + Ok(mb_opt) + } _ => bail!("Mailbox does not exist: {}", name), } } -- cgit v1.2.3