crabmail

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

commit f4ac001c2a35169aad9d848e507db4a46cc80d7e
parent 0a352310c65eadb72345af63c187da3e0e7eab34
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Sun, 13 Mar 2022 17:49:35 -0700

start html parsing

Diffstat:
Msrc/main.rs | 9++++++---
Msrc/models.rs | 4+++-
Msrc/templates/html.rs | 38+++++++++++++++++++++++++++++++++-----
3 files changed, 42 insertions(+), 9 deletions(-)

diff --git a/src/main.rs b/src/main.rs @@ -55,8 +55,11 @@ fn write_if_unchanged(path: &PathBuf, data: &[u8]) -> bool { // / is disallowed in paths. ; is disallowed in message IDs // assumes unix-like filesystem. TODO windows compatability if someone asks -fn pathescape_msg_id(s: &str) -> PathBuf { - PathBuf::from(s.replace("/", ";")) + +enum Format { + XML, + HTML, + GMI, } impl List { @@ -100,7 +103,7 @@ impl List { for thread_ids in &self.thread_idx.threads { // Load thread let thread = Thread::new(thread_ids); - let basepath = thread_dir.join(&pathescape_msg_id(&thread.messages[0].id)); + let basepath = thread_dir.join(&thread.messages[0].pathescape_msg_id()); write_if_unchanged( &basepath.with_extension("html"), thread.to_html().as_bytes(), diff --git a/src/models.rs b/src/models.rs @@ -83,7 +83,9 @@ pub struct StrMessage { } impl StrMessage { - pub fn from_file() {} + pub fn pathescape_msg_id(&self) -> PathBuf { + PathBuf::from(self.id.replace("/", ";")) + } } // i suck at Cow and strings diff --git a/src/templates/html.rs b/src/templates/html.rs @@ -1,22 +1,25 @@ use super::util::xml_escape; +use super::util::xml_safe as x; use crate::models::*; use linkify::{LinkFinder, LinkKind}; use nanotemplate::template; use std::borrow::Cow; -const layout: &str = r#"<!DOCTYPE html> +const header: &str = r#"<!DOCTYPE html> <html> <head> <title>{title}</title> <meta http-equiv='Permissions-Policy' content='interest-cohort=()'/> -<link rel='stylesheet' type='text/css' href='style.css' /> +<link rel='stylesheet' type='text/css' href='../../style.css' /> <meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0,user-scalable=0' /> <link rel='icon' href='data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>📧</text></svg>'></head> <meta name="description" content="{title}"/> <body> -{core} +"#; + +const footer: &str = r#" <hr> -"Archive generated with <a href='https://crabmail.flounder.online/'>crabmail</a>"; +Archive generated with <a href='https://crabmail.flounder.online/'>crabmail</a> </body> </html> "#; @@ -54,7 +57,32 @@ impl List { impl Thread { pub fn to_html(&self) -> String { - template(r#""#, &[("title", "tbd")]).unwrap() + let root = &self.messages[0]; + let mut body = r#" + <h1 class="page-title">{title}</h1> + <a href="{path_id}.xml"><img alt="Atom Feed" src='{rss_svg}'></a> + <div> + <a href="../">Back</a> + <a href="\#bottom">Latest</a> + <hr> + <div> + "# + .to_string(); + for msg in &self.messages { + let ms = "newmail"; + body.push_str(ms); + } + body.push_str("</div>"); + template( + &format!("{}{}{}", header, body, footer), + // TODO html escape + &[ + ("title", x(&root.subject).as_ref()), + ("rss_svg", RSS_SVG), + ("path_id", &x(root.pathescape_msg_id().to_str().unwrap())), + ], + ) + .unwrap() } }