diff options
| -rw-r--r-- | Cargo.lock | 64 | ||||
| -rw-r--r-- | Cargo.toml | 4 | ||||
| -rw-r--r-- | src/main.rs | 23 | 
3 files changed, 78 insertions, 13 deletions
| @@ -1,23 +1,71 @@  # This file is automatically @generated by Cargo.  # It is not intended for manual editing.  [[package]] -name = "buf-read-ext" -version = "0.3.0" +name = "base64" +version = "0.10.1"  source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd2b3bef6c7a0f62d42a25a3cce9a40d558f3f4e15b70a7eef4aaea5c2a419ab" +checksum = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e" +dependencies = [ + "byteorder", +] + +[[package]] +name = "base64" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" + +[[package]] +name = "byteorder" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae44d1a3d5a19df61dd0c8beb138458ac2a53a7ac09eba97d55592540004306b" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "charset" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f426e64df1c3de26cbf44593c6ffff5dbfd43bbf9de0d075058558126b3fc73" +dependencies = [ + "base64 0.10.1", + "encoding_rs", +] + +[[package]] +name = "encoding_rs" +version = "0.8.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80df024fbc5ac80f87dfef0d9f5209a252f2a497f7f42944cff24d8253cac065" +dependencies = [ + "cfg-if", +]  [[package]] -name = "email-format" -version = "0.8.0" +name = "mailparse" +version = "0.13.2"  source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8eb503420bb8f3576592fed3c40baa2cca5f41420baa9ceef8e1d2c09327bb" +checksum = "31de1f9043c582efde7dbd93de56600df12b6c4488a67eeaefa74ea364019b22"  dependencies = [ - "buf-read-ext", + "base64 0.12.3", + "charset", + "quoted_printable",  ]  [[package]]  name = "ottolangy"  version = "0.0.1"  dependencies = [ - "email-format", + "mailparse",  ] + +[[package]] +name = "quoted_printable" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47b080c5db639b292ac79cbd34be0cfc5d36694768d8341109634d90b86930e2" @@ -5,6 +5,6 @@ edition = "2018"  [dependencies]  # email-parser = "0.5.0" -# mailparse = "0.13.2" +mailparse = "0.13.2"  # email-format = "0.8.0" -email = "0.0.21" +# email = "0.0.21" 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::  } | 
