diff options
author | Alex Auvolat <alex@adnab.me> | 2022-07-21 12:50:44 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-07-21 12:50:44 +0200 |
commit | 441730e1f7a27541d52d1aaccc59a8204a96d079 (patch) | |
tree | 793b5f3cf1fede10881de7cca165023ad4966800 /src/mail/user.rs | |
parent | 54c467d3f77fae964400e9c1d78d32d9067c3b0f (diff) | |
download | aerogramme-441730e1f7a27541d52d1aaccc59a8204a96d079.tar.gz aerogramme-441730e1f7a27541d52d1aaccc59a8204a96d079.zip |
Fix open_mailbox
Diffstat (limited to 'src/mail/user.rs')
-rw-r--r-- | src/mail/user.rs | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/src/mail/user.rs b/src/mail/user.rs index fd858d3..d921e6d 100644 --- a/src/mail/user.rs +++ b/src/mail/user.rs @@ -77,17 +77,15 @@ impl User { } if let Some((uidvalidity, Some(mbid))) = list.get_mailbox(name) { - 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 { - list.update_uidvalidity(name, mb_uidvalidity); - self.save_mailbox_list(&list, ct).await?; - } + let mb = self.open_mailbox_by_id(mbid, uidvalidity).await?; + let mb_uidvalidity = mb.current_uid_index().await.uidvalidity; + if mb_uidvalidity > uidvalidity { + list.update_uidvalidity(name, mb_uidvalidity); + self.save_mailbox_list(&list, ct).await?; } - Ok(mb_opt) + Ok(Some(mb)) } else { - bail!("Mailbox does not exist: {}", name); + Ok(None) } } @@ -203,11 +201,11 @@ impl User { &self, id: UniqueIdent, min_uidvalidity: ImapUidvalidity, - ) -> Result<Option<Arc<Mailbox>>> { + ) -> Result<Arc<Mailbox>> { { let cache = self.mailboxes.lock().unwrap(); if let Some(mb) = cache.get(&id).and_then(Weak::upgrade) { - return Ok(Some(mb)); + return Ok(mb); } } @@ -216,10 +214,10 @@ impl User { let mut cache = self.mailboxes.lock().unwrap(); if let Some(concurrent_mb) = cache.get(&id).and_then(Weak::upgrade) { drop(mb); // we worked for nothing but at least we didn't starve someone else - Ok(Some(concurrent_mb)) + Ok(concurrent_mb) } else { cache.insert(id, Arc::downgrade(&mb)); - Ok(Some(mb)) + Ok(mb) } } |