From 2a9059f9b4274885c25d49228ab81dc8426bb302 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Sun, 1 Mar 2020 17:45:55 +0200 Subject: [PATCH] Add add-attachment from pipe, default_header_values --- meli.1 | 4 ++++ meli.conf.5 | 2 ++ src/components/mail/compose.rs | 17 +++++++++++++++++ src/conf/composing.rs | 6 ++++++ src/execute.rs | 10 ++++++++-- src/execute/actions.rs | 1 + src/types/helpers.rs | 2 +- 7 files changed, 39 insertions(+), 3 deletions(-) diff --git a/meli.1 b/meli.1 index 2a9b9812..ce0b21c2 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 e43bf943..f1cc7bd6 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 0fd3cbac..7ad5a183 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 a497eaac..89bf8c71 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 6678b692..80cda54b 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 cdb339c4..d9bc9a56 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 ac089e28..393ef0e6 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)