Skip to content

Commit

Permalink
introduce signature feature
Browse files Browse the repository at this point in the history
  • Loading branch information
soywod committed Apr 3, 2021
1 parent 1a26ac4 commit 1711531
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/config/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down Expand Up @@ -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>,
Expand Down Expand Up @@ -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())
}
}
39 changes: 39 additions & 0 deletions src/msg/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
}

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

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

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

0 comments on commit 1711531

Please sign in to comment.