crabmail

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

commit 4a0b7afdd2651c0a8dbed741ac3558de0f0aad05
parent ded9adf3769f360db4599296aa756b626839cd58
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Thu, 16 Dec 2021 20:54:18 -0800

cargo check

Diffstat:
Msrc/main.rs | 23++++++++++++-----------
Msrc/mbox.rs | 7+++----
Msrc/utils.rs | 2+-
3 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/src/main.rs b/src/main.rs @@ -3,7 +3,6 @@ use horrorshow::helper::doctype; use horrorshow::owned_html; use horrorshow::prelude::*; use horrorshow::Template; -use std::io; use std::io::BufWriter; use std::path::Path; use std::str; @@ -17,7 +16,7 @@ use sha3::{ Shake128, }; use std::collections::HashMap; -use std::fs::{File, OpenOptions}; +use std::fs::File; use std::io::prelude::*; use urlencoding; @@ -121,7 +120,7 @@ impl<'a> ThreadList<'a> { } }; - let mut file = File::create(&out_dir.join("index.html"))?; + let file = File::create(&out_dir.join("index.html"))?; let mut br = BufWriter::new(file); layout(Config::global().list_name.as_str(), tmp).write_to_io(&mut br)?; Ok(()) @@ -184,7 +183,7 @@ impl<'a> MailThread<'a> { let thread_dir = out_dir.join("threads"); std::fs::create_dir(&thread_dir).ok(); - let mut file = File::create(&thread_dir.join(format!("{}.html", &self.hash)))?; + let file = File::create(&thread_dir.join(format!("{}.html", &self.hash)))?; let mut br = BufWriter::new(file); layout(root.subject.as_str(), tmp).write_to_io(&mut br)?; Ok(()) @@ -323,6 +322,7 @@ fn main() -> Result<()> { .unwrap_or("crabmail.conf".into()); let in_mbox = pargs.value_from_os_str(["-m", "--mbox"], parse_path)?; + // out_dir is temp hack let config = Config::from_file(&config_file).unwrap(); // TODO better err handling INSTANCE.set(config).unwrap(); @@ -395,25 +395,26 @@ fn main() -> Result<()> { thread.last_reply = thread.last_reply(); - thread.write_to_file(&out_dir); + thread.write_to_file(&out_dir)?; threads.push(thread); } threads.sort_by_key(|a| a.last_reply); threads.reverse(); - ThreadList { threads }.write_to_file(&out_dir); + ThreadList { threads }.write_to_file(&out_dir)?; // kinda clunky let css = include_bytes!("style.css"); let mut css_root = File::create(out_dir.join("style.css"))?; - css_root.write(css); + css_root.write(css)?; let mut css_sub = File::create(out_dir.join("threads").join("style.css"))?; - css_sub.write(css); + css_sub.write(css)?; Ok(()) } -// TODO -// delete all files -fn remove_missing() {} +// Use the sha3 hash of the ID. It is what it is. +fn get_current_messages() { + let paths = std::fs::read_dir("./").unwrap(); +} fn parse_path(s: &std::ffi::OsStr) -> Result<std::path::PathBuf, &'static str> { Ok(s.into()) diff --git a/src/mbox.rs b/src/mbox.rs @@ -3,7 +3,7 @@ // (which has minor issues, described therein) use anyhow::Result; use std::fs::File; -use std::io::{self, BufRead, BufReader}; +use std::io::{BufRead, BufReader}; use std::path::Path; pub struct MboxReader<T> @@ -31,7 +31,7 @@ impl<T: BufRead> MboxReader<T> { pub fn from_file(p: &Path) -> Result<MboxReader<BufReader<File>>> { let f = File::open(p)?; let mut reader = BufReader::new(f); - let mut mboxr = MboxReader::from_reader(reader); + let mboxr = MboxReader::from_reader(reader); Ok(mboxr) } // not the prettiest but it works @@ -44,8 +44,7 @@ impl<T: BufRead> Iterator for MboxReader<T> { return None; } let mut record = Vec::new(); - let mut current_line = Vec::new(); - let mut started = true; + let mut current_line; let mut res = 1; while res != 0 { current_line = vec![]; diff --git a/src/utils.rs b/src/utils.rs @@ -19,7 +19,7 @@ pub fn email_body(body: &str) -> String { in_reply = false } - let mut finder = LinkFinder::new(); + let finder = LinkFinder::new(); for span in finder.spans(line) { match span.kind() { Some(LinkKind::Url) => {