diff options
author | Alex Auvolat <alex@adnab.me> | 2022-06-30 16:04:38 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-06-30 16:04:51 +0200 |
commit | 3277fb16a84d1b7335a4590d69a3c65229204370 (patch) | |
tree | 7b64769fc1c28b51533be5468e508775cf8d38be /src | |
parent | 90c20a840dfdbb47ddc63725baa04feafec0ee1b (diff) | |
download | aerogramme-3277fb16a84d1b7335a4590d69a3c65229204370.tar.gz aerogramme-3277fb16a84d1b7335a4590d69a3c65229204370.zip |
update uid in mailbox list when opening mailbox
Diffstat (limited to 'src')
-rw-r--r-- | src/mail/user.rs | 16 |
1 files changed, 13 insertions, 3 deletions
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<Option<Arc<Mailbox>>> { - 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), } } |