mirror of
https://github.com/FliegendeWurst/inboxid.git
synced 2024-11-25 02:15:04 +00:00
new: display date
This commit is contained in:
parent
929dc6633c
commit
545b1f7c2f
3
Cargo.lock
generated
3
Cargo.lock
generated
@ -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",
|
||||
|
@ -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"
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user