Skip to content

Commit

Permalink
use stdin to send message (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
soywod committed May 3, 2021
1 parent 08f1026 commit 4668d51
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down
23 changes: 21 additions & 2 deletions src/msg/cli.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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)?;
Expand Down
2 changes: 1 addition & 1 deletion vim/autoload/himalaya/msg.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4668d51

Please sign in to comment.