~aodag/maildirview

407aa1dcb9eefacf0cebc95ac11c41dc45fd2005 — Atsushi Odagiri 10 months ago
first commit
5 files changed, 59 insertions(+), 0 deletions(-)

A .gitignore
A Cargo.toml
A README.md
A viewer/Cargo.toml
A viewer/src/main.rs
A  => .gitignore +21 -0
@@ 1,21 @@

# Created by https://www.toptal.com/developers/gitignore/api/rust
# Edit at https://www.toptal.com/developers/gitignore?templates=rust

### Rust ###
# Generated by Cargo
# will have compiled files and executables
debug/
target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

# End of https://www.toptal.com/developers/gitignore/api/rust
\ No newline at end of file

A  => Cargo.toml +3 -0
@@ 1,3 @@
[workspace]

members = ["viewer"]
\ No newline at end of file

A  => README.md +1 -0
@@ 1,1 @@
# maildirview

A  => viewer/Cargo.toml +10 -0
@@ 1,10 @@
[package]
name = "viewer"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
maildir = "0.5.0"
mailparse = "0.13.8"

A  => viewer/src/main.rs +24 -0
@@ 1,24 @@
use maildir::*;
use mailparse::*;
use std::env::args;

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() {
    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"),
            }
        }
    }
}