Create select_folder::Error

This commit is contained in:
Alexander Krotov
2019-12-03 20:39:35 +03:00
committed by holger krekel
parent 49b9b28c99
commit 069541f374
2 changed files with 34 additions and 16 deletions

View File

@@ -36,9 +36,6 @@ type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Fail)] #[derive(Debug, Fail)]
pub enum Error { pub enum Error {
#[fail(display = "IMAP Could not obtain imap-session object.")]
NoSession,
#[fail(display = "IMAP Connect without configured params")] #[fail(display = "IMAP Connect without configured params")]
ConnectWithoutConfigure, ConnectWithoutConfigure,
@@ -63,15 +60,6 @@ pub enum Error {
#[fail(display = "IMAP server does not have IDLE capability")] #[fail(display = "IMAP server does not have IDLE capability")]
IdleAbilityMissing, 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")] #[fail(display = "IMAP operation attempted while it is torn down")]
InTeardown, InTeardown,
@@ -81,6 +69,9 @@ pub enum Error {
#[fail(display = "IMAP got error from elsewhere: {:?}", _0)] #[fail(display = "IMAP got error from elsewhere: {:?}", _0)]
WrappedError(#[cause] crate::error::Error), WrappedError(#[cause] crate::error::Error),
#[fail(display = "IMAP select folder error")]
SelectFolderError(#[cause] select_folder::Error),
#[fail(display = "IMAP other error: {:?}", _0)] #[fail(display = "IMAP other error: {:?}", _0)]
Other(String), Other(String),
} }
@@ -103,6 +94,12 @@ impl From<Error> for crate::error::Error {
} }
} }
impl From<select_folder::Error> for Error {
fn from(err: select_folder::Error) -> Error {
Error::SelectFolderError(err)
}
}
#[derive(Debug, Display, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Display, Clone, Copy, PartialEq, Eq)]
pub enum ImapActionResult { pub enum ImapActionResult {
Failed, Failed,
@@ -1080,15 +1077,15 @@ impl Imap {
} }
match self.select_folder(context, Some(&folder)).await { match self.select_folder(context, Some(&folder)).await {
Ok(()) => None, Ok(()) => None,
Err(Error::ConnectionLost) => { Err(select_folder::Error::ConnectionLost) => {
warn!(context, "Lost imap connection"); warn!(context, "Lost imap connection");
Some(ImapActionResult::RetryLater) Some(ImapActionResult::RetryLater)
} }
Err(Error::NoSession) => { Err(select_folder::Error::NoSession) => {
warn!(context, "no imap session"); warn!(context, "no imap session");
Some(ImapActionResult::Failed) Some(ImapActionResult::Failed)
} }
Err(Error::BadFolderName(folder_name)) => { Err(select_folder::Error::BadFolderName(folder_name)) => {
warn!(context, "invalid folder name: {:?}", folder_name); warn!(context, "invalid folder name: {:?}", folder_name);
Some(ImapActionResult::Failed) Some(ImapActionResult::Failed)
} }

View File

@@ -1,6 +1,27 @@
use super::{Result, Error, Imap}; use super::Imap;
use crate::context::Context; use crate::context::Context;
type Result<T> = std::result::Result<T, Error>;
#[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 { impl Imap {
/// select a folder, possibly update uid_validity and, if needed, /// select a folder, possibly update uid_validity and, if needed,
/// expunge the folder to remove delete-marked messages. /// expunge the folder to remove delete-marked messages.