diff --git a/Cargo.lock b/Cargo.lock index 5fabb49..f672761 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1212,7 +1212,7 @@ dependencies = [ [[package]] name = "email-lib" version = "0.22.3" -source = "git+https://git.sr.ht/~soywod/pimalaya#5774d5ac5176eb79543bb3bb075bbd026866559f" +source = "git+https://git.sr.ht/~soywod/pimalaya#ed7d5770064ed5e3409da426a954a5457f59d85a" dependencies = [ "advisory-lock", "anyhow", diff --git a/src/account/config.rs b/src/account/config.rs index 32b802f..a40ac30 100644 --- a/src/account/config.rs +++ b/src/account/config.rs @@ -17,6 +17,7 @@ use email::notmuch::config::NotmuchConfig; use email::sendmail::config::SendmailConfig; #[cfg(feature = "smtp")] use email::smtp::config::SmtpConfig; +use email::template::config::TemplateConfig; use serde::{Deserialize, Serialize}; use std::{collections::HashSet, path::PathBuf}; @@ -46,6 +47,7 @@ pub struct TomlAccountConfig { pub envelope: Option, pub flag: Option, pub message: Option, + pub template: Option, #[cfg(feature = "imap")] pub imap: Option, diff --git a/src/config/mod.rs b/src/config/mod.rs index cb5c7dd..2082fc6 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -257,6 +257,7 @@ impl TomlConfig { #[cfg(feature = "account-sync")] sync: c.sync, }), + template: config.template, #[cfg(feature = "account-sync")] sync: config.sync, #[cfg(feature = "pgp")] diff --git a/src/email/message/command/forward.rs b/src/email/message/command/forward.rs index 1a85aca..c586561 100644 --- a/src/email/message/command/forward.rs +++ b/src/email/message/command/forward.rs @@ -76,7 +76,7 @@ impl MessageForwardCommand { .await? .first() .ok_or(anyhow!("cannot find message"))? - .to_forward_tpl_builder(&account_config) + .to_forward_tpl_builder(account_config.clone()) .with_headers(self.headers.raw) .with_body(self.body.raw()) .build() diff --git a/src/email/message/command/mailto.rs b/src/email/message/command/mailto.rs index da4c495..20b3e6e 100644 --- a/src/email/message/command/mailto.rs +++ b/src/email/message/command/mailto.rs @@ -1,7 +1,7 @@ use anyhow::Result; use clap::Parser; use email::backend::feature::BackendFeatureSource; -use log::{debug, info}; +use log::info; use mail_builder::MessageBuilder; use url::Url; @@ -79,12 +79,8 @@ impl MessageMailtoCommand { } match account_config.find_full_signature() { - Ok(Some(ref signature)) => builder = builder.text_body(body + "\n\n" + signature), - Ok(None) => builder = builder.text_body(body), - Err(err) => { - debug!("cannot add signature to mailto message, skipping it: {err}"); - debug!("{err:?}"); - } + Some(ref sig) => builder = builder.text_body(body + "\n\n" + sig), + None => builder = builder.text_body(body), } let tpl = account_config @@ -92,7 +88,8 @@ impl MessageMailtoCommand { .with_show_only_headers(account_config.get_message_write_headers()) .build() .from_msg_builder(builder) - .await?; + .await? + .into(); editor::edit_tpl_with_editor(account_config, printer, &backend, tpl).await } diff --git a/src/email/message/command/reply.rs b/src/email/message/command/reply.rs index 04e1539..33830cd 100644 --- a/src/email/message/command/reply.rs +++ b/src/email/message/command/reply.rs @@ -78,7 +78,7 @@ impl MessageReplyCommand { .await? .first() .ok_or(anyhow!("cannot find message {id}"))? - .to_reply_tpl_builder(&account_config) + .to_reply_tpl_builder(account_config.clone()) .with_headers(self.headers.raw) .with_body(self.body.raw()) .with_reply_all(self.reply.all) diff --git a/src/email/message/command/write.rs b/src/email/message/command/write.rs index 1a53255..0746fcc 100644 --- a/src/email/message/command/write.rs +++ b/src/email/message/command/write.rs @@ -60,7 +60,7 @@ impl MessageWriteCommand { ) .await?; - let tpl = Message::new_tpl_builder(&account_config) + let tpl = Message::new_tpl_builder(account_config.clone()) .with_headers(self.headers.raw) .with_body(self.body.raw()) .build() diff --git a/src/email/message/template/command/forward.rs b/src/email/message/template/command/forward.rs index 472ff72..086205c 100644 --- a/src/email/message/template/command/forward.rs +++ b/src/email/message/template/command/forward.rs @@ -70,7 +70,7 @@ impl TemplateForwardCommand { .await? .first() .ok_or(anyhow!("cannot find message {id}"))? - .to_forward_tpl_builder(&account_config) + .to_forward_tpl_builder(account_config) .with_headers(self.headers.raw) .with_body(self.body.raw()) .build() diff --git a/src/email/message/template/command/reply.rs b/src/email/message/template/command/reply.rs index 9502b19..c7f40fa 100644 --- a/src/email/message/template/command/reply.rs +++ b/src/email/message/template/command/reply.rs @@ -74,7 +74,7 @@ impl TemplateReplyCommand { .await? .first() .ok_or(anyhow!("cannot find message {id}"))? - .to_reply_tpl_builder(&account_config) + .to_reply_tpl_builder(account_config) .with_headers(self.headers.raw) .with_body(self.body.raw()) .with_reply_all(self.reply.all) diff --git a/src/email/message/template/command/write.rs b/src/email/message/template/command/write.rs index e05b342..a3accc1 100644 --- a/src/email/message/template/command/write.rs +++ b/src/email/message/template/command/write.rs @@ -41,7 +41,7 @@ impl TemplateWriteCommand { self.cache.disable, )?; - let tpl = Message::new_tpl_builder(&account_config) + let tpl = Message::new_tpl_builder(account_config) .with_headers(self.headers.raw) .with_body(self.body.raw()) .build() diff --git a/src/email/message/template/mod.rs b/src/email/message/template/mod.rs index 1a3a73a..2272a00 100644 --- a/src/email/message/template/mod.rs +++ b/src/email/message/template/mod.rs @@ -1,2 +1,14 @@ pub mod arg; pub mod command; + +use anyhow::Result; +use email::template::Template; + +use crate::printer::{Print, WriteColor}; + +impl Print for Template { + fn print(&self, writer: &mut dyn WriteColor) -> Result<()> { + self.as_str().print(writer)?; + Ok(writer.reset()?) + } +} diff --git a/src/ui/editor.rs b/src/ui/editor.rs index b0adbe9..2d53e60 100644 --- a/src/ui/editor.rs +++ b/src/ui/editor.rs @@ -5,6 +5,7 @@ use email::{ flag::{Flag, Flags}, folder::DRAFTS, message::{add::AddMessage, send::SendMessageThenSaveCopy}, + template::Template, }; use log::debug; use mml::MmlCompilerBuilder; @@ -17,7 +18,7 @@ use crate::{ ui::choice::{self, PostEditChoice, PreEditChoice}, }; -pub async fn open_with_tpl(tpl: String) -> Result { +pub async fn open_with_tpl(tpl: Template) -> Result