update uid in mailbox list when opening mailbox

This commit is contained in:
Alex 2022-06-30 16:04:38 +02:00
parent 90c20a840d
commit 3277fb16a8
Signed by: lx
GPG key ID: 0E496D15096376BE

View file

@ -69,12 +69,22 @@ impl User {
/// Opens an existing mailbox given its IMAP name. /// Opens an existing mailbox given its IMAP name.
pub async fn open_mailbox(&self, name: &str) -> Result<Option<Arc<Mailbox>>> { pub async fn open_mailbox(&self, name: &str) -> Result<Option<Arc<Mailbox>>> {
let (list, _ct) = self.load_mailbox_list().await?; let (mut list, ct) = self.load_mailbox_list().await?;
match list.get(name) { match list.get_mut(name) {
Some(MailboxListEntry { Some(MailboxListEntry {
id_lww: (_, Some(mbid)), id_lww: (_, Some(mbid)),
uidvalidity, 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), _ => bail!("Mailbox does not exist: {}", name),
} }
} }