aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTeddy Wing2021-03-09 00:23:03 +0100
committerTeddy Wing2021-03-09 00:23:03 +0100
commitdf0704c5958993692319850e809cb0cf4e85589f (patch)
tree9990ae44add49f8f5a378fa9324b3862cf6b8b99 /src
parent34f470d2fbfff09a448a54f60addb385db6aa036 (diff)
downloadmutt-ottolangy-df0704c5958993692319850e809cb0cf4e85589f.tar.bz2
Work out how to get the body of a multipart email
Figured out why I was getting an empty string before: I was inputting a multipart email. I need to actually look through each part to get the message body. Look for the body of the "text/plain" part.
Diffstat (limited to 'src')
-rw-r--r--src/main.rs23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index 4e3bf83..6d3c6cd 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,8 +1,8 @@
// use email_parser::email::Email;
-// use mailparse;
+use mailparse;
// use email_format::Email;
// use email_format::rfc5322::Parsable;
-use email::rfc5322::Rfc5322Parser;
+// use email::rfc5322::Rfc5322Parser;
use std::io::{self, Read};
@@ -24,11 +24,28 @@ fn main() {
// let email = mailparse::parse_mail(&email_input).unwrap();
// let body = email.get_body().unwrap();
// println!("{:?}", body);
+ let email = mailparse::parse_mail(&email_input).unwrap();
+ if email.subparts.is_empty() {
+ let body = email.get_body_raw().unwrap();
+ println!("{:?}", String::from_utf8(body).unwrap());
+ } else {
+ for part in email.subparts {
+ for header in part.get_headers() {
+ println!("{}: {}", header.get_key(), header.get_value());
+
+ if header.get_key() == "Content-Type"
+ && header.get_value().starts_with("text/plain")
+ {
+ print!("{}", part.get_body().unwrap());
+ }
+ }
+ }
+ }
// email-format
// let email = Email::parse(&email_input).unwrap().0;
// print!("{:?}", email.get_body().unwrap());
// email
- let email = Rfc5322Parser::
+ // let email = Rfc5322Parser::
}