add one cargo feature per backend feature

This commit is contained in:
Clément DOUIN
2024-01-07 23:48:45 +01:00
parent 9ffac16e05
commit a6b863759c
55 changed files with 1248 additions and 598 deletions
+7 -3
View File
@@ -1,4 +1,4 @@
use anyhow::{anyhow, Context, Result};
use anyhow::{anyhow, bail, Context, Result};
use log::{debug, error};
use std::io::{self, Write};
@@ -43,9 +43,11 @@ pub fn pre_edit() -> Result<PreEditChoice> {
}
pub enum PostEditChoice {
#[cfg(feature = "message-send")]
Send,
Edit,
LocalDraft,
#[cfg(feature = "message-add")]
RemoteDraft,
Discard,
}
@@ -60,6 +62,7 @@ pub fn post_edit() -> Result<PostEditChoice> {
.context("cannot read stdin")?;
match buf.bytes().next().map(|bytes| bytes as char) {
#[cfg(feature = "message-send")]
Some('s') => {
debug!("send choice matched");
Ok(PostEditChoice::Send)
@@ -68,6 +71,7 @@ pub fn post_edit() -> Result<PostEditChoice> {
debug!("save local draft choice matched");
Ok(PostEditChoice::LocalDraft)
}
#[cfg(feature = "message-add")]
Some('r') => {
debug!("save remote draft matched");
Ok(PostEditChoice::RemoteDraft)
@@ -82,11 +86,11 @@ pub fn post_edit() -> Result<PostEditChoice> {
}
Some(choice) => {
error!(r#"invalid choice "{}""#, choice);
Err(anyhow!(r#"invalid choice "{}""#, choice))
bail!("invalid choice {choice}");
}
None => {
error!("empty choice");
Err(anyhow!("empty choice"))
bail!("empty choice");
}
}
}
+10 -3
View File
@@ -2,10 +2,14 @@ use anyhow::{Context, Result};
use email::{
account::config::AccountConfig,
email::utils::{local_draft_path, remove_local_draft},
};
#[cfg(feature = "message-add")]
use email::{
flag::{Flag, Flags},
folder::DRAFTS,
};
use log::debug;
#[cfg(any(feature = "message-send", feature = "template-send"))]
use mml::MmlCompilerBuilder;
use process::SingleCmd;
use std::{env, fs};
@@ -44,8 +48,9 @@ pub async fn open_with_local_draft() -> Result<String> {
open_with_tpl(content).await
}
#[allow(unused)]
pub async fn edit_tpl_with_editor<P: Printer>(
#[allow(unused)] config: &AccountConfig,
config: &AccountConfig,
printer: &mut P,
backend: &Backend,
mut tpl: String,
@@ -77,6 +82,7 @@ pub async fn edit_tpl_with_editor<P: Printer>(
loop {
match choice::post_edit() {
#[cfg(feature = "message-send")]
Ok(PostEditChoice::Send) => {
printer.print_log("Sending email…")?;
@@ -88,7 +94,7 @@ pub async fn edit_tpl_with_editor<P: Printer>(
let email = compiler.build(tpl.as_str())?.compile().await?.into_vec()?;
backend.send_raw_message(&email).await?;
backend.send_message(&email).await?;
remove_local_draft()?;
printer.print("Done!")?;
@@ -102,6 +108,7 @@ pub async fn edit_tpl_with_editor<P: Printer>(
printer.print("Email successfully saved locally")?;
break;
}
#[cfg(feature = "message-add")]
Ok(PostEditChoice::RemoteDraft) => {
#[allow(unused_mut)]
let mut compiler = MmlCompilerBuilder::new();
@@ -112,7 +119,7 @@ pub async fn edit_tpl_with_editor<P: Printer>(
let email = compiler.build(tpl.as_str())?.compile().await?.into_vec()?;
backend
.add_raw_message_with_flags(
.add_message_with_flags(
DRAFTS,
&email,
&Flags::from_iter([Flag::Seen, Flag::Draft]),