From 6b3c4d57d6282d94b730d195fc69ae0e1f64ae55 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Sat, 6 Apr 2019 01:08:33 +0300 Subject: [PATCH] ui: add mailer setting and send shortcut in composer --- ui/src/components/mail/compose.rs | 37 ++++++++++++++++++++++++- ui/src/components/mail/view.rs | 7 +++-- ui/src/components/mail/view/envelope.rs | 7 +++-- ui/src/conf.rs | 5 ++++ ui/src/conf/mailer.rs | 28 +++++++++++++++++++ 5 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 ui/src/conf/mailer.rs diff --git a/ui/src/components/mail/compose.rs b/ui/src/components/mail/compose.rs index 50bb2ed37..8c749ed9b 100644 --- a/ui/src/components/mail/compose.rs +++ b/ui/src/components/mail/compose.rs @@ -539,6 +539,40 @@ impl Component for Composer { self.set_dirty(); return true; } + UIEventType::Input(Key::Char('s')) if self.mode.is_overview() => { + use std::io::Write; + use std::process::{Command, Stdio}; + let settings = &context.settings; + let parts = split_command!(settings.mailer.mailer_cmd); + let (cmd, args) = (parts[0], &parts[1..]); + let mut msmtp = Command::new(cmd) + .args(args) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .spawn() + .expect("Failed to start mailer command"); + { + let mut stdin = msmtp.stdin.as_mut().expect("failed to open stdin"); + let draft = self.draft.clone().finalise().unwrap(); + stdin + .write_all(draft.as_bytes()) + .expect("Failed to write to stdin"); + } + context.replies.push_back(UIEvent { + id: 0, + event_type: UIEventType::Notification( + Some("Sent.".into()), + format!( + "Mailer output: {:#?}", + msmtp + .wait_with_output() + .expect("Failed to wait on filter") + .stdout + ), + ), + }); + return true; + } UIEventType::Input(Key::Char('e')) if self.cursor == Cursor::Body => { /* Edit draft in $EDITOR */ use std::process::{Command, Stdio}; @@ -627,7 +661,8 @@ impl Component for Composer { } if self.mode.is_overview() { - map.insert("Switch to edit mode", Key::Char('o')); + map.insert("Switch to edit mode.", Key::Char('o')); + map.insert("Deliver draft to mailer.", Key::Char('s')); } if self.mode.is_edit() { map.insert("Switch to overview", Key::Char('v')); diff --git a/ui/src/components/mail/view.rs b/ui/src/components/mail/view.rs index b73056fb7..0fb3b77a1 100644 --- a/ui/src/components/mail/view.rs +++ b/ui/src/components/mail/view.rs @@ -158,8 +158,11 @@ impl MailView { .unwrap() .write_all(&v) .expect("Failed to write to stdin"); - *v = format!("Text piped through `{}`. Press `v` to open in web browser. \n\n", - filter_invocation).into_bytes(); + *v = format!( + "Text piped through `{}`. Press `v` to open in web browser. \n\n", + filter_invocation + ) + .into_bytes(); v.extend(html_filter.wait_with_output().unwrap().stdout); } } diff --git a/ui/src/components/mail/view/envelope.rs b/ui/src/components/mail/view/envelope.rs index 5c490579c..51299f122 100644 --- a/ui/src/components/mail/view/envelope.rs +++ b/ui/src/components/mail/view/envelope.rs @@ -125,8 +125,11 @@ impl EnvelopeView { .unwrap() .write_all(&v) .expect("Failed to write to stdin"); - *v = format!("Text piped through `{}`. Press `v` to open in web browser. \n\n", - filter_invocation).into_bytes(); + *v = format!( + "Text piped through `{}`. Press `v` to open in web browser. \n\n", + filter_invocation + ) + .into_bytes(); v.extend(html_filter.wait_with_output().unwrap().stdout); } } diff --git a/ui/src/conf.rs b/ui/src/conf.rs index 2a5c96e1f..58bed6425 100644 --- a/ui/src/conf.rs +++ b/ui/src/conf.rs @@ -24,6 +24,7 @@ extern crate config; extern crate serde; extern crate xdg; +pub mod mailer; pub mod notifications; pub mod pager; pub mod shortcuts; @@ -31,6 +32,7 @@ pub mod shortcuts; pub mod accounts; pub use self::accounts::Account; use self::config::{Config, File, FileFormat}; +pub use self::mailer::*; pub use self::shortcuts::*; use self::default_vals::*; @@ -131,6 +133,7 @@ struct FileSettings { pager: PagerSettings, notifications: NotificationsSettings, shortcuts: Shortcuts, + mailer: MailerSettings, } #[derive(Debug, Clone, Default)] @@ -157,6 +160,7 @@ pub struct Settings { pub pager: PagerSettings, pub notifications: NotificationsSettings, pub shortcuts: Shortcuts, + pub mailer: MailerSettings, } impl FileSettings { @@ -204,6 +208,7 @@ impl Settings { pager: fs.pager, notifications: fs.notifications, shortcuts: fs.shortcuts, + mailer: fs.mailer, } } } diff --git a/ui/src/conf/mailer.rs b/ui/src/conf/mailer.rs new file mode 100644 index 000000000..e555746f2 --- /dev/null +++ b/ui/src/conf/mailer.rs @@ -0,0 +1,28 @@ +/* + * meli - notifications conf module + * + * Copyright 2019 Manos Pitsidianakis + * + * This file is part of meli. + * + * meli is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * meli is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with meli. If not, see . + */ + +/// Settings for the mailer function. +#[derive(Debug, Deserialize, Clone, Default)] +pub struct MailerSettings { + /// A command to pipe new emails to + /// Required + pub mailer_cmd: String, +}