aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
blob: 487db2c68e2b285ff0f175a933a07ef712ac9176 (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
use mailparse;

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


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

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

    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());
                }
            }
        }
    }
}