diff --git a/Cargo.lock b/Cargo.lock index 72f178e..7e1bd0f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -20,7 +20,7 @@ checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" [[package]] name = "ascii_table" version = "3.0.2" -source = "git+https://gitlab.com/arnekeller/ascii-table.git?rev=7fffb5d93b8c63283fc1359ee3c6dbfcf12ed90b#7fffb5d93b8c63283fc1359ee3c6dbfcf12ed90b" +source = "git+https://gitlab.com/arnekeller/ascii-table.git?branch=master#7fffb5d93b8c63283fc1359ee3c6dbfcf12ed90b" [[package]] name = "autocfg" @@ -178,6 +178,7 @@ name = "inboxid" version = "0.1.0" dependencies = [ "ascii_table", + "chrono", "imap", "itertools", "maildir", diff --git a/Cargo.toml b/Cargo.toml index 482d7ec..b447c24 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,4 +13,5 @@ itertools = "0.10.0" maildir = { path = "../maildir" } mailparse = "0.13.2" rustls-connector = "0.13.1" -ascii_table = { git = "https://gitlab.com/arnekeller/ascii-table.git", rev = "7fffb5d93b8c63283fc1359ee3c6dbfcf12ed90b" } +ascii_table = { git = "https://gitlab.com/arnekeller/ascii-table.git", branch = "master" } +chrono = "0.4.19" diff --git a/src/bin/new.rs b/src/bin/new.rs index e52e0cd..386de64 100644 --- a/src/bin/new.rs +++ b/src/bin/new.rs @@ -1,5 +1,6 @@ use ascii_table::{Align, AsciiTable, Column}; -use mailparse::MailHeaderMap; +use chrono::{Local, NaiveDateTime, TimeZone}; +use mailparse::{MailHeaderMap, dateparse}; use inboxid::*; @@ -11,19 +12,26 @@ fn show_listing(mailbox: &str) -> Result<()> { let maildir = get_maildir(mailbox)?; let mut rows = Vec::new(); - for mail in maildir.list_new_sorted(Box::new(|name| { + for mut mail in maildir.list_new_sorted(Box::new(|name| { // sort by UID name.splitn(2, '_').nth(1).map(|x| x.parse().unwrap_or(0)).unwrap_or(0) })) { - match mail { - Ok(mut mail) => { - let mail = mail.parsed()?; + match mail.as_mut().map(|x| x.parsed()) { + Ok(Ok(mail)) => { let headers = mail.get_headers(); let from = headers.get_all_values("From").join(" "); let subj = headers.get_all_values("Subject").join(" "); - rows.push(vec![from, subj]); + let date = headers.get_all_values("Date").join(" "); + let date = dateparse(&date).map(|x| { + let dt = Local.from_utc_datetime(&NaiveDateTime::from_timestamp(x, 0)); + dt.format("%Y-%m-%d %H:%M").to_string() + }).unwrap_or(date); + rows.push(vec![from, subj, date]); } - Err(e) => { + Ok(Err(e)) => { + println!("error parsing mail: {:?}", e); + } + Err(e) => { println!("error: {:?}", e); } } @@ -35,6 +43,7 @@ fn show_listing(mailbox: &str) -> Result<()> { for (i, &(header, align)) in [ ("From", Align::Left), ("Subject", Align::Left), + ("Date", Align::Left), ].iter().enumerate() { let mut column = Column::default(); column.header = header.to_owned();