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