crabmail

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

commit 3c55a01ef5b27dfa76229f5e92e0ccc6e9a9d29f
parent bd69c0f6cc6fe1e9fc7f3200f845b47c1d773632
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Sun, 20 Mar 2022 13:29:03 -0700

bug fixy

Diffstat:
MTODO | 4+---
Msrc/arg.rs | 2+-
Msrc/config.rs | 3+--
Msrc/main.rs | 51+++++++++++++++++++++++++++++++++------------------
4 files changed, 36 insertions(+), 24 deletions(-)

diff --git a/TODO b/TODO @@ -4,10 +4,8 @@ atom feeds working paginate list home fix docs check for html escape bugz -add date to generated string -fix date fmt -add "exclude html" flag fix "to" in email export +delete files if not written reference mblaze command, add examples to readme fix all the build warnings remove unused diff --git a/src/arg.rs b/src/arg.rs @@ -25,7 +25,7 @@ fn usage() -> ! { MAILDIR A directory containing the maildirs of lists you want to parse -FLAGS: +FLAGS (default -gh if none set) -g include gemini output -h include HTML output diff --git a/src/config.rs b/src/config.rs @@ -28,9 +28,8 @@ pub struct Config { pub base_url: String, pub description: String, pub include_gemini: bool, + pub include_html: bool, pub out_dir: PathBuf, // TODO rem - pub relative_times: bool, // TODO rem - pub include_raw: bool, // TODO rem pub now: String, // TODO rem pub reply_add_link: bool, // Might remove this pub subsections: Vec<Subsection>, diff --git a/src/main.rs b/src/main.rs @@ -41,7 +41,9 @@ impl Lists { let css = include_bytes!("style.css"); write_if_unchanged(&self.out_dir.join("style.css"), css); let base_path = self.out_dir.join("index"); - write_if_unchanged(&base_path.with_extension("html"), self.to_html().as_bytes()); + if Config::global().include_html { + write_if_unchanged(&base_path.with_extension("html"), self.to_html().as_bytes()); + } if Config::global().include_gemini { write_if_unchanged(&base_path.with_extension("gmi"), self.to_gmi().as_bytes()); } @@ -76,6 +78,7 @@ enum Format { impl List { fn persist(&mut self) { // let written = hashset + std::fs::create_dir_all(&self.out_dir); self.write_index(); self.write_threads(); // for file in threads, messages @@ -85,23 +88,27 @@ impl List { fn write_index(&self) { // TODO fix lazy copy paste // TODO return files written - for (n, gmi) in self.to_gmi().iter().enumerate() { - let index; - if n == 0 { - index = self.out_dir.join("index"); - } else { - index = self.out_dir.join(format!("{}-{}", "index", n)); + if Config::global().include_gemini { + for (n, gmi) in self.to_gmi().iter().enumerate() { + let index; + if n == 0 { + index = self.out_dir.join("index"); + } else { + index = self.out_dir.join(format!("{}-{}", "index", n)); + } + write_if_unchanged(&index.with_extension("gmi"), gmi.as_bytes()); } - write_if_unchanged(&index.with_extension("gmi"), gmi.as_bytes()); } - for (n, html) in self.to_html().iter().enumerate() { - let index; - if n == 0 { - index = self.out_dir.join("index"); - } else { - index = self.out_dir.join(format!("{}-{}", "index", n)); + if Config::global().include_html { + for (n, html) in self.to_html().iter().enumerate() { + let index; + if n == 0 { + index = self.out_dir.join("index"); + } else { + index = self.out_dir.join(format!("{}-{}", "index", n)); + } + write_if_unchanged(&index.with_extension("html"), html.as_bytes()); } - write_if_unchanged(&index.with_extension("html"), html.as_bytes()); } // write_if_unchanged(&self.out_dir.join("atom.xml"), self.to_xml().as_bytes()); } @@ -117,7 +124,9 @@ impl List { let thread = Thread::new(thread_ids, &self.config.name); let basepath = thread_dir.join(&thread.messages[0].pathescape_msg_id()); // hacky - write_if_unchanged(&append_ext("html", &basepath), thread.to_html().as_bytes()); + if Config::global().include_html { + write_if_unchanged(&append_ext("html", &basepath), thread.to_html().as_bytes()); + } write_if_unchanged(&append_ext("xml", &basepath), thread.to_xml().as_bytes()); if Config::global().include_gemini { write_if_unchanged(&append_ext("gmi", &basepath), thread.to_gmi().as_bytes()); @@ -143,8 +152,14 @@ fn main() -> Result<()> { let args = arg::Args::from_env(); let maildir = &args.positional[0]; let mut config = Config::from_file(&args.config)?; - // TODO cleanup - config.include_gemini = args.include_gemini; + // Default to both true if both absent + if !args.include_gemini && !args.include_html { + config.include_gemini = true; + config.include_html = true; + } else { + config.include_gemini = args.include_gemini; + config.include_html = args.include_html; + } config.out_dir = args.out_dir; INSTANCE.set(config).unwrap();