~aodag/maildirview

ed445b3903220f67a759c8e80cf20f3ff4f1e951 — Atsushi Odagiri 8 months ago f429656
clap
2 files changed, 14 insertions(+), 8 deletions(-)

M viewer/Cargo.toml
M viewer/src/main.rs
M viewer/Cargo.toml => viewer/Cargo.toml +1 -0
@@ 6,5 6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = {version="3.0.12", features=["derive"]}
maildir = "0.5.0"
mailparse = "0.13.8"

M viewer/src/main.rs => viewer/src/main.rs +13 -8
@@ 1,6 1,12 @@
use clap::Parser;
use maildir::*;
use mailparse::*;
use std::env::args;

#[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 {


@@ 12,13 18,12 @@ fn get_subject(headers: Vec<MailHeader>) -> Result<String, ()> {
}

fn main() {
    for dir in args() {
        let maildir = Maildir::from(dir);
        for entry in maildir.list_new() {
            match get_subject(entry.unwrap().headers().unwrap()) {
                Ok(s) => println!("Subject: {}", s),
                Err(_) => println!("failed"),
            }
    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"),
        }
    }
}