mirror of
https://github.com/FliegendeWurst/inboxid.git
synced 2024-11-22 00:45:01 +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]]
|
[[package]]
|
||||||
name = "ascii_table"
|
name = "ascii_table"
|
||||||
version = "3.0.2"
|
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]]
|
[[package]]
|
||||||
name = "autocfg"
|
name = "autocfg"
|
||||||
@ -178,6 +178,7 @@ name = "inboxid"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ascii_table",
|
"ascii_table",
|
||||||
|
"chrono",
|
||||||
"imap",
|
"imap",
|
||||||
"itertools",
|
"itertools",
|
||||||
"maildir",
|
"maildir",
|
||||||
|
@ -13,4 +13,5 @@ itertools = "0.10.0"
|
|||||||
maildir = { path = "../maildir" }
|
maildir = { path = "../maildir" }
|
||||||
mailparse = "0.13.2"
|
mailparse = "0.13.2"
|
||||||
rustls-connector = "0.13.1"
|
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 ascii_table::{Align, AsciiTable, Column};
|
||||||
use mailparse::MailHeaderMap;
|
use chrono::{Local, NaiveDateTime, TimeZone};
|
||||||
|
use mailparse::{MailHeaderMap, dateparse};
|
||||||
|
|
||||||
use inboxid::*;
|
use inboxid::*;
|
||||||
|
|
||||||
@ -11,19 +12,26 @@ fn show_listing(mailbox: &str) -> Result<()> {
|
|||||||
let maildir = get_maildir(mailbox)?;
|
let maildir = get_maildir(mailbox)?;
|
||||||
|
|
||||||
let mut rows = Vec::new();
|
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
|
// sort by UID
|
||||||
name.splitn(2, '_').nth(1).map(|x| x.parse().unwrap_or(0)).unwrap_or(0)
|
name.splitn(2, '_').nth(1).map(|x| x.parse().unwrap_or(0)).unwrap_or(0)
|
||||||
})) {
|
})) {
|
||||||
match mail {
|
match mail.as_mut().map(|x| x.parsed()) {
|
||||||
Ok(mut mail) => {
|
Ok(Ok(mail)) => {
|
||||||
let mail = mail.parsed()?;
|
|
||||||
let headers = mail.get_headers();
|
let headers = mail.get_headers();
|
||||||
let from = headers.get_all_values("From").join(" ");
|
let from = headers.get_all_values("From").join(" ");
|
||||||
let subj = headers.get_all_values("Subject").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);
|
println!("error: {:?}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -35,6 +43,7 @@ fn show_listing(mailbox: &str) -> Result<()> {
|
|||||||
for (i, &(header, align)) in [
|
for (i, &(header, align)) in [
|
||||||
("From", Align::Left),
|
("From", Align::Left),
|
||||||
("Subject", Align::Left),
|
("Subject", Align::Left),
|
||||||
|
("Date", Align::Left),
|
||||||
].iter().enumerate() {
|
].iter().enumerate() {
|
||||||
let mut column = Column::default();
|
let mut column = Column::default();
|
||||||
column.header = header.to_owned();
|
column.header = header.to_owned();
|
||||||
|
Loading…
Reference in New Issue
Block a user