diff --git a/meli.1 b/meli.1 index 2a9b98128..ce0b21c26 100644 --- a/meli.1 +++ b/meli.1 @@ -339,6 +339,10 @@ composing mail commands: in composer, add .Ar PATH as an attachment +.It Cm add-attachment < Ar CMD Ar ARGS +in composer, pipe +.Ar CMD Ar ARGS +output into an attachment .It Cm remove-attachment Ar INDEX remove attachment with given index .It Cm toggle sign diff --git a/meli.conf.5 b/meli.conf.5 index e43bf9437..f1cc7bd68 100644 --- a/meli.conf.5 +++ b/meli.conf.5 @@ -281,6 +281,8 @@ If it's missing, the environment variable $EDITOR is looked up. (optional) set format=flowed [RFC3676] in text/plain attachments. .\" default value .Pq Em true +.It Ic default_header_values Ar hash table String[String] +Default header values used when creating a new draft. .El .Sh SHORTCUTS Shortcuts can take the following values: diff --git a/src/components/mail/compose.rs b/src/components/mail/compose.rs index 0fd3cbac6..7ad5a1832 100644 --- a/src/components/mail/compose.rs +++ b/src/components/mail/compose.rs @@ -147,6 +147,23 @@ impl Composer { id: ComponentId::new_v4(), ..Default::default() }; + for (h, v) in context.settings.composing.default_header_values.iter() { + if v.is_empty() { + continue; + } + if let Some(k) = ret + .draft + .headers() + .keys() + .find(|k| k.eq_ignore_ascii_case(h)) + { + let _k = k.clone(); + ret.draft.headers_mut().insert(_k, v.into()); + } else { + /* set_header() also updates draft's header_order field */ + ret.draft.set_header(h, v.into()); + } + } ret.pager .set_colors(crate::conf::value(context, "theme_default")); ret diff --git a/src/conf/composing.rs b/src/conf/composing.rs index a497eaac0..89bf8c71a 100644 --- a/src/conf/composing.rs +++ b/src/conf/composing.rs @@ -21,6 +21,7 @@ //! Configuration for composing email. use super::default_vals::{false_val, none, true_val}; +use std::collections::HashMap; /// Settings for writing and sending new e-mail #[derive(Debug, Serialize, Deserialize, Clone)] @@ -38,6 +39,10 @@ pub struct ComposingSettings { /// Default: true #[serde(default = "true_val")] pub format_flowed: bool, + /// Set default header values for new drafts + /// Default: empty + #[serde(default)] + pub default_header_values: HashMap, } impl Default for ComposingSettings { @@ -47,6 +52,7 @@ impl Default for ComposingSettings { editor_cmd: None, embed: false, format_flowed: true, + default_header_values: HashMap::default(), } } } diff --git a/src/execute.rs b/src/execute.rs index 6678b6929..80cda54b0 100644 --- a/src/execute.rs +++ b/src/execute.rs @@ -216,10 +216,16 @@ define_commands!([ desc: "add-attachment PATH", parser:( named!( add_attachment, - do_parse!( + alt_complete!( + do_parse!( + ws!(tag!("add-attachment")) + >> ws!(tag!("<")) + >> cmd: quoted_argument + >> (Compose(AddAttachmentPipe(cmd.to_string())))) + | do_parse!( ws!(tag!("add-attachment")) >> path: quoted_argument - >> (Compose(AddAttachment(path.to_string()))) + >> (Compose(AddAttachment(path.to_string())))) ) ); ) diff --git a/src/execute/actions.rs b/src/execute/actions.rs index cdb339c47..d9bc9a567 100644 --- a/src/execute/actions.rs +++ b/src/execute/actions.rs @@ -77,6 +77,7 @@ pub enum ViewAction { #[derive(Debug)] pub enum ComposeAction { AddAttachment(String), + AddAttachmentPipe(String), RemoveAttachment(usize), ToggleSign, } diff --git a/src/types/helpers.rs b/src/types/helpers.rs index ac089e280..393ef0e6f 100644 --- a/src/types/helpers.rs +++ b/src/types/helpers.rs @@ -43,7 +43,7 @@ impl Drop for File { } impl File { - pub fn file(&mut self) -> std::fs::File { + pub fn file(&self) -> std::fs::File { OpenOptions::new() .read(true) .write(true)