server: include headers in debug output

This commit is contained in:
Bill Thiede 2023-12-02 15:12:40 -08:00
parent 714b057fdb
commit 7a32d5c630

View File

@ -339,6 +339,10 @@ fn extract_unhandled(m: &ParsedMail) -> Result<Body, Error> {
text: msg, 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<Body, Error> { fn extract_alternative(m: &ParsedMail) -> Result<Body, Error> {
for sp in &m.subparts { for sp in &m.subparts {
if sp.ctype.mimetype == "text/html" { if sp.ctype.mimetype == "text/html" {
@ -355,6 +359,8 @@ fn extract_alternative(m: &ParsedMail) -> Result<Body, Error> {
Err("extract_alternative".into()) 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<Body, Error> { fn extract_mixed(m: &ParsedMail) -> Result<Body, Error> {
for sp in &m.subparts { for sp in &m.subparts {
if sp.ctype.mimetype == "multipart/alternative" { if sp.ctype.mimetype == "multipart/alternative" {
@ -400,15 +406,18 @@ fn render_content_type_tree(m: &ParsedMail) -> String {
let mut parts = Vec::new(); let mut parts = Vec::new();
let msg = format!("{} {}", "-".repeat(depth * WIDTH), m.ctype.mimetype); let msg = format!("{} {}", "-".repeat(depth * WIDTH), m.ctype.mimetype);
parts.push(msg); parts.push(msg);
let indent = " ".repeat(depth * WIDTH);
if !m.ctype.charset.is_empty() { if !m.ctype.charset.is_empty() {
parts.push(format!( parts.push(format!("{indent} Character Set: {}", m.ctype.charset));
"{} Character Set: {}",
" ".repeat(depth * WIDTH),
m.ctype.charset
));
} }
for (k, v) in m.ctype.params.iter() { 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 { for sp in &m.subparts {
parts.push(render_rec(sp, depth + 1)) parts.push(render_rec(sp, depth + 1))