mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-17 05:07:55 +08:00
fix new/reply/forward issue in vim plugin (#176)
This commit is contained in:
+1
-1
@@ -559,7 +559,7 @@ fn msg_matches_send(ctx: &Ctx, matches: &clap::ArgMatches) -> Result<bool> {
|
||||
|
||||
let mut imap_conn = ImapConnector::new(&ctx.account)?;
|
||||
|
||||
let msg = if atty::is(Stream::Stdin) {
|
||||
let msg = if atty::is(Stream::Stdin) || ctx.output.is_json() {
|
||||
matches
|
||||
.value_of("message")
|
||||
.unwrap_or_default()
|
||||
|
||||
+7
-7
@@ -118,7 +118,7 @@ pub fn tpl_matches(ctx: &Ctx, matches: &clap::ArgMatches) -> Result<bool> {
|
||||
}
|
||||
}
|
||||
|
||||
fn override_tpl_with_args(tpl: &mut Tpl, matches: &clap::ArgMatches) {
|
||||
fn override_tpl_with_args(ctx: &Ctx, tpl: &mut Tpl, matches: &clap::ArgMatches) {
|
||||
if let Some(from) = matches.value_of("from") {
|
||||
debug!("overriden from: {:?}", from);
|
||||
tpl.header("From", from);
|
||||
@@ -155,7 +155,7 @@ fn override_tpl_with_args(tpl: &mut Tpl, matches: &clap::ArgMatches) {
|
||||
tpl.header(key, val);
|
||||
}
|
||||
|
||||
if atty::isnt(Stream::Stdin) {
|
||||
if atty::isnt(Stream::Stdin) && ctx.output.is_plain() {
|
||||
let body = io::stdin()
|
||||
.lock()
|
||||
.lines()
|
||||
@@ -180,7 +180,7 @@ fn tpl_matches_new(ctx: &Ctx, matches: &clap::ArgMatches) -> Result<bool> {
|
||||
debug!("new command matched");
|
||||
|
||||
let mut tpl = Tpl::new(&ctx);
|
||||
override_tpl_with_args(&mut tpl, &matches);
|
||||
override_tpl_with_args(&ctx, &mut tpl, &matches);
|
||||
trace!("tpl: {:?}", tpl);
|
||||
ctx.output.print(tpl);
|
||||
|
||||
@@ -197,11 +197,11 @@ fn tpl_matches_reply(ctx: &Ctx, matches: &clap::ArgMatches) -> Result<bool> {
|
||||
let msg = &imap_conn.read_msg(&ctx.mbox, &uid)?;
|
||||
let msg = mailparse::parse_mail(&msg)?;
|
||||
let mut tpl = if matches.is_present("reply-all") {
|
||||
Tpl::reply(&ctx, &msg)
|
||||
} else {
|
||||
Tpl::reply_all(&ctx, &msg)
|
||||
} else {
|
||||
Tpl::reply(&ctx, &msg)
|
||||
};
|
||||
override_tpl_with_args(&mut tpl, &matches);
|
||||
override_tpl_with_args(&ctx, &mut tpl, &matches);
|
||||
trace!("tpl: {:?}", tpl);
|
||||
ctx.output.print(tpl);
|
||||
|
||||
@@ -218,7 +218,7 @@ fn tpl_matches_forward(ctx: &Ctx, matches: &clap::ArgMatches) -> Result<bool> {
|
||||
let msg = &imap_conn.read_msg(&ctx.mbox, &uid)?;
|
||||
let msg = mailparse::parse_mail(&msg)?;
|
||||
let mut tpl = Tpl::forward(&ctx, &msg);
|
||||
override_tpl_with_args(&mut tpl, &matches);
|
||||
override_tpl_with_args(&ctx, &mut tpl, &matches);
|
||||
trace!("tpl: {:?}", tpl);
|
||||
ctx.output.print(tpl);
|
||||
|
||||
|
||||
+21
-8
@@ -14,6 +14,7 @@ pub struct Tpl {
|
||||
headers: HashMap<String, String>,
|
||||
body: Option<String>,
|
||||
signature: Option<String>,
|
||||
raw: String,
|
||||
}
|
||||
|
||||
impl Tpl {
|
||||
@@ -23,11 +24,14 @@ impl Tpl {
|
||||
headers.insert("To".to_string(), String::new());
|
||||
headers.insert("Subject".to_string(), String::new());
|
||||
|
||||
Self {
|
||||
let mut tpl = Self {
|
||||
headers,
|
||||
body: None,
|
||||
signature: ctx.config.signature(ctx.account),
|
||||
}
|
||||
raw: String::new(),
|
||||
};
|
||||
tpl.raw = tpl.to_string();
|
||||
tpl
|
||||
}
|
||||
|
||||
pub fn reply(ctx: &Ctx, msg: &mailparse::ParsedMail) -> Self {
|
||||
@@ -65,11 +69,14 @@ impl Tpl {
|
||||
.collect::<Vec<String>>()
|
||||
.join("\n");
|
||||
|
||||
Self {
|
||||
let mut tpl = Self {
|
||||
headers,
|
||||
body: Some(body),
|
||||
signature: ctx.config.signature(&ctx.account),
|
||||
}
|
||||
raw: String::new(),
|
||||
};
|
||||
tpl.raw = tpl.to_string();
|
||||
tpl
|
||||
}
|
||||
|
||||
pub fn reply_all(ctx: &Ctx, msg: &mailparse::ParsedMail) -> Self {
|
||||
@@ -140,11 +147,14 @@ impl Tpl {
|
||||
.collect::<Vec<String>>()
|
||||
.join("\n");
|
||||
|
||||
Self {
|
||||
let mut tpl = Self {
|
||||
headers,
|
||||
body: Some(body),
|
||||
signature: ctx.config.signature(&ctx.account),
|
||||
}
|
||||
raw: String::new(),
|
||||
};
|
||||
tpl.raw = tpl.to_string();
|
||||
tpl
|
||||
}
|
||||
|
||||
pub fn forward(ctx: &Ctx, msg: &mailparse::ParsedMail) -> Self {
|
||||
@@ -167,11 +177,14 @@ impl Tpl {
|
||||
let mut body = String::from("-------- Forwarded Message --------\n");
|
||||
body.push_str(&parts.join("\r\n\r\n").replace("\r", ""));
|
||||
|
||||
Self {
|
||||
let mut tpl = Self {
|
||||
headers,
|
||||
body: Some(body),
|
||||
signature: ctx.config.signature(&ctx.account),
|
||||
}
|
||||
raw: String::new(),
|
||||
};
|
||||
tpl.raw = tpl.to_string();
|
||||
tpl
|
||||
}
|
||||
|
||||
pub fn header<K: ToString, V: ToString>(&mut self, key: K, val: V) -> &Self {
|
||||
|
||||
+9
-1
@@ -3,7 +3,7 @@ use std::fmt;
|
||||
|
||||
// Output format
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub enum OutputFmt {
|
||||
Plain,
|
||||
Json,
|
||||
@@ -64,6 +64,14 @@ impl Output {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_plain(&self) -> bool {
|
||||
self.fmt == OutputFmt::Plain
|
||||
}
|
||||
|
||||
pub fn is_json(&self) -> bool {
|
||||
self.fmt == OutputFmt::Json
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Output {
|
||||
|
||||
Reference in New Issue
Block a user