mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-17 05:07:55 +08:00
add one cargo feature per backend feature
This commit is contained in:
@@ -1,20 +1,21 @@
|
||||
use anyhow::Result;
|
||||
use clap::Parser;
|
||||
#[cfg(feature = "imap")]
|
||||
use email::message::add_raw::imap::AddRawMessageImap;
|
||||
use email::message::add::imap::AddMessageImap;
|
||||
#[cfg(feature = "maildir")]
|
||||
use email::message::add_raw_with_flags::maildir::AddRawMessageWithFlagsMaildir;
|
||||
use email::message::add_with_flags::maildir::AddMessageWithFlagsMaildir;
|
||||
#[cfg(feature = "sendmail")]
|
||||
use email::message::send_raw::sendmail::SendRawMessageSendmail;
|
||||
use email::message::send::sendmail::SendMessageSendmail;
|
||||
#[cfg(feature = "smtp")]
|
||||
use email::message::send_raw::smtp::SendRawMessageSmtp;
|
||||
use email::message::send::smtp::SendMessageSmtp;
|
||||
use email::message::Message;
|
||||
use log::info;
|
||||
|
||||
#[cfg(feature = "sync")]
|
||||
use crate::cache::arg::disable::CacheDisableFlag;
|
||||
use crate::{
|
||||
account::arg::name::AccountNameFlag,
|
||||
backend::{Backend, BackendKind},
|
||||
cache::arg::disable::CacheDisableFlag,
|
||||
config::TomlConfig,
|
||||
message::arg::{body::MessageRawBodyArg, header::HeaderRawArgs},
|
||||
printer::Printer,
|
||||
@@ -35,6 +36,7 @@ pub struct MessageWriteCommand {
|
||||
#[command(flatten)]
|
||||
pub body: MessageRawBodyArg,
|
||||
|
||||
#[cfg(feature = "sync")]
|
||||
#[command(flatten)]
|
||||
pub cache: CacheDisableFlag,
|
||||
|
||||
@@ -48,11 +50,12 @@ impl MessageWriteCommand {
|
||||
|
||||
let (toml_account_config, account_config) = config.clone().into_account_configs(
|
||||
self.account.name.as_ref().map(String::as_str),
|
||||
#[cfg(feature = "sync")]
|
||||
self.cache.disable,
|
||||
)?;
|
||||
|
||||
let add_message_kind = toml_account_config.add_raw_message_kind();
|
||||
let send_message_kind = toml_account_config.send_raw_message_kind();
|
||||
let add_message_kind = toml_account_config.add_message_kind();
|
||||
let send_message_kind = toml_account_config.send_message_kind();
|
||||
|
||||
let backend = Backend::new(
|
||||
&toml_account_config,
|
||||
@@ -60,24 +63,25 @@ impl MessageWriteCommand {
|
||||
add_message_kind.into_iter().chain(send_message_kind),
|
||||
|builder| {
|
||||
match add_message_kind {
|
||||
Some(BackendKind::Maildir) => {
|
||||
builder.set_add_raw_message_with_flags(|ctx| {
|
||||
ctx.maildir
|
||||
.as_ref()
|
||||
.and_then(AddRawMessageWithFlagsMaildir::new)
|
||||
});
|
||||
}
|
||||
Some(BackendKind::MaildirForSync) => {
|
||||
builder.set_add_raw_message_with_flags(|ctx| {
|
||||
ctx.maildir_for_sync
|
||||
.as_ref()
|
||||
.and_then(AddRawMessageWithFlagsMaildir::new)
|
||||
});
|
||||
}
|
||||
#[cfg(feature = "imap")]
|
||||
Some(BackendKind::Imap) => {
|
||||
builder.set_add_raw_message(|ctx| {
|
||||
ctx.imap.as_ref().and_then(AddRawMessageImap::new)
|
||||
builder
|
||||
.set_add_message(|ctx| ctx.imap.as_ref().and_then(AddMessageImap::new));
|
||||
}
|
||||
#[cfg(feature = "maildir")]
|
||||
Some(BackendKind::Maildir) => {
|
||||
builder.set_add_message_with_flags(|ctx| {
|
||||
ctx.maildir
|
||||
.as_ref()
|
||||
.and_then(AddMessageWithFlagsMaildir::new)
|
||||
});
|
||||
}
|
||||
#[cfg(feature = "sync")]
|
||||
Some(BackendKind::MaildirForSync) => {
|
||||
builder.set_add_message_with_flags(|ctx| {
|
||||
ctx.maildir_for_sync
|
||||
.as_ref()
|
||||
.and_then(AddMessageWithFlagsMaildir::new)
|
||||
});
|
||||
}
|
||||
_ => (),
|
||||
@@ -86,14 +90,14 @@ impl MessageWriteCommand {
|
||||
match send_message_kind {
|
||||
#[cfg(feature = "smtp")]
|
||||
Some(BackendKind::Smtp) => {
|
||||
builder.set_send_raw_message(|ctx| {
|
||||
ctx.smtp.as_ref().and_then(SendRawMessageSmtp::new)
|
||||
builder.set_send_message(|ctx| {
|
||||
ctx.smtp.as_ref().and_then(SendMessageSmtp::new)
|
||||
});
|
||||
}
|
||||
#[cfg(feature = "sendmail")]
|
||||
Some(BackendKind::Sendmail) => {
|
||||
builder.set_send_raw_message(|ctx| {
|
||||
ctx.sendmail.as_ref().and_then(SendRawMessageSendmail::new)
|
||||
builder.set_send_message(|ctx| {
|
||||
ctx.sendmail.as_ref().and_then(SendMessageSendmail::new)
|
||||
});
|
||||
}
|
||||
_ => (),
|
||||
|
||||
Reference in New Issue
Block a user