aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
blob: 6d3c6cd51893969c85a561e81648102ac01592e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// use email_parser::email::Email;
use mailparse;
// use email_format::Email;
// use email_format::rfc5322::Parsable;
// use email::rfc5322::Rfc5322Parser;

use std::io::{self, Read};


fn main() {
    // let mut email_input: Vec<u8> = Vec::with_capacity(2048);
    let mut email_input: Vec<u8> = Vec::new();

    let mut stdin = io::stdin();
    stdin.read_to_end(&mut email_input).unwrap();

    // println!("{}", String::from_utf8(email_input).unwrap());

    // email-parser
    // let email = Email::parse(&email_input).unwrap();
    // println!("{:?}", email.body);

    // mailparse
    // 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::
}