summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2022-08-31 22:33:02 +0300
committerManos Pitsidianakis <el13635@mail.ntua.gr>2022-09-01 22:32:33 +0300
commitaa99b0d787463be4267913b801117bd4d2ea5003 (patch)
treed7adc73cc10810dce96bb954c152c2cb69a9203d /src
parentda9c80ccfd7aa87842c2c3c089ba2b784a583ab6 (diff)
downloadmeli-aa99b0d787463be4267913b801117bd4d2ea5003.zip
compose: implement configurable subject prefix stripping when replying
Introduce functionality to strip email subject from a set list of prefixes or from a user set list. Also, added a setting for the reply prefix (default is "Re:"). Closes #142
Diffstat (limited to 'src')
-rw-r--r--src/components/mail/compose.rs35
-rw-r--r--src/conf/composing.rs13
-rw-r--r--src/conf/overrides.rs11
3 files changed, 51 insertions, 8 deletions
diff --git a/src/components/mail/compose.rs b/src/components/mail/compose.rs
index 3e3acdf3..62cd923e 100644
--- a/src/components/mail/compose.rs
+++ b/src/components/mail/compose.rs
@@ -219,15 +219,34 @@ impl Composer {
let mut ret = Composer::with_account(coordinates.0, context);
let account = &context.accounts[&coordinates.0];
let envelope = account.collection.get_env(coordinates.2);
- let subject = envelope.subject();
- ret.draft.set_header(
- "Subject",
- if !subject.starts_with("Re: ") {
- format!("Re: {}", subject)
+ let subject = {
+ let subject = envelope.subject();
+ let prefix_list = account_settings!(
+ context[ret.account_hash]
+ .composing
+ .reply_prefix_list_to_strip
+ )
+ .as_ref()
+ .map(|v| v.iter().map(String::as_str).collect::<Vec<&str>>())
+ .unwrap_or(vec![]);
+ let subject = subject
+ .as_ref()
+ .strip_prefixes_from_list(if prefix_list.is_empty() {
+ <&str>::USUAL_PREFIXES
+ } else {
+ &prefix_list
+ })
+ .to_string();
+
+ let prefix =
+ account_settings!(context[ret.account_hash].composing.reply_prefix).as_str();
+ if !subject.starts_with(prefix) {
+ format!("{prefix} {subject}", prefix = prefix, subject = subject)
} else {
- subject.into()
- },
- );
+ subject.to_string()
+ }
+ };
+ ret.draft.set_header("Subject", subject);
ret.draft.set_header(
"References",
format!(
diff --git a/src/conf/composing.rs b/src/conf/composing.rs
index 10408682..edfe46bf 100644
--- a/src/conf/composing.rs
+++ b/src/conf/composing.rs
@@ -77,6 +77,13 @@ pub struct ComposingSettings {
/// Default: ask
#[serde(default = "ask", alias = "forward-as-attachment")]
pub forward_as_attachment: ToggleFlag,
+ /// Alternative lists of reply prefixes (etc. ["Re:", "RE:", ...]) to strip
+ /// Default: `["Re:", "RE:", "Fwd:", "Fw:", "回复:", "回覆:", "SV:", "Sv:", "VS:", "Antw:", "Doorst:", "VS:", "VL:", "REF:", "TR:", "TR:", "AW:", "WG:", "ΑΠ:", "Απ:", "απ:", "ΠΡΘ:", "Πρθ:", "πρθ:", "ΣΧΕΤ:", "Σχετ:", "σχετ:", "ΠΡΘ:", "Πρθ:", "πρθ:", "Vá:", "Továbbítás:", "R:", "I:", "RIF:", "FS:", "BLS:", "TRS:", "VS:", "VB:", "RV:", "RES:", "Res", "ENC:", "Odp:", "PD:", "YNT:", "İLT:", "ATB:", "YML:"]`
+ #[serde(default, alias = "reply-prefix-list-to-strip")]
+ pub reply_prefix_list_to_strip: Option<Vec<String>>,
+ /// The prefix to use in reply subjects. The de facto prefix is "Re:".
+ #[serde(default = "res", alias = "reply-prefix")]
+ pub reply_prefix: String,
}
impl Default for ComposingSettings {
@@ -92,10 +99,16 @@ impl Default for ComposingSettings {
attribution_format_string: None,
attribution_use_posix_locale: true,
forward_as_attachment: ToggleFlag::Ask,
+ reply_prefix_list_to_strip: None,
+ reply_prefix: res(),
}
}
}
+fn res() -> String {
+ "Re:".to_string()
+}
+
macro_rules! named_unit_variant {
($variant:ident) => {
pub mod $variant {
diff --git a/src/conf/overrides.rs b/src/conf/overrides.rs
index 581c35e1..7c312c31 100644
--- a/src/conf/overrides.rs
+++ b/src/conf/overrides.rs
@@ -323,6 +323,15 @@ pub struct ComposingSettingsOverride {
#[serde(alias = "forward-as-attachment")]
#[serde(default)]
pub forward_as_attachment: Option<ToggleFlag>,
+ #[doc = " Alternative lists of reply prefixes (etc. [\"Re:\", \"RE:\", ...]) to strip"]
+ #[doc = " Default: `[\"Re:\", \"RE:\", \"Fwd:\", \"Fw:\", \"回复:\", \"回覆:\", \"SV:\", \"Sv:\", \"VS:\", \"Antw:\", \"Doorst:\", \"VS:\", \"VL:\", \"REF:\", \"TR:\", \"TR:\", \"AW:\", \"WG:\", \"ΑΠ:\", \"Απ:\", \"απ:\", \"ΠΡΘ:\", \"Πρθ:\", \"πρθ:\", \"ΣΧΕΤ:\", \"Σχετ:\", \"σχετ:\", \"ΠΡΘ:\", \"Πρθ:\", \"πρθ:\", \"Vá:\", \"Továbbítás:\", \"R:\", \"I:\", \"RIF:\", \"FS:\", \"BLS:\", \"TRS:\", \"VS:\", \"VB:\", \"RV:\", \"RES:\", \"Res\", \"ENC:\", \"Odp:\", \"PD:\", \"YNT:\", \"İLT:\", \"ATB:\", \"YML:\"]`"]
+ #[serde(alias = "reply-prefix-list-to-strip")]
+ #[serde(default)]
+ pub reply_prefix_list_to_strip: Option<Option<Vec<String>>>,
+ #[doc = " The prefix to use in reply subjects. The de facto prefix is \"Re:\"."]
+ #[serde(alias = "reply-prefix")]
+ #[serde(default)]
+ pub reply_prefix: Option<String>,
}
impl Default for ComposingSettingsOverride {
fn default() -> Self {
@@ -337,6 +346,8 @@ impl Default for ComposingSettingsOverride {
attribution_format_string: None,
attribution_use_posix_locale: None,
forward_as_attachment: None,
+ reply_prefix_list_to_strip: None,
+ reply_prefix: None,
}
}
}