From 7a32d5c6300be1058320fb3a22200cb506f0a30a Mon Sep 17 00:00:00 2001 From: Bill Thiede Date: Sat, 2 Dec 2023 15:12:40 -0800 Subject: [PATCH] server: include headers in debug output --- server/src/graphql.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/server/src/graphql.rs b/server/src/graphql.rs index 314fe51..d63d527 100644 --- a/server/src/graphql.rs +++ b/server/src/graphql.rs @@ -339,6 +339,10 @@ fn extract_unhandled(m: &ParsedMail) -> Result { text: msg, })) } + +// multipart/alternative defines multiple representations of the same message, and clients should +// show the fanciest they can display. For this program, the priority is text/html, text/plain, +// then give up. fn extract_alternative(m: &ParsedMail) -> Result { for sp in &m.subparts { if sp.ctype.mimetype == "text/html" { @@ -355,6 +359,8 @@ fn extract_alternative(m: &ParsedMail) -> Result { Err("extract_alternative".into()) } +// multipart/mixed defines multiple types of context all of which should be presented to the user +// 'serially'. fn extract_mixed(m: &ParsedMail) -> Result { for sp in &m.subparts { if sp.ctype.mimetype == "multipart/alternative" { @@ -400,15 +406,18 @@ fn render_content_type_tree(m: &ParsedMail) -> String { let mut parts = Vec::new(); let msg = format!("{} {}", "-".repeat(depth * WIDTH), m.ctype.mimetype); parts.push(msg); + let indent = " ".repeat(depth * WIDTH); if !m.ctype.charset.is_empty() { - parts.push(format!( - "{} Character Set: {}", - " ".repeat(depth * WIDTH), - m.ctype.charset - )); + parts.push(format!("{indent} Character Set: {}", m.ctype.charset)); } for (k, v) in m.ctype.params.iter() { - parts.push(format!("{} {k}: {v}", " ".repeat(depth * WIDTH),)); + parts.push(format!("{indent} {k}: {v}")); + } + if !m.headers.is_empty() { + parts.push(format!("{indent} == headers ==")); + for h in &m.headers { + parts.push(format!("{indent} {}: {}", h.get_key(), h.get_value())); + } } for sp in &m.subparts { parts.push(render_rec(sp, depth + 1))