diff --git a/Cargo.lock b/Cargo.lock index 3f0e202..ec64b67 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -522,6 +522,7 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" name = "hello-ratatui" version = "0.1.0" dependencies = [ + "chrono", "crossterm", "imap", "native-tls", diff --git a/Cargo.toml b/Cargo.toml index aa0bd1d..71559ce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,4 +10,4 @@ imap = "2.4" native-tls = "0.2" serde = { version = "1.0", features = ["derive"] } toml = "1.0" -regex = "1.12" \ No newline at end of file +chrono = "0.4" \ No newline at end of file diff --git a/src/inbox.rs b/src/inbox.rs index 829bfc9..ce0a560 100644 --- a/src/inbox.rs +++ b/src/inbox.rs @@ -1,4 +1,4 @@ -use regex::Regex; +use chrono::{DateTime, FixedOffset, Local}; use crate::config::Config; use crate::connect::ImapSession; use crate::{connect, Email}; @@ -77,7 +77,11 @@ fn parse_emails(fetches: &[imap::types::Fetch]) -> Vec { } else if let Some(val) = line.strip_prefix("From: ") { from = val.to_string(); } else if let Some(val) = line.strip_prefix("Date: ") { - date = Regex::new(r#" \(...\)$"#).unwrap().replace_all(val, "").to_string(); + date = DateTime::parse_from_rfc2822(val) + .map(|dt: DateTime| { + dt.with_timezone(&Local).format("%Y-%m-%d %H:%M").to_string() + }) + .unwrap_or_else(|_| val.to_string()); } }