From 8f14a2373e16b9b4af22f9388fae84235dd08123 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Tue, 6 Jun 2023 08:02:29 +0300 Subject: [PATCH] melib/imap: put imap-codec logic under the imap_backend feature --- Cargo.toml | 1 + melib/src/backends/imap.rs | 1 + melib/src/backends/imap/error.rs | 115 +++++++++++++++++++++++++++++++ melib/src/email.rs | 6 +- melib/src/error.rs | 93 ------------------------- tools/Cargo.toml | 2 + 6 files changed, 122 insertions(+), 96 deletions(-) create mode 100644 melib/src/backends/imap/error.rs diff --git a/Cargo.toml b/Cargo.toml index 48c2df8d..c53dffbe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ path = "src/lib.rs" [[bin]] name = "managesieve-client" path = "src/managesieve.rs" +required-features = ["melib/imap_backend"] [dependencies] async-task = "^4.2.0" diff --git a/melib/src/backends/imap.rs b/melib/src/backends/imap.rs index ec561dbc..5d05e2f4 100644 --- a/melib/src/backends/imap.rs +++ b/melib/src/backends/imap.rs @@ -35,6 +35,7 @@ mod search; pub use search::*; mod cache; use cache::{ImapCacheReset, ModSequence}; +pub mod error; pub mod managesieve; mod untagged; diff --git a/melib/src/backends/imap/error.rs b/melib/src/backends/imap/error.rs new file mode 100644 index 00000000..7effdbb8 --- /dev/null +++ b/melib/src/backends/imap/error.rs @@ -0,0 +1,115 @@ +/* + * meli - imap module. + * + * Copyright 2023 Damian Poddebniak + * + * This file is part of meli. + * + * meli is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * meli is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with meli. If not, see . + */ + +use std::{fmt, sync::Arc}; + +use imap_codec::{ + command::{AppendError, CopyError, ListError}, + core::LiteralError, + extensions::r#move::MoveError, + sequence::SequenceSetError, +}; + +use crate::error::{Error, ErrorKind}; + +impl From for Error { + #[inline] + fn from(error: LiteralError) -> Error { + Error { + summary: error.to_string().into(), + details: None, + source: Some(Arc::new(error)), + kind: ErrorKind::Configuration, + } + } +} + +impl From for Error { + #[inline] + fn from(error: SequenceSetError) -> Error { + Error { + summary: error.to_string().into(), + details: None, + source: Some(Arc::new(error)), + kind: ErrorKind::Bug, + } + } +} + +impl From> for Error +where + AppendError: fmt::Debug + fmt::Display + Sync + Send + 'static, +{ + #[inline] + fn from(error: AppendError) -> Error { + Error { + summary: error.to_string().into(), + details: None, + source: Some(Arc::new(error)), + kind: ErrorKind::Bug, + } + } +} + +impl From> for Error +where + CopyError: fmt::Debug + fmt::Display + Sync + Send + 'static, +{ + #[inline] + fn from(error: CopyError) -> Error { + Error { + summary: error.to_string().into(), + details: None, + source: Some(Arc::new(error)), + kind: ErrorKind::Bug, + } + } +} + +impl From> for Error +where + MoveError: fmt::Debug + fmt::Display + Sync + Send + 'static, +{ + #[inline] + fn from(error: MoveError) -> Error { + Error { + summary: error.to_string().into(), + details: None, + source: Some(Arc::new(error)), + kind: ErrorKind::Bug, + } + } +} + +impl From> for Error +where + ListError: fmt::Debug + fmt::Display + Sync + Send + 'static, +{ + #[inline] + fn from(error: ListError) -> Error { + Error { + summary: error.to_string().into(), + details: None, + source: Some(Arc::new(error)), + kind: ErrorKind::Bug, + } + } +} diff --git a/melib/src/email.rs b/melib/src/email.rs index d2d6a413..5ec7533a 100644 --- a/melib/src/email.rs +++ b/melib/src/email.rs @@ -112,6 +112,7 @@ pub use address::{Address, MessageID, References, StrBuild, StrBuilder}; pub use attachments::{Attachment, AttachmentBuilder}; pub use compose::{attachment_from_file, Draft}; pub use headers::*; +#[cfg(feature = "imap_backend")] use imap_codec::{ core::{AString, Atom, NonEmptyVec}, fetch::{FetchAttribute, MacroOrFetchAttributes}, @@ -128,6 +129,7 @@ use crate::{ TagHash, }; +#[cfg(feature = "imap_backend")] // TODO(#222): Make this `const` as soon as it is possible. pub(crate) fn common_attributes() -> MacroOrFetchAttributes<'static> { MacroOrFetchAttributes::FetchAttributes(vec![ @@ -187,10 +189,8 @@ impl Flag { flag_impl!(fn is_trashed, Flag::TRASHED); flag_impl!(fn is_draft, Flag::DRAFT); flag_impl!(fn is_flagged, Flag::FLAGGED); -} -#[cfg(feature = "imap_backend")] -impl Flag { + #[cfg(feature = "imap_backend")] pub(crate) fn derive_imap_codec_flags(&self) -> Vec { let mut flags = Vec::new(); diff --git a/melib/src/error.rs b/melib/src/error.rs index 813e01cf..357ed726 100644 --- a/melib/src/error.rs +++ b/melib/src/error.rs @@ -716,96 +716,3 @@ impl<'a> From<&'a Error> for Error { kind.clone() } } - -// ----- imap-codec ----- - -use imap_codec::{ - command::{AppendError, CopyError, ListError}, - core::LiteralError, - extensions::r#move::MoveError, - sequence::SequenceSetError, -}; - -impl From for Error { - #[inline] - fn from(error: LiteralError) -> Error { - Error { - summary: error.to_string().into(), - details: None, - source: Some(Arc::new(error)), - kind: ErrorKind::Configuration, - } - } -} - -impl From for Error { - #[inline] - fn from(error: SequenceSetError) -> Error { - Error { - summary: error.to_string().into(), - details: None, - source: Some(Arc::new(error)), - kind: ErrorKind::Bug, - } - } -} - -impl From> for Error -where - AppendError: fmt::Debug + fmt::Display + Sync + Send + 'static, -{ - #[inline] - fn from(error: AppendError) -> Error { - Error { - summary: error.to_string().into(), - details: None, - source: Some(Arc::new(error)), - kind: ErrorKind::Bug, - } - } -} - -impl From> for Error -where - CopyError: fmt::Debug + fmt::Display + Sync + Send + 'static, -{ - #[inline] - fn from(error: CopyError) -> Error { - Error { - summary: error.to_string().into(), - details: None, - source: Some(Arc::new(error)), - kind: ErrorKind::Bug, - } - } -} - -impl From> for Error -where - MoveError: fmt::Debug + fmt::Display + Sync + Send + 'static, -{ - #[inline] - fn from(error: MoveError) -> Error { - Error { - summary: error.to_string().into(), - details: None, - source: Some(Arc::new(error)), - kind: ErrorKind::Bug, - } - } -} - -impl From> for Error -where - ListError: fmt::Debug + fmt::Display + Sync + Send + 'static, -{ - #[inline] - fn from(error: ListError) -> Error { - Error { - summary: error.to_string().into(), - details: None, - source: Some(Arc::new(error)), - kind: ErrorKind::Bug, - } - } -} diff --git a/tools/Cargo.toml b/tools/Cargo.toml index 423bf953..e0c766a2 100644 --- a/tools/Cargo.toml +++ b/tools/Cargo.toml @@ -16,10 +16,12 @@ path = "src/mboxparse.rs" [[bin]] name = "imapshell" path = "src/imapshell.rs" +required-features = ["melib/imap_backend"] [[bin]] name = "smtp_conn" path = "src/smtp_conn.rs" +required-features = ["melib/smtp"] [[bin]] name = "embed"