Add add-attachment from pipe, default_header_values

memfd
Manos Pitsidianakis 2020-03-01 17:45:55 +02:00
parent 6079909f9c
commit 2a9059f9b4
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
7 changed files with 39 additions and 3 deletions

4
meli.1
View File

@ -339,6 +339,10 @@ composing mail commands:
in composer, add in composer, add
.Ar PATH .Ar PATH
as an attachment 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 .It Cm remove-attachment Ar INDEX
remove attachment with given index remove attachment with given index
.It Cm toggle sign .It Cm toggle sign

View File

@ -281,6 +281,8 @@ If it's missing, the environment variable $EDITOR is looked up.
(optional) set format=flowed [RFC3676] in text/plain attachments. (optional) set format=flowed [RFC3676] in text/plain attachments.
.\" default value .\" default value
.Pq Em true .Pq Em true
.It Ic default_header_values Ar hash table String[String]
Default header values used when creating a new draft.
.El .El
.Sh SHORTCUTS .Sh SHORTCUTS
Shortcuts can take the following values: Shortcuts can take the following values:

View File

@ -147,6 +147,23 @@ impl Composer {
id: ComponentId::new_v4(), id: ComponentId::new_v4(),
..Default::default() ..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 ret.pager
.set_colors(crate::conf::value(context, "theme_default")); .set_colors(crate::conf::value(context, "theme_default"));
ret ret

View File

@ -21,6 +21,7 @@
//! Configuration for composing email. //! Configuration for composing email.
use super::default_vals::{false_val, none, true_val}; use super::default_vals::{false_val, none, true_val};
use std::collections::HashMap;
/// Settings for writing and sending new e-mail /// Settings for writing and sending new e-mail
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
@ -38,6 +39,10 @@ pub struct ComposingSettings {
/// Default: true /// Default: true
#[serde(default = "true_val")] #[serde(default = "true_val")]
pub format_flowed: bool, pub format_flowed: bool,
/// Set default header values for new drafts
/// Default: empty
#[serde(default)]
pub default_header_values: HashMap<String, String>,
} }
impl Default for ComposingSettings { impl Default for ComposingSettings {
@ -47,6 +52,7 @@ impl Default for ComposingSettings {
editor_cmd: None, editor_cmd: None,
embed: false, embed: false,
format_flowed: true, format_flowed: true,
default_header_values: HashMap::default(),
} }
} }
} }

View File

@ -216,10 +216,16 @@ define_commands!([
desc: "add-attachment PATH", desc: "add-attachment PATH",
parser:( parser:(
named!( add_attachment<Action>, named!( add_attachment<Action>,
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")) ws!(tag!("add-attachment"))
>> path: quoted_argument >> path: quoted_argument
>> (Compose(AddAttachment(path.to_string()))) >> (Compose(AddAttachment(path.to_string()))))
) )
); );
) )

View File

@ -77,6 +77,7 @@ pub enum ViewAction {
#[derive(Debug)] #[derive(Debug)]
pub enum ComposeAction { pub enum ComposeAction {
AddAttachment(String), AddAttachment(String),
AddAttachmentPipe(String),
RemoveAttachment(usize), RemoveAttachment(usize),
ToggleSign, ToggleSign,
} }

View File

@ -43,7 +43,7 @@ impl Drop for File {
} }
impl File { impl File {
pub fn file(&mut self) -> std::fs::File { pub fn file(&self) -> std::fs::File {
OpenOptions::new() OpenOptions::new()
.read(true) .read(true)
.write(true) .write(true)