mirror of
https://github.com/soywod/himalaya.git
synced 2024-11-22 02:50:19 +00:00
refactor new backend api
This commit is contained in:
parent
16266dbc0b
commit
4f9705952a
37 changed files with 819 additions and 1897 deletions
16
Cargo.lock
generated
16
Cargo.lock
generated
|
@ -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"
|
||||
|
|
14
Cargo.toml
14
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"
|
||||
|
|
|
@ -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<ProgressStyle> = 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<TomlAccountConfig>,
|
||||
builder: BackendBuilder<BackendContextBuilder>,
|
||||
}
|
||||
|
||||
impl AccountSyncBackendBuilder {
|
||||
pub async fn new(
|
||||
toml_account_config: Arc<TomlAccountConfig>,
|
||||
account_config: Arc<AccountConfig>,
|
||||
) -> Result<Self> {
|
||||
#[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<Backend> {
|
||||
Ok(Backend {
|
||||
toml_account_config: self.toml_account_config,
|
||||
backend: self.builder.build().await?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for AccountSyncBackendBuilder {
|
||||
type Target = BackendBuilder<BackendContextBuilder>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.builder
|
||||
}
|
||||
}
|
||||
|
||||
impl From<AccountSyncBackendBuilder> for BackendBuilder<BackendContextBuilder> {
|
||||
fn from(backend_builder: AccountSyncBackendBuilder) -> Self {
|
||||
backend_builder.builder
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
|
|
1140
src/backend/mod.rs
1140
src/backend/mod.rs
File diff suppressed because it is too large
Load diff
|
@ -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<TomlAccountConfig>, Arc<AccountConfig>)> {
|
||||
#[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)))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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?;
|
||||
|
||||
|
|
|
@ -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?;
|
||||
|
||||
|
|
|
@ -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<ListEnvelopesConfig>,
|
||||
#[cfg(feature = "envelope-watch")]
|
||||
pub watch: Option<WatchEnvelopesConfig>,
|
||||
#[cfg(feature = "envelope-get")]
|
||||
#[cfg(any(feature = "account-sync", feature = "envelope-get"))]
|
||||
pub get: Option<GetEnvelopeConfig>,
|
||||
}
|
||||
|
||||
|
@ -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<BackendKind>,
|
||||
|
@ -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<BackendKind>,
|
||||
}
|
||||
|
||||
#[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();
|
||||
|
|
|
@ -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?;
|
||||
|
||||
|
|
|
@ -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?;
|
||||
|
||||
|
|
|
@ -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?;
|
||||
|
||||
|
|
|
@ -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<Envelope>);
|
||||
|
||||
#[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<Envelope>;
|
||||
|
||||
|
@ -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)?;
|
||||
|
|
|
@ -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?;
|
||||
|
||||
|
|
|
@ -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?;
|
||||
|
||||
|
|
|
@ -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?;
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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")]
|
||||
|
|
|
@ -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?;
|
||||
|
|
@ -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?;
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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?;
|
||||
|
||||
|
|
|
@ -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?;
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<MessageAddConfig>,
|
||||
#[cfg(any(feature = "message-send", feature = "template-send"))]
|
||||
pub send: Option<MessageSendConfig>,
|
||||
#[cfg(feature = "message-peek")]
|
||||
#[cfg(feature = "account-sync")]
|
||||
pub peek: Option<MessagePeekConfig>,
|
||||
#[cfg(any(feature = "message-get", feature = "message-read"))]
|
||||
#[cfg(any(feature = "account-sync", feature = "message-get"))]
|
||||
pub read: Option<MessageGetConfig>,
|
||||
#[cfg(feature = "message-copy")]
|
||||
pub copy: Option<MessageCopyConfig>,
|
||||
#[cfg(feature = "message-move")]
|
||||
#[serde(rename = "move")]
|
||||
pub move_: Option<MessageMoveConfig>,
|
||||
#[cfg(any(feature = "account-sync", feature = "message-move"))]
|
||||
pub r#move: Option<MessageMoveConfig>,
|
||||
#[cfg(feature = "message-delete")]
|
||||
pub delete: Option<MessageDeleteConfig>,
|
||||
}
|
||||
|
@ -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<BackendKind>,
|
||||
|
@ -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<BackendKind>,
|
||||
}
|
||||
|
||||
#[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<BackendKind>,
|
||||
|
@ -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<BackendKind>,
|
||||
}
|
||||
|
||||
#[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();
|
||||
|
|
|
@ -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?;
|
||||
|
||||
|
|
|
@ -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?;
|
||||
|
||||
|
|
|
@ -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?;
|
||||
|
||||
|
|
|
@ -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?;
|
||||
|
|
|
@ -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?;
|
||||
|
||||
|
|
|
@ -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?;
|
||||
|
||||
|
|
|
@ -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?;
|
||||
|
||||
|
|
|
@ -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?;
|
||||
|
||||
|
|
|
@ -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?;
|
||||
|
||||
|
|
|
@ -8,15 +8,15 @@ pub struct FolderConfig {
|
|||
#[serde(alias = "aliases")]
|
||||
pub alias: Option<HashMap<String, String>>,
|
||||
|
||||
#[cfg(feature = "folder-add")]
|
||||
#[cfg(any(feature = "account-sync", feature = "folder-add"))]
|
||||
pub add: Option<FolderAddConfig>,
|
||||
#[cfg(feature = "folder-list")]
|
||||
#[cfg(any(feature = "account-sync", feature = "folder-list"))]
|
||||
pub list: Option<FolderListConfig>,
|
||||
#[cfg(feature = "folder-expunge")]
|
||||
#[cfg(any(feature = "account-sync", feature = "folder-expunge"))]
|
||||
pub expunge: Option<FolderExpungeConfig>,
|
||||
#[cfg(feature = "folder-purge")]
|
||||
pub purge: Option<FolderPurgeConfig>,
|
||||
#[cfg(feature = "folder-delete")]
|
||||
#[cfg(any(feature = "account-sync", feature = "folder-delete"))]
|
||||
pub delete: Option<FolderDeleteConfig>,
|
||||
}
|
||||
|
||||
|
@ -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<BackendKind>,
|
||||
}
|
||||
|
||||
#[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<BackendKind>,
|
||||
|
@ -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<BackendKind>,
|
||||
}
|
||||
|
||||
#[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<BackendKind>,
|
||||
}
|
||||
|
||||
#[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();
|
||||
|
|
|
@ -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<String> {
|
|||
|
||||
#[allow(unused)]
|
||||
pub async fn edit_tpl_with_editor<P: Printer>(
|
||||
config: &AccountConfig,
|
||||
config: Arc<AccountConfig>,
|
||||
printer: &mut P,
|
||||
backend: &Backend,
|
||||
mut tpl: String,
|
||||
|
|
Loading…
Reference in a new issue