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,12 +1,20 @@
|
||||
use anyhow::Result;
|
||||
use clap::Parser;
|
||||
#[cfg(feature = "sendmail")]
|
||||
use email::message::send_raw::sendmail::SendRawMessageSendmail;
|
||||
#[cfg(feature = "smtp")]
|
||||
use email::message::send_raw::smtp::SendRawMessageSmtp;
|
||||
use log::info;
|
||||
use mml::MmlCompilerBuilder;
|
||||
use std::io::{self, BufRead, IsTerminal};
|
||||
|
||||
use crate::{
|
||||
account::arg::name::AccountNameFlag, backend::Backend, cache::arg::disable::CacheDisableFlag,
|
||||
config::TomlConfig, email::template::arg::TemplateRawArg, printer::Printer,
|
||||
account::arg::name::AccountNameFlag,
|
||||
backend::{Backend, BackendKind},
|
||||
cache::arg::disable::CacheDisableFlag,
|
||||
config::TomlConfig,
|
||||
email::template::arg::TemplateRawArg,
|
||||
printer::Printer,
|
||||
};
|
||||
|
||||
/// Send a template.
|
||||
@@ -31,12 +39,36 @@ impl TemplateSendCommand {
|
||||
pub async fn execute(self, printer: &mut impl Printer, config: &TomlConfig) -> Result<()> {
|
||||
info!("executing template send command");
|
||||
|
||||
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(
|
||||
self.account.name.as_ref().map(String::as_str),
|
||||
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(), true).await?;
|
||||
let send_message_kind = toml_account_config.send_raw_message_kind();
|
||||
|
||||
let backend = Backend::new(
|
||||
&toml_account_config,
|
||||
&account_config,
|
||||
send_message_kind,
|
||||
|builder| {
|
||||
match send_message_kind {
|
||||
#[cfg(feature = "smtp")]
|
||||
Some(BackendKind::Smtp) => {
|
||||
builder.set_send_raw_message(|ctx| {
|
||||
ctx.smtp.as_ref().and_then(SendRawMessageSmtp::new)
|
||||
});
|
||||
}
|
||||
#[cfg(feature = "sendmail")]
|
||||
Some(BackendKind::Sendmail) => {
|
||||
builder.set_send_raw_message(|ctx| {
|
||||
ctx.sendmail.as_ref().and_then(SendRawMessageSendmail::new)
|
||||
});
|
||||
}
|
||||
_ => (),
|
||||
};
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
||||
let tpl = if io::stdin().is_terminal() {
|
||||
self.template.raw()
|
||||
|
||||
Reference in New Issue
Block a user