diff --git a/server/src/graphql.rs b/server/src/graphql.rs index 3549298..21cadf2 100644 --- a/server/src/graphql.rs +++ b/server/src/graphql.rs @@ -104,6 +104,7 @@ pub struct Header { #[derive(Debug)] pub struct UnhandledContentType { text: String, + content_tree: String, } #[Object] @@ -111,6 +112,9 @@ impl UnhandledContentType { async fn contents(&self) -> &str { &self.text } + async fn content_tree(&self) -> &str { + &self.content_tree + } } #[derive(Debug)] @@ -368,6 +372,23 @@ impl QueryRoot { content_tree }, }), + + Body::UnhandledContentType(UnhandledContentType { content_tree, .. }) => { + let body_start = mmap + .windows(2) + .take(20_000) + .position(|w| w == b"\n\n") + .unwrap_or(0); + let body = mmap[body_start + 2..].to_vec(); + Body::UnhandledContentType(UnhandledContentType { + text: String::from_utf8(body)?, + content_tree: if debug_content_tree { + render_content_type_tree(&m) + } else { + content_tree + }, + }) + } b => b, }; let headers = m @@ -508,7 +529,8 @@ fn extract_unhandled(m: &ParsedMail) -> Result
{ render_content_type_tree(m) ); Ok(Body::UnhandledContentType(UnhandledContentType { - text: msg, + text: m.get_body()?, + content_tree: render_content_type_tree(m), })) } @@ -628,8 +650,15 @@ fn flatten_body_parts(parts: &[Body]) -> Body { ) } Body::Html(Html { html, .. }) => html.clone(), - Body::UnhandledContentType(UnhandledContentType { text }) => { - format!(r#"{text}
"#) + Body::UnhandledContentType(UnhandledContentType { text, .. }) => { + error!("text len {}", text.len()); + format!( + r#"{}
"#, + // Trim newlines to prevent excessive white space at the beginning/end of + // presenation. Leave tabs and spaces incase plain text attempts to center a + // header on the first line. + linkify_html(&text.trim_matches('\n')) + ) } }) .collect::