use stdin to send message (#78)

This commit is contained in:
Clément DOUIN 2021-05-04 00:15:11 +02:00
parent 08f10266e3
commit 4668d51476
No known key found for this signature in database
GPG key ID: 69C9B9CFFDEE2DEF
3 changed files with 27 additions and 3 deletions

View file

@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- Send message via stdin [#78]
### Fixed
- Table with subject containing `\r` or `\n`[#141]
@ -215,6 +219,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#71]: https://github.com/soywod/himalaya/issues/71
[#74]: https://github.com/soywod/himalaya/issues/74
[#75]: https://github.com/soywod/himalaya/issues/75
[#78]: https://github.com/soywod/himalaya/issues/78
[#79]: https://github.com/soywod/himalaya/issues/79
[#83]: https://github.com/soywod/himalaya/issues/83
[#84]: https://github.com/soywod/himalaya/issues/84

View file

@ -1,7 +1,11 @@
use clap;
use error_chain::error_chain;
use log::{debug, error, trace};
use std::{fs, ops::Deref};
use std::{
fs,
io::{self, BufRead},
ops::Deref,
};
use crate::{
app::App,
@ -590,7 +594,22 @@ pub fn msg_matches(app: &App) -> Result<bool> {
debug!("send command matched");
let mut imap_conn = ImapConnector::new(&app.account)?;
let msg = matches.value_of("message").unwrap();
let msg = if matches.is_present("message") {
matches
.value_of("message")
.unwrap_or_default()
.replace("\r", "")
.replace("\n", "\r\n")
} else {
io::stdin()
.lock()
.lines()
.filter_map(|ln| ln.ok())
.map(|ln| ln.to_string())
.collect::<Vec<_>>()
.join("\r\n")
};
let msg = Msg::from(msg.to_string());
let msg = msg.to_sendable_msg()?;
smtp::send(&app.account, &msg)?;

View file

@ -148,7 +148,7 @@ function! himalaya#msg#forward()
endfunction
function! himalaya#msg#draft_save()
let s:draft = join(getline(1, "$"), "\r\n")
let s:draft = join(getline(1, "$"), "\n")
redraw | call s:log("Save draft [OK]")
let &modified = 0
endfunction