From 4f9705952ace576b5c4e2b5ccc5122e718cda1cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20DOUIN?= Date: Sat, 27 Jan 2024 11:15:03 +0100 Subject: [PATCH] refactor new backend api --- Cargo.lock | 16 +- Cargo.toml | 14 +- src/account/command/sync.rs | 136 +- src/account/config.rs | 26 +- src/backend/mod.rs | 1140 +++++++---------- src/config/mod.rs | 13 +- src/email/envelope/command/list.rs | 42 +- src/email/envelope/command/watch.rs | 48 +- src/email/envelope/config.rs | 16 +- src/email/envelope/flag/command/add.rs | 38 +- src/email/envelope/flag/command/remove.rs | 41 +- src/email/envelope/flag/command/set.rs | 38 +- src/email/envelope/mod.rs | 17 +- .../message/attachment/command/download.rs | 45 +- src/email/message/command/copy.rs | 43 +- src/email/message/command/delete.rs | 58 +- src/email/message/command/forward.rs | 68 +- src/email/message/command/mailto.rs | 68 +- src/email/message/command/mod.rs | 4 +- .../message/command/{move_.rs => move.rs} | 42 +- src/email/message/command/read.rs | 58 +- src/email/message/command/reply.rs | 68 +- src/email/message/command/save.rs | 46 +- src/email/message/command/send.rs | 83 +- src/email/message/command/write.rs | 68 +- src/email/message/config.rs | 37 +- src/email/message/template/command/forward.rs | 41 +- src/email/message/template/command/reply.rs | 41 +- src/email/message/template/command/save.rs | 38 +- src/email/message/template/command/send.rs | 75 +- src/folder/command/add.rs | 40 +- src/folder/command/delete.rs | 43 +- src/folder/command/expunge.rs | 43 +- src/folder/command/list.rs | 42 +- src/folder/command/purge.rs | 44 +- src/folder/config.rs | 32 +- src/ui/editor.rs | 4 +- 37 files changed, 819 insertions(+), 1897 deletions(-) rename src/email/message/command/{move_.rs => move.rs} (52%) diff --git a/Cargo.lock b/Cargo.lock index 189bf95..8e571f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1216,8 +1216,9 @@ dependencies = [ [[package]] name = "email-lib" -version = "0.20.1" -source = "git+https://git.sr.ht/~soywod/pimalaya#db699eb29b71e22bc74ccbb99003c3ac06816d69" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fe5898733e36f6faf030398be1481b8e80ed041372236a64bf7da0e05eb1223" dependencies = [ "advisory-lock", "anyhow", @@ -1225,6 +1226,7 @@ dependencies = [ "chrono", "convert_case", "dirs 4.0.0", + "email-macros", "email_address", "futures", "hickory-resolver", @@ -1262,6 +1264,16 @@ dependencies = [ "utf7-imap", ] +[[package]] +name = "email-macros" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c6354267c9a1db068b10ad982db9b8a82445f73f9bc9a57ed4924ddb913a065" +dependencies = [ + "quote", + "syn 2.0.41", +] + [[package]] name = "email_address" version = "0.2.4" diff --git a/Cargo.toml b/Cargo.toml index 7c1fe24..3501f65 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,19 +40,19 @@ default = [ # "pgp-native", ] -wizard = ["email-lib/account-discovery"] - imap = ["email-lib/imap"] maildir = ["email-lib/maildir"] notmuch = ["email-lib/notmuch"] smtp = ["email-lib/smtp"] sendmail = ["email-lib/sendmail"] +wizard = ["email-lib/account-discovery"] account = ["account-configure", "account-list", "account-sync"] account-subcmd = [] account-configure = ["account-subcmd"] account-list = ["account-subcmd"] -account-sync = ["account-subcmd", "email-lib/sync"] +account-sync = ["account-subcmd", "email-lib/account-sync"] + folder = ["folder-add", "folder-list", "folder-expunge", "folder-purge", "folder-delete"] folder-subcmd = [] folder-add = ["folder-subcmd", "email-lib/folder-add"] @@ -60,16 +60,19 @@ folder-list = ["folder-subcmd", "email-lib/folder-list"] folder-expunge = ["folder-subcmd", "email-lib/folder-expunge"] folder-purge = ["folder-subcmd", "email-lib/folder-purge"] folder-delete = ["folder-subcmd", "email-lib/folder-delete"] + envelope = ["envelope-list", "envelope-watch", "envelope-get"] envelope-subcmd = [] envelope-list = ["envelope-subcmd", "email-lib/envelope-list"] envelope-watch = ["envelope-subcmd", "email-lib/envelope-watch"] envelope-get = ["envelope-subcmd", "email-lib/envelope-get"] + flag = ["flag-add", "flag-set", "flag-remove"] flag-subcmd = [] flag-add = ["flag-subcmd", "email-lib/flag-add"] flag-set = ["flag-subcmd", "email-lib/flag-set"] flag-remove = ["flag-subcmd", "email-lib/flag-remove"] + message = ["message-read", "message-write", "message-mailto", "message-reply", "message-forward", "message-save", "message-send", "message-copy", "message-move", "message-delete"] message-subcmd = [] message-add = ["email-lib/message-add"] @@ -85,9 +88,11 @@ message-reply = ["message-get", "message-add", "message-send"] message-forward = ["message-get", "message-add", "message-send"] message-save = ["message-add"] message-send = ["message-subcmd", "email-lib/message-send"] + attachment = ["attachment-download"] attachment-subcmd = [] attachment-download = ["attachment-subcmd", "message-read"] + template = ["template-write", "template-reply", "template-forward", "template-save", "template-send"] template-subcmd = [] template-write = ["template-subcmd"] @@ -115,8 +120,7 @@ clap_mangen = "0.2" console = "0.15.2" dialoguer = "0.10.2" dirs = "4.0" -# email-lib = { version = "=0.20.1", default-features = false } -email-lib = { git = "https://git.sr.ht/~soywod/pimalaya", default-features = false } +email-lib = { version = "=0.21.0", default-features = false } email_address = "0.2.4" env_logger = "0.8" erased-serde = "0.3" diff --git a/src/account/command/sync.rs b/src/account/command/sync.rs index e0367af..5f6024e 100644 --- a/src/account/command/sync.rs +++ b/src/account/command/sync.rs @@ -1,7 +1,25 @@ +use crate::{ + account::{arg::name::OptionalAccountNameArg, config::TomlAccountConfig}, + backend::{Backend, BackendContextBuilder, BackendKind}, + config::TomlConfig, + printer::Printer, +}; use anyhow::Result; use clap::{ArgAction, Parser}; +#[cfg(feature = "imap")] +use email::imap::ImapContextBuilder; +#[cfg(feature = "account-sync")] +use email::maildir::config::MaildirConfig; +#[cfg(feature = "maildir")] +use email::maildir::MaildirContextBuilder; +#[cfg(feature = "notmuch")] +use email::notmuch::NotmuchContextBuilder; use email::{ - account::sync::{AccountSyncBuilder, AccountSyncProgressEvent}, + account::{ + config::AccountConfig, + sync::{AccountSyncBuilder, AccountSyncProgressEvent}, + }, + backend::BackendBuilder, folder::sync::FolderSyncStrategy, }; use indicatif::{MultiProgress, ProgressBar, ProgressFinish, ProgressStyle}; @@ -9,12 +27,8 @@ use log::info; use once_cell::sync::Lazy; use std::{ collections::{HashMap, HashSet}, - sync::Mutex, -}; - -use crate::{ - account::arg::name::OptionalAccountNameArg, backend::BackendBuilder, config::TomlConfig, - printer::Printer, + ops::Deref, + sync::{Arc, Mutex}, }; static MAIN_PROGRESS_STYLE: Lazy = Lazy::new(|| { @@ -101,8 +115,8 @@ impl AccountSyncCommand { let account_name = account_config.name.as_str(); let backend_builder = - BackendBuilder::new(toml_account_config, account_config.clone()).await?; - let sync_builder = AccountSyncBuilder::new(backend_builder.into()) + AccountSyncBackendBuilder::new(toml_account_config, account_config.clone()).await?; + let sync_builder = AccountSyncBuilder::new(account_config.clone(), backend_builder.into()) .await? .with_some_folders_strategy(strategy) .with_dry_run(self.dry_run); @@ -251,3 +265,107 @@ impl AccountSyncCommand { Ok(()) } } + +pub struct AccountSyncBackendBuilder { + toml_account_config: Arc, + builder: BackendBuilder, +} + +impl AccountSyncBackendBuilder { + pub async fn new( + toml_account_config: Arc, + account_config: Arc, + ) -> Result { + #[allow(unused)] + let used_backends = toml_account_config.get_used_backends(); + + #[cfg(feature = "imap")] + let is_imap_used = used_backends.contains(&BackendKind::Imap); + #[cfg(feature = "maildir")] + let is_maildir_used = used_backends.contains(&BackendKind::Maildir); + #[cfg(feature = "account-sync")] + let is_maildir_for_sync_used = used_backends.contains(&BackendKind::MaildirForSync); + #[cfg(feature = "notmuch")] + let is_notmuch_used = used_backends.contains(&BackendKind::Notmuch); + + let backend_ctx_builder = BackendContextBuilder { + toml_account_config: toml_account_config.clone(), + account_config: account_config.clone(), + + #[cfg(feature = "imap")] + imap: { + let builder = toml_account_config + .imap + .as_ref() + .filter(|_| is_imap_used) + .map(Clone::clone) + .map(Arc::new) + .map(|config| ImapContextBuilder::new(config).with_prebuilt_credentials()); + match builder { + Some(builder) => Some(builder.await?), + None => None, + } + }, + + #[cfg(feature = "maildir")] + maildir: toml_account_config + .maildir + .as_ref() + .filter(|_| is_maildir_used) + .map(Clone::clone) + .map(Arc::new) + .map(MaildirContextBuilder::new), + + #[cfg(feature = "account-sync")] + maildir_for_sync: Some(MaildirConfig { + root_dir: account_config.get_sync_dir()?, + }) + .filter(|_| is_maildir_for_sync_used) + .map(Arc::new) + .map(MaildirContextBuilder::new), + + #[cfg(feature = "notmuch")] + notmuch: toml_account_config + .notmuch + .as_ref() + .filter(|_| is_notmuch_used) + .map(Clone::clone) + .map(Arc::new) + .map(NotmuchContextBuilder::new), + + #[cfg(feature = "smtp")] + smtp: None, + + #[cfg(feature = "sendmail")] + sendmail: None, + }; + + let backend_builder = BackendBuilder::new(account_config.clone(), backend_ctx_builder); + + Ok(Self { + toml_account_config, + builder: backend_builder, + }) + } + + pub async fn build(self) -> Result { + Ok(Backend { + toml_account_config: self.toml_account_config, + backend: self.builder.build().await?, + }) + } +} + +impl Deref for AccountSyncBackendBuilder { + type Target = BackendBuilder; + + fn deref(&self) -> &Self::Target { + &self.builder + } +} + +impl From for BackendBuilder { + fn from(backend_builder: AccountSyncBackendBuilder) -> Self { + backend_builder.builder + } +} diff --git a/src/account/config.rs b/src/account/config.rs index 4268618..375b0cd 100644 --- a/src/account/config.rs +++ b/src/account/config.rs @@ -60,7 +60,7 @@ pub struct TomlAccountConfig { } impl TomlAccountConfig { - #[cfg(feature = "folder-add")] + #[cfg(any(feature = "account-sync", feature = "folder-add"))] pub fn add_folder_kind(&self) -> Option<&BackendKind> { self.folder .as_ref() @@ -69,7 +69,7 @@ impl TomlAccountConfig { .or(self.backend.as_ref()) } - #[cfg(feature = "folder-list")] + #[cfg(any(feature = "account-sync", feature = "folder-list"))] pub fn list_folders_kind(&self) -> Option<&BackendKind> { self.folder .as_ref() @@ -78,7 +78,7 @@ impl TomlAccountConfig { .or(self.backend.as_ref()) } - #[cfg(feature = "folder-expunge")] + #[cfg(any(feature = "account-sync", feature = "folder-expunge"))] pub fn expunge_folder_kind(&self) -> Option<&BackendKind> { self.folder .as_ref() @@ -96,7 +96,7 @@ impl TomlAccountConfig { .or(self.backend.as_ref()) } - #[cfg(feature = "folder-delete")] + #[cfg(any(feature = "account-sync", feature = "folder-delete"))] pub fn delete_folder_kind(&self) -> Option<&BackendKind> { self.folder .as_ref() @@ -105,7 +105,7 @@ impl TomlAccountConfig { .or(self.backend.as_ref()) } - #[cfg(feature = "envelope-get")] + #[cfg(any(feature = "account-sync", feature = "envelope-get"))] pub fn get_envelope_kind(&self) -> Option<&BackendKind> { self.envelope .as_ref() @@ -114,7 +114,7 @@ impl TomlAccountConfig { .or(self.backend.as_ref()) } - #[cfg(feature = "envelope-list")] + #[cfg(any(feature = "account-sync", feature = "envelope-list"))] pub fn list_envelopes_kind(&self) -> Option<&BackendKind> { self.envelope .as_ref() @@ -132,7 +132,7 @@ impl TomlAccountConfig { .or(self.backend.as_ref()) } - #[cfg(feature = "flag-add")] + #[cfg(any(feature = "account-sync", feature = "flag-add"))] pub fn add_flags_kind(&self) -> Option<&BackendKind> { self.flag .as_ref() @@ -141,7 +141,7 @@ impl TomlAccountConfig { .or(self.backend.as_ref()) } - #[cfg(feature = "flag-set")] + #[cfg(any(feature = "account-sync", feature = "flag-set"))] pub fn set_flags_kind(&self) -> Option<&BackendKind> { self.flag .as_ref() @@ -159,7 +159,7 @@ impl TomlAccountConfig { .or(self.backend.as_ref()) } - #[cfg(feature = "message-add")] + #[cfg(any(feature = "account-sync", feature = "message-add"))] pub fn add_message_kind(&self) -> Option<&BackendKind> { self.message .as_ref() @@ -168,7 +168,7 @@ impl TomlAccountConfig { .or(self.backend.as_ref()) } - #[cfg(feature = "message-peek")] + #[cfg(any(feature = "account-sync", feature = "message-peek"))] pub fn peek_messages_kind(&self) -> Option<&BackendKind> { self.message .as_ref() @@ -177,7 +177,7 @@ impl TomlAccountConfig { .or(self.backend.as_ref()) } - #[cfg(feature = "message-get")] + #[cfg(any(feature = "account-sync", feature = "message-get"))] pub fn get_messages_kind(&self) -> Option<&BackendKind> { self.message .as_ref() @@ -195,11 +195,11 @@ impl TomlAccountConfig { .or(self.backend.as_ref()) } - #[cfg(feature = "message-move")] + #[cfg(any(feature = "account-sync", feature = "message-move"))] pub fn move_messages_kind(&self) -> Option<&BackendKind> { self.message .as_ref() - .and_then(|message| message.move_.as_ref()) + .and_then(|message| message.r#move.as_ref()) .and_then(|move_| move_.backend.as_ref()) .or(self.backend.as_ref()) } diff --git a/src/backend/mod.rs b/src/backend/mod.rs index 6e9f439..d9a2475 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -4,126 +4,68 @@ pub(crate) mod wizard; use anyhow::Result; use async_trait::async_trait; -use std::ops::Deref; +use std::{ops::Deref, sync::Arc}; -use email::account::config::AccountConfig; -#[cfg(all(feature = "envelope-get", feature = "imap"))] -use email::envelope::get::imap::GetImapEnvelope; -#[cfg(all(feature = "envelope-get", feature = "maildir"))] -use email::envelope::get::maildir::GetMaildirEnvelope; -#[cfg(all(feature = "envelope-get", feature = "notmuch"))] -use email::envelope::get::notmuch::GetNotmuchEnvelope; -#[cfg(all(feature = "envelope-list", feature = "imap"))] -use email::envelope::list::imap::ListImapEnvelopes; -#[cfg(all(feature = "envelope-list", feature = "maildir"))] -use email::envelope::list::maildir::ListMaildirEnvelopes; -#[cfg(all(feature = "envelope-list", feature = "notmuch"))] -use email::envelope::list::notmuch::ListNotmuchEnvelopes; -#[cfg(all(feature = "envelope-watch", feature = "imap"))] -use email::envelope::watch::imap::WatchImapEnvelopes; -#[cfg(all(feature = "envelope-watch", feature = "maildir"))] -use email::envelope::watch::maildir::WatchMaildirEnvelopes; -// #[cfg(all(feature = "envelope-watch", feature = "notmuch"))] -// use email::envelope::watch::notmuch::WatchNotmuchEnvelopes; -#[cfg(feature = "message-add")] -use email::envelope::SingleId; -#[cfg(all(feature = "flag-add", feature = "imap"))] -use email::flag::add::imap::AddImapFlags; -#[cfg(all(feature = "flag-add", feature = "maildir"))] -use email::flag::add::maildir::AddMaildirFlags; -#[cfg(all(feature = "flag-add", feature = "notmuch"))] -use email::flag::add::notmuch::AddNotmuchFlags; -#[cfg(all(feature = "flag-remove", feature = "imap"))] -use email::flag::remove::imap::RemoveImapFlags; -#[cfg(all(feature = "flag-remove", feature = "maildir"))] -use email::flag::remove::maildir::RemoveMaildirFlags; -#[cfg(all(feature = "flag-remove", feature = "notmuch"))] -use email::flag::remove::notmuch::RemoveNotmuchFlags; -#[cfg(all(feature = "flag-set", feature = "imap"))] -use email::flag::set::imap::SetImapFlags; -#[cfg(all(feature = "flag-set", feature = "maildir"))] -use email::flag::set::maildir::SetMaildirFlags; -#[cfg(all(feature = "flag-set", feature = "notmuch"))] -use email::flag::set::notmuch::SetNotmuchFlags; -#[cfg(all(feature = "folder-add", feature = "imap"))] -use email::folder::add::imap::AddImapFolder; -#[cfg(all(feature = "folder-add", feature = "maildir"))] -use email::folder::add::maildir::AddMaildirFolder; -#[cfg(all(feature = "folder-add", feature = "notmuch"))] -use email::folder::add::notmuch::AddNotmuchFolder; -#[cfg(all(feature = "folder-delete", feature = "imap"))] -use email::folder::delete::imap::DeleteImapFolder; -#[cfg(all(feature = "folder-delete", feature = "maildir"))] -use email::folder::delete::maildir::DeleteMaildirFolder; -// #[cfg(all(feature = "folder-delete", feature = "notmuch"))] -// use email::folder::delete::notmuch::DeleteNotmuchFolder; -#[cfg(all(feature = "folder-expunge", feature = "imap"))] -use email::folder::expunge::imap::ExpungeImapFolder; -#[cfg(all(feature = "folder-expunge", feature = "maildir"))] -use email::folder::expunge::maildir::ExpungeMaildirFolder; -// #[cfg(all(feature = "folder-expunge", feature = "notmuch"))] -// use email::folder::expunge::notmuch::ExpungeNotmuchFolder; -#[cfg(all(feature = "folder-list", feature = "imap"))] -use email::folder::list::imap::ListImapFolders; -#[cfg(all(feature = "folder-list", feature = "maildir"))] -use email::folder::list::maildir::ListMaildirFolders; -#[cfg(all(feature = "folder-list", feature = "notmuch"))] -use email::folder::list::notmuch::ListNotmuchFolders; -#[cfg(all(feature = "folder-purge", feature = "imap"))] -use email::folder::purge::imap::PurgeImapFolder; -// #[cfg(all(feature = "folder-purge", feature = "maildir"))] -// use email::folder::purge::maildir::PurgeMaildirFolder; -// #[cfg(all(feature = "folder-purge", feature = "notmuch"))] -// use email::folder::purge::notmuch::PurgeNotmuchFolder; +#[cfg(any(feature = "account-sync", feature = "envelope-get"))] +use email::envelope::get::GetEnvelope; +#[cfg(any(feature = "account-sync", feature = "envelope-list"))] +use email::envelope::list::ListEnvelopes; +#[cfg(feature = "envelope-watch")] +use email::envelope::watch::WatchEnvelopes; +#[cfg(any(feature = "account-sync", feature = "flag-add"))] +use email::flag::add::AddFlags; +#[cfg(feature = "flag-remove")] +use email::flag::remove::RemoveFlags; +#[cfg(any(feature = "account-sync", feature = "flag-set"))] +use email::flag::set::SetFlags; +#[cfg(any(feature = "account-sync", feature = "folder-add"))] +use email::folder::add::AddFolder; +#[cfg(any(feature = "account-sync", feature = "folder-delete"))] +use email::folder::delete::DeleteFolder; +#[cfg(any(feature = "account-sync", feature = "folder-expunge"))] +use email::folder::expunge::ExpungeFolder; +#[cfg(any(feature = "account-sync", feature = "folder-list"))] +use email::folder::list::ListFolders; +#[cfg(feature = "folder-purge")] +use email::folder::purge::PurgeFolder; #[cfg(feature = "imap")] use email::imap::{ImapContextBuilder, ImapContextSync}; #[cfg(feature = "account-sync")] use email::maildir::config::MaildirConfig; -#[cfg(feature = "maildir")] +#[cfg(any(feature = "account-sync", feature = "maildir"))] use email::maildir::{MaildirContextBuilder, MaildirContextSync}; -#[cfg(all(feature = "message-add", feature = "imap"))] -use email::message::add::imap::AddImapMessage; -#[cfg(all(feature = "message-add", feature = "maildir"))] -use email::message::add::maildir::AddMaildirMessage; -#[cfg(all(feature = "message-add", feature = "notmuch"))] -use email::message::add::notmuch::AddNotmuchMessage; -#[cfg(all(feature = "message-copy", feature = "imap"))] -use email::message::copy::imap::CopyImapMessages; -#[cfg(all(feature = "message-copy", feature = "maildir"))] -use email::message::copy::maildir::CopyMaildirMessages; -#[cfg(all(feature = "message-copy", feature = "notmuch"))] -use email::message::copy::notmuch::CopyNotmuchMessages; -#[cfg(all(feature = "message-get", feature = "imap"))] -use email::message::get::imap::GetImapMessages; -#[cfg(all(feature = "message-move", feature = "imap"))] -use email::message::move_::imap::MoveImapMessages; -#[cfg(all(feature = "message-move", feature = "maildir"))] -use email::message::move_::maildir::MoveMaildirMessages; -#[cfg(all(feature = "message-move", feature = "notmuch"))] -use email::message::move_::notmuch::MoveNotmuchMessages; -#[cfg(all(feature = "message-peek", feature = "imap"))] -use email::message::peek::imap::PeekImapMessages; -#[cfg(all(feature = "message-peek", feature = "maildir"))] -use email::message::peek::maildir::PeekMaildirMessages; -#[cfg(all(feature = "message-peek", feature = "notmuch"))] -use email::message::peek::notmuch::PeekNotmuchMessages; -#[cfg(any(feature = "message-peek", feature = "message-get"))] -use email::message::Messages; +#[cfg(any(feature = "account-sync", feature = "message-add"))] +use email::message::add::AddMessage; +#[cfg(feature = "message-copy")] +use email::message::copy::CopyMessages; +#[cfg(feature = "message-delete")] +use email::message::delete::DeleteMessages; +#[cfg(any(feature = "account-sync", feature = "message-get"))] +use email::message::get::GetMessages; +#[cfg(any(feature = "account-sync", feature = "message-peek"))] +use email::message::peek::PeekMessages; +#[cfg(any(feature = "account-sync", feature = "message-move"))] +use email::message::r#move::MoveMessages; +#[cfg(feature = "message-send")] +use email::message::send::SendMessage; #[cfg(feature = "notmuch")] use email::notmuch::{NotmuchContextBuilder, NotmuchContextSync}; #[cfg(feature = "sendmail")] -use email::sendmail::{SendmailContext, SendmailContextBuilder}; +use email::sendmail::{SendmailContextBuilder, SendmailContextSync}; #[cfg(feature = "smtp")] use email::smtp::{SmtpContextBuilder, SmtpContextSync}; - -#[allow(unused)] use email::{ - envelope::Id, + account::config::AccountConfig, + backend::{ + macros::BackendContext, BackendFeatureBuilder, FindBackendSubcontext, MapBackendFeature, + }, + envelope::{Id, SingleId}, flag::{Flag, Flags}, + message::Messages, }; use serde::{Deserialize, Serialize}; -#[cfg(feature = "envelope-list")] +#[cfg(any(feature = "account-sync", feature = "envelope-list"))] use crate::envelope::Envelopes; use crate::{account::config::TomlAccountConfig, cache::IdMapper}; @@ -170,72 +112,96 @@ impl ToString for BackendKind { #[derive(Clone, Default)] pub struct BackendContextBuilder { + pub toml_account_config: Arc, + pub account_config: Arc, + #[cfg(feature = "imap")] pub imap: Option, + #[cfg(feature = "maildir")] pub maildir: Option, + #[cfg(feature = "account-sync")] pub maildir_for_sync: Option, + #[cfg(feature = "notmuch")] pub notmuch: Option, + #[cfg(feature = "smtp")] pub smtp: Option, + #[cfg(feature = "sendmail")] pub sendmail: Option, } impl BackendContextBuilder { - #[allow(unused)] pub async fn new( - toml_account_config: &TomlAccountConfig, - account_config: &AccountConfig, + toml_account_config: Arc, + account_config: Arc, kinds: Vec<&BackendKind>, ) -> Result { Ok(Self { + toml_account_config: toml_account_config.clone(), + account_config: account_config.clone(), + #[cfg(feature = "imap")] imap: { - let ctx_builder = toml_account_config + let builder = toml_account_config .imap .as_ref() .filter(|_| kinds.contains(&&BackendKind::Imap)) - .map(|config| { - ImapContextBuilder::new(config.clone()).with_prebuilt_credentials() - }); - match ctx_builder { - Some(ctx_builder) => Some(ctx_builder.await?), + .map(Clone::clone) + .map(Arc::new) + .map(|config| ImapContextBuilder::new(config).with_prebuilt_credentials()); + match builder { + Some(builder) => Some(builder.await?), None => None, } }, + #[cfg(feature = "maildir")] maildir: toml_account_config .maildir .as_ref() .filter(|_| kinds.contains(&&BackendKind::Maildir)) - .map(|config| MaildirContextBuilder::new(config.clone())), + .map(Clone::clone) + .map(Arc::new) + .map(MaildirContextBuilder::new), + #[cfg(feature = "account-sync")] maildir_for_sync: Some(MaildirConfig { root_dir: account_config.get_sync_dir()?, }) .filter(|_| kinds.contains(&&BackendKind::MaildirForSync)) - .map(|config| MaildirContextBuilder::new(config)), + .map(Arc::new) + .map(MaildirContextBuilder::new), + #[cfg(feature = "notmuch")] notmuch: toml_account_config .notmuch .as_ref() .filter(|_| kinds.contains(&&BackendKind::Notmuch)) - .map(|config| NotmuchContextBuilder::new(config.clone())), + .map(Clone::clone) + .map(Arc::new) + .map(NotmuchContextBuilder::new), + #[cfg(feature = "smtp")] smtp: toml_account_config .smtp .as_ref() .filter(|_| kinds.contains(&&BackendKind::Smtp)) - .map(|config| SmtpContextBuilder::new(config.clone())), + .map(Clone::clone) + .map(Arc::new) + .map(SmtpContextBuilder::new), + #[cfg(feature = "sendmail")] sendmail: toml_account_config .sendmail .as_ref() .filter(|_| kinds.contains(&&BackendKind::Sendmail)) - .map(|config| SendmailContextBuilder::new(config.clone())), + .map(Clone::clone) + .map(Arc::new) + .map(SendmailContextBuilder::new), }) } } @@ -244,616 +210,438 @@ impl BackendContextBuilder { impl email::backend::BackendContextBuilder for BackendContextBuilder { type Context = BackendContext; - async fn build(self, config: &AccountConfig) -> Result { - #[allow(unused_mut)] + #[cfg(any(feature = "account-sync", feature = "folder-add"))] + fn add_folder(&self) -> BackendFeatureBuilder { + match self.toml_account_config.add_folder_kind() { + #[cfg(feature = "imap")] + Some(BackendKind::Imap) => self.add_folder_from(self.imap.as_ref()), + #[cfg(feature = "maildir")] + Some(BackendKind::Maildir) => self.add_folder_from(self.maildir.as_ref()), + #[cfg(feature = "account-sync")] + Some(BackendKind::MaildirForSync) => { + let f = self.maildir_for_sync.as_ref()?.add_folder()?; + Some(Arc::new(move |ctx| f(ctx.maildir_for_sync.as_ref()?))) + } + #[cfg(feature = "notmuch")] + Some(BackendKind::Notmuch) => self.add_folder_from(self.notmuch.as_ref()), + _ => None, + } + } + + #[cfg(any(feature = "account-sync", feature = "folder-list"))] + fn list_folders(&self) -> BackendFeatureBuilder { + match self.toml_account_config.list_folders_kind() { + #[cfg(feature = "imap")] + Some(BackendKind::Imap) => self.list_folders_from(self.imap.as_ref()), + #[cfg(feature = "maildir")] + Some(BackendKind::Maildir) => self.list_folders_from(self.maildir.as_ref()), + #[cfg(feature = "account-sync")] + Some(BackendKind::MaildirForSync) => { + let f = self.maildir_for_sync.as_ref()?.list_folders()?; + Some(Arc::new(move |ctx| f(ctx.maildir_for_sync.as_ref()?))) + } + #[cfg(feature = "notmuch")] + Some(BackendKind::Notmuch) => self.list_folders_from(self.notmuch.as_ref()), + _ => None, + } + } + + #[cfg(any(feature = "account-sync", feature = "folder-expunge"))] + fn expunge_folder(&self) -> BackendFeatureBuilder { + match self.toml_account_config.expunge_folder_kind() { + #[cfg(feature = "imap")] + Some(BackendKind::Imap) => self.expunge_folder_from(self.imap.as_ref()), + #[cfg(feature = "maildir")] + Some(BackendKind::Maildir) => self.expunge_folder_from(self.maildir.as_ref()), + #[cfg(feature = "account-sync")] + Some(BackendKind::MaildirForSync) => { + let f = self.maildir_for_sync.as_ref()?.expunge_folder()?; + Some(Arc::new(move |ctx| f(ctx.maildir_for_sync.as_ref()?))) + } + #[cfg(feature = "notmuch")] + Some(BackendKind::Notmuch) => self.expunge_folder_from(self.notmuch.as_ref()), + _ => None, + } + } + + #[cfg(feature = "folder-purge")] + fn purge_folder(&self) -> BackendFeatureBuilder { + match self.toml_account_config.purge_folder_kind() { + #[cfg(feature = "imap")] + Some(BackendKind::Imap) => self.purge_folder_from(self.imap.as_ref()), + #[cfg(feature = "maildir")] + Some(BackendKind::Maildir) => self.purge_folder_from(self.maildir.as_ref()), + #[cfg(feature = "account-sync")] + Some(BackendKind::MaildirForSync) => { + let f = self.maildir_for_sync.as_ref()?.purge_folder()?; + Some(Arc::new(move |ctx| f(ctx.maildir_for_sync.as_ref()?))) + } + #[cfg(feature = "notmuch")] + Some(BackendKind::Notmuch) => self.purge_folder_from(self.notmuch.as_ref()), + _ => None, + } + } + + #[cfg(any(feature = "account-sync", feature = "folder-delete"))] + fn delete_folder(&self) -> BackendFeatureBuilder { + match self.toml_account_config.delete_folder_kind() { + #[cfg(feature = "imap")] + Some(BackendKind::Imap) => self.delete_folder_from(self.imap.as_ref()), + #[cfg(feature = "maildir")] + Some(BackendKind::Maildir) => self.delete_folder_from(self.maildir.as_ref()), + #[cfg(feature = "account-sync")] + Some(BackendKind::MaildirForSync) => { + let f = self.maildir_for_sync.as_ref()?.delete_folder()?; + Some(Arc::new(move |ctx| f(ctx.maildir_for_sync.as_ref()?))) + } + #[cfg(feature = "notmuch")] + Some(BackendKind::Notmuch) => self.delete_folder_from(self.notmuch.as_ref()), + _ => None, + } + } + + #[cfg(any(feature = "account-sync", feature = "envelope-list"))] + fn list_envelopes(&self) -> BackendFeatureBuilder { + match self.toml_account_config.list_envelopes_kind() { + #[cfg(feature = "imap")] + Some(BackendKind::Imap) => self.list_envelopes_from(self.imap.as_ref()), + #[cfg(feature = "maildir")] + Some(BackendKind::Maildir) => self.list_envelopes_from(self.maildir.as_ref()), + #[cfg(feature = "account-sync")] + Some(BackendKind::MaildirForSync) => { + let f = self.maildir_for_sync.as_ref()?.list_envelopes()?; + Some(Arc::new(move |ctx| f(ctx.maildir_for_sync.as_ref()?))) + } + #[cfg(feature = "notmuch")] + Some(BackendKind::Notmuch) => self.list_envelopes_from(self.notmuch.as_ref()), + _ => None, + } + } + + #[cfg(feature = "envelope-watch")] + fn watch_envelopes(&self) -> BackendFeatureBuilder { + match self.toml_account_config.watch_envelopes_kind() { + #[cfg(feature = "imap")] + Some(BackendKind::Imap) => self.watch_envelopes_from(self.imap.as_ref()), + #[cfg(feature = "maildir")] + Some(BackendKind::Maildir) => self.watch_envelopes_from(self.maildir.as_ref()), + #[cfg(feature = "account-sync")] + Some(BackendKind::MaildirForSync) => { + let f = self.maildir_for_sync.as_ref()?.watch_envelopes()?; + Some(Arc::new(move |ctx| f(ctx.maildir_for_sync.as_ref()?))) + } + #[cfg(feature = "notmuch")] + Some(BackendKind::Notmuch) => self.watch_envelopes_from(self.notmuch.as_ref()), + _ => None, + } + } + + #[cfg(any(feature = "account-sync", feature = "envelope-get"))] + fn get_envelope(&self) -> BackendFeatureBuilder { + match self.toml_account_config.get_envelope_kind() { + #[cfg(feature = "imap")] + Some(BackendKind::Imap) => self.get_envelope_from(self.imap.as_ref()), + #[cfg(feature = "maildir")] + Some(BackendKind::Maildir) => self.get_envelope_from(self.maildir.as_ref()), + #[cfg(feature = "account-sync")] + Some(BackendKind::MaildirForSync) => { + let f = self.maildir_for_sync.as_ref()?.get_envelope()?; + Some(Arc::new(move |ctx| f(ctx.maildir_for_sync.as_ref()?))) + } + #[cfg(feature = "notmuch")] + Some(BackendKind::Notmuch) => self.get_envelope_from(self.notmuch.as_ref()), + _ => None, + } + } + + #[cfg(any(feature = "account-sync", feature = "flag-add"))] + fn add_flags(&self) -> BackendFeatureBuilder { + match self.toml_account_config.add_flags_kind() { + #[cfg(feature = "imap")] + Some(BackendKind::Imap) => self.add_flags_from(self.imap.as_ref()), + #[cfg(feature = "maildir")] + Some(BackendKind::Maildir) => self.add_flags_from(self.maildir.as_ref()), + #[cfg(feature = "account-sync")] + Some(BackendKind::MaildirForSync) => { + let f = self.maildir_for_sync.as_ref()?.add_flags()?; + Some(Arc::new(move |ctx| f(ctx.maildir_for_sync.as_ref()?))) + } + #[cfg(feature = "notmuch")] + Some(BackendKind::Notmuch) => self.add_flags_from(self.notmuch.as_ref()), + _ => None, + } + } + + #[cfg(any(feature = "account-sync", feature = "flag-set"))] + fn set_flags(&self) -> BackendFeatureBuilder { + match self.toml_account_config.set_flags_kind() { + #[cfg(feature = "imap")] + Some(BackendKind::Imap) => self.set_flags_from(self.imap.as_ref()), + #[cfg(feature = "maildir")] + Some(BackendKind::Maildir) => self.set_flags_from(self.maildir.as_ref()), + #[cfg(feature = "account-sync")] + Some(BackendKind::MaildirForSync) => { + let f = self.maildir_for_sync.as_ref()?.set_flags()?; + Some(Arc::new(move |ctx| f(ctx.maildir_for_sync.as_ref()?))) + } + #[cfg(feature = "notmuch")] + Some(BackendKind::Notmuch) => self.set_flags_from(self.notmuch.as_ref()), + _ => None, + } + } + + #[cfg(feature = "flag-remove")] + fn remove_flags(&self) -> BackendFeatureBuilder { + match self.toml_account_config.remove_flags_kind() { + #[cfg(feature = "imap")] + Some(BackendKind::Imap) => self.remove_flags_from(self.imap.as_ref()), + #[cfg(feature = "maildir")] + Some(BackendKind::Maildir) => self.remove_flags_from(self.maildir.as_ref()), + #[cfg(feature = "account-sync")] + Some(BackendKind::MaildirForSync) => { + let f = self.maildir_for_sync.as_ref()?.remove_flags()?; + Some(Arc::new(move |ctx| f(ctx.maildir_for_sync.as_ref()?))) + } + #[cfg(feature = "notmuch")] + Some(BackendKind::Notmuch) => self.remove_flags_from(self.notmuch.as_ref()), + _ => None, + } + } + + #[cfg(any(feature = "account-sync", feature = "message-add"))] + fn add_message(&self) -> BackendFeatureBuilder { + match self.toml_account_config.add_message_kind() { + #[cfg(feature = "imap")] + Some(BackendKind::Imap) => self.add_message_from(self.imap.as_ref()), + #[cfg(feature = "maildir")] + Some(BackendKind::Maildir) => self.add_message_from(self.maildir.as_ref()), + #[cfg(feature = "account-sync")] + Some(BackendKind::MaildirForSync) => { + let f = self.maildir_for_sync.as_ref()?.add_message()?; + Some(Arc::new(move |ctx| f(ctx.maildir_for_sync.as_ref()?))) + } + #[cfg(feature = "notmuch")] + Some(BackendKind::Notmuch) => self.add_message_from(self.notmuch.as_ref()), + _ => None, + } + } + + #[cfg(feature = "message-send")] + fn send_message(&self) -> BackendFeatureBuilder { + match self.toml_account_config.send_message_kind() { + #[cfg(feature = "smtp")] + Some(BackendKind::Smtp) => self.send_message_from(self.smtp.as_ref()), + #[cfg(feature = "sendmail")] + Some(BackendKind::Sendmail) => self.send_message_from(self.sendmail.as_ref()), + _ => None, + } + } + + #[cfg(any(feature = "account-sync", feature = "message-peek"))] + fn peek_messages(&self) -> BackendFeatureBuilder { + match self.toml_account_config.peek_messages_kind() { + #[cfg(feature = "imap")] + Some(BackendKind::Imap) => self.peek_messages_from(self.imap.as_ref()), + #[cfg(feature = "maildir")] + Some(BackendKind::Maildir) => self.peek_messages_from(self.maildir.as_ref()), + #[cfg(feature = "account-sync")] + Some(BackendKind::MaildirForSync) => { + let f = self.maildir_for_sync.as_ref()?.peek_messages()?; + Some(Arc::new(move |ctx| f(ctx.maildir_for_sync.as_ref()?))) + } + #[cfg(feature = "notmuch")] + Some(BackendKind::Notmuch) => self.peek_messages_from(self.notmuch.as_ref()), + _ => None, + } + } + + #[cfg(any(feature = "account-sync", feature = "message-get"))] + fn get_messages(&self) -> BackendFeatureBuilder { + match self.toml_account_config.get_messages_kind() { + #[cfg(feature = "imap")] + Some(BackendKind::Imap) => self.get_messages_from(self.imap.as_ref()), + #[cfg(feature = "maildir")] + Some(BackendKind::Maildir) => self.get_messages_from(self.maildir.as_ref()), + #[cfg(feature = "account-sync")] + Some(BackendKind::MaildirForSync) => { + let f = self.maildir_for_sync.as_ref()?.get_messages()?; + Some(Arc::new(move |ctx| f(ctx.maildir_for_sync.as_ref()?))) + } + #[cfg(feature = "notmuch")] + Some(BackendKind::Notmuch) => self.get_messages_from(self.notmuch.as_ref()), + _ => None, + } + } + + #[cfg(feature = "message-copy")] + fn copy_messages(&self) -> BackendFeatureBuilder { + match self.toml_account_config.copy_messages_kind() { + #[cfg(feature = "imap")] + Some(BackendKind::Imap) => self.copy_messages_from(self.imap.as_ref()), + #[cfg(feature = "maildir")] + Some(BackendKind::Maildir) => self.copy_messages_from(self.maildir.as_ref()), + #[cfg(feature = "account-sync")] + Some(BackendKind::MaildirForSync) => { + let f = self.maildir_for_sync.as_ref()?.copy_messages()?; + Some(Arc::new(move |ctx| f(ctx.maildir_for_sync.as_ref()?))) + } + #[cfg(feature = "notmuch")] + Some(BackendKind::Notmuch) => self.copy_messages_from(self.notmuch.as_ref()), + _ => None, + } + } + + #[cfg(any(feature = "account-sync", feature = "message-move"))] + fn move_messages(&self) -> BackendFeatureBuilder { + match self.toml_account_config.move_messages_kind() { + #[cfg(feature = "imap")] + Some(BackendKind::Imap) => self.move_messages_from(self.imap.as_ref()), + #[cfg(feature = "maildir")] + Some(BackendKind::Maildir) => self.move_messages_from(self.maildir.as_ref()), + #[cfg(feature = "account-sync")] + Some(BackendKind::MaildirForSync) => { + let f = self.maildir_for_sync.as_ref()?.move_messages()?; + Some(Arc::new(move |ctx| f(ctx.maildir_for_sync.as_ref()?))) + } + #[cfg(feature = "notmuch")] + Some(BackendKind::Notmuch) => self.move_messages_from(self.notmuch.as_ref()), + _ => None, + } + } + + #[cfg(feature = "message-delete")] + fn delete_messages(&self) -> BackendFeatureBuilder { + match self.toml_account_config.delete_messages_kind() { + #[cfg(feature = "imap")] + Some(BackendKind::Imap) => self.delete_messages_from(self.imap.as_ref()), + #[cfg(feature = "maildir")] + Some(BackendKind::Maildir) => self.delete_messages_from(self.maildir.as_ref()), + #[cfg(feature = "account-sync")] + Some(BackendKind::MaildirForSync) => { + let f = self.maildir_for_sync.as_ref()?.delete_messages()?; + Some(Arc::new(move |ctx| f(ctx.maildir_for_sync.as_ref()?))) + } + #[cfg(feature = "notmuch")] + Some(BackendKind::Notmuch) => self.delete_messages_from(self.notmuch.as_ref()), + _ => None, + } + } + + async fn build(self, config: Arc) -> Result { let mut ctx = BackendContext::default(); #[cfg(feature = "imap")] if let Some(imap) = self.imap { - ctx.imap = Some(imap.build(config).await?); + ctx.imap = Some(imap.build(config.clone()).await?); } #[cfg(feature = "maildir")] if let Some(maildir) = self.maildir { - ctx.maildir = Some(maildir.build(config).await?); + ctx.maildir = Some(maildir.build(config.clone()).await?); } #[cfg(feature = "account-sync")] if let Some(maildir) = self.maildir_for_sync { - ctx.maildir_for_sync = Some(maildir.build(config).await?); + ctx.maildir_for_sync = Some(maildir.build(config.clone()).await?); } #[cfg(feature = "notmuch")] if let Some(notmuch) = self.notmuch { - ctx.notmuch = Some(notmuch.build(config).await?); + ctx.notmuch = Some(notmuch.build(config.clone()).await?); } #[cfg(feature = "smtp")] if let Some(smtp) = self.smtp { - ctx.smtp = Some(smtp.build(config).await?); + ctx.smtp = Some(smtp.build(config.clone()).await?); } #[cfg(feature = "sendmail")] if let Some(sendmail) = self.sendmail { - ctx.sendmail = Some(sendmail.build(config).await?); + ctx.sendmail = Some(sendmail.build(config.clone()).await?); } Ok(ctx) } } -#[derive(Default)] +#[derive(BackendContext, Default)] pub struct BackendContext { #[cfg(feature = "imap")] pub imap: Option, + #[cfg(feature = "maildir")] pub maildir: Option, + #[cfg(feature = "account-sync")] pub maildir_for_sync: Option, + #[cfg(feature = "notmuch")] pub notmuch: Option, + #[cfg(feature = "smtp")] pub smtp: Option, + #[cfg(feature = "sendmail")] - pub sendmail: Option, + pub sendmail: Option, } -pub struct BackendBuilder { - toml_account_config: TomlAccountConfig, - builder: email::backend::BackendBuilder, -} - -impl BackendBuilder { - pub async fn new( - toml_account_config: TomlAccountConfig, - account_config: AccountConfig, - ) -> Result { - #[allow(unused)] - let used_backends = toml_account_config.get_used_backends(); - - #[cfg(feature = "imap")] - let is_imap_used = used_backends.contains(&BackendKind::Imap); - #[cfg(feature = "maildir")] - let is_maildir_used = used_backends.contains(&BackendKind::Maildir); - #[cfg(feature = "account-sync")] - let is_maildir_for_sync_used = used_backends.contains(&BackendKind::MaildirForSync); - - let backend_ctx_builder = BackendContextBuilder { - #[cfg(feature = "imap")] - imap: { - let ctx_builder = toml_account_config - .imap - .as_ref() - .filter(|_| is_imap_used) - .map(|config| { - ImapContextBuilder::new(config.clone()).with_prebuilt_credentials() - }); - - match ctx_builder { - Some(ctx_builder) => Some(ctx_builder.await?), - None => None, - } - }, - #[cfg(feature = "maildir")] - maildir: toml_account_config - .maildir - .as_ref() - .filter(|_| is_maildir_used) - .map(|config| MaildirContextBuilder::new(config.clone())), - #[cfg(feature = "account-sync")] - maildir_for_sync: Some(MaildirConfig { - root_dir: account_config.get_sync_dir()?, - }) - .filter(|_| is_maildir_for_sync_used) - .map(|config| MaildirContextBuilder::new(config)), - ..Default::default() - }; - - #[allow(unused_mut)] - let mut backend_builder = - email::backend::BackendBuilder::new(account_config.clone(), backend_ctx_builder); - - #[cfg(feature = "folder-add")] - match toml_account_config.add_folder_kind() { - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - backend_builder = backend_builder - .with_add_folder(|ctx| ctx.maildir.as_ref().map(AddMaildirFolder::new_boxed)); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - backend_builder = backend_builder.with_add_folder(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(AddMaildirFolder::new_boxed) - }); - } - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - backend_builder = backend_builder - .with_add_folder(|ctx| ctx.imap.as_ref().map(AddImapFolder::new_boxed)); - } - #[cfg(feature = "notmuch")] - Some(BackendKind::Notmuch) => { - backend_builder = backend_builder - .with_add_folder(|ctx| ctx.notmuch.as_ref().map(AddNotmuchFolder::new_boxed)); - } - _ => (), - } - - #[cfg(feature = "folder-list")] - match toml_account_config.list_folders_kind() { - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - backend_builder = backend_builder.with_list_folders(|ctx| { - ctx.maildir.as_ref().map(ListMaildirFolders::new_boxed) - }); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - backend_builder = backend_builder.with_list_folders(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(ListMaildirFolders::new_boxed) - }); - } - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - backend_builder = backend_builder - .with_list_folders(|ctx| ctx.imap.as_ref().map(ListImapFolders::new_boxed)); - } - #[cfg(feature = "notmuch")] - Some(BackendKind::Notmuch) => { - backend_builder = backend_builder.with_list_folders(|ctx| { - ctx.notmuch.as_ref().map(ListNotmuchFolders::new_boxed) - }); - } - _ => (), - } - - #[cfg(feature = "folder-expunge")] - match toml_account_config.expunge_folder_kind() { - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - backend_builder = backend_builder.with_expunge_folder(|ctx| { - ctx.maildir.as_ref().map(ExpungeMaildirFolder::new_boxed) - }); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - backend_builder = backend_builder.with_expunge_folder(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(ExpungeMaildirFolder::new_boxed) - }); - } - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - backend_builder = backend_builder - .with_expunge_folder(|ctx| ctx.imap.as_ref().map(ExpungeImapFolder::new_boxed)); - } - #[cfg(feature = "notmuch")] - Some(BackendKind::Notmuch) => { - // TODO - // backend_builder = backend_builder.with_expunge_folder(|ctx| { - // ctx.notmuch.as_ref().map(ExpungeNotmuchFolder::new_boxed) - // }); - } - _ => (), - } - - #[cfg(feature = "folder-purge")] - match toml_account_config.purge_folder_kind() { - // TODO - // #[cfg(feature = "maildir")] - // Some(BackendKind::Maildir) => { - // backend_builder = backend_builder - // .with_purge_folder(|ctx| ctx.maildir.as_ref().map(PurgeMaildirFolder::new_boxed)); - // } - // TODO - // #[cfg(feature = "account-sync")] - // Some(BackendKind::MaildirForSync) => { - // backend_builder = backend_builder - // .with_purge_folder(|ctx| ctx.maildir_for_sync.as_ref().map(PurgeMaildirFolder::new_boxed)); - // } - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - backend_builder = backend_builder - .with_purge_folder(|ctx| ctx.imap.as_ref().map(PurgeImapFolder::new_boxed)); - } - #[cfg(feature = "notmuch")] - Some(BackendKind::Notmuch) => { - // TODO - // backend_builder = backend_builder.with_purge_folder(|ctx| { - // ctx.notmuch.as_ref().map(PurgeNotmuchFolder::new_boxed) - // }); - } - _ => (), - } - - #[cfg(feature = "folder-delete")] - match toml_account_config.delete_folder_kind() { - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - backend_builder = backend_builder.with_delete_folder(|ctx| { - ctx.maildir.as_ref().map(DeleteMaildirFolder::new_boxed) - }); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - backend_builder = backend_builder.with_delete_folder(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(DeleteMaildirFolder::new_boxed) - }); - } - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - backend_builder = backend_builder - .with_delete_folder(|ctx| ctx.imap.as_ref().map(DeleteImapFolder::new_boxed)); - } - #[cfg(feature = "notmuch")] - Some(BackendKind::Notmuch) => { - // TODO - // backend_builder = backend_builder.with_delete_folder(|ctx| { - // ctx.notmuch.as_ref().map(DeleteNotmuchFolder::new_boxed) - // }); - } - _ => (), - } - - #[cfg(feature = "envelope-list")] - match toml_account_config.list_envelopes_kind() { - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - backend_builder = backend_builder.with_list_envelopes(|ctx| { - ctx.maildir.as_ref().map(ListMaildirEnvelopes::new_boxed) - }); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - backend_builder = backend_builder.with_list_envelopes(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(ListMaildirEnvelopes::new_boxed) - }); - } - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - backend_builder = backend_builder - .with_list_envelopes(|ctx| ctx.imap.as_ref().map(ListImapEnvelopes::new_boxed)); - } - #[cfg(feature = "notmuch")] - Some(BackendKind::Notmuch) => { - backend_builder = backend_builder.with_list_envelopes(|ctx| { - ctx.notmuch.as_ref().map(ListNotmuchEnvelopes::new_boxed) - }); - } - _ => (), - } - - #[cfg(feature = "envelope-watch")] - match toml_account_config.watch_envelopes_kind() { - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - backend_builder = backend_builder.with_watch_envelopes(|ctx| { - ctx.maildir.as_ref().map(WatchMaildirEnvelopes::new_boxed) - }); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - backend_builder = backend_builder.with_watch_envelopes(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(WatchMaildirEnvelopes::new_boxed) - }); - } - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - backend_builder = backend_builder.with_watch_envelopes(|ctx| { - ctx.imap.as_ref().map(WatchImapEnvelopes::new_boxed) - }); - } - #[cfg(feature = "notmuch")] - Some(BackendKind::Notmuch) => { - // TODO - // backend_builder = backend_builder.with_watch_envelopes(|ctx| { - // ctx.notmuch.as_ref().map(WatchNotmuchEnvelopes::new_boxed) - // }); - } - _ => (), - } - - #[cfg(feature = "envelope-get")] - match toml_account_config.get_envelope_kind() { - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - backend_builder = backend_builder.with_get_envelope(|ctx| { - ctx.maildir.as_ref().map(GetMaildirEnvelope::new_boxed) - }); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - backend_builder = backend_builder.with_get_envelope(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(GetMaildirEnvelope::new_boxed) - }); - } - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - backend_builder = backend_builder - .with_get_envelope(|ctx| ctx.imap.as_ref().map(GetImapEnvelope::new_boxed)); - } - #[cfg(feature = "notmuch")] - Some(BackendKind::Notmuch) => { - backend_builder = backend_builder.with_get_envelope(|ctx| { - ctx.notmuch.as_ref().map(GetNotmuchEnvelope::new_boxed) - }); - } - _ => (), - } - - #[cfg(feature = "flag-add")] - match toml_account_config.add_flags_kind() { - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - backend_builder = backend_builder - .with_add_flags(|ctx| ctx.maildir.as_ref().map(AddMaildirFlags::new_boxed)); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - backend_builder = backend_builder.with_add_flags(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(AddMaildirFlags::new_boxed) - }); - } - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - backend_builder = backend_builder - .with_add_flags(|ctx| ctx.imap.as_ref().map(AddImapFlags::new_boxed)); - } - #[cfg(feature = "notmuch")] - Some(BackendKind::Notmuch) => { - backend_builder = backend_builder - .with_add_flags(|ctx| ctx.notmuch.as_ref().map(AddNotmuchFlags::new_boxed)); - } - _ => (), - } - - #[cfg(feature = "flag-set")] - match toml_account_config.set_flags_kind() { - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - backend_builder = backend_builder - .with_set_flags(|ctx| ctx.maildir.as_ref().map(SetMaildirFlags::new_boxed)); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - backend_builder = backend_builder.with_set_flags(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(SetMaildirFlags::new_boxed) - }); - } - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - backend_builder = backend_builder - .with_set_flags(|ctx| ctx.imap.as_ref().map(SetImapFlags::new_boxed)); - } - #[cfg(feature = "notmuch")] - Some(BackendKind::Notmuch) => { - backend_builder = backend_builder - .with_set_flags(|ctx| ctx.notmuch.as_ref().map(SetNotmuchFlags::new_boxed)); - } - _ => (), - } - - #[cfg(feature = "flag-remove")] - match toml_account_config.remove_flags_kind() { - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - backend_builder = backend_builder.with_remove_flags(|ctx| { - ctx.maildir.as_ref().map(RemoveMaildirFlags::new_boxed) - }); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - backend_builder = backend_builder.with_remove_flags(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(RemoveMaildirFlags::new_boxed) - }); - } - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - backend_builder = backend_builder - .with_remove_flags(|ctx| ctx.imap.as_ref().map(RemoveImapFlags::new_boxed)); - } - #[cfg(feature = "notmuch")] - Some(BackendKind::Notmuch) => { - backend_builder = backend_builder.with_remove_flags(|ctx| { - ctx.notmuch.as_ref().map(RemoveNotmuchFlags::new_boxed) - }); - } - _ => (), - } - - #[cfg(feature = "message-add")] - match toml_account_config.add_message_kind() { - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - backend_builder = backend_builder - .with_add_message(|ctx| ctx.imap.as_ref().map(AddImapMessage::new_boxed)) - .with_add_message(|ctx| ctx.imap.as_ref().map(AddImapMessage::new_boxed)); - } - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - backend_builder = backend_builder - .with_add_message(|ctx| ctx.maildir.as_ref().map(AddMaildirMessage::new_boxed)); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - backend_builder = backend_builder.with_add_message(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(AddMaildirMessage::new_boxed) - }); - } - #[cfg(feature = "notmuch")] - Some(BackendKind::Notmuch) => { - backend_builder = backend_builder - .with_add_message(|ctx| ctx.notmuch.as_ref().map(AddNotmuchMessage::new_boxed)); - } - _ => (), - } - - #[cfg(feature = "message-peek")] - match toml_account_config.peek_messages_kind() { - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - backend_builder = backend_builder.with_peek_messages(|ctx| { - ctx.maildir.as_ref().map(PeekMaildirMessages::new_boxed) - }); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - backend_builder = backend_builder.with_peek_messages(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(PeekMaildirMessages::new_boxed) - }); - } - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - backend_builder = backend_builder - .with_peek_messages(|ctx| ctx.imap.as_ref().map(PeekImapMessages::new_boxed)); - } - #[cfg(feature = "notmuch")] - Some(BackendKind::Notmuch) => { - backend_builder = backend_builder.with_peek_messages(|ctx| { - ctx.notmuch.as_ref().map(PeekNotmuchMessages::new_boxed) - }); - } - _ => (), - } - - #[cfg(feature = "message-get")] - match toml_account_config.get_messages_kind() { - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - backend_builder = backend_builder - .with_get_messages(|ctx| ctx.imap.as_ref().map(GetImapMessages::new_boxed)); - } - _ => (), - } - - #[cfg(feature = "message-copy")] - match toml_account_config.copy_messages_kind() { - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - backend_builder = backend_builder.with_copy_messages(|ctx| { - ctx.maildir.as_ref().map(CopyMaildirMessages::new_boxed) - }); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - backend_builder = backend_builder.with_copy_messages(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(CopyMaildirMessages::new_boxed) - }); - } - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - backend_builder = backend_builder - .with_copy_messages(|ctx| ctx.imap.as_ref().map(CopyImapMessages::new_boxed)); - } - #[cfg(feature = "notmuch")] - Some(BackendKind::Notmuch) => { - backend_builder = backend_builder.with_copy_messages(|ctx| { - ctx.notmuch.as_ref().map(CopyNotmuchMessages::new_boxed) - }); - } - _ => (), - } - - #[cfg(feature = "message-move")] - match toml_account_config.move_messages_kind() { - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - backend_builder = backend_builder.with_move_messages(|ctx| { - ctx.maildir.as_ref().map(MoveMaildirMessages::new_boxed) - }); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - backend_builder = backend_builder.with_move_messages(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(MoveMaildirMessages::new_boxed) - }); - } - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - backend_builder = backend_builder - .with_move_messages(|ctx| ctx.imap.as_ref().map(MoveImapMessages::new_boxed)); - } - #[cfg(feature = "notmuch")] - Some(BackendKind::Notmuch) => { - backend_builder = backend_builder.with_move_messages(|ctx| { - ctx.notmuch.as_ref().map(MoveNotmuchMessages::new_boxed) - }); - } - _ => (), - } - - Ok(Self { - toml_account_config, - builder: backend_builder, - }) - } - - pub async fn build(self) -> Result { - Ok(Backend { - toml_account_config: self.toml_account_config, - backend: self.builder.build().await?, - }) +#[cfg(feature = "imap")] +impl FindBackendSubcontext for BackendContext { + fn find_subcontext(&self) -> Option<&ImapContextSync> { + self.imap.as_ref() } } -impl Deref for BackendBuilder { - type Target = email::backend::BackendBuilder; - - fn deref(&self) -> &Self::Target { - &self.builder +#[cfg(feature = "maildir")] +impl FindBackendSubcontext for BackendContext { + fn find_subcontext(&self) -> Option<&MaildirContextSync> { + self.maildir.as_ref() } } -impl From for email::backend::BackendBuilder { - fn from(backend_builder: BackendBuilder) -> Self { - backend_builder.builder + +#[cfg(feature = "notmuch")] +impl FindBackendSubcontext for BackendContext { + fn find_subcontext(&self) -> Option<&NotmuchContextSync> { + self.notmuch.as_ref() + } +} + +#[cfg(feature = "smtp")] +impl FindBackendSubcontext for BackendContext { + fn find_subcontext(&self) -> Option<&SmtpContextSync> { + self.smtp.as_ref() + } +} + +#[cfg(feature = "sendmail")] +impl FindBackendSubcontext for BackendContext { + fn find_subcontext(&self) -> Option<&SendmailContextSync> { + self.sendmail.as_ref() } } pub struct Backend { - #[allow(unused)] - toml_account_config: TomlAccountConfig, - backend: email::backend::Backend, + pub toml_account_config: Arc, + pub backend: email::backend::Backend, } impl Backend { pub async fn new( - toml_account_config: &TomlAccountConfig, - account_config: &AccountConfig, + toml_account_config: Arc, + account_config: Arc, backend_kinds: impl IntoIterator, with_features: impl Fn(&mut email::backend::BackendBuilder), ) -> Result { let backend_kinds = backend_kinds.into_iter().collect(); - let backend_ctx_builder = - BackendContextBuilder::new(toml_account_config, account_config, backend_kinds).await?; + let backend_ctx_builder = BackendContextBuilder::new( + toml_account_config.clone(), + account_config.clone(), + backend_kinds, + ) + .await?; let mut backend_builder = - email::backend::BackendBuilder::new(account_config.clone(), backend_ctx_builder); + email::backend::BackendBuilder::new(account_config.clone(), backend_ctx_builder) + .with_default_features_disabled(); with_features(&mut backend_builder); @@ -883,6 +671,7 @@ impl Backend { )?; } } + #[cfg(feature = "account-sync")] Some(BackendKind::MaildirForSync) => { id_mapper = IdMapper::new( @@ -891,6 +680,7 @@ impl Backend { self.backend.account_config.get_sync_dir()?, )?; } + #[cfg(feature = "notmuch")] Some(BackendKind::Notmuch) => { if let Some(notmuch_config) = &self.toml_account_config.notmuch { @@ -907,7 +697,7 @@ impl Backend { Ok(id_mapper) } - #[cfg(feature = "envelope-list")] + #[cfg(any(feature = "account-sync", feature = "envelope-list"))] pub async fn list_envelopes( &self, folder: &str, @@ -921,7 +711,7 @@ impl Backend { Ok(envelopes) } - #[cfg(feature = "flag-add")] + #[cfg(any(feature = "account-sync", feature = "flag-add"))] pub async fn add_flags(&self, folder: &str, ids: &[usize], flags: &Flags) -> Result<()> { let backend_kind = self.toml_account_config.add_flags_kind(); let id_mapper = self.build_id_mapper(folder, backend_kind)?; @@ -929,7 +719,7 @@ impl Backend { self.backend.add_flags(folder, &ids, flags).await } - #[cfg(feature = "flag-add")] + #[cfg(any(feature = "account-sync", feature = "flag-add"))] pub async fn add_flag(&self, folder: &str, ids: &[usize], flag: Flag) -> Result<()> { let backend_kind = self.toml_account_config.add_flags_kind(); let id_mapper = self.build_id_mapper(folder, backend_kind)?; @@ -937,7 +727,7 @@ impl Backend { self.backend.add_flag(folder, &ids, flag).await } - #[cfg(feature = "flag-set")] + #[cfg(any(feature = "account-sync", feature = "flag-set"))] pub async fn set_flags(&self, folder: &str, ids: &[usize], flags: &Flags) -> Result<()> { let backend_kind = self.toml_account_config.set_flags_kind(); let id_mapper = self.build_id_mapper(folder, backend_kind)?; @@ -945,7 +735,7 @@ impl Backend { self.backend.set_flags(folder, &ids, flags).await } - #[cfg(feature = "flag-set")] + #[cfg(any(feature = "account-sync", feature = "flag-set"))] pub async fn set_flag(&self, folder: &str, ids: &[usize], flag: Flag) -> Result<()> { let backend_kind = self.toml_account_config.set_flags_kind(); let id_mapper = self.build_id_mapper(folder, backend_kind)?; @@ -969,7 +759,7 @@ impl Backend { self.backend.remove_flag(folder, &ids, flag).await } - #[cfg(feature = "message-add")] + #[cfg(any(feature = "account-sync", feature = "message-add"))] pub async fn add_message(&self, folder: &str, email: &[u8]) -> Result { let backend_kind = self.toml_account_config.add_message_kind(); let id_mapper = self.build_id_mapper(folder, backend_kind)?; @@ -978,7 +768,7 @@ impl Backend { Ok(id) } - #[cfg(feature = "message-peek")] + #[cfg(any(feature = "account-sync", feature = "message-peek"))] pub async fn peek_messages(&self, folder: &str, ids: &[usize]) -> Result { let backend_kind = self.toml_account_config.get_messages_kind(); let id_mapper = self.build_id_mapper(folder, backend_kind)?; @@ -986,7 +776,7 @@ impl Backend { self.backend.peek_messages(folder, &ids).await } - #[cfg(feature = "message-get")] + #[cfg(any(feature = "account-sync", feature = "message-get"))] pub async fn get_messages(&self, folder: &str, ids: &[usize]) -> Result { let backend_kind = self.toml_account_config.get_messages_kind(); let id_mapper = self.build_id_mapper(folder, backend_kind)?; @@ -1009,7 +799,7 @@ impl Backend { .await } - #[cfg(feature = "message-move")] + #[cfg(any(feature = "account-sync", feature = "message-move"))] pub async fn move_messages( &self, from_folder: &str, diff --git a/src/config/mod.rs b/src/config/mod.rs index 0912b86..dff26c2 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -15,6 +15,7 @@ use std::{ collections::HashMap, fs, path::{Path, PathBuf}, + sync::Arc, }; use toml; @@ -185,7 +186,7 @@ impl TomlConfig { self, account_name: Option<&str>, #[cfg(feature = "account-sync")] disable_cache: bool, - ) -> Result<(TomlAccountConfig, AccountConfig)> { + ) -> Result<(Arc, Arc)> { #[cfg_attr(not(feature = "account-sync"), allow(unused_mut))] let (account_name, mut toml_account_config) = self.into_toml_account_config(account_name)?; @@ -217,19 +218,19 @@ impl TomlConfig { folder: config.folder.map(|#[allow(unused)] c| FolderConfig { aliases: c.alias, - #[cfg(feature = "folder-list")] + #[cfg(any(feature = "account-sync", feature = "folder-list"))] list: c.list.map(|c| c.remote), }), envelope: config.envelope.map(|#[allow(unused)] c| EnvelopeConfig { - #[cfg(feature = "envelope-list")] + #[cfg(any(feature = "account-sync", feature = "envelope-list"))] list: c.list.map(|c| c.remote), #[cfg(feature = "envelope-watch")] watch: c.watch.map(|c| c.remote), }), message: config.message.map(|#[allow(unused)] c| MessageConfig { - #[cfg(feature = "message-read")] + #[cfg(any(feature = "account-sync", feature = "message-read"))] read: c.read.map(|c| c.remote), - #[cfg(feature = "message-write")] + #[cfg(any(feature = "account-sync", feature = "message-write"))] write: c.write.map(|c| c.remote), #[cfg(feature = "message-send")] send: c.send.map(|c| c.remote), @@ -246,7 +247,7 @@ impl TomlConfig { let account_config = config.account(account_name)?; - Ok((toml_account_config, account_config)) + Ok((Arc::new(toml_account_config), Arc::new(account_config))) } } diff --git a/src/email/envelope/command/list.rs b/src/email/envelope/command/list.rs index fdcf653..968f039 100644 --- a/src/email/envelope/command/list.rs +++ b/src/email/envelope/command/list.rs @@ -1,18 +1,12 @@ use anyhow::Result; use clap::Parser; -#[cfg(feature = "imap")] -use email::envelope::list::imap::ListImapEnvelopes; -#[cfg(feature = "maildir")] -use email::envelope::list::maildir::ListMaildirEnvelopes; -#[cfg(feature = "notmuch")] -use email::envelope::list::notmuch::ListNotmuchEnvelopes; use log::info; #[cfg(feature = "account-sync")] use crate::cache::arg::disable::CacheDisableFlag; use crate::{ account::arg::name::AccountNameFlag, - backend::{Backend, BackendKind}, + backend::Backend, config::TomlConfig, folder::arg::name::FolderNameOptionalArg, printer::{PrintTableOpts, Printer}, @@ -85,38 +79,10 @@ impl ListEnvelopesCommand { let list_envelopes_kind = toml_account_config.list_envelopes_kind(); let backend = Backend::new( - &toml_account_config, - &account_config, + toml_account_config.clone(), + account_config.clone(), list_envelopes_kind, - |builder| match list_envelopes_kind { - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - builder.set_list_envelopes(|ctx| { - ctx.imap.as_ref().map(ListImapEnvelopes::new_boxed) - }); - } - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - builder.set_list_envelopes(|ctx| { - ctx.maildir.as_ref().map(ListMaildirEnvelopes::new_boxed) - }); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - builder.set_list_envelopes(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(ListMaildirEnvelopes::new_boxed) - }); - } - #[cfg(feature = "notmuch")] - Some(BackendKind::Notmuch) => { - builder.set_list_envelopes(|ctx| { - ctx.notmuch.as_ref().map(ListNotmuchEnvelopes::new_boxed) - }); - } - _ => (), - }, + |builder| builder.set_list_envelopes(Some(None)), ) .await?; diff --git a/src/email/envelope/command/watch.rs b/src/email/envelope/command/watch.rs index 8701e57..18008b6 100644 --- a/src/email/envelope/command/watch.rs +++ b/src/email/envelope/command/watch.rs @@ -1,21 +1,12 @@ use anyhow::Result; use clap::Parser; -#[cfg(feature = "imap")] -use email::envelope::watch::imap::WatchImapEnvelopes; -#[cfg(feature = "maildir")] -use email::envelope::watch::maildir::WatchMaildirEnvelopes; -// #[cfg(feature = "notmuch")] -// use email::envelope::watch::notmuch::WatchNotmuchEnvelopes; use log::info; #[cfg(feature = "account-sync")] use crate::cache::arg::disable::CacheDisableFlag; use crate::{ - account::arg::name::AccountNameFlag, - backend::{Backend, BackendKind}, - config::TomlConfig, - folder::arg::name::FolderNameOptionalFlag, - printer::Printer, + account::arg::name::AccountNameFlag, backend::Backend, config::TomlConfig, + folder::arg::name::FolderNameOptionalFlag, printer::Printer, }; /// Watch envelopes for changes. @@ -49,39 +40,10 @@ impl WatchEnvelopesCommand { let watch_envelopes_kind = toml_account_config.watch_envelopes_kind(); let backend = Backend::new( - &toml_account_config, - &account_config, + toml_account_config.clone(), + account_config, watch_envelopes_kind, - |builder| match watch_envelopes_kind { - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - builder.set_watch_envelopes(|ctx| { - ctx.imap.as_ref().map(WatchImapEnvelopes::new_boxed) - }); - } - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - builder.set_watch_envelopes(|ctx| { - ctx.maildir.as_ref().map(WatchMaildirEnvelopes::new_boxed) - }); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - builder.set_watch_envelopes(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(WatchMaildirEnvelopes::new_boxed) - }); - } - #[cfg(feature = "notmuch")] - Some(BackendKind::Notmuch) => { - // TODO - // builder.set_watch_envelopes(|ctx| { - // ctx.notmuch.as_ref().map(WatchNotmuchEnvelopes::new_boxed) - // }); - } - _ => (), - }, + |builder| builder.set_watch_envelopes(Some(None)), ) .await?; diff --git a/src/email/envelope/config.rs b/src/email/envelope/config.rs index a17bea4..63d38f6 100644 --- a/src/email/envelope/config.rs +++ b/src/email/envelope/config.rs @@ -5,11 +5,11 @@ use crate::backend::BackendKind; #[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)] pub struct EnvelopeConfig { - #[cfg(feature = "envelope-list")] + #[cfg(any(feature = "account-sync", feature = "envelope-list"))] pub list: Option, #[cfg(feature = "envelope-watch")] pub watch: Option, - #[cfg(feature = "envelope-get")] + #[cfg(any(feature = "account-sync", feature = "envelope-get"))] pub get: Option, } @@ -18,7 +18,7 @@ impl EnvelopeConfig { #[allow(unused_mut)] let mut kinds = HashSet::default(); - #[cfg(feature = "envelope-list")] + #[cfg(any(feature = "account-sync", feature = "envelope-list"))] if let Some(list) = &self.list { kinds.extend(list.get_used_backends()); } @@ -28,7 +28,7 @@ impl EnvelopeConfig { kinds.extend(watch.get_used_backends()); } - #[cfg(feature = "envelope-get")] + #[cfg(any(feature = "account-sync", feature = "envelope-get"))] if let Some(get) = &self.get { kinds.extend(get.get_used_backends()); } @@ -37,7 +37,7 @@ impl EnvelopeConfig { } } -#[cfg(feature = "envelope-list")] +#[cfg(any(feature = "account-sync", feature = "envelope-list"))] #[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)] pub struct ListEnvelopesConfig { pub backend: Option, @@ -46,7 +46,7 @@ pub struct ListEnvelopesConfig { pub remote: email::envelope::list::config::EnvelopeListConfig, } -#[cfg(feature = "envelope-list")] +#[cfg(any(feature = "account-sync", feature = "envelope-list"))] impl ListEnvelopesConfig { pub fn get_used_backends(&self) -> HashSet<&BackendKind> { let mut kinds = HashSet::default(); @@ -81,13 +81,13 @@ impl WatchEnvelopesConfig { } } -#[cfg(feature = "envelope-get")] +#[cfg(any(feature = "account-sync", feature = "envelope-get"))] #[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)] pub struct GetEnvelopeConfig { pub backend: Option, } -#[cfg(feature = "envelope-get")] +#[cfg(any(feature = "account-sync", feature = "envelope-get"))] impl GetEnvelopeConfig { pub fn get_used_backends(&self) -> HashSet<&BackendKind> { let mut kinds = HashSet::default(); diff --git a/src/email/envelope/flag/command/add.rs b/src/email/envelope/flag/command/add.rs index a56e446..61cbe8d 100644 --- a/src/email/envelope/flag/command/add.rs +++ b/src/email/envelope/flag/command/add.rs @@ -1,18 +1,12 @@ use anyhow::Result; use clap::Parser; -#[cfg(feature = "imap")] -use email::flag::add::imap::AddImapFlags; -#[cfg(feature = "maildir")] -use email::flag::add::maildir::AddMaildirFlags; -#[cfg(feature = "notmuch")] -use email::flag::add::notmuch::AddNotmuchFlags; use log::info; #[cfg(feature = "account-sync")] use crate::cache::arg::disable::CacheDisableFlag; use crate::{ account::arg::name::AccountNameFlag, - backend::{Backend, BackendKind}, + backend::Backend, config::TomlConfig, flag::arg::ids_and_flags::{into_tuple, IdsAndFlagsArgs}, folder::arg::name::FolderNameOptionalFlag, @@ -54,34 +48,10 @@ impl FlagAddCommand { let add_flags_kind = toml_account_config.add_flags_kind(); let backend = Backend::new( - &toml_account_config, - &account_config, + toml_account_config.clone(), + account_config, add_flags_kind, - |builder| match add_flags_kind { - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - builder.set_add_flags(|ctx| ctx.imap.as_ref().map(AddImapFlags::new_boxed)); - } - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - builder - .set_add_flags(|ctx| ctx.maildir.as_ref().map(AddMaildirFlags::new_boxed)); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - builder.set_add_flags(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(AddMaildirFlags::new_boxed) - }); - } - #[cfg(feature = "notmuch")] - Some(BackendKind::Notmuch) => { - builder - .set_add_flags(|ctx| ctx.notmuch.as_ref().map(AddNotmuchFlags::new_boxed)); - } - _ => (), - }, + |builder| builder.set_add_flags(Some(None)), ) .await?; diff --git a/src/email/envelope/flag/command/remove.rs b/src/email/envelope/flag/command/remove.rs index 6803c97..596370d 100644 --- a/src/email/envelope/flag/command/remove.rs +++ b/src/email/envelope/flag/command/remove.rs @@ -1,18 +1,12 @@ use anyhow::Result; use clap::Parser; -#[cfg(feature = "imap")] -use email::flag::remove::imap::RemoveImapFlags; -#[cfg(feature = "maildir")] -use email::flag::remove::maildir::RemoveMaildirFlags; -#[cfg(feature = "notmuch")] -use email::flag::remove::notmuch::RemoveNotmuchFlags; use log::info; #[cfg(feature = "account-sync")] use crate::cache::arg::disable::CacheDisableFlag; use crate::{ account::arg::name::AccountNameFlag, - backend::{Backend, BackendKind}, + backend::Backend, config::TomlConfig, flag::arg::ids_and_flags::{into_tuple, IdsAndFlagsArgs}, folder::arg::name::FolderNameOptionalFlag, @@ -54,37 +48,10 @@ impl FlagRemoveCommand { let remove_flags_kind = toml_account_config.remove_flags_kind(); let backend = Backend::new( - &toml_account_config, - &account_config, + toml_account_config.clone(), + account_config, remove_flags_kind, - |builder| match remove_flags_kind { - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - builder - .set_remove_flags(|ctx| ctx.imap.as_ref().map(RemoveImapFlags::new_boxed)); - } - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - builder.set_remove_flags(|ctx| { - ctx.maildir.as_ref().map(RemoveMaildirFlags::new_boxed) - }); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - builder.set_remove_flags(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(RemoveMaildirFlags::new_boxed) - }); - } - #[cfg(feature = "notmuch")] - Some(BackendKind::Notmuch) => { - builder.set_remove_flags(|ctx| { - ctx.notmuch.as_ref().map(RemoveNotmuchFlags::new_boxed) - }); - } - _ => (), - }, + |builder| builder.set_remove_flags(Some(None)), ) .await?; diff --git a/src/email/envelope/flag/command/set.rs b/src/email/envelope/flag/command/set.rs index fa9bd76..f8baae7 100644 --- a/src/email/envelope/flag/command/set.rs +++ b/src/email/envelope/flag/command/set.rs @@ -1,18 +1,12 @@ use anyhow::Result; use clap::Parser; -#[cfg(feature = "imap")] -use email::flag::set::imap::SetImapFlags; -#[cfg(feature = "maildir")] -use email::flag::set::maildir::SetMaildirFlags; -#[cfg(feature = "notmuch")] -use email::flag::set::notmuch::SetNotmuchFlags; use log::info; #[cfg(feature = "account-sync")] use crate::cache::arg::disable::CacheDisableFlag; use crate::{ account::arg::name::AccountNameFlag, - backend::{Backend, BackendKind}, + backend::Backend, config::TomlConfig, flag::arg::ids_and_flags::{into_tuple, IdsAndFlagsArgs}, folder::arg::name::FolderNameOptionalFlag, @@ -54,34 +48,10 @@ impl FlagSetCommand { let set_flags_kind = toml_account_config.set_flags_kind(); let backend = Backend::new( - &toml_account_config, - &account_config, + toml_account_config.clone(), + account_config, set_flags_kind, - |builder| match set_flags_kind { - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - builder.set_set_flags(|ctx| ctx.imap.as_ref().map(SetImapFlags::new_boxed)); - } - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - builder - .set_set_flags(|ctx| ctx.maildir.as_ref().map(SetMaildirFlags::new_boxed)); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - builder.set_set_flags(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(SetMaildirFlags::new_boxed) - }); - } - #[cfg(feature = "notmuch")] - Some(BackendKind::Notmuch) => { - builder - .set_set_flags(|ctx| ctx.notmuch.as_ref().map(SetNotmuchFlags::new_boxed)); - } - _ => (), - }, + |builder| builder.set_set_flags(Some(None)), ) .await?; diff --git a/src/email/envelope/mod.rs b/src/email/envelope/mod.rs index de3df78..8833690 100644 --- a/src/email/envelope/mod.rs +++ b/src/email/envelope/mod.rs @@ -3,19 +3,14 @@ pub mod command; pub mod config; pub mod flag; -#[cfg(feature = "envelope-list")] use anyhow::Result; -#[cfg(feature = "envelope-list")] use email::account::config::AccountConfig; use serde::Serialize; -#[cfg(feature = "envelope-list")] use std::ops; -use crate::flag::Flags; -#[cfg(feature = "envelope-list")] use crate::{ cache::IdMapper, - flag::Flag, + flag::{Flag, Flags}, printer::{PrintTable, PrintTableOpts, WriteColor}, ui::{Cell, Row, Table}, }; @@ -35,7 +30,7 @@ pub struct Envelope { pub date: String, } -#[cfg(feature = "envelope-list")] +#[cfg(any(feature = "account-sync", feature = "envelope-list"))] impl Table for Envelope { fn head() -> Row { Row::new() @@ -81,12 +76,12 @@ impl Table for Envelope { } } -#[cfg(feature = "envelope-list")] +#[cfg(any(feature = "account-sync", feature = "envelope-list"))] /// Represents the list of envelopes. #[derive(Clone, Debug, Default, Serialize)] pub struct Envelopes(Vec); -#[cfg(feature = "envelope-list")] +#[cfg(any(feature = "account-sync", feature = "envelope-list"))] impl Envelopes { pub fn from_backend( config: &AccountConfig, @@ -113,7 +108,7 @@ impl Envelopes { } } -#[cfg(feature = "envelope-list")] +#[cfg(any(feature = "account-sync", feature = "envelope-list"))] impl ops::Deref for Envelopes { type Target = Vec; @@ -122,7 +117,7 @@ impl ops::Deref for Envelopes { } } -#[cfg(feature = "envelope-list")] +#[cfg(any(feature = "account-sync", feature = "envelope-list"))] impl PrintTable for Envelopes { fn print_table(&self, writer: &mut dyn WriteColor, opts: PrintTableOpts) -> Result<()> { writeln!(writer)?; diff --git a/src/email/message/attachment/command/download.rs b/src/email/message/attachment/command/download.rs index 80425b8..3462135 100644 --- a/src/email/message/attachment/command/download.rs +++ b/src/email/message/attachment/command/download.rs @@ -1,9 +1,5 @@ use anyhow::{Context, Result}; use clap::Parser; -#[cfg(feature = "imap")] -use email::message::get::imap::GetImapMessages; -#[cfg(feature = "maildir")] -use email::{flag::add::maildir::AddMaildirFlags, message::peek::maildir::PeekMaildirMessages}; use log::info; use std::{fs, path::PathBuf}; use uuid::Uuid; @@ -11,11 +7,8 @@ use uuid::Uuid; #[cfg(feature = "account-sync")] use crate::cache::arg::disable::CacheDisableFlag; use crate::{ - account::arg::name::AccountNameFlag, - backend::{Backend, BackendKind}, - config::TomlConfig, - envelope::arg::ids::EnvelopeIdsArgs, - folder::arg::name::FolderNameOptionalFlag, + account::arg::name::AccountNameFlag, backend::Backend, config::TomlConfig, + envelope::arg::ids::EnvelopeIdsArgs, folder::arg::name::FolderNameOptionalFlag, printer::Printer, }; @@ -55,38 +48,10 @@ impl AttachmentDownloadCommand { let get_messages_kind = toml_account_config.get_messages_kind(); let backend = Backend::new( - &toml_account_config, - &account_config, + toml_account_config.clone(), + account_config.clone(), get_messages_kind, - |builder| match get_messages_kind { - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - builder - .set_get_messages(|ctx| ctx.imap.as_ref().map(GetImapMessages::new_boxed)); - } - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - builder.set_peek_messages(|ctx| { - ctx.maildir.as_ref().map(PeekMaildirMessages::new_boxed) - }); - builder - .set_add_flags(|ctx| ctx.maildir.as_ref().map(AddMaildirFlags::new_boxed)); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - builder.set_peek_messages(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(PeekMaildirMessages::new_boxed) - }); - builder.set_add_flags(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(AddMaildirFlags::new_boxed) - }); - } - _ => (), - }, + |builder| builder.set_get_messages(Some(None)), ) .await?; diff --git a/src/email/message/command/copy.rs b/src/email/message/command/copy.rs index 9230365..0b55dc1 100644 --- a/src/email/message/command/copy.rs +++ b/src/email/message/command/copy.rs @@ -1,19 +1,12 @@ use anyhow::Result; use clap::Parser; -#[cfg(feature = "imap")] -use email::message::copy::imap::CopyImapMessages; -#[cfg(feature = "maildir")] -use email::message::copy::maildir::CopyMaildirMessages; -#[cfg(feature = "notmuch")] -use email::message::copy::notmuch::CopyNotmuchMessages; use log::info; #[cfg(feature = "account-sync")] use crate::cache::arg::disable::CacheDisableFlag; -#[allow(unused)] use crate::{ account::arg::name::AccountNameFlag, - backend::{Backend, BackendKind}, + backend::Backend, config::TomlConfig, envelope::arg::ids::EnvelopeIdsArgs, folder::arg::name::{SourceFolderNameOptionalFlag, TargetFolderNameArg}, @@ -57,38 +50,10 @@ impl MessageCopyCommand { let copy_messages_kind = toml_account_config.copy_messages_kind(); let backend = Backend::new( - &toml_account_config, - &account_config, + toml_account_config.clone(), + account_config, copy_messages_kind, - |#[allow(unused)] builder| match copy_messages_kind { - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - builder.set_copy_messages(|ctx| { - ctx.imap.as_ref().map(CopyImapMessages::new_boxed) - }); - } - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - builder.set_copy_messages(|ctx| { - ctx.maildir.as_ref().map(CopyMaildirMessages::new_boxed) - }); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - builder.set_copy_messages(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(CopyMaildirMessages::new_boxed) - }); - } - #[cfg(feature = "notmuch")] - Some(BackendKind::Notmuch) => { - builder.set_copy_messages(|ctx| { - ctx.notmuch.as_ref().map(CopyNotmuchMessages::new_boxed) - }); - } - _ => (), - }, + |builder| builder.set_copy_messages(Some(None)), ) .await?; diff --git a/src/email/message/command/delete.rs b/src/email/message/command/delete.rs index 57aa05b..a6c0e97 100644 --- a/src/email/message/command/delete.rs +++ b/src/email/message/command/delete.rs @@ -1,22 +1,12 @@ use anyhow::Result; use clap::Parser; -#[cfg(feature = "imap")] -use email::{flag::add::imap::AddImapFlags, message::move_::imap::MoveImapMessages}; -#[cfg(feature = "maildir")] -use email::{flag::add::maildir::AddMaildirFlags, message::move_::maildir::MoveMaildirMessages}; -#[cfg(feature = "notmuch")] -use email::{flag::add::notmuch::AddNotmuchFlags, message::move_::notmuch::MoveNotmuchMessages}; use log::info; #[cfg(feature = "account-sync")] use crate::cache::arg::disable::CacheDisableFlag; -#[allow(unused)] use crate::{ - account::arg::name::AccountNameFlag, - backend::{Backend, BackendKind}, - config::TomlConfig, - envelope::arg::ids::EnvelopeIdsArgs, - folder::arg::name::FolderNameOptionalFlag, + account::arg::name::AccountNameFlag, backend::Backend, config::TomlConfig, + envelope::arg::ids::EnvelopeIdsArgs, folder::arg::name::FolderNameOptionalFlag, printer::Printer, }; @@ -58,48 +48,10 @@ impl MessageDeleteCommand { let delete_messages_kind = toml_account_config.delete_messages_kind(); let backend = Backend::new( - &toml_account_config, - &account_config, + toml_account_config.clone(), + account_config, delete_messages_kind, - |#[allow(unused)] builder| match delete_messages_kind { - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - builder.set_move_messages(|ctx| { - ctx.imap.as_ref().map(MoveImapMessages::new_boxed) - }); - builder.set_add_flags(|ctx| ctx.imap.as_ref().map(AddImapFlags::new_boxed)); - } - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - builder.set_move_messages(|ctx| { - ctx.maildir.as_ref().map(MoveMaildirMessages::new_boxed) - }); - builder - .set_add_flags(|ctx| ctx.maildir.as_ref().map(AddMaildirFlags::new_boxed)); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - builder.set_move_messages(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(MoveMaildirMessages::new_boxed) - }); - builder.set_add_flags(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(AddMaildirFlags::new_boxed) - }); - } - #[cfg(feature = "notmuch")] - Some(BackendKind::Notmuch) => { - builder.set_move_messages(|ctx| { - ctx.notmuch.as_ref().map(MoveNotmuchMessages::new_boxed) - }); - builder - .set_add_flags(|ctx| ctx.notmuch.as_ref().map(AddNotmuchFlags::new_boxed)); - } - _ => (), - }, + |builder| builder.set_delete_messages(Some(None)), ) .await?; diff --git a/src/email/message/command/forward.rs b/src/email/message/command/forward.rs index 633b8e4..71fe74a 100644 --- a/src/email/message/command/forward.rs +++ b/src/email/message/command/forward.rs @@ -1,23 +1,12 @@ use anyhow::{anyhow, Result}; use clap::Parser; -#[cfg(feature = "imap")] -use email::message::add::imap::AddImapMessage; -#[cfg(feature = "maildir")] -use email::message::add::maildir::AddMaildirMessage; -#[cfg(feature = "notmuch")] -use email::message::add::notmuch::AddNotmuchMessage; -#[cfg(feature = "sendmail")] -use email::message::send::sendmail::SendSendmailMessage; -#[cfg(feature = "smtp")] -use email::message::send::smtp::SendSmtpMessage; use log::info; #[cfg(feature = "account-sync")] use crate::cache::arg::disable::CacheDisableFlag; -#[allow(unused)] use crate::{ account::arg::name::AccountNameFlag, - backend::{Backend, BackendKind}, + backend::Backend, config::TomlConfig, envelope::arg::ids::EnvelopeIdArg, folder::arg::name::FolderNameOptionalFlag, @@ -70,55 +59,12 @@ impl MessageForwardCommand { let send_message_kind = toml_account_config.send_message_kind(); let backend = Backend::new( - &toml_account_config, - &account_config, + toml_account_config.clone(), + account_config.clone(), add_message_kind.into_iter().chain(send_message_kind), - |#[allow(unused)] builder| { - match add_message_kind { - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - builder.set_add_message(|ctx| { - ctx.imap.as_ref().map(AddImapMessage::new_boxed) - }); - } - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - builder.set_add_message(|ctx| { - ctx.maildir.as_ref().map(AddMaildirMessage::new_boxed) - }); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - builder.set_add_message(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(AddMaildirMessage::new_boxed) - }); - } - #[cfg(feature = "notmuch")] - Some(BackendKind::Notmuch) => { - builder.set_add_message(|ctx| { - ctx.notmuch.as_ref().map(AddNotmuchMessage::new_boxed) - }); - } - _ => (), - }; - - match send_message_kind { - #[cfg(feature = "smtp")] - Some(BackendKind::Smtp) => { - builder.set_send_message(|ctx| { - ctx.smtp.as_ref().map(SendSmtpMessage::new_boxed) - }); - } - #[cfg(feature = "sendmail")] - Some(BackendKind::Sendmail) => { - builder.set_send_message(|ctx| { - ctx.sendmail.as_ref().map(SendSendmailMessage::new_boxed) - }); - } - _ => (), - }; + |builder| { + builder.set_add_message(Some(None)); + builder.set_send_message(Some(None)); }, ) .await?; @@ -134,6 +80,6 @@ impl MessageForwardCommand { .with_body(self.body.raw()) .build() .await?; - editor::edit_tpl_with_editor(&account_config, printer, &backend, tpl).await + editor::edit_tpl_with_editor(account_config, printer, &backend, tpl).await } } diff --git a/src/email/message/command/mailto.rs b/src/email/message/command/mailto.rs index 15b7e28..f3011f3 100644 --- a/src/email/message/command/mailto.rs +++ b/src/email/message/command/mailto.rs @@ -1,15 +1,5 @@ use anyhow::Result; use clap::Parser; -#[cfg(feature = "imap")] -use email::message::add::imap::AddImapMessage; -#[cfg(feature = "maildir")] -use email::message::add::maildir::AddMaildirMessage; -#[cfg(feature = "notmuch")] -use email::message::add::notmuch::AddNotmuchMessage; -#[cfg(feature = "sendmail")] -use email::message::send::sendmail::SendSendmailMessage; -#[cfg(feature = "smtp")] -use email::message::send::smtp::SendSmtpMessage; use log::{debug, info}; use mail_builder::MessageBuilder; use url::Url; @@ -17,10 +7,7 @@ use url::Url; #[cfg(feature = "account-sync")] use crate::cache::arg::disable::CacheDisableFlag; use crate::{ - account::arg::name::AccountNameFlag, - backend::{Backend, BackendKind}, - config::TomlConfig, - printer::Printer, + account::arg::name::AccountNameFlag, backend::Backend, config::TomlConfig, printer::Printer, ui::editor, }; @@ -67,55 +54,12 @@ impl MessageMailtoCommand { let send_message_kind = toml_account_config.send_message_kind(); let backend = Backend::new( - &toml_account_config, - &account_config, + toml_account_config.clone(), + account_config.clone(), add_message_kind.into_iter().chain(send_message_kind), |builder| { - match add_message_kind { - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - builder.set_add_message(|ctx| { - ctx.imap.as_ref().map(AddImapMessage::new_boxed) - }); - } - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - builder.set_add_message(|ctx| { - ctx.maildir.as_ref().map(AddMaildirMessage::new_boxed) - }); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - builder.set_add_message(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(AddMaildirMessage::new_boxed) - }); - } - #[cfg(feature = "notmuch")] - Some(BackendKind::Notmuch) => { - builder.set_add_message(|ctx| { - ctx.notmuch.as_ref().map(AddNotmuchMessage::new_boxed) - }); - } - _ => (), - }; - - match send_message_kind { - #[cfg(feature = "smtp")] - Some(BackendKind::Smtp) => { - builder.set_send_message(|ctx| { - ctx.smtp.as_ref().map(SendSmtpMessage::new_boxed) - }); - } - #[cfg(feature = "sendmail")] - Some(BackendKind::Sendmail) => { - builder.set_send_message(|ctx| { - ctx.sendmail.as_ref().map(SendSendmailMessage::new_boxed) - }); - } - _ => (), - }; + builder.set_add_message(Some(None)); + builder.set_send_message(Some(None)); }, ) .await?; @@ -149,6 +93,6 @@ impl MessageMailtoCommand { .from_msg_builder(builder) .await?; - editor::edit_tpl_with_editor(&account_config, printer, &backend, tpl).await + editor::edit_tpl_with_editor(account_config, printer, &backend, tpl).await } } diff --git a/src/email/message/command/mod.rs b/src/email/message/command/mod.rs index 0f053e6..6c68577 100644 --- a/src/email/message/command/mod.rs +++ b/src/email/message/command/mod.rs @@ -7,7 +7,7 @@ pub mod forward; #[cfg(feature = "message-mailto")] pub mod mailto; #[cfg(feature = "message-move")] -pub mod move_; +pub mod r#move; #[cfg(feature = "message-read")] pub mod read; #[cfg(feature = "message-reply")] @@ -33,7 +33,7 @@ use self::forward::MessageForwardCommand; #[cfg(feature = "message-mailto")] use self::mailto::MessageMailtoCommand; #[cfg(feature = "message-move")] -use self::move_::MessageMoveCommand; +use self::r#move::MessageMoveCommand; #[cfg(feature = "message-read")] use self::read::MessageReadCommand; #[cfg(feature = "message-reply")] diff --git a/src/email/message/command/move_.rs b/src/email/message/command/move.rs similarity index 52% rename from src/email/message/command/move_.rs rename to src/email/message/command/move.rs index bc69243..6ffb994 100644 --- a/src/email/message/command/move_.rs +++ b/src/email/message/command/move.rs @@ -1,11 +1,5 @@ use anyhow::Result; use clap::Parser; -#[cfg(feature = "imap")] -use email::message::move_::imap::MoveImapMessages; -#[cfg(feature = "maildir")] -use email::message::move_::maildir::MoveMaildirMessages; -#[cfg(feature = "notmuch")] -use email::message::move_::notmuch::MoveNotmuchMessages; use log::info; #[cfg(feature = "account-sync")] @@ -13,7 +7,7 @@ use crate::cache::arg::disable::CacheDisableFlag; #[allow(unused)] use crate::{ account::arg::name::AccountNameFlag, - backend::{Backend, BackendKind}, + backend::Backend, config::TomlConfig, envelope::arg::ids::EnvelopeIdsArgs, folder::arg::name::{SourceFolderNameOptionalFlag, TargetFolderNameArg}, @@ -57,38 +51,10 @@ impl MessageMoveCommand { let move_messages_kind = toml_account_config.move_messages_kind(); let backend = Backend::new( - &toml_account_config, - &account_config, + toml_account_config.clone(), + account_config, move_messages_kind, - |#[allow(unused)] builder| match move_messages_kind { - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - builder.set_move_messages(|ctx| { - ctx.imap.as_ref().map(MoveImapMessages::new_boxed) - }); - } - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - builder.set_move_messages(|ctx| { - ctx.maildir.as_ref().map(MoveMaildirMessages::new_boxed) - }); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - builder.set_move_messages(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(MoveMaildirMessages::new_boxed) - }); - } - #[cfg(feature = "notmuch")] - Some(BackendKind::Notmuch) => { - builder.set_move_messages(|ctx| { - ctx.notmuch.as_ref().map(MoveNotmuchMessages::new_boxed) - }); - } - _ => (), - }, + |builder| builder.set_move_messages(Some(None)), ) .await?; diff --git a/src/email/message/command/read.rs b/src/email/message/command/read.rs index 6fb8388..26fbafd 100644 --- a/src/email/message/command/read.rs +++ b/src/email/message/command/read.rs @@ -1,11 +1,5 @@ use anyhow::Result; use clap::Parser; -#[cfg(feature = "imap")] -use email::message::{get::imap::GetImapMessages, peek::imap::PeekImapMessages}; -#[cfg(feature = "maildir")] -use email::{flag::add::maildir::AddMaildirFlags, message::peek::maildir::PeekMaildirMessages}; -#[cfg(feature = "notmuch")] -use email::{flag::add::notmuch::AddNotmuchFlags, message::peek::notmuch::PeekNotmuchMessages}; use log::info; use mml::message::FilterParts; @@ -13,11 +7,8 @@ use mml::message::FilterParts; use crate::cache::arg::disable::CacheDisableFlag; #[allow(unused)] use crate::{ - account::arg::name::AccountNameFlag, - backend::{Backend, BackendKind}, - config::TomlConfig, - envelope::arg::ids::EnvelopeIdsArgs, - folder::arg::name::FolderNameOptionalFlag, + account::arg::name::AccountNameFlag, backend::Backend, config::TomlConfig, + envelope::arg::ids::EnvelopeIdsArgs, folder::arg::name::FolderNameOptionalFlag, printer::Printer, }; @@ -102,49 +93,10 @@ impl MessageReadCommand { let get_messages_kind = toml_account_config.get_messages_kind(); let backend = Backend::new( - &toml_account_config, - &account_config, + toml_account_config.clone(), + account_config.clone(), get_messages_kind, - |#[allow(unused)] builder| match get_messages_kind { - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - builder.set_peek_messages(|ctx| { - ctx.imap.as_ref().map(PeekImapMessages::new_boxed) - }); - builder - .set_get_messages(|ctx| ctx.imap.as_ref().map(GetImapMessages::new_boxed)); - } - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - builder.set_peek_messages(|ctx| { - ctx.maildir.as_ref().map(PeekMaildirMessages::new_boxed) - }); - builder - .set_add_flags(|ctx| ctx.maildir.as_ref().map(AddMaildirFlags::new_boxed)); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - builder.set_peek_messages(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(PeekMaildirMessages::new_boxed) - }); - builder.set_add_flags(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(AddMaildirFlags::new_boxed) - }); - } - #[cfg(feature = "notmuch")] - Some(BackendKind::Notmuch) => { - builder.set_peek_messages(|ctx| { - ctx.notmuch.as_ref().map(PeekNotmuchMessages::new_boxed) - }); - builder - .set_add_flags(|ctx| ctx.notmuch.as_ref().map(AddNotmuchFlags::new_boxed)); - } - _ => (), - }, + |builder| builder.set_get_messages(Some(None)), ) .await?; diff --git a/src/email/message/command/reply.rs b/src/email/message/command/reply.rs index 5d4fce3..4fb1f62 100644 --- a/src/email/message/command/reply.rs +++ b/src/email/message/command/reply.rs @@ -1,23 +1,12 @@ use anyhow::{anyhow, Result}; use clap::Parser; -#[cfg(feature = "imap")] -use email::message::add::imap::AddImapMessage; -#[cfg(feature = "maildir")] -use email::message::add::maildir::AddMaildirMessage; -#[cfg(feature = "notmuch")] -use email::message::add::notmuch::AddNotmuchMessage; -#[cfg(feature = "sendmail")] -use email::message::send::sendmail::SendSendmailMessage; -#[cfg(feature = "smtp")] -use email::message::send::smtp::SendSmtpMessage; use log::info; #[cfg(feature = "account-sync")] use crate::cache::arg::disable::CacheDisableFlag; -#[allow(unused)] use crate::{ account::arg::name::AccountNameFlag, - backend::{Backend, BackendKind}, + backend::Backend, config::TomlConfig, envelope::arg::ids::EnvelopeIdArg, folder::arg::name::FolderNameOptionalFlag, @@ -72,55 +61,12 @@ impl MessageReplyCommand { let send_message_kind = toml_account_config.send_message_kind(); let backend = Backend::new( - &toml_account_config, - &account_config, + toml_account_config.clone(), + account_config.clone(), add_message_kind.into_iter().chain(send_message_kind), - |#[allow(unused)] builder| { - match add_message_kind { - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - builder.set_add_message(|ctx| { - ctx.imap.as_ref().map(AddImapMessage::new_boxed) - }); - } - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - builder.set_add_message(|ctx| { - ctx.maildir.as_ref().map(AddMaildirMessage::new_boxed) - }); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - builder.set_add_message(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(AddMaildirMessage::new_boxed) - }); - } - #[cfg(feature = "notmuch")] - Some(BackendKind::Notmuch) => { - builder.set_add_message(|ctx| { - ctx.notmuch.as_ref().map(AddNotmuchMessage::new_boxed) - }); - } - _ => (), - }; - - match send_message_kind { - #[cfg(feature = "smtp")] - Some(BackendKind::Smtp) => { - builder.set_send_message(|ctx| { - ctx.smtp.as_ref().map(SendSmtpMessage::new_boxed) - }); - } - #[cfg(feature = "sendmail")] - Some(BackendKind::Sendmail) => { - builder.set_send_message(|ctx| { - ctx.sendmail.as_ref().map(SendSendmailMessage::new_boxed) - }); - } - _ => (), - }; + |builder| { + builder.set_add_message(Some(None)); + builder.set_send_message(Some(None)); }, ) .await?; @@ -137,6 +83,6 @@ impl MessageReplyCommand { .with_reply_all(self.reply.all) .build() .await?; - editor::edit_tpl_with_editor(&account_config, printer, &backend, tpl).await + editor::edit_tpl_with_editor(account_config, printer, &backend, tpl).await } } diff --git a/src/email/message/command/save.rs b/src/email/message/command/save.rs index 95592b4..43fe40e 100644 --- a/src/email/message/command/save.rs +++ b/src/email/message/command/save.rs @@ -1,11 +1,5 @@ use anyhow::Result; use clap::Parser; -#[cfg(feature = "imap")] -use email::message::add::imap::AddImapMessage; -#[cfg(feature = "maildir")] -use email::message::add::maildir::AddMaildirMessage; -#[cfg(feature = "notmuch")] -use email::message::add::notmuch::AddNotmuchMessage; use log::info; use std::io::{self, BufRead, IsTerminal}; @@ -13,12 +7,8 @@ use std::io::{self, BufRead, IsTerminal}; use crate::cache::arg::disable::CacheDisableFlag; #[allow(unused)] use crate::{ - account::arg::name::AccountNameFlag, - backend::{Backend, BackendKind}, - config::TomlConfig, - folder::arg::name::FolderNameOptionalFlag, - message::arg::MessageRawArg, - printer::Printer, + account::arg::name::AccountNameFlag, backend::Backend, config::TomlConfig, + folder::arg::name::FolderNameOptionalFlag, message::arg::MessageRawArg, printer::Printer, }; /// Save a message to a folder. @@ -55,36 +45,10 @@ impl MessageSaveCommand { let add_message_kind = toml_account_config.add_message_kind(); let backend = Backend::new( - &toml_account_config, - &account_config, + toml_account_config.clone(), + account_config, add_message_kind, - |#[allow(unused)] builder| match add_message_kind { - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - builder.set_add_message(|ctx| ctx.imap.as_ref().map(AddImapMessage::new_boxed)); - } - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - builder.set_add_message(|ctx| { - ctx.maildir.as_ref().map(AddMaildirMessage::new_boxed) - }); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - builder.set_add_message(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(AddMaildirMessage::new_boxed) - }); - } - #[cfg(feature = "notmuch")] - Some(BackendKind::Notmuch) => { - builder.set_add_message(|ctx| { - ctx.notmuch.as_ref().map(AddNotmuchMessage::new_boxed) - }); - } - _ => (), - }, + |builder| builder.set_add_message(Some(None)), ) .await?; diff --git a/src/email/message/command/send.rs b/src/email/message/command/send.rs index 4535fa3..dcb1f74 100644 --- a/src/email/message/command/send.rs +++ b/src/email/message/command/send.rs @@ -1,27 +1,13 @@ use anyhow::Result; use clap::Parser; -#[cfg(feature = "imap")] -use email::message::add::imap::AddImapMessage; -#[cfg(feature = "maildir")] -use email::message::add::maildir::AddMaildirMessage; -#[cfg(feature = "notmuch")] -use email::message::add::notmuch::AddNotmuchMessage; -#[cfg(feature = "sendmail")] -use email::message::send::sendmail::SendSendmailMessage; -#[cfg(feature = "smtp")] -use email::message::send::smtp::SendSmtpMessage; use log::info; use std::io::{self, BufRead, IsTerminal}; #[cfg(feature = "account-sync")] use crate::cache::arg::disable::CacheDisableFlag; -#[allow(unused)] use crate::{ - account::arg::name::AccountNameFlag, - backend::{Backend, BackendKind}, - config::TomlConfig, - message::arg::MessageRawArg, - printer::Printer, + account::arg::name::AccountNameFlag, backend::Backend, config::TomlConfig, + message::arg::MessageRawArg, printer::Printer, }; /// Send a message. @@ -54,61 +40,20 @@ impl MessageSendCommand { let send_message_kind = toml_account_config.send_message_kind(); #[cfg(feature = "message-add")] - let add_message_kind = toml_account_config - .add_message_kind() - .filter(|_| account_config.should_save_copy_sent_message()); - #[cfg(not(feature = "message-add"))] - let add_message_kind = None; + let send_message_kind = send_message_kind.into_iter().chain( + toml_account_config + .add_message_kind() + .filter(|_| account_config.should_save_copy_sent_message()), + ); let backend = Backend::new( - &toml_account_config, - &account_config, - send_message_kind.into_iter().chain(add_message_kind), - |#[allow(unused)] builder| { - match add_message_kind { - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - builder.set_add_message(|ctx| { - ctx.imap.as_ref().map(AddImapMessage::new_boxed) - }); - } - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - builder.set_add_message(|ctx| { - ctx.maildir.as_ref().map(AddMaildirMessage::new_boxed) - }); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - builder.set_add_message(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(AddMaildirMessage::new_boxed) - }); - } - #[cfg(feature = "notmuch")] - Some(BackendKind::Notmuch) => { - builder.set_add_message(|ctx| { - ctx.notmuch.as_ref().map(AddNotmuchMessage::new_boxed) - }); - } - _ => (), - }; - match send_message_kind { - #[cfg(feature = "smtp")] - Some(BackendKind::Smtp) => { - builder.set_send_message(|ctx| { - ctx.smtp.as_ref().map(SendSmtpMessage::new_boxed) - }); - } - #[cfg(feature = "sendmail")] - Some(BackendKind::Sendmail) => { - builder.set_send_message(|ctx| { - ctx.sendmail.as_ref().map(SendSendmailMessage::new_boxed) - }); - } - _ => (), - }; + toml_account_config.clone(), + account_config, + send_message_kind, + |builder| { + builder.set_send_message(Some(None)); + #[cfg(feature = "message-add")] + builder.set_add_message(Some(None)); }, ) .await?; diff --git a/src/email/message/command/write.rs b/src/email/message/command/write.rs index ecf2639..79036f1 100644 --- a/src/email/message/command/write.rs +++ b/src/email/message/command/write.rs @@ -1,24 +1,13 @@ use anyhow::Result; use clap::Parser; -#[cfg(feature = "imap")] -use email::message::add::imap::AddImapMessage; -#[cfg(feature = "maildir")] -use email::message::add::maildir::AddMaildirMessage; -#[cfg(feature = "notmuch")] -use email::message::add::notmuch::AddNotmuchMessage; -#[cfg(feature = "sendmail")] -use email::message::send::sendmail::SendSendmailMessage; -#[cfg(feature = "smtp")] -use email::message::send::smtp::SendSmtpMessage; use email::message::Message; use log::info; #[cfg(feature = "account-sync")] use crate::cache::arg::disable::CacheDisableFlag; -#[allow(unused)] use crate::{ account::arg::name::AccountNameFlag, - backend::{Backend, BackendKind}, + backend::Backend, config::TomlConfig, message::arg::{body::MessageRawBodyArg, header::HeaderRawArgs}, printer::Printer, @@ -61,55 +50,12 @@ impl MessageWriteCommand { let send_message_kind = toml_account_config.send_message_kind(); let backend = Backend::new( - &toml_account_config, - &account_config, + toml_account_config.clone(), + account_config.clone(), add_message_kind.into_iter().chain(send_message_kind), - |#[allow(unused)] builder| { - match add_message_kind { - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - builder.set_add_message(|ctx| { - ctx.imap.as_ref().map(AddImapMessage::new_boxed) - }); - } - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - builder.set_add_message(|ctx| { - ctx.maildir.as_ref().map(AddMaildirMessage::new_boxed) - }); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - builder.set_add_message(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(AddMaildirMessage::new_boxed) - }); - } - #[cfg(feature = "notmuch")] - Some(BackendKind::Notmuch) => { - builder.set_add_message(|ctx| { - ctx.notmuch.as_ref().map(AddNotmuchMessage::new_boxed) - }); - } - _ => (), - }; - - match send_message_kind { - #[cfg(feature = "smtp")] - Some(BackendKind::Smtp) => { - builder.set_send_message(|ctx| { - ctx.smtp.as_ref().map(SendSmtpMessage::new_boxed) - }); - } - #[cfg(feature = "sendmail")] - Some(BackendKind::Sendmail) => { - builder.set_send_message(|ctx| { - ctx.sendmail.as_ref().map(SendSendmailMessage::new_boxed) - }); - } - _ => (), - }; + |builder| { + builder.set_add_message(Some(None)); + builder.set_send_message(Some(None)); }, ) .await?; @@ -120,6 +66,6 @@ impl MessageWriteCommand { .build() .await?; - editor::edit_tpl_with_editor(&account_config, printer, &backend, tpl).await + editor::edit_tpl_with_editor(account_config, printer, &backend, tpl).await } } diff --git a/src/email/message/config.rs b/src/email/message/config.rs index 695e1cd..1c72562 100644 --- a/src/email/message/config.rs +++ b/src/email/message/config.rs @@ -5,19 +5,18 @@ use crate::backend::BackendKind; #[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)] pub struct MessageConfig { - #[cfg(any(feature = "message-add", feature = "message-write"))] + #[cfg(any(feature = "account-sync", feature = "message-add"))] pub write: Option, #[cfg(any(feature = "message-send", feature = "template-send"))] pub send: Option, - #[cfg(feature = "message-peek")] + #[cfg(feature = "account-sync")] pub peek: Option, - #[cfg(any(feature = "message-get", feature = "message-read"))] + #[cfg(any(feature = "account-sync", feature = "message-get"))] pub read: Option, #[cfg(feature = "message-copy")] pub copy: Option, - #[cfg(feature = "message-move")] - #[serde(rename = "move")] - pub move_: Option, + #[cfg(any(feature = "account-sync", feature = "message-move"))] + pub r#move: Option, #[cfg(feature = "message-delete")] pub delete: Option, } @@ -27,7 +26,7 @@ impl MessageConfig { #[allow(unused_mut)] let mut kinds = HashSet::default(); - #[cfg(any(feature = "message-add", feature = "message-write"))] + #[cfg(any(feature = "account-sync", feature = "message-add"))] if let Some(add) = &self.write { kinds.extend(add.get_used_backends()); } @@ -37,12 +36,12 @@ impl MessageConfig { kinds.extend(send.get_used_backends()); } - #[cfg(feature = "message-peek")] + #[cfg(feature = "account-sync")] if let Some(peek) = &self.peek { kinds.extend(peek.get_used_backends()); } - #[cfg(any(feature = "message-get", feature = "message-read"))] + #[cfg(any(feature = "account-sync", feature = "message-get"))] if let Some(get) = &self.read { kinds.extend(get.get_used_backends()); } @@ -52,8 +51,8 @@ impl MessageConfig { kinds.extend(copy.get_used_backends()); } - #[cfg(feature = "message-move")] - if let Some(move_) = &self.move_ { + #[cfg(any(feature = "account-sync", feature = "message-move"))] + if let Some(move_) = &self.r#move { kinds.extend(move_.get_used_backends()); } @@ -61,7 +60,7 @@ impl MessageConfig { } } -#[cfg(any(feature = "message-add", feature = "message-write"))] +#[cfg(any(feature = "account-sync", feature = "message-add"))] #[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)] pub struct MessageAddConfig { pub backend: Option, @@ -70,7 +69,7 @@ pub struct MessageAddConfig { pub remote: email::message::add::config::MessageWriteConfig, } -#[cfg(any(feature = "message-add", feature = "message-write"))] +#[cfg(any(feature = "account-sync", feature = "message-add"))] impl MessageAddConfig { pub fn get_used_backends(&self) -> HashSet<&BackendKind> { let mut kinds = HashSet::default(); @@ -105,13 +104,13 @@ impl MessageSendConfig { } } -#[cfg(feature = "message-peek")] +#[cfg(any(feature = "account-sync", feature = "message-peek"))] #[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)] pub struct MessagePeekConfig { pub backend: Option, } -#[cfg(feature = "message-peek")] +#[cfg(any(feature = "account-sync", feature = "message-peek"))] impl MessagePeekConfig { pub fn get_used_backends(&self) -> HashSet<&BackendKind> { let mut kinds = HashSet::default(); @@ -124,7 +123,7 @@ impl MessagePeekConfig { } } -#[cfg(any(feature = "message-get", feature = "message-read"))] +#[cfg(any(feature = "account-sync", feature = "message-get"))] #[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)] pub struct MessageGetConfig { pub backend: Option, @@ -133,7 +132,7 @@ pub struct MessageGetConfig { pub remote: email::message::get::config::MessageReadConfig, } -#[cfg(any(feature = "message-get", feature = "message-read"))] +#[cfg(any(feature = "account-sync", feature = "message-get"))] impl MessageGetConfig { pub fn get_used_backends(&self) -> HashSet<&BackendKind> { let mut kinds = HashSet::default(); @@ -165,13 +164,13 @@ impl MessageCopyConfig { } } -#[cfg(feature = "message-move")] +#[cfg(any(feature = "account-sync", feature = "message-move"))] #[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)] pub struct MessageMoveConfig { pub backend: Option, } -#[cfg(feature = "message-move")] +#[cfg(any(feature = "account-sync", feature = "message-move"))] impl MessageMoveConfig { pub fn get_used_backends(&self) -> HashSet<&BackendKind> { let mut kinds = HashSet::default(); diff --git a/src/email/message/template/command/forward.rs b/src/email/message/template/command/forward.rs index 109b771..3d3ac58 100644 --- a/src/email/message/template/command/forward.rs +++ b/src/email/message/template/command/forward.rs @@ -1,17 +1,12 @@ use anyhow::{anyhow, Result}; use clap::Parser; -#[cfg(feature = "imap")] -use email::message::get::imap::GetImapMessages; -#[cfg(feature = "maildir")] -use email::{flag::add::maildir::AddMaildirFlags, message::peek::maildir::PeekMaildirMessages}; use log::info; #[cfg(feature = "account-sync")] use crate::cache::arg::disable::CacheDisableFlag; -#[allow(unused)] use crate::{ account::arg::name::AccountNameFlag, - backend::{Backend, BackendKind}, + backend::Backend, config::TomlConfig, envelope::arg::ids::EnvelopeIdArg, folder::arg::name::FolderNameOptionalFlag, @@ -61,38 +56,10 @@ impl TemplateForwardCommand { let get_messages_kind = toml_account_config.get_messages_kind(); let backend = Backend::new( - &toml_account_config, - &account_config, + toml_account_config.clone(), + account_config.clone(), get_messages_kind, - |#[allow(unused)] builder| match get_messages_kind { - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - builder - .set_get_messages(|ctx| ctx.imap.as_ref().map(GetImapMessages::new_boxed)); - } - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - builder.set_peek_messages(|ctx| { - ctx.maildir.as_ref().map(PeekMaildirMessages::new_boxed) - }); - builder - .set_add_flags(|ctx| ctx.maildir.as_ref().map(AddMaildirFlags::new_boxed)); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - builder.set_peek_messages(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(PeekMaildirMessages::new_boxed) - }); - builder.set_add_flags(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(AddMaildirFlags::new_boxed) - }); - } - _ => (), - }, + |builder| builder.set_get_messages(Some(None)), ) .await?; diff --git a/src/email/message/template/command/reply.rs b/src/email/message/template/command/reply.rs index d905a57..4857a7d 100644 --- a/src/email/message/template/command/reply.rs +++ b/src/email/message/template/command/reply.rs @@ -1,17 +1,12 @@ use anyhow::{anyhow, Result}; use clap::Parser; -#[cfg(feature = "imap")] -use email::message::get::imap::GetImapMessages; -#[cfg(feature = "maildir")] -use email::{flag::add::maildir::AddMaildirFlags, message::peek::maildir::PeekMaildirMessages}; use log::info; #[cfg(feature = "account-sync")] use crate::cache::arg::disable::CacheDisableFlag; -#[allow(unused)] use crate::{ account::arg::name::AccountNameFlag, - backend::{Backend, BackendKind}, + backend::Backend, config::TomlConfig, envelope::arg::ids::EnvelopeIdArg, folder::arg::name::FolderNameOptionalFlag, @@ -66,38 +61,10 @@ impl TemplateReplyCommand { let get_messages_kind = toml_account_config.get_messages_kind(); let backend = Backend::new( - &toml_account_config, - &account_config, + toml_account_config.clone(), + account_config.clone(), get_messages_kind, - |#[allow(unused)] builder| match get_messages_kind { - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - builder - .set_get_messages(|ctx| ctx.imap.as_ref().map(GetImapMessages::new_boxed)); - } - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - builder.set_peek_messages(|ctx| { - ctx.maildir.as_ref().map(PeekMaildirMessages::new_boxed) - }); - builder - .set_add_flags(|ctx| ctx.maildir.as_ref().map(AddMaildirFlags::new_boxed)); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - builder.set_peek_messages(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(PeekMaildirMessages::new_boxed) - }); - builder.set_add_flags(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(AddMaildirFlags::new_boxed) - }); - } - _ => (), - }, + |builder| builder.set_get_messages(Some(None)), ) .await?; diff --git a/src/email/message/template/command/save.rs b/src/email/message/template/command/save.rs index dbf92e5..65abb30 100644 --- a/src/email/message/template/command/save.rs +++ b/src/email/message/template/command/save.rs @@ -1,22 +1,14 @@ use anyhow::Result; use clap::Parser; -#[cfg(feature = "imap")] -use email::message::add::imap::AddImapMessage; -#[cfg(feature = "maildir")] -use email::message::add::maildir::AddMaildirMessage; use log::info; use mml::MmlCompilerBuilder; use std::io::{self, BufRead, IsTerminal}; #[cfg(feature = "account-sync")] use crate::cache::arg::disable::CacheDisableFlag; -#[allow(unused)] use crate::{ - account::arg::name::AccountNameFlag, - backend::{Backend, BackendKind}, - config::TomlConfig, - email::template::arg::TemplateRawArg, - folder::arg::name::FolderNameOptionalFlag, + account::arg::name::AccountNameFlag, backend::Backend, config::TomlConfig, + email::template::arg::TemplateRawArg, folder::arg::name::FolderNameOptionalFlag, printer::Printer, }; @@ -57,30 +49,10 @@ impl TemplateSaveCommand { let add_message_kind = toml_account_config.add_message_kind(); let backend = Backend::new( - &toml_account_config, - &account_config, + toml_account_config.clone(), + account_config.clone(), add_message_kind, - |#[allow(unused)] builder| match add_message_kind { - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - builder.set_add_message(|ctx| ctx.imap.as_ref().map(AddImapMessage::new_boxed)); - } - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - builder.set_add_message(|ctx| { - ctx.maildir.as_ref().map(AddMaildirMessage::new_boxed) - }); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - builder.set_add_message(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(AddMaildirMessage::new_boxed) - }); - } - _ => (), - }, + |builder| builder.set_add_message(Some(None)), ) .await?; diff --git a/src/email/message/template/command/send.rs b/src/email/message/template/command/send.rs index 8b6e3e3..c323f4f 100644 --- a/src/email/message/template/command/send.rs +++ b/src/email/message/template/command/send.rs @@ -1,26 +1,14 @@ use anyhow::Result; use clap::Parser; -#[cfg(feature = "imap")] -use email::message::add::imap::AddImapMessage; -#[cfg(feature = "maildir")] -use email::message::add::maildir::AddMaildirMessage; -#[cfg(feature = "sendmail")] -use email::message::send::sendmail::SendSendmailMessage; -#[cfg(feature = "smtp")] -use email::message::send::smtp::SendSmtpMessage; use log::info; use mml::MmlCompilerBuilder; use std::io::{self, BufRead, IsTerminal}; #[cfg(feature = "account-sync")] use crate::cache::arg::disable::CacheDisableFlag; -#[allow(unused)] use crate::{ - account::arg::name::AccountNameFlag, - backend::{Backend, BackendKind}, - config::TomlConfig, - email::template::arg::TemplateRawArg, - printer::Printer, + account::arg::name::AccountNameFlag, backend::Backend, config::TomlConfig, + email::template::arg::TemplateRawArg, printer::Printer, }; /// Send a template. @@ -55,55 +43,20 @@ impl TemplateSendCommand { let send_message_kind = toml_account_config.send_message_kind(); #[cfg(feature = "message-add")] - let add_message_kind = toml_account_config - .add_message_kind() - .filter(|_| account_config.should_save_copy_sent_message()); - #[cfg(not(feature = "message-add"))] - let add_message_kind = None; + let send_message_kind = send_message_kind.into_iter().chain( + toml_account_config + .add_message_kind() + .filter(|_| account_config.should_save_copy_sent_message()), + ); let backend = Backend::new( - &toml_account_config, - &account_config, - send_message_kind.into_iter().chain(add_message_kind), - |#[allow(unused)] builder| { - match add_message_kind { - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - builder.set_add_message(|ctx| { - ctx.imap.as_ref().map(AddImapMessage::new_boxed) - }); - } - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - builder.set_add_message(|ctx| { - ctx.maildir.as_ref().map(AddMaildirMessage::new_boxed) - }); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - builder.set_add_message(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(AddMaildirMessage::new_boxed) - }); - } - _ => (), - }; - match send_message_kind { - #[cfg(feature = "smtp")] - Some(BackendKind::Smtp) => { - builder.set_send_message(|ctx| { - ctx.smtp.as_ref().map(SendSmtpMessage::new_boxed) - }); - } - #[cfg(feature = "sendmail")] - Some(BackendKind::Sendmail) => { - builder.set_send_message(|ctx| { - ctx.sendmail.as_ref().map(SendSendmailMessage::new_boxed) - }); - } - _ => (), - }; + toml_account_config.clone(), + account_config.clone(), + send_message_kind, + |builder| { + builder.set_send_message(Some(None)); + #[cfg(feature = "message-add")] + builder.set_add_message(Some(None)); }, ) .await?; diff --git a/src/folder/command/add.rs b/src/folder/command/add.rs index 751a1fa..8f1493f 100644 --- a/src/folder/command/add.rs +++ b/src/folder/command/add.rs @@ -1,15 +1,7 @@ use anyhow::Result; use clap::Parser; -#[cfg(feature = "imap")] -use email::folder::add::imap::AddImapFolder; -#[cfg(feature = "maildir")] -use email::folder::add::maildir::AddMaildirFolder; -#[cfg(feature = "notmuch")] -use email::folder::add::notmuch::AddNotmuchFolder; use log::info; -#[cfg(any(feature = "imap", feature = "maildir", feature = "account-sync"))] -use crate::backend::BackendKind; #[cfg(feature = "account-sync")] use crate::cache::arg::disable::CacheDisableFlag; use crate::{ @@ -48,36 +40,10 @@ impl AddFolderCommand { let add_folder_kind = toml_account_config.add_folder_kind(); let backend = Backend::new( - &toml_account_config, - &account_config, + toml_account_config.clone(), + account_config, add_folder_kind, - |builder| match add_folder_kind { - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - builder.set_add_folder(|ctx| ctx.imap.as_ref().map(AddImapFolder::new_boxed)); - } - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - builder.set_add_folder(|ctx| { - ctx.maildir.as_ref().map(AddMaildirFolder::new_boxed) - }); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - builder.set_add_folder(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(AddMaildirFolder::new_boxed) - }); - } - #[cfg(feature = "notmuch")] - Some(BackendKind::Notmuch) => { - builder.set_add_folder(|ctx| { - ctx.notmuch.as_ref().map(AddNotmuchFolder::new_boxed) - }); - } - _ => (), - }, + |builder| builder.set_add_folder(Some(None)), ) .await?; diff --git a/src/folder/command/delete.rs b/src/folder/command/delete.rs index c52e73a..85d18e4 100644 --- a/src/folder/command/delete.rs +++ b/src/folder/command/delete.rs @@ -1,17 +1,9 @@ use anyhow::Result; use clap::Parser; use dialoguer::Confirm; -#[cfg(feature = "imap")] -use email::folder::delete::imap::DeleteImapFolder; -#[cfg(feature = "maildir")] -use email::folder::delete::maildir::DeleteMaildirFolder; -// #[cfg(feature = "notmuch")] -// use email::folder::delete::notmuch::DeleteNotmuchFolder; use log::info; use std::process; -#[cfg(any(feature = "imap", feature = "maildir", feature = "account-sync"))] -use crate::backend::BackendKind; #[cfg(feature = "account-sync")] use crate::cache::arg::disable::CacheDisableFlag; use crate::{ @@ -61,39 +53,10 @@ impl FolderDeleteCommand { let delete_folder_kind = toml_account_config.delete_folder_kind(); let backend = Backend::new( - &toml_account_config, - &account_config, + toml_account_config.clone(), + account_config, delete_folder_kind, - |builder| match delete_folder_kind { - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - builder.set_delete_folder(|ctx| { - ctx.imap.as_ref().map(DeleteImapFolder::new_boxed) - }); - } - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - builder.set_delete_folder(|ctx| { - ctx.maildir.as_ref().map(DeleteMaildirFolder::new_boxed) - }); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - builder.set_delete_folder(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(DeleteMaildirFolder::new_boxed) - }); - } - #[cfg(feature = "notmuch")] - Some(BackendKind::Notmuch) => { - // TODO - // builder.set_delete_folder(|ctx| { - // ctx.notmuch.as_ref().map(DeleteNotmuchFolder::new_boxed) - // }); - } - _ => (), - }, + |builder| builder.set_delete_folder(Some(None)), ) .await?; diff --git a/src/folder/command/expunge.rs b/src/folder/command/expunge.rs index cc0087e..0b7841d 100644 --- a/src/folder/command/expunge.rs +++ b/src/folder/command/expunge.rs @@ -1,15 +1,7 @@ use anyhow::Result; use clap::Parser; -#[cfg(feature = "imap")] -use email::folder::expunge::imap::ExpungeImapFolder; -#[cfg(feature = "maildir")] -use email::folder::expunge::maildir::ExpungeMaildirFolder; -// #[cfg(feature = "notmuch")] -// use email::folder::expunge::notmuch::ExpungeNotmuchFolder; use log::info; -#[cfg(any(feature = "imap", feature = "maildir", feature = "account-sync"))] -use crate::backend::BackendKind; #[cfg(feature = "account-sync")] use crate::cache::arg::disable::CacheDisableFlag; use crate::{ @@ -49,39 +41,10 @@ impl FolderExpungeCommand { let expunge_folder_kind = toml_account_config.expunge_folder_kind(); let backend = Backend::new( - &toml_account_config, - &account_config, + toml_account_config.clone(), + account_config, expunge_folder_kind, - |builder| match expunge_folder_kind { - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - builder.set_expunge_folder(|ctx| { - ctx.imap.as_ref().map(ExpungeImapFolder::new_boxed) - }); - } - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - builder.set_expunge_folder(|ctx| { - ctx.maildir.as_ref().map(ExpungeMaildirFolder::new_boxed) - }); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - builder.set_expunge_folder(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(ExpungeMaildirFolder::new_boxed) - }); - } - #[cfg(feature = "notmuch")] - Some(BackendKind::Notmuch) => { - // TODO - // builder.set_expunge_folder(|ctx| { - // ctx.notmuch.as_ref().map(ExpungeNotmuchFolder::new_boxed) - // }); - } - _ => (), - }, + |builder| builder.set_expunge_folder(Some(None)), ) .await?; diff --git a/src/folder/command/list.rs b/src/folder/command/list.rs index b120168..8d71247 100644 --- a/src/folder/command/list.rs +++ b/src/folder/command/list.rs @@ -1,15 +1,7 @@ use anyhow::Result; use clap::Parser; -#[cfg(feature = "imap")] -use email::folder::list::imap::ListImapFolders; -#[cfg(feature = "maildir")] -use email::folder::list::maildir::ListMaildirFolders; -#[cfg(feature = "notmuch")] -use email::folder::list::notmuch::ListNotmuchFolders; use log::info; -#[cfg(any(feature = "imap", feature = "maildir", feature = "account-sync"))] -use crate::backend::BackendKind; #[cfg(feature = "account-sync")] use crate::cache::arg::disable::CacheDisableFlag; use crate::{ @@ -50,38 +42,10 @@ impl FolderListCommand { let list_folders_kind = toml_account_config.list_folders_kind(); let backend = Backend::new( - &toml_account_config, - &account_config, + toml_account_config.clone(), + account_config.clone(), list_folders_kind, - |builder| match list_folders_kind { - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - builder - .set_list_folders(|ctx| ctx.imap.as_ref().map(ListImapFolders::new_boxed)); - } - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - builder.set_list_folders(|ctx| { - ctx.maildir.as_ref().map(ListMaildirFolders::new_boxed) - }); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - builder.set_list_folders(|ctx| { - ctx.maildir_for_sync - .as_ref() - .map(ListMaildirFolders::new_boxed) - }); - } - #[cfg(feature = "notmuch")] - Some(BackendKind::Notmuch) => { - builder.set_list_folders(|ctx| { - ctx.notmuch.as_ref().map(ListNotmuchFolders::new_boxed) - }); - } - - _ => (), - }, + |builder| builder.set_list_folders(Some(None)), ) .await?; diff --git a/src/folder/command/purge.rs b/src/folder/command/purge.rs index 97a8156..aab6c47 100644 --- a/src/folder/command/purge.rs +++ b/src/folder/command/purge.rs @@ -1,17 +1,9 @@ use anyhow::Result; use clap::Parser; use dialoguer::Confirm; -#[cfg(feature = "imap")] -use email::folder::purge::imap::PurgeImapFolder; -// #[cfg(feature = "maildir")] -// use email::folder::purge::maildir::PurgeMaildirFolder; -// #[cfg(feature = "notmuch")] -// use email::folder::purge::notmuch::PurgeNotmuchFolder; use log::info; use std::process; -#[cfg(any(feature = "imap", feature = "maildir", feature = "account-sync"))] -use crate::backend::BackendKind; #[cfg(feature = "account-sync")] use crate::cache::arg::disable::CacheDisableFlag; use crate::{ @@ -61,40 +53,10 @@ impl FolderPurgeCommand { let purge_folder_kind = toml_account_config.purge_folder_kind(); let backend = Backend::new( - &toml_account_config, - &account_config, + toml_account_config.clone(), + account_config, purge_folder_kind, - |builder| match purge_folder_kind { - #[cfg(feature = "imap")] - Some(BackendKind::Imap) => { - builder - .set_purge_folder(|ctx| ctx.imap.as_ref().map(PurgeImapFolder::new_boxed)); - } - #[cfg(feature = "maildir")] - Some(BackendKind::Maildir) => { - // TODO - // builder.set_purge_folder(|ctx| { - // ctx.maildir.as_ref().map(PurgeMaildirFolder::new_boxed) - // }); - } - #[cfg(feature = "account-sync")] - Some(BackendKind::MaildirForSync) => { - // TODO - // builder.set_purge_folder(|ctx| { - // ctx.maildir_for_sync - // .as_ref() - // .map(PurgeMaildirFolder::new_boxed) - // }); - } - #[cfg(feature = "notmuch")] - Some(BackendKind::Notmuch) => { - // TODO - // builder.set_purge_folder(|ctx| { - // ctx.notmuch.as_ref().map(PurgeNotmuchFolder::new_boxed) - // }); - } - _ => (), - }, + |builder| builder.set_purge_folder(Some(None)), ) .await?; diff --git a/src/folder/config.rs b/src/folder/config.rs index e917672..e1ebd90 100644 --- a/src/folder/config.rs +++ b/src/folder/config.rs @@ -8,15 +8,15 @@ pub struct FolderConfig { #[serde(alias = "aliases")] pub alias: Option>, - #[cfg(feature = "folder-add")] + #[cfg(any(feature = "account-sync", feature = "folder-add"))] pub add: Option, - #[cfg(feature = "folder-list")] + #[cfg(any(feature = "account-sync", feature = "folder-list"))] pub list: Option, - #[cfg(feature = "folder-expunge")] + #[cfg(any(feature = "account-sync", feature = "folder-expunge"))] pub expunge: Option, #[cfg(feature = "folder-purge")] pub purge: Option, - #[cfg(feature = "folder-delete")] + #[cfg(any(feature = "account-sync", feature = "folder-delete"))] pub delete: Option, } @@ -25,17 +25,17 @@ impl FolderConfig { #[allow(unused_mut)] let mut kinds = HashSet::default(); - #[cfg(feature = "folder-add")] + #[cfg(any(feature = "account-sync", feature = "folder-add"))] if let Some(add) = &self.add { kinds.extend(add.get_used_backends()); } - #[cfg(feature = "folder-list")] + #[cfg(any(feature = "account-sync", feature = "folder-list"))] if let Some(list) = &self.list { kinds.extend(list.get_used_backends()); } - #[cfg(feature = "folder-expunge")] + #[cfg(any(feature = "account-sync", feature = "folder-expunge"))] if let Some(expunge) = &self.expunge { kinds.extend(expunge.get_used_backends()); } @@ -45,7 +45,7 @@ impl FolderConfig { kinds.extend(purge.get_used_backends()); } - #[cfg(feature = "folder-delete")] + #[cfg(any(feature = "account-sync", feature = "folder-delete"))] if let Some(delete) = &self.delete { kinds.extend(delete.get_used_backends()); } @@ -54,13 +54,13 @@ impl FolderConfig { } } -#[cfg(feature = "folder-add")] +#[cfg(any(feature = "account-sync", feature = "folder-add"))] #[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)] pub struct FolderAddConfig { pub backend: Option, } -#[cfg(feature = "folder-add")] +#[cfg(any(feature = "account-sync", feature = "folder-add"))] impl FolderAddConfig { pub fn get_used_backends(&self) -> HashSet<&BackendKind> { let mut kinds = HashSet::default(); @@ -73,7 +73,7 @@ impl FolderAddConfig { } } -#[cfg(feature = "folder-list")] +#[cfg(any(feature = "account-sync", feature = "folder-list"))] #[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)] pub struct FolderListConfig { pub backend: Option, @@ -82,7 +82,7 @@ pub struct FolderListConfig { pub remote: email::folder::list::config::FolderListConfig, } -#[cfg(feature = "folder-list")] +#[cfg(any(feature = "account-sync", feature = "folder-list"))] impl FolderListConfig { pub fn get_used_backends(&self) -> HashSet<&BackendKind> { let mut kinds = HashSet::default(); @@ -95,13 +95,13 @@ impl FolderListConfig { } } -#[cfg(feature = "folder-expunge")] +#[cfg(any(feature = "account-sync", feature = "folder-expunge"))] #[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)] pub struct FolderExpungeConfig { pub backend: Option, } -#[cfg(feature = "folder-expunge")] +#[cfg(any(feature = "account-sync", feature = "folder-expunge"))] impl FolderExpungeConfig { pub fn get_used_backends(&self) -> HashSet<&BackendKind> { let mut kinds = HashSet::default(); @@ -133,13 +133,13 @@ impl FolderPurgeConfig { } } -#[cfg(feature = "folder-delete")] +#[cfg(any(feature = "account-sync", feature = "folder-delete"))] #[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)] pub struct FolderDeleteConfig { pub backend: Option, } -#[cfg(feature = "folder-delete")] +#[cfg(any(feature = "account-sync", feature = "folder-delete"))] impl FolderDeleteConfig { pub fn get_used_backends(&self) -> HashSet<&BackendKind> { let mut kinds = HashSet::default(); diff --git a/src/ui/editor.rs b/src/ui/editor.rs index ef2ccb6..4033bad 100644 --- a/src/ui/editor.rs +++ b/src/ui/editor.rs @@ -12,7 +12,7 @@ use log::debug; #[cfg(any(feature = "message-send", feature = "template-send"))] use mml::MmlCompilerBuilder; use process::SingleCmd; -use std::{env, fs}; +use std::{env, fs, sync::Arc}; use crate::{ backend::Backend, @@ -50,7 +50,7 @@ pub async fn open_with_local_draft() -> Result { #[allow(unused)] pub async fn edit_tpl_with_editor( - config: &AccountConfig, + config: Arc, printer: &mut P, backend: &Backend, mut tpl: String,