aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index 42e921c..734e302 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,5 +1,6 @@
use mailparse;
+use std::error::Error;
use std::io::{self, Read};
@@ -9,10 +10,17 @@ fn main() {
let mut stdin = io::stdin();
stdin.read_to_end(&mut email_input).unwrap();
- let email = mailparse::parse_mail(&email_input).unwrap();
+ let body = get_email_body(&email_input).unwrap();
+ print!("{}", body);
+}
+
+fn get_email_body(email: &[u8]) -> Result<String, Box<dyn Error>> {
+ let email = mailparse::parse_mail(&email).unwrap();
+
if email.subparts.is_empty() {
let body = email.get_body().unwrap();
- println!("{}", body);
+
+ return Ok(body);
} else {
for part in email.subparts {
for header in part.get_headers() {
@@ -21,9 +29,11 @@ fn main() {
if header.get_key() == "Content-Type"
&& header.get_value().starts_with("text/plain")
{
- print!("{}", part.get_body().unwrap());
+ return Ok(part.get_body().unwrap());
}
}
}
}
+
+ Err("parse".into())
}