melib/imap: put imap-codec logic under the imap_backend feature

pull/223/head
Manos Pitsidianakis 2023-06-06 08:02:29 +03:00
parent 330887c4f5
commit 8f14a2373e
Signed by: Manos Pitsidianakis
GPG Key ID: 7729C7707F7E09D0
6 changed files with 122 additions and 96 deletions

View File

@ -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"

View File

@ -35,6 +35,7 @@ mod search;
pub use search::*;
mod cache;
use cache::{ImapCacheReset, ModSequence};
pub mod error;
pub mod managesieve;
mod untagged;

View File

@ -0,0 +1,115 @@
/*
* meli - imap module.
*
* Copyright 2023 Damian Poddebniak <poddebniak@mailbox.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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<LiteralError> 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<SequenceSetError> 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<S, L> From<AppendError<S, L>> for Error
where
AppendError<S, L>: fmt::Debug + fmt::Display + Sync + Send + 'static,
{
#[inline]
fn from(error: AppendError<S, L>) -> Error {
Error {
summary: error.to_string().into(),
details: None,
source: Some(Arc::new(error)),
kind: ErrorKind::Bug,
}
}
}
impl<S, L> From<CopyError<S, L>> for Error
where
CopyError<S, L>: fmt::Debug + fmt::Display + Sync + Send + 'static,
{
#[inline]
fn from(error: CopyError<S, L>) -> Error {
Error {
summary: error.to_string().into(),
details: None,
source: Some(Arc::new(error)),
kind: ErrorKind::Bug,
}
}
}
impl<S, M> From<MoveError<S, M>> for Error
where
MoveError<S, M>: fmt::Debug + fmt::Display + Sync + Send + 'static,
{
#[inline]
fn from(error: MoveError<S, M>) -> Error {
Error {
summary: error.to_string().into(),
details: None,
source: Some(Arc::new(error)),
kind: ErrorKind::Bug,
}
}
}
impl<L1, L2> From<ListError<L1, L2>> for Error
where
ListError<L1, L2>: fmt::Debug + fmt::Display + Sync + Send + 'static,
{
#[inline]
fn from(error: ListError<L1, L2>) -> Error {
Error {
summary: error.to_string().into(),
details: None,
source: Some(Arc::new(error)),
kind: ErrorKind::Bug,
}
}
}

View File

@ -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<ImapCodecFlag> {
let mut flags = Vec::new();

View File

@ -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<LiteralError> 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<SequenceSetError> 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<S, L> From<AppendError<S, L>> for Error
where
AppendError<S, L>: fmt::Debug + fmt::Display + Sync + Send + 'static,
{
#[inline]
fn from(error: AppendError<S, L>) -> Error {
Error {
summary: error.to_string().into(),
details: None,
source: Some(Arc::new(error)),
kind: ErrorKind::Bug,
}
}
}
impl<S, L> From<CopyError<S, L>> for Error
where
CopyError<S, L>: fmt::Debug + fmt::Display + Sync + Send + 'static,
{
#[inline]
fn from(error: CopyError<S, L>) -> Error {
Error {
summary: error.to_string().into(),
details: None,
source: Some(Arc::new(error)),
kind: ErrorKind::Bug,
}
}
}
impl<S, M> From<MoveError<S, M>> for Error
where
MoveError<S, M>: fmt::Debug + fmt::Display + Sync + Send + 'static,
{
#[inline]
fn from(error: MoveError<S, M>) -> Error {
Error {
summary: error.to_string().into(),
details: None,
source: Some(Arc::new(error)),
kind: ErrorKind::Bug,
}
}
}
impl<L1, L2> From<ListError<L1, L2>> for Error
where
ListError<L1, L2>: fmt::Debug + fmt::Display + Sync + Send + 'static,
{
#[inline]
fn from(error: ListError<L1, L2>) -> Error {
Error {
summary: error.to_string().into(),
details: None,
source: Some(Arc::new(error)),
kind: ErrorKind::Bug,
}
}
}

View File

@ -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"