crabmail

Static HTML email archive viewer in Rust
git clone git://git.alexwennerberg.com/crabmail
Log | Files | Refs | README | LICENSE

commit f05eae35fae254042dd41fb9505cc90bda96e316
parent 6477599fa326701436e7840fbb9457efaf58d0e0
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Fri, 24 Dec 2021 14:39:53 -0800

minor cleanup

Diffstat:
Msrc/arg.rs | 3+--
Msrc/main.rs | 4+---
Msrc/mbox.rs | 2+-
Msrc/time.rs | 36+++++++++++++++++++-----------------
4 files changed, 22 insertions(+), 23 deletions(-)

diff --git a/src/arg.rs b/src/arg.rs @@ -12,7 +12,6 @@ // Copy/paste this code and you have a CLI! No library needed! use std::env; -use std::ffi::OsString; use std::path::PathBuf; use std::process::exit; @@ -41,7 +40,7 @@ impl Args { // let mut flags = String::new(); let mut mbox: Option<String> = None; let mut out_dir = "site".into(); - let mut config = PathBuf::from("crabmail.conf"); + let mut config = "crabmail.conf".into(); let mut args = env::args().skip(1); diff --git a/src/main.rs b/src/main.rs @@ -111,7 +111,6 @@ impl<'a> ThreadList<'a> { let mut last_updated = u64::MAX; for thread in &self.threads { let root = thread.messages[0]; - let last_reply = thread.last_reply(); let tmpl = format!( r#"<entry> <title>{title}</title> @@ -461,7 +460,7 @@ fn local_parse_email(data: &[u8]) -> Result<Email> { } fn main() -> Result<()> { - let mut args = arg::Args::from_env(); + let args = arg::Args::from_env(); let mut config = Config::from_file(&args.config).unwrap(); // TODO better err handling config.out_dir = args.out_dir; @@ -506,7 +505,6 @@ fn main() -> Result<()> { && (em.subject.starts_with("Re: ") || em.subject.starts_with("RE: ")) { // TODO O(n^2) - let mut tmp = String::new(); for (_, em2) in &email_index { if em2.subject == em.subject[4..] { match thread_index.get(&em2.id) { diff --git a/src/mbox.rs b/src/mbox.rs @@ -30,7 +30,7 @@ impl<T: BufRead> MboxReader<T> { // ugly im bad at rust pub fn from_file(p: &Path) -> Result<MboxReader<BufReader<File>>> { let f = File::open(p)?; - let mut reader = BufReader::new(f); + let reader = BufReader::new(f); let mboxr = MboxReader::from_reader(reader); Ok(mboxr) } diff --git a/src/time.rs b/src/time.rs @@ -6,20 +6,21 @@ const DAYS_IN_MONTHS: [i64; 12] = [31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 2 /* 2000-03-01 (mod 400 year, immediately after feb29 */ const LEAP_EPOCH: i64 = 946684800 + 86400 * (31 + 29); -const DAYS_PER_400Y: i64 = (365 * 400 + 97); -const DAYS_PER_100Y: i64 = (365 * 100 + 24); -const DAYS_PER_4Y: i64 = (365 * 4 + 1); +const DAYS_PER_400Y: i64 = 365 * 400 + 97; +const DAYS_PER_100Y: i64 = 365 * 100 + 24; +const DAYS_PER_4Y: i64 = 365 * 4 + 1; // TODO fiture out types #[derive(Debug, Clone)] pub struct Date { year: u32, - month: u32, - day_of_month: u32, - day_of_week: u32, - hour: u32, - minute: u32, - second: u32, + month: u8, + day_of_year: u32, + day_of_month: u8, + day_of_week: u8, + hour: u8, + minute: u8, + second: u8, } impl Date { @@ -46,7 +47,7 @@ pub fn secs_to_date(unixtime: u64) -> Date { let secs = unixtime as i64 - LEAP_EPOCH; let mut days = secs / 86400; let mut remsecs = secs % 86400; - if (remsecs < 0) { + if remsecs < 0 { remsecs += 86400; days -= 1; } @@ -97,18 +98,19 @@ pub fn secs_to_date(unixtime: u64) -> Date { // some sort of weird off by 1 error from my musl translation months += 1; - if (months > 10) { + if months > 10 { months -= 12; years += 1; } Date { year: (years + 2000) as u32, - month: (months + 2) as u32, - day_of_month: (remdays + 1) as u32, - day_of_week: (wday) as u32, - hour: (remsecs / 3600) as u32, - minute: ((remsecs / 60) % 60) as u32, - second: (remsecs % 60) as u32, + month: (months + 2) as u8, + day_of_year: yday as u32, + day_of_month: (remdays + 1) as u8, + day_of_week: (wday) as u8, + hour: (remsecs / 3600) as u8, + minute: ((remsecs / 60) % 60) as u8, + second: (remsecs % 60) as u8, } }