Browse Source

Rename _cmd options to _command for consistency

async
Manos Pitsidianakis 1 year ago
parent
commit
899d497c9c
Signed by untrusted user: epilys GPG Key ID: 73627C2F690DF710
  1. 4
      meli.1
  2. 8
      meli.conf.5
  3. 4
      samples/sample-config.toml
  4. 41
      src/components/mail/compose.rs
  5. 17
      src/conf/composing.rs
  6. 11
      src/conf/overrides.rs

4
meli.1

@ -213,7 +213,7 @@ At any time you may press
to launch your editor (see
.Xr meli.conf 5 COMPOSING Ns
, setting
.Ic editor_cmd
.Ic editor_command
for how to select which editor to launch).
Attachments may be handled with the
.Em add-attachment Ns
@ -225,7 +225,7 @@ Finally, pressing
will send your message by piping it into a binary of your choosing (see
.Xr meli.conf 5 COMPOSING Ns
, setting
.Ic mailer_cmd Ns
.Ic mailer_command Ns
).
To save your draft without sending it, issue command
.Cm close

8
meli.conf.5

@ -106,8 +106,8 @@ script = "notify-send"
[composing]
# required for sending e-mail
mailer_cmd = 'msmtp --read-recipients --read-envelope-from'
editor_cmd = 'vim +/^$'
mailer_command = 'msmtp --read-recipients --read-envelope-from'
editor_command = 'vim +/^$'
[shortcuts]
[shortcuts.composing]
@ -323,9 +323,9 @@ Example:
.El
.Sh COMPOSING
.Bl -tag -width 36n
.It Ic mailer_cmd Ar String
.It Ic mailer_command Ar String
command to pipe new mail to, exit code must be 0 for success.
.It Ic editor_cmd Ar String
.It Ic editor_command Ar String
command to launch editor.
Can have arguments.
Draft filename is given as the last argument.

4
samples/sample-config.toml

@ -105,8 +105,8 @@
#[composing]
# required for sending e-mail
#mailer_cmd = 'msmtp --read-recipients --read-envelope-from'
#editor_cmd = 'vim +/^$' # optional, by default $EDITOR is used.
#mailer_command = 'msmtp --read-recipients --read-envelope-from'
#editor_command = 'vim +/^$' # optional, by default $EDITOR is used.
#
#
#[pgp]

41
src/components/mail/compose.rs

@ -947,17 +947,17 @@ impl Component for Composer {
&& shortcut!(key == shortcuts[Self::DESCRIPTION]["edit_mail"]) =>
{
/* Edit draft in $EDITOR */
let editor = if let Some(editor_cmd) =
mailbox_acc_settings!(context[self.account_cursor].composing.editor_cmd)
let editor = if let Some(editor_command) =
mailbox_acc_settings!(context[self.account_cursor].composing.editor_command)
.as_ref()
{
editor_cmd.to_string()
editor_command.to_string()
} else {
match std::env::var("EDITOR") {
Err(e) => {
context.replies.push_back(UIEvent::Notification(
Some(e.to_string()),
"$EDITOR is not set. You can change an envvar's value with setenv or set composing.editor_cmd setting in your configuration.".to_string(),
"$EDITOR is not set. You can change an envvar's value with setenv or set composing.editor_command setting in your configuration.".to_string(),
Some(NotificationType::ERROR),
));
return true;
@ -1000,13 +1000,16 @@ impl Component for Composer {
context.input_kill();
}
let editor_cmd = format!("{} {}", editor, f.path().display());
let editor_command = format!("{} {}", editor, f.path().display());
log(
format!("Executing: sh -c \"{}\"", editor_cmd.replace("\"", "\\\"")),
format!(
"Executing: sh -c \"{}\"",
editor_command.replace("\"", "\\\"")
),
DEBUG,
);
match Command::new("sh")
.args(&["-c", &editor_cmd])
.args(&["-c", &editor_command])
.stdin(Stdio::inherit())
.stdout(Stdio::inherit())
.spawn()
@ -1051,18 +1054,18 @@ impl Component for Composer {
}
UIEvent::Action(ref a) => {
match a {
Action::Compose(ComposeAction::AddAttachmentPipe(ref cmd)) => {
if cmd.is_empty() {
Action::Compose(ComposeAction::AddAttachmentPipe(ref command)) => {
if command.is_empty() {
context.replies.push_back(UIEvent::Notification(
None,
format!("pipe cmd value is invalid: {}", cmd),
format!("pipe command value is invalid: {}", command),
Some(NotificationType::ERROR),
));
return false;
}
let f = create_temp_file(&[], None, None, true);
match std::process::Command::new("sh")
.args(&["-c", cmd])
.args(&["-c", command])
.stdin(std::process::Stdio::null())
.stdout(std::process::Stdio::from(f.file()))
.spawn()
@ -1070,7 +1073,7 @@ impl Component for Composer {
Ok(child) => {
let _ = child
.wait_with_output()
.expect("failed to launch cmd")
.expect("failed to launch command")
.stdout;
let mut attachment =
match melib::email::attachment_from_file(f.path()) {
@ -1100,7 +1103,7 @@ impl Component for Composer {
Err(err) => {
context.replies.push_back(UIEvent::Notification(
None,
format!("could not execute pipe cmd {}: {}", cmd, err),
format!("could not execute pipe command {}: {}", command, err),
Some(NotificationType::ERROR),
));
return true;
@ -1280,18 +1283,18 @@ pub fn send_draft(
use std::io::Write;
use std::process::{Command, Stdio};
let format_flowed = *mailbox_acc_settings!(context[account_cursor].composing.format_flowed);
let cmd = mailbox_acc_settings!(context[account_cursor].composing.mailer_cmd);
if cmd.is_empty() {
let command = mailbox_acc_settings!(context[account_cursor].composing.mailer_command);
if command.is_empty() {
context.replies.push_back(UIEvent::Notification(
None,
String::from("mailer_cmd configuration value is empty"),
String::from("mailer_command configuration value is empty"),
Some(NotificationType::ERROR),
));
return false;
}
let bytes;
let mut msmtp = Command::new("sh")
.args(&["-c", cmd])
.args(&["-c", command])
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()
@ -1395,12 +1398,12 @@ pub fn send_draft(
let error_message = if let Some(exit_code) = output.code() {
format!(
"Could not send e-mail using `{}`: Process exited with {}",
cmd, exit_code
command, exit_code
)
} else {
format!(
"Could not send e-mail using `{}`: Process was killed by signal",
cmd
command
)
};
context.replies.push_back(UIEvent::Notification(

17
src/conf/composing.rs

@ -28,11 +28,16 @@ use std::collections::HashMap;
pub struct ComposingSettings {
/// A command to pipe new emails to
/// Required
#[serde(alias = "mailer-cmd")]
pub mailer_cmd: String,
#[serde(alias = "mailer-command", alias = "mailer-cmd", alias = "mailer_cmd")]
pub mailer_command: String,
/// Command to launch editor. Can have arguments. Draft filename is given as the last argument. If it's missing, the environment variable $EDITOR is looked up.
#[serde(default = "none", alias = "editor-cmd")]
pub editor_cmd: Option<String>,
#[serde(
default = "none",
alias = "editor-command",
alias = "editor-cmd",
alias = "editor_cmd"
)]
pub editor_command: Option<String>,
/// Embed editor (for terminal interfaces) instead of forking and waiting.
#[serde(default = "false_val")]
pub embed: bool,
@ -49,8 +54,8 @@ pub struct ComposingSettings {
impl Default for ComposingSettings {
fn default() -> Self {
ComposingSettings {
mailer_cmd: String::new(),
editor_cmd: None,
mailer_command: String::new(),
editor_command: None,
embed: false,
format_flowed: true,
default_header_values: HashMap::default(),

11
src/conf/overrides.rs

@ -202,12 +202,13 @@ impl Default for ShortcutsOverride {
pub struct ComposingSettingsOverride {
#[doc = " A command to pipe new emails to"]
#[doc = " Required"]
#[serde(alias = "mailer-command", alias = "mailer-cmd", alias = "mailer_cmd")]
#[serde(default)]
pub mailer_cmd: Option<String>,
pub mailer_command: Option<String>,
#[doc = " Command to launch editor. Can have arguments. Draft filename is given as the last argument. If it's missing, the environment variable $EDITOR is looked up."]
#[serde(alias = "editor-cmd")]
#[serde(alias = "editor-command", alias = "editor-cmd", alias = "editor_cmd")]
#[serde(default)]
pub editor_cmd: Option<Option<String>>,
pub editor_command: Option<Option<String>>,
#[doc = " Embed editor (for terminal interfaces) instead of forking and waiting."]
#[serde(default)]
pub embed: Option<bool>,
@ -225,8 +226,8 @@ pub struct ComposingSettingsOverride {
impl Default for ComposingSettingsOverride {
fn default() -> Self {
ComposingSettingsOverride {
mailer_cmd: None,
editor_cmd: None,
mailer_command: None,
editor_command: None,
embed: None,
format_flowed: None,
default_header_values: None,

Loading…
Cancel
Save