add --raw arg for read cmd (#79)

This commit is contained in:
Clément DOUIN 2021-04-09 00:30:07 +02:00
parent f26051685c
commit 570c67a2bb
No known key found for this signature in database
GPG key ID: 69C9B9CFFDEE2DEF
2 changed files with 22 additions and 2 deletions

View file

@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Wiki entry for Gmail users [#58]
- Info logs for copy/move/delete cmd + silent mode [#74]
- `--raw` arg for `read` cmd [#79]
### Changed
@ -139,3 +140,4 @@ 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
[#79]: https://github.com/soywod/himalaya/issues/79

View file

@ -21,6 +21,9 @@ error_chain! {
MsgModel(crate::msg::model::Error, crate::msg::model::ErrorKind);
Smtp(crate::smtp::Error, crate::smtp::ErrorKind);
}
foreign_links {
Utf8(std::string::FromUtf8Error);
}
}
pub fn uid_arg<'a>() -> Arg<'a, 'a> {
@ -106,6 +109,12 @@ pub fn msg_subcmds<'a>() -> Vec<App<'a, 'a>> {
.value_name("STRING")
.possible_values(&["plain", "html"])
.default_value("plain"),
)
.arg(
Arg::with_name("raw")
.help("Reads raw message")
.long("raw")
.short("r"),
),
SubCommand::with_name("attachments")
.aliases(&["attach", "att", "a"])
@ -230,10 +239,19 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> {
debug!("UID: {}", &uid);
let mime = format!("text/{}", matches.value_of("mime-type").unwrap());
debug!("MIME: {}", &mime);
let raw = matches.is_present("raw");
debug!("Raw: {}", &raw);
let msg = imap_conn.read_msg(&mbox, &uid)?;
let msg = ReadableMsg::from_bytes(&mime, &msg)?;
info!("{}", msg);
if raw {
let msg = String::from_utf8(msg)
.chain_err(|| "Could not decode raw message as utf8 string")?;
let msg = msg.trim_end_matches("\n");
info!("{}", msg);
} else {
let msg = ReadableMsg::from_bytes(&mime, &msg)?;
info!("{}", msg);
}
imap_conn.logout();
return Ok(());