From 17115319ee1d393e3c246c74629f4f1b0ad79d1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20DOUIN?= Date: Sat, 3 Apr 2021 11:50:07 +0200 Subject: [PATCH] introduce signature feature --- src/config/model.rs | 10 ++++++++++ src/msg/model.rs | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/src/config/model.rs b/src/config/model.rs index abd6f29..881777d 100644 --- a/src/config/model.rs +++ b/src/config/model.rs @@ -16,6 +16,7 @@ pub struct Account { // Override pub name: Option, pub downloads_dir: Option, + pub signature: Option, // Specific pub default: Option, @@ -76,6 +77,7 @@ pub struct Config { pub name: String, pub downloads_dir: Option, pub notify_cmd: Option, + pub signature: Option, #[serde(flatten)] pub accounts: HashMap, @@ -170,4 +172,12 @@ impl Config { Ok(()) } + + pub fn signature(&self, account: &Account) -> Option { + account + .signature + .as_ref() + .or_else(|| self.signature.as_ref()) + .map(|sig| sig.to_owned()) + } } diff --git a/src/msg/model.rs b/src/msg/model.rs index 080c72a..31c5523 100644 --- a/src/msg/model.rs +++ b/src/msg/model.rs @@ -360,6 +360,18 @@ impl<'m> Msg<'m> { // "Subject" header tpl.push("Subject: ".to_string()); + // Separator between headers and body + tpl.push(String::new()); + + // Signature + if let Some(sig) = config.signature(&account) { + tpl.push(String::new()); + tpl.push("--".to_string()); + for line in sig.split("\n") { + tpl.push(line.to_string()); + } + } + Ok(Tpl(tpl.join("\r\n"))) } @@ -404,6 +416,15 @@ impl<'m> Msg<'m> { .join("\r\n"); tpl.push(thread); + // Signature + if let Some(sig) = config.signature(&account) { + tpl.push(String::new()); + tpl.push("--".to_string()); + for line in sig.split("\n") { + tpl.push(line.to_string()); + } + } + Ok(Tpl(tpl.join("\r\n"))) } @@ -489,6 +510,15 @@ impl<'m> Msg<'m> { .join("\r\n"); tpl.push(thread); + // Signature + if let Some(sig) = config.signature(&account) { + tpl.push(String::new()); + tpl.push("--".to_string()); + for line in sig.split("\n") { + tpl.push(line.to_string()); + } + } + Ok(Tpl(tpl.join("\r\n"))) } @@ -518,6 +548,15 @@ impl<'m> Msg<'m> { tpl.push("-------- Forwarded Message --------".to_string()); tpl.push(self.text_bodies("text/plain")?); + // Signature + if let Some(sig) = config.signature(&account) { + tpl.push(String::new()); + tpl.push("--".to_string()); + for line in sig.split("\n") { + tpl.push(line.to_string()); + } + } + Ok(Tpl(tpl.join("\r\n"))) } }