introduce signature feature

This commit is contained in:
Clément DOUIN 2021-04-03 11:50:07 +02:00
parent 1a26ac4b2c
commit 17115319ee
No known key found for this signature in database
GPG key ID: 69C9B9CFFDEE2DEF
2 changed files with 49 additions and 0 deletions

View file

@ -16,6 +16,7 @@ pub struct Account {
// Override
pub name: Option<String>,
pub downloads_dir: Option<PathBuf>,
pub signature: Option<String>,
// Specific
pub default: Option<bool>,
@ -76,6 +77,7 @@ pub struct Config {
pub name: String,
pub downloads_dir: Option<PathBuf>,
pub notify_cmd: Option<String>,
pub signature: Option<String>,
#[serde(flatten)]
pub accounts: HashMap<String, Account>,
@ -170,4 +172,12 @@ impl Config {
Ok(())
}
pub fn signature(&self, account: &Account) -> Option<String> {
account
.signature
.as_ref()
.or_else(|| self.signature.as_ref())
.map(|sig| sig.to_owned())
}
}

View file

@ -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")))
}
}