ui: add mailer setting and send shortcut in composer

embed
Manos Pitsidianakis 2019-04-06 01:08:33 +03:00
parent ce2317da95
commit 6b3c4d57d6
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
5 changed files with 79 additions and 5 deletions

View File

@ -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'));

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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,
}
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
/// 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,
}