mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-17 05:07:55 +08:00
refactor new backend api
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user