mirror of
https://github.com/soywod/himalaya.git
synced 2024-11-22 02:50:19 +00:00
add config opt signature-delimiter
This commit is contained in:
parent
32d8cf0163
commit
a6b30b746c
4 changed files with 22 additions and 5 deletions
|
@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
|
||||
- Config option `signature-delimiter` to customize the signature delimiter (default to `-- \n`) [[#114](https://github.com/soywod/himalaya/pull/114)]
|
||||
|
||||
### Fixed
|
||||
|
||||
- New/reply/forward from Vim plugin since Tpl refactor [#176]
|
||||
|
|
|
@ -26,6 +26,7 @@ pub struct Account {
|
|||
// Override
|
||||
pub name: Option<String>,
|
||||
pub downloads_dir: Option<PathBuf>,
|
||||
pub signature_delimiter: Option<String>,
|
||||
pub signature: Option<String>,
|
||||
pub default_page_size: Option<usize>,
|
||||
pub watch_cmds: Option<Vec<String>>,
|
||||
|
@ -114,6 +115,7 @@ impl Default for Account {
|
|||
Self {
|
||||
name: None,
|
||||
downloads_dir: None,
|
||||
signature_delimiter: None,
|
||||
signature: None,
|
||||
default_page_size: None,
|
||||
default: None,
|
||||
|
@ -143,6 +145,7 @@ pub struct Config {
|
|||
pub name: String,
|
||||
pub downloads_dir: Option<PathBuf>,
|
||||
pub notify_cmd: Option<String>,
|
||||
pub signature_delimiter: Option<String>,
|
||||
pub signature: Option<String>,
|
||||
pub default_page_size: Option<usize>,
|
||||
pub watch_cmds: Option<Vec<String>>,
|
||||
|
@ -251,6 +254,12 @@ impl Config {
|
|||
}
|
||||
|
||||
pub fn signature(&self, account: &Account) -> Option<String> {
|
||||
let default_sig_delim = String::from("-- \n");
|
||||
let sig_delim = account
|
||||
.signature_delimiter
|
||||
.as_ref()
|
||||
.or_else(|| self.signature_delimiter.as_ref())
|
||||
.unwrap_or(&default_sig_delim);
|
||||
let sig = account
|
||||
.signature
|
||||
.as_ref()
|
||||
|
@ -258,6 +267,7 @@ impl Config {
|
|||
|
||||
sig.and_then(|sig| fs::read_to_string(sig).ok())
|
||||
.or_else(|| sig.map(|sig| sig.to_owned()))
|
||||
.map(|sig| String::new() + sig_delim + sig.as_ref())
|
||||
}
|
||||
|
||||
pub fn default_page_size(&self, account: &Account) -> usize {
|
||||
|
@ -297,6 +307,7 @@ impl Default for Config {
|
|||
name: String::new(),
|
||||
downloads_dir: None,
|
||||
notify_cmd: None,
|
||||
signature_delimiter: None,
|
||||
signature: None,
|
||||
default_page_size: None,
|
||||
watch_cmds: None,
|
||||
|
|
|
@ -319,7 +319,7 @@ mod tests {
|
|||
let account = Account {
|
||||
name: Some(String::from("Test")),
|
||||
email: String::from("test@localhost"),
|
||||
signature: Some(String::from("-- \nCordialement,")),
|
||||
signature: Some(String::from("Cordialement,")),
|
||||
..Account::default()
|
||||
};
|
||||
let config = Config {
|
||||
|
@ -374,7 +374,8 @@ mod tests {
|
|||
let account = Account {
|
||||
name: Some(String::from("Test")),
|
||||
email: String::from("test@localhost"),
|
||||
signature: Some(String::from("-- \nCordialement,")),
|
||||
signature_delimiter: Some(String::from("~~\n")),
|
||||
signature: Some(String::from("Cordialement,")),
|
||||
..Account::default()
|
||||
};
|
||||
let config = Config {
|
||||
|
@ -394,7 +395,7 @@ mod tests {
|
|||
let tpl = Tpl::reply(&ctx, &parsed_mail);
|
||||
|
||||
assert_eq!(
|
||||
"From: Test <test@localhost>\nTo: Sender <sender@localhost>\nSubject: Re: Test\n\n>Hello, world!\n\n-- \nCordialement,",
|
||||
"From: Test <test@localhost>\nTo: Sender <sender@localhost>\nSubject: Re: Test\n\n>Hello, world!\n\n~~\nCordialement,",
|
||||
tpl.to_string()
|
||||
);
|
||||
}
|
||||
|
@ -446,7 +447,7 @@ Subject: Re: Test
|
|||
let account = Account {
|
||||
name: Some(String::from("Test")),
|
||||
email: String::from("test@localhost"),
|
||||
signature: Some(String::from("-- \nCordialement,")),
|
||||
signature: Some(String::from("Cordialement,")),
|
||||
..Account::default()
|
||||
};
|
||||
let config = Config {
|
||||
|
@ -505,7 +506,7 @@ Subject: Re: Test
|
|||
let account = Account {
|
||||
name: Some(String::from("Test")),
|
||||
email: String::from("test@localhost"),
|
||||
signature: Some(String::from("-- \nCordialement,")),
|
||||
signature: Some(String::from("Cordialement,")),
|
||||
..Account::default()
|
||||
};
|
||||
let config = Config {
|
||||
|
|
|
@ -8,6 +8,7 @@ fn get_account(addr: &str) -> Account {
|
|||
Account {
|
||||
name: None,
|
||||
downloads_dir: None,
|
||||
signature_delimiter: None,
|
||||
signature: None,
|
||||
default_page_size: None,
|
||||
default: Some(true),
|
||||
|
|
Loading…
Reference in a new issue