mirror of
https://github.com/chatmail/core.git
synced 2026-05-02 04:46:29 +03:00
Use anyhow for close_folder() errors
This commit is contained in:
@@ -19,35 +19,31 @@ pub enum Error {
|
|||||||
#[error("Got a NO response when trying to select {0}, usually this means that it doesn't exist: {1}")]
|
#[error("Got a NO response when trying to select {0}, usually this means that it doesn't exist: {1}")]
|
||||||
NoFolder(String, String),
|
NoFolder(String, String),
|
||||||
|
|
||||||
#[error("IMAP close/expunge failed")]
|
|
||||||
CloseExpungeFailed(#[from] async_imap::error::Error),
|
|
||||||
|
|
||||||
#[error("IMAP other error: {0}")]
|
#[error("IMAP other error: {0}")]
|
||||||
Other(String),
|
Other(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<anyhow::Error> for Error {
|
||||||
|
fn from(err: anyhow::Error) -> Error {
|
||||||
|
Error::Other(err.to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Imap {
|
impl Imap {
|
||||||
/// Issues a CLOSE command to expunge selected folder.
|
/// Issues a CLOSE command to expunge selected folder.
|
||||||
///
|
///
|
||||||
/// CLOSE is considerably faster than an EXPUNGE, see
|
/// CLOSE is considerably faster than an EXPUNGE, see
|
||||||
/// <https://tools.ietf.org/html/rfc3501#section-6.4.2>
|
/// <https://tools.ietf.org/html/rfc3501#section-6.4.2>
|
||||||
pub(super) async fn close_folder(&mut self, context: &Context) -> Result<()> {
|
pub(super) async fn close_folder(&mut self, context: &Context) -> anyhow::Result<()> {
|
||||||
if let Some(ref folder) = self.config.selected_folder {
|
if let Some(ref folder) = self.config.selected_folder {
|
||||||
info!(context, "Expunge messages in \"{}\".", folder);
|
info!(context, "Expunge messages in \"{}\".", folder);
|
||||||
|
|
||||||
if let Some(ref mut session) = self.session {
|
let session = self.session.as_mut().context("no session")?;
|
||||||
match session.close().await {
|
if let Err(err) = session.close().await.context("IMAP close/expunge failed") {
|
||||||
Ok(_) => {
|
self.trigger_reconnect(context).await;
|
||||||
info!(context, "close/expunge succeeded");
|
return Err(err);
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
self.trigger_reconnect(context).await;
|
|
||||||
return Err(Error::CloseExpungeFailed(err));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return Err(Error::NoSession);
|
|
||||||
}
|
}
|
||||||
|
info!(context, "close/expunge succeeded");
|
||||||
}
|
}
|
||||||
self.config.selected_folder = None;
|
self.config.selected_folder = None;
|
||||||
self.config.selected_folder_needs_expunge = false;
|
self.config.selected_folder_needs_expunge = false;
|
||||||
@@ -56,7 +52,7 @@ impl Imap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Issues a CLOSE command if selected folder needs expunge.
|
/// Issues a CLOSE command if selected folder needs expunge.
|
||||||
pub(crate) async fn maybe_close_folder(&mut self, context: &Context) -> Result<()> {
|
pub(crate) async fn maybe_close_folder(&mut self, context: &Context) -> anyhow::Result<()> {
|
||||||
if self.config.selected_folder_needs_expunge {
|
if self.config.selected_folder_needs_expunge {
|
||||||
self.close_folder(context).await?;
|
self.close_folder(context).await?;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user