mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-17 13:17:55 +08:00
improve backend features management for every command
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
use anyhow::Result;
|
||||
use clap::Parser;
|
||||
#[cfg(feature = "imap")]
|
||||
use email::message::copy::imap::CopyMessagesImap;
|
||||
#[cfg(feature = "maildir")]
|
||||
use email::message::copy::maildir::CopyMessagesMaildir;
|
||||
use log::info;
|
||||
|
||||
use crate::{
|
||||
account::arg::name::AccountNameFlag,
|
||||
backend::Backend,
|
||||
backend::{Backend, BackendKind},
|
||||
cache::arg::disable::CacheDisableFlag,
|
||||
config::TomlConfig,
|
||||
envelope::arg::ids::EnvelopeIdsArgs,
|
||||
@@ -33,22 +37,50 @@ pub struct MessageCopyCommand {
|
||||
|
||||
impl MessageCopyCommand {
|
||||
pub async fn execute(self, printer: &mut impl Printer, config: &TomlConfig) -> Result<()> {
|
||||
info!("executing message copy command");
|
||||
|
||||
let from_folder = &self.source_folder.name;
|
||||
let to_folder = &self.target_folder.name;
|
||||
let account = self.account.name.as_ref().map(String::as_str);
|
||||
let cache = self.cache.disable;
|
||||
|
||||
let (toml_account_config, account_config) =
|
||||
config.clone().into_account_configs(account, cache)?;
|
||||
let backend = Backend::new(toml_account_config, account_config.clone(), false).await?;
|
||||
info!("executing copy message(s) command");
|
||||
|
||||
let source = &self.source_folder.name;
|
||||
let target = &self.target_folder.name;
|
||||
let ids = &self.envelopes.ids;
|
||||
backend.copy_messages(from_folder, to_folder, ids).await?;
|
||||
|
||||
let (toml_account_config, account_config) = config.clone().into_account_configs(
|
||||
self.account.name.as_ref().map(String::as_str),
|
||||
self.cache.disable,
|
||||
)?;
|
||||
|
||||
let copy_messages_kind = toml_account_config.copy_messages_kind();
|
||||
|
||||
let backend = Backend::new(
|
||||
&toml_account_config,
|
||||
&account_config,
|
||||
copy_messages_kind,
|
||||
|builder| match copy_messages_kind {
|
||||
Some(BackendKind::Maildir) => {
|
||||
builder.set_copy_messages(|ctx| {
|
||||
ctx.maildir.as_ref().and_then(CopyMessagesMaildir::new)
|
||||
});
|
||||
}
|
||||
Some(BackendKind::MaildirForSync) => {
|
||||
builder.set_copy_messages(|ctx| {
|
||||
ctx.maildir_for_sync
|
||||
.as_ref()
|
||||
.and_then(CopyMessagesMaildir::new)
|
||||
});
|
||||
}
|
||||
#[cfg(feature = "imap")]
|
||||
Some(BackendKind::Imap) => {
|
||||
builder
|
||||
.set_copy_messages(|ctx| ctx.imap.as_ref().and_then(CopyMessagesImap::new));
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
||||
backend.copy_messages(source, target, ids).await?;
|
||||
|
||||
printer.print(format!(
|
||||
"Message(s) successfully copied from {from_folder} to {to_folder}!"
|
||||
"Message(s) successfully copied from {source} to {target}!"
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user