diff --git a/src/imap/mod.rs b/src/imap/mod.rs index 20badb9c2..15a824159 100644 --- a/src/imap/mod.rs +++ b/src/imap/mod.rs @@ -36,9 +36,6 @@ type Result = std::result::Result; #[derive(Debug, Fail)] pub enum Error { - #[fail(display = "IMAP Could not obtain imap-session object.")] - NoSession, - #[fail(display = "IMAP Connect without configured params")] ConnectWithoutConfigure, @@ -63,15 +60,6 @@ pub enum Error { #[fail(display = "IMAP server does not have IDLE capability")] IdleAbilityMissing, - #[fail(display = "IMAP Connection Lost or no connection established")] - ConnectionLost, - - #[fail(display = "IMAP close/expunge failed: {}", _0)] - CloseExpungeFailed(#[cause] async_imap::error::Error), - - #[fail(display = "IMAP Folder name invalid: {:?}", _0)] - BadFolderName(String), - #[fail(display = "IMAP operation attempted while it is torn down")] InTeardown, @@ -81,6 +69,9 @@ pub enum Error { #[fail(display = "IMAP got error from elsewhere: {:?}", _0)] WrappedError(#[cause] crate::error::Error), + #[fail(display = "IMAP select folder error")] + SelectFolderError(#[cause] select_folder::Error), + #[fail(display = "IMAP other error: {:?}", _0)] Other(String), } @@ -103,6 +94,12 @@ impl From for crate::error::Error { } } +impl From for Error { + fn from(err: select_folder::Error) -> Error { + Error::SelectFolderError(err) + } +} + #[derive(Debug, Display, Clone, Copy, PartialEq, Eq)] pub enum ImapActionResult { Failed, @@ -1080,15 +1077,15 @@ impl Imap { } match self.select_folder(context, Some(&folder)).await { Ok(()) => None, - Err(Error::ConnectionLost) => { + Err(select_folder::Error::ConnectionLost) => { warn!(context, "Lost imap connection"); Some(ImapActionResult::RetryLater) } - Err(Error::NoSession) => { + Err(select_folder::Error::NoSession) => { warn!(context, "no imap session"); Some(ImapActionResult::Failed) } - Err(Error::BadFolderName(folder_name)) => { + Err(select_folder::Error::BadFolderName(folder_name)) => { warn!(context, "invalid folder name: {:?}", folder_name); Some(ImapActionResult::Failed) } diff --git a/src/imap/select_folder.rs b/src/imap/select_folder.rs index 46d13fb5e..7aa8884fd 100644 --- a/src/imap/select_folder.rs +++ b/src/imap/select_folder.rs @@ -1,6 +1,27 @@ -use super::{Result, Error, Imap}; +use super::Imap; + use crate::context::Context; +type Result = std::result::Result; + +#[derive(Debug, Fail)] +pub enum Error { + #[fail(display = "IMAP Could not obtain imap-session object.")] + NoSession, + + #[fail(display = "IMAP Connection Lost or no connection established")] + ConnectionLost, + + #[fail(display = "IMAP Folder name invalid: {:?}", _0)] + BadFolderName(String), + + #[fail(display = "IMAP close/expunge failed: {}", _0)] + CloseExpungeFailed(#[cause] async_imap::error::Error), + + #[fail(display = "IMAP other error: {:?}", _0)] + Other(String), +} + impl Imap { /// select a folder, possibly update uid_validity and, if needed, /// expunge the folder to remove delete-marked messages.