crabmail

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

commit 6c2decf8bd0a9a66a17d1e8f1ec1fd56d7f22650
parent 335532a2bf61068989d327bff02d6aefad748e81
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Sun, 27 Mar 2022 09:11:09 -0700

list xml base

Diffstat:
MTODO | 5+----
Msrc/main.rs | 2+-
Msrc/models.rs | 11+++++++----
Msrc/templates/html.rs | 11+++++++----
Msrc/templates/xml.rs | 19++++++++++++-------
5 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/TODO b/TODO @@ -3,10 +3,7 @@ TODO atom feeds working -> pull last x into threads paginate list home only unformat flowed if we are format flowed in gmi, html, xml - -feature water line ----------- -test a ton +URL encode spaces in links for gemini export reference mblaze command, add examples to readme fix docs check for html escape bugz diff --git a/src/main.rs b/src/main.rs @@ -118,7 +118,7 @@ impl List { std::fs::create_dir_all(&message_dir).ok(); for thread_ids in &self.thread_idx.threads { // Load thread - let thread = Thread::new(thread_ids, &self.config.name); + let thread = Thread::new(thread_ids, &self.config.name, &self.config.email); let basepath = thread_dir.join(&thread.messages[0].pathescape_msg_id()); // hacky if Config::global().include_html { diff --git a/src/models.rs b/src/models.rs @@ -28,9 +28,11 @@ impl Lists { Some(sub) => sub, None => Config::global().default_subsection(name), }; + let url = format!("{}/{}", Config::global().base_url, config.name); self.lists.push(List { thread_idx, config, + url, thread_topics: vec![], recent_messages: vec![], out_dir: self.out_dir.join(name), @@ -43,6 +45,7 @@ pub struct List { pub recent_messages: Vec<StrMessage>, pub config: Subsection, // path pub out_dir: PathBuf, + pub url: String, } // doesnt include full msg data @@ -57,12 +60,12 @@ pub struct Thread { } impl Thread { - pub fn new(thread_idx: &Vec<Msg>, list_name: &str) -> Self { + pub fn new(thread_idx: &Vec<Msg>, list_name: &str, list_email: &str) -> Self { let mut out = vec![]; for m in thread_idx { let data = std::fs::read(&m.path).unwrap(); let mut msg = StrMessage::new(&Message::parse(&data).unwrap()); - msg.mailto = msg.mailto(list_name); + msg.mailto = msg.mailto(list_name, list_email); out.push(msg); } Thread { messages: out } @@ -160,8 +163,8 @@ impl StrMessage { output } - pub fn mailto(&self, list_name: &str) -> String { - let mut url = format!("mailto:{}?", self.from.address); + pub fn mailto(&self, list_name: &str, list_email: &str) -> String { + let mut url = format!("mailto:{}?", list_email); let from = self.from.address.clone(); // make sure k is already urlencoded diff --git a/src/templates/html.rs b/src/templates/html.rs @@ -13,7 +13,7 @@ const HEADER: &str = r#"<!DOCTYPE html> <meta http-equiv='Permissions-Policy' content='interest-cohort=()'/> <link rel='stylesheet' type='text/css' href='{css_path}' /> <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> +<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>'> <meta name="description" content="{title}"/> </head> <body> @@ -89,8 +89,10 @@ impl List { } // TODO use summary?? let page = template( - r#" - {header} + &format!( + "{}{}{}", + HEADER, + r#" <h1 class="page-title"> {title} <a href="atom.xml"> @@ -101,8 +103,9 @@ impl List { <a href="{mailto:list_email}">{list_email}</a> <hr> {threads} - {footer} "#, + FOOTER + ), &[ ("header", HEADER), ("description", &self.config.description), diff --git a/src/templates/xml.rs b/src/templates/xml.rs @@ -57,20 +57,25 @@ impl List { .unwrap(), ); } + // Sometimes its unclear whether to do stuff like this in models.rs or here. could refactor + let last_updated = self + .recent_messages + .get(0) + .and_then(|x| Some(x.received)) + .unwrap_or(1); template( FEED_TEMPLATE, &[ - ("feed_link", "asdf"), - ("feed_id", "asdf"), - ("feed_title", "asdf"), - ("last_updated", "adf"), + ("feed_link", &self.url), + ("feed_id", &self.url), + ("feed_title", &self.config.name), + ("last_updated", &Date::from(last_updated).rfc3339()), ("entry_list", &entry_list), - ("author_name", ""), - ("author_email", ""), + ("author_name", &self.config.email), + ("author_email", &self.config.email), ], ) .unwrap() - // last_updated = time::secs_to_date(last_updated).rfc3339(), } }