mirror of
https://github.com/soywod/himalaya.git
synced 2024-07-01 06:55:13 +00:00
fix new/reply/forward issue in vim plugin (#176)
This commit is contained in:
parent
63090a2f01
commit
7b046f87ee
|
@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- New/reply/forward from Vim plugin since Tpl refactor [#176]
|
||||||
|
|
||||||
## [0.4.0] - 2021-06-03
|
## [0.4.0] - 2021-06-03
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
@ -296,3 +300,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
[#144]: https://github.com/soywod/himalaya/issues/144
|
[#144]: https://github.com/soywod/himalaya/issues/144
|
||||||
[#146]: https://github.com/soywod/himalaya/issues/146
|
[#146]: https://github.com/soywod/himalaya/issues/146
|
||||||
[#160]: https://github.com/soywod/himalaya/issues/160
|
[#160]: https://github.com/soywod/himalaya/issues/160
|
||||||
|
[#176]: https://github.com/soywod/himalaya/issues/176
|
||||||
|
|
|
@ -559,7 +559,7 @@ fn msg_matches_send(ctx: &Ctx, matches: &clap::ArgMatches) -> Result<bool> {
|
||||||
|
|
||||||
let mut imap_conn = ImapConnector::new(&ctx.account)?;
|
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
|
matches
|
||||||
.value_of("message")
|
.value_of("message")
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
|
|
|
@ -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") {
|
if let Some(from) = matches.value_of("from") {
|
||||||
debug!("overriden from: {:?}", from);
|
debug!("overriden from: {:?}", from);
|
||||||
tpl.header("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);
|
tpl.header(key, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
if atty::isnt(Stream::Stdin) {
|
if atty::isnt(Stream::Stdin) && ctx.output.is_plain() {
|
||||||
let body = io::stdin()
|
let body = io::stdin()
|
||||||
.lock()
|
.lock()
|
||||||
.lines()
|
.lines()
|
||||||
|
@ -180,7 +180,7 @@ fn tpl_matches_new(ctx: &Ctx, matches: &clap::ArgMatches) -> Result<bool> {
|
||||||
debug!("new command matched");
|
debug!("new command matched");
|
||||||
|
|
||||||
let mut tpl = Tpl::new(&ctx);
|
let mut tpl = Tpl::new(&ctx);
|
||||||
override_tpl_with_args(&mut tpl, &matches);
|
override_tpl_with_args(&ctx, &mut tpl, &matches);
|
||||||
trace!("tpl: {:?}", tpl);
|
trace!("tpl: {:?}", tpl);
|
||||||
ctx.output.print(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 = &imap_conn.read_msg(&ctx.mbox, &uid)?;
|
||||||
let msg = mailparse::parse_mail(&msg)?;
|
let msg = mailparse::parse_mail(&msg)?;
|
||||||
let mut tpl = if matches.is_present("reply-all") {
|
let mut tpl = if matches.is_present("reply-all") {
|
||||||
Tpl::reply(&ctx, &msg)
|
|
||||||
} else {
|
|
||||||
Tpl::reply_all(&ctx, &msg)
|
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);
|
trace!("tpl: {:?}", tpl);
|
||||||
ctx.output.print(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 = &imap_conn.read_msg(&ctx.mbox, &uid)?;
|
||||||
let msg = mailparse::parse_mail(&msg)?;
|
let msg = mailparse::parse_mail(&msg)?;
|
||||||
let mut tpl = Tpl::forward(&ctx, &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);
|
trace!("tpl: {:?}", tpl);
|
||||||
ctx.output.print(tpl);
|
ctx.output.print(tpl);
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ pub struct Tpl {
|
||||||
headers: HashMap<String, String>,
|
headers: HashMap<String, String>,
|
||||||
body: Option<String>,
|
body: Option<String>,
|
||||||
signature: Option<String>,
|
signature: Option<String>,
|
||||||
|
raw: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Tpl {
|
impl Tpl {
|
||||||
|
@ -23,11 +24,14 @@ impl Tpl {
|
||||||
headers.insert("To".to_string(), String::new());
|
headers.insert("To".to_string(), String::new());
|
||||||
headers.insert("Subject".to_string(), String::new());
|
headers.insert("Subject".to_string(), String::new());
|
||||||
|
|
||||||
Self {
|
let mut tpl = Self {
|
||||||
headers,
|
headers,
|
||||||
body: None,
|
body: None,
|
||||||
signature: ctx.config.signature(ctx.account),
|
signature: ctx.config.signature(ctx.account),
|
||||||
}
|
raw: String::new(),
|
||||||
|
};
|
||||||
|
tpl.raw = tpl.to_string();
|
||||||
|
tpl
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reply(ctx: &Ctx, msg: &mailparse::ParsedMail) -> Self {
|
pub fn reply(ctx: &Ctx, msg: &mailparse::ParsedMail) -> Self {
|
||||||
|
@ -65,11 +69,14 @@ impl Tpl {
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
.join("\n");
|
.join("\n");
|
||||||
|
|
||||||
Self {
|
let mut tpl = Self {
|
||||||
headers,
|
headers,
|
||||||
body: Some(body),
|
body: Some(body),
|
||||||
signature: ctx.config.signature(&ctx.account),
|
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 {
|
pub fn reply_all(ctx: &Ctx, msg: &mailparse::ParsedMail) -> Self {
|
||||||
|
@ -140,11 +147,14 @@ impl Tpl {
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
.join("\n");
|
.join("\n");
|
||||||
|
|
||||||
Self {
|
let mut tpl = Self {
|
||||||
headers,
|
headers,
|
||||||
body: Some(body),
|
body: Some(body),
|
||||||
signature: ctx.config.signature(&ctx.account),
|
signature: ctx.config.signature(&ctx.account),
|
||||||
}
|
raw: String::new(),
|
||||||
|
};
|
||||||
|
tpl.raw = tpl.to_string();
|
||||||
|
tpl
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn forward(ctx: &Ctx, msg: &mailparse::ParsedMail) -> Self {
|
pub fn forward(ctx: &Ctx, msg: &mailparse::ParsedMail) -> Self {
|
||||||
|
@ -167,11 +177,14 @@ impl Tpl {
|
||||||
let mut body = String::from("-------- Forwarded Message --------\n");
|
let mut body = String::from("-------- Forwarded Message --------\n");
|
||||||
body.push_str(&parts.join("\r\n\r\n").replace("\r", ""));
|
body.push_str(&parts.join("\r\n\r\n").replace("\r", ""));
|
||||||
|
|
||||||
Self {
|
let mut tpl = Self {
|
||||||
headers,
|
headers,
|
||||||
body: Some(body),
|
body: Some(body),
|
||||||
signature: ctx.config.signature(&ctx.account),
|
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 {
|
pub fn header<K: ToString, V: ToString>(&mut self, key: K, val: V) -> &Self {
|
||||||
|
|
|
@ -3,7 +3,7 @@ use std::fmt;
|
||||||
|
|
||||||
// Output format
|
// Output format
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Eq, PartialEq)]
|
||||||
pub enum OutputFmt {
|
pub enum OutputFmt {
|
||||||
Plain,
|
Plain,
|
||||||
Json,
|
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 {
|
impl Default for Output {
|
||||||
|
|
|
@ -86,7 +86,7 @@ function! himalaya#msg#write()
|
||||||
let account = himalaya#account#curr()
|
let account = himalaya#account#curr()
|
||||||
let msg = s:cli("--account %s template new", [shellescape(account)], "Fetching new template", 0)
|
let msg = s:cli("--account %s template new", [shellescape(account)], "Fetching new template", 0)
|
||||||
silent! edit Himalaya write
|
silent! edit Himalaya write
|
||||||
call append(0, split(substitute(msg.template, "\r", "", "g"), "\n"))
|
call append(0, split(substitute(msg.raw, "\r", "", "g"), "\n"))
|
||||||
silent execute "$d"
|
silent execute "$d"
|
||||||
setlocal filetype=himalaya-msg-write
|
setlocal filetype=himalaya-msg-write
|
||||||
let &modified = 0
|
let &modified = 0
|
||||||
|
@ -112,7 +112,7 @@ function! himalaya#msg#reply()
|
||||||
\0,
|
\0,
|
||||||
\)
|
\)
|
||||||
execute printf("silent! edit Himalaya reply [%d]", msg_id)
|
execute printf("silent! edit Himalaya reply [%d]", msg_id)
|
||||||
call append(0, split(substitute(msg.template, "\r", "", "g"), "\n"))
|
call append(0, split(substitute(msg.raw, "\r", "", "g"), "\n"))
|
||||||
silent execute "$d"
|
silent execute "$d"
|
||||||
setlocal filetype=himalaya-msg-write
|
setlocal filetype=himalaya-msg-write
|
||||||
let &modified = 0
|
let &modified = 0
|
||||||
|
@ -138,7 +138,7 @@ function! himalaya#msg#reply_all()
|
||||||
\0
|
\0
|
||||||
\)
|
\)
|
||||||
execute printf("silent! edit Himalaya reply all [%d]", msg_id)
|
execute printf("silent! edit Himalaya reply all [%d]", msg_id)
|
||||||
call append(0, split(substitute(msg.template, "\r", "", "g"), "\n"))
|
call append(0, split(substitute(msg.raw, "\r", "", "g"), "\n"))
|
||||||
silent execute "$d"
|
silent execute "$d"
|
||||||
setlocal filetype=himalaya-msg-write
|
setlocal filetype=himalaya-msg-write
|
||||||
let &modified = 0
|
let &modified = 0
|
||||||
|
@ -164,7 +164,7 @@ function! himalaya#msg#forward()
|
||||||
\0
|
\0
|
||||||
\)
|
\)
|
||||||
execute printf("silent! edit Himalaya forward [%d]", msg_id)
|
execute printf("silent! edit Himalaya forward [%d]", msg_id)
|
||||||
call append(0, split(substitute(msg.template, "\r", "", "g"), "\n"))
|
call append(0, split(substitute(msg.raw, "\r", "", "g"), "\n"))
|
||||||
silent execute "$d"
|
silent execute "$d"
|
||||||
setlocal filetype=himalaya-msg-write
|
setlocal filetype=himalaya-msg-write
|
||||||
let &modified = 0
|
let &modified = 0
|
||||||
|
|
2
wiki
2
wiki
|
@ -1 +1 @@
|
||||||
Subproject commit 5f3d7ed3519ddaeced9521a698d31319c6cd7836
|
Subproject commit 2c064c801e174d9cc84c1753f2c5f3e0240fa2ed
|
Loading…
Reference in a new issue