~aodag/maildirview

ref: ed445b3903220f67a759c8e80cf20f3ff4f1e951 maildirview/viewer/src/main.rs -rw-r--r-- 657 bytes
ed445b39Atsushi Odagiri clap 10 months ago
                                                                                
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 clap::Parser;
use maildir::*;
use mailparse::*;

#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
struct Cli {
    maildir: String,
}

fn get_subject(headers: Vec<MailHeader>) -> Result<String, ()> {
    for h in headers {
        if h.get_key() == "Subject" {
            return Ok(h.get_value());
        }
    }
    Err(())
}

fn main() {
    let cli = Cli::parse();
    let maildir = Maildir::from(cli.maildir);
    for entry in maildir.list_new() {
        match get_subject(entry.unwrap().headers().unwrap()) {
            Ok(s) => println!("Subject: {}", s),
            Err(_) => println!("failed"),
        }
    }
}