diff --git a/docs/meli.conf.5 b/docs/meli.conf.5 index 078d324d..87aa1641 100644 --- a/docs/meli.conf.5 +++ b/docs/meli.conf.5 @@ -540,6 +540,24 @@ Whether the strftime call for the attribution string uses the POSIX locale inste Forward emails as attachment? (Alternative is inline). .\" default value .Pq Em ask +.It Ic reply_prefix_list_to_strip Ar [String] +.Pq Em optional +Alternative lists of reply prefixes (etc. ["Re:", "RE:", ...]) to strip. +.\" default value +.Pq Em ["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:"] +.It Ic reply_prefix Ar String +.Pq Em optional +The prefix to use in reply subjects. +The de facto prefix is "Re:". +.\" default value +.Pq Em `Re:` +.Pp +RFC 2822, "Internet Message Format" has this to say on the matter: +.Bd -literal -offset indent -compact +When used in a reply, the field body MAY start with the string "Re: " (from +the Latin "res", in the matter of) followed by the contents of the "Subject:" +field body of the original message. +.Ed .El .Sh SHORTCUTS Shortcuts can take the following values: 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::>()) + .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>, + /// 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, + #[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>>, + #[doc = " The prefix to use in reply subjects. The de facto prefix is \"Re:\"."] + #[serde(alias = "reply-prefix")] + #[serde(default)] + pub reply_prefix: Option, } 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, } } }