web & server: improved debug printing of unhandled mime types

This commit is contained in:
2023-11-26 18:50:32 -08:00
parent 11366b6fac
commit 1261bdf8a9
2 changed files with 30 additions and 2 deletions

View File

@@ -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<QueryRoot, EmptyMutation, EmptySubscription>;
fn email_addresses(path: &str, m: &ParsedMail, header_name: &str) -> Result<Vec<Email>, Error> {