From 1261bdf8a9166e67d9cb84a07ad0785e2e5350c0 Mon Sep 17 00:00:00 2001 From: Bill Thiede Date: Sun, 26 Nov 2023 18:50:32 -0800 Subject: [PATCH] web & server: improved debug printing of unhandled mime types --- server/src/graphql.rs | 30 +++++++++++++++++++++++++++++- web/src/lib.rs | 2 +- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/server/src/graphql.rs b/server/src/graphql.rs index abc7eee..ad4070f 100644 --- a/server/src/graphql.rs +++ b/server/src/graphql.rs @@ -246,7 +246,10 @@ impl QueryRoot { "text/plain" => Body::PlainText(PlainText { text: body }), "text/html" => Body::Html(Html { html: body }), _ => { - let msg = format!("Unhandled body content type: {}", m.ctype.mimetype); + let msg = format!( + "Unhandled body content type:\n{}", + render_content_type_tree(&m) + ); warn!("{}", msg); Body::UnhandledContentType(UnhandledContentType { text: msg }) } @@ -273,6 +276,31 @@ impl QueryRoot { } } +fn render_content_type_tree(m: &ParsedMail) -> String { + const WIDTH: usize = 4; + fn render_rec(m: &ParsedMail, depth: usize) -> String { + let mut parts = Vec::new(); + let msg = format!("{} {}", "-".repeat(depth * WIDTH), m.ctype.mimetype); + println!("{msg}",); + parts.push(msg); + if !m.ctype.charset.is_empty() { + parts.push(format!( + "{} Character Set: {}", + " ".repeat(depth * WIDTH), + m.ctype.charset + )); + } + for (k, v) in m.ctype.params.iter() { + parts.push(format!("{} {k}: {v}", " ".repeat(depth * WIDTH),)); + } + for sp in &m.subparts { + parts.push(render_rec(sp, depth + 1)) + } + parts.join("\n") + } + render_rec(m, 1) +} + pub type GraphqlSchema = Schema; fn email_addresses(path: &str, m: &ParsedMail, header_name: &str) -> Result, Error> { diff --git a/web/src/lib.rs b/web/src/lib.rs index dec57c7..a12bdc8 100644 --- a/web/src/lib.rs +++ b/web/src/lib.rs @@ -1059,7 +1059,7 @@ fn view_thread(thread: &ShowThreadQueryThread) -> Node { match &msg.body { ShowThreadQueryThreadMessagesBody::UnhandledContentType( ShowThreadQueryThreadMessagesBodyOnUnhandledContentType { contents }, - ) => div![C!["error"], contents], + ) => pre![C!["error"], contents], ShowThreadQueryThreadMessagesBody::PlainText( ShowThreadQueryThreadMessagesBodyOnPlainText { contents }, ) => div![C!["view-part-text-plain"], contents],