diff --git a/meli.1 b/meli.1 index 0f28afd5..ab50f69d 100644 --- a/meli.1 +++ b/meli.1 @@ -77,6 +77,42 @@ The view into each folder has 4 modes: plain, threaded, conversations and compac ^^ (`-=-=-=-=-`) `-=-=-=-=-` ^^ .Ed +.Sh COMPOSING +To send mail, press +.Cm m +while viewing the appropriate account to open a new composing tab. To reply to a mail, press +.Cm R Ns +\&. You can edit some of the header fields from within the view, by selecting with the arrow keys and pressing +.Cm enter +to enter +.Ar INSERT +mode. At any time you can press +.Cm e +to launch your editor (see +.Xr meli.conf 5 +.Em COMPOSING +for how to select which editor to launch). Attachments can be handled with the +.Em add-attachment Ns +, +.Em remove-attachment +commands (see below). Finally, pressing +.Ar s +will send your message by piping it into a binary of your choosing (see +.Xr meli.conf 5 +.Em COMPOSING Ns +, setting +.Em mailer_cmd Ns +). To save your draft without sending it, issue command +.Cm close +and select 'save as draft'. +.Pp +If there is no Draft or Sent folder, meli tries first saving mail in your INBOX and then at any other folder. On complete failure to save your draft or sent message it will be saved in your +.Em tmp +directory instead and you will be notified of its location. +.Pp +To open a draft for editing later, select your draft in the mail listing and press +.Cm e Ns +\&. .Sh EXECUTE mode Commands are issued in EXECUTE mode, by default started with the space character and exited with Escape key. .Pp diff --git a/meli.conf.5 b/meli.conf.5 index ffec8d0d..18c69693 100644 --- a/meli.conf.5 +++ b/meli.conf.5 @@ -41,7 +41,7 @@ Newline means LF (0x0A) or CRLF (0x0D 0x0A). .Pp Refer to TOML documentation for valid TOML syntax. .Sh SECTIONS -The top level sections of the config are accounts, shortcuts, notifications, pager, mailer, pgp. +The top level sections of the config are accounts, shortcuts, notifications, pager, composing, pgp. .Pp .Sy example configuration .Bd -literal @@ -74,9 +74,10 @@ filter = "/usr/bin/pygmentize" [notifications] script = "notify-send" -[mailer] +[composing] # required for sending e-mail mailer_cmd = 'msmtp --read-recipients --read-envelope-from' +editor_cmd = 'vim +/^$' [shortcuts] scroll_up = 'k' @@ -172,7 +173,7 @@ example: otherwise usage is inferred from the folder title. .It Cm conf_override Ar boolean (optional) override global settings for this folder. available sections to override are -.Em pager, notifications, shortcuts, mailer +.Em pager, notifications, shortcuts, composing and the account options .Em identity and index_style Ns \&. example: @@ -183,10 +184,12 @@ and the account options filter = "" .Ed .El -.Sh MAILER +.Sh COMPOSING .Bl -tag -width "danger_accept_invalid_certs boolean" -offset -indent .It Cm mailer_cmd Ar String command to pipe new mail to, exit code must be 0 for success. +.It Cm editor_cmd Ar 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. .El .Sh SHORTCUTS Shortcuts can take the following values: diff --git a/sample-config b/sample-config index 632202f8..480c114b 100644 --- a/sample-config +++ b/sample-config @@ -54,6 +54,7 @@ #page_up = PageUp, #page_down = PageDown, -#[mailer] +#[composing] # required for sending e-mail #mailer_cmd = 'msmtp --read-recipients --read-envelope-from' +#editor_cmd = 'vim +/^$' # optional, by default $EDITOR is used. diff --git a/ui/src/components/mail/compose.rs b/ui/src/components/mail/compose.rs index 41522690..0da317d7 100644 --- a/ui/src/components/mail/compose.rs +++ b/ui/src/components/mail/compose.rs @@ -589,22 +589,24 @@ impl Component for Composer { } return true; } - UIEvent::Input(Key::Char('e')) if self.cursor == Cursor::Body => { + UIEvent::Input(Key::Char('e')) => { /* Edit draft in $EDITOR */ use std::process::{Command, Stdio}; - let editor = match std::env::var("EDITOR") { - Err(e) => { - context.replies.push_back(UIEvent::Notification( - Some( - "$EDITOR is not set. You can change an envvar's value with setenv" - .to_string(), - ), - e.to_string(), + let settings = &context.settings; + let editor = if let Some(editor_cmd) = settings.composing.editor_cmd.as_ref() { + editor_cmd.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(), Some(NotificationType::ERROR), )); - return true; + return true; + } + Ok(v) => v, } - Ok(v) => v, }; /* Kill input thread so that spawned command can be sole receiver of stdin */ { @@ -619,9 +621,10 @@ impl Component for Composer { true, ); - // TODO: check exit status - if let Err(e) = Command::new(&editor) - .arg("+/^$") + let parts = split_command!(editor); + let (cmd, args) = (parts[0], &parts[1..]); + if let Err(e) = Command::new(cmd) + .args(args) .arg(&f.path()) .stdin(Stdio::inherit()) .stdout(Stdio::inherit()) @@ -760,7 +763,7 @@ pub fn send_draft(context: &mut Context, account_cursor: usize, draft: Draft) -> use std::process::{Command, Stdio}; let mut failure = true; let settings = &context.settings; - let parts = split_command!(settings.mailer.mailer_cmd); + let parts = split_command!(settings.composing.mailer_cmd); let (cmd, args) = (parts[0], &parts[1..]); let mut msmtp = Command::new(cmd) .args(args) diff --git a/ui/src/conf.rs b/ui/src/conf.rs index b4ca7967..dc6cc169 100644 --- a/ui/src/conf.rs +++ b/ui/src/conf.rs @@ -24,7 +24,7 @@ extern crate serde; extern crate toml; extern crate xdg; -pub mod mailer; +pub mod composing; pub mod notifications; pub mod pager; pub mod pgp; @@ -32,7 +32,7 @@ pub mod shortcuts; pub mod accounts; pub use self::accounts::Account; -pub use self::mailer::*; +pub use self::composing::*; pub use self::pgp::*; pub use self::shortcuts::*; @@ -96,7 +96,7 @@ pub struct MailUIConf { pub pager: Option, pub notifications: Option, pub shortcuts: Option, - pub mailer: Option, + pub composing: Option, pub identity: Option, pub index_style: Option, } @@ -273,7 +273,7 @@ struct FileSettings { notifications: NotificationsSettings, #[serde(default)] shortcuts: Shortcuts, - mailer: MailerSettings, + composing: ComposingSettings, #[serde(default)] pgp: PGPSettings, } @@ -303,7 +303,7 @@ pub struct Settings { pub pager: PagerSettings, pub notifications: NotificationsSettings, pub shortcuts: Shortcuts, - pub mailer: MailerSettings, + pub composing: ComposingSettings, pub pgp: PGPSettings, } @@ -391,7 +391,7 @@ impl Settings { pager: fs.pager, notifications: fs.notifications, shortcuts: fs.shortcuts, - mailer: fs.mailer, + composing: fs.composing, pgp: fs.pgp, } } diff --git a/ui/src/conf/mailer.rs b/ui/src/conf/composing.rs similarity index 73% rename from ui/src/conf/mailer.rs rename to ui/src/conf/composing.rs index 56fc6641..deded5a4 100644 --- a/ui/src/conf/mailer.rs +++ b/ui/src/conf/composing.rs @@ -1,5 +1,5 @@ /* - * meli - notifications conf module + * meli - conf module * * Copyright 2019 Manos Pitsidianakis * @@ -19,10 +19,12 @@ * along with meli. If not, see . */ -/// Settings for the mailer function. +/// Settings for writing and sending new e-mail #[derive(Debug, Serialize, Deserialize, Clone, Default)] -pub struct MailerSettings { +pub struct ComposingSettings { /// A command to pipe new emails to /// Required pub mailer_cmd: 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. + pub editor_cmd: Option, }