Fix open_mailbox
This commit is contained in:
parent
54c467d3f7
commit
441730e1f7
3 changed files with 20 additions and 16 deletions
|
@ -1,6 +1,6 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use anyhow::{bail, Result};
|
||||
use anyhow::Result;
|
||||
use boitalettres::proto::Request;
|
||||
use boitalettres::proto::Response;
|
||||
use imap_codec::types::command::CommandBody;
|
||||
|
@ -99,7 +99,13 @@ impl<'a> SelectedContext<'a> {
|
|||
let mb_opt = self.user.open_mailbox(&name).await?;
|
||||
let mb = match mb_opt {
|
||||
Some(mb) => mb,
|
||||
None => bail!("Mailbox does not exist"),
|
||||
None => {
|
||||
return Ok((
|
||||
Response::no("Destination mailbox does not exist")?
|
||||
.with_extra_code(Code::TryCreate),
|
||||
flow::Transition::None,
|
||||
))
|
||||
}
|
||||
};
|
||||
|
||||
let (uidval, uid_map) = self.mailbox.copy(sequence_set, mb, uid).await?;
|
||||
|
|
|
@ -109,7 +109,7 @@ async fn incoming_mail_watch_process_internal(
|
|||
if Some(id) != inbox.as_ref().map(|b| b.id) {
|
||||
match user.open_mailbox_by_id(id, uidvalidity).await {
|
||||
Ok(mb) => {
|
||||
inbox = mb;
|
||||
inbox = Some(mb);
|
||||
}
|
||||
Err(e) => {
|
||||
inbox = None;
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue