crabmail

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

commit fd94cdd1382767145420bf09874fa9a201278b61
parent 9d1b8243d86e2ccbd21de5f91fa14a848cdebfca
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Wed, 19 May 2021 20:14:55 -0700

mess with headers a bit

Diffstat:
Msrc/main.rs | 17+++++++++--------
Msrc/utils.rs | 2+-
2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/src/main.rs b/src/main.rs @@ -59,20 +59,21 @@ fn parse_path(s: &std::ffi::OsStr) -> Result<std::path::PathBuf, &'static str> { fn email_to_html(email: ParsedMail) -> String { // TODO use format strings here i think + let escaped_header = |f: &str| { + let mut s = String::new(); + let field = &email.headers.get_first_value(f).unwrap_or("".to_string()); + utils::escape_html(&mut s, &field); + return s; + }; + return format!( r#" <b>From<b>: {from}<br> <b>Subject</b>: {subject} <div id="body"> {body} </div> "#, - from = &email - .headers - .get_first_value("From") - .unwrap_or("".to_string()), - subject = &email - .headers - .get_first_value("Subject") - .unwrap_or("".to_string()), + from = escaped_header("From"), + subject = escaped_header("Subject"), body = &email.get_body().unwrap() ); } diff --git a/src/utils.rs b/src/utils.rs @@ -17,7 +17,7 @@ static HTML_ESCAPE_TABLE: [u8; 256] = create_html_escape_table(); static HTML_ESCAPES: [&str; 5] = ["", "&quot;", "&amp;", "&lt;", "&gt;"]; -fn escape_html(mut w: String, s: &str) { +pub fn escape_html(w: &mut String, s: &str) { let bytes = s.as_bytes(); let mut mark = 0; let mut i = 0;