web&server: show raw body contents of UnhandledContentType
This commit is contained in:
parent
d4038f40d6
commit
1b221d5c16
@ -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<Body, Error> {
|
||||
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#"<p class="view-part-unhandled">{text}</p>"#)
|
||||
Body::UnhandledContentType(UnhandledContentType { text, .. }) => {
|
||||
error!("text len {}", text.len());
|
||||
format!(
|
||||
r#"<p class="view-part-unhandled">{}</p>"#,
|
||||
// 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::<Vec<_>>()
|
||||
|
||||
@ -1505,6 +1505,22 @@
|
||||
"ofType": null
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"args": [],
|
||||
"deprecationReason": null,
|
||||
"description": null,
|
||||
"isDeprecated": false,
|
||||
"name": "contentTree",
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "SCALAR",
|
||||
"name": "String",
|
||||
"ofType": null
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"inputFields": null,
|
||||
|
||||
@ -23,6 +23,7 @@ query ShowThreadQuery($threadId: String!) {
|
||||
__typename
|
||||
... on UnhandledContentType {
|
||||
contents
|
||||
contentTree
|
||||
}
|
||||
... on PlainText {
|
||||
contents
|
||||
|
||||
@ -691,8 +691,13 @@ fn message_render(msg: &ShowThreadQueryThreadMessages, open: bool) -> Node<Msg>
|
||||
C!["body"],
|
||||
match &msg.body {
|
||||
ShowThreadQueryThreadMessagesBody::UnhandledContentType(
|
||||
ShowThreadQueryThreadMessagesBodyOnUnhandledContentType { contents },
|
||||
) => pre![C!["error"], contents],
|
||||
ShowThreadQueryThreadMessagesBodyOnUnhandledContentType { contents ,content_tree},
|
||||
) => div![
|
||||
raw_text_message(&contents),
|
||||
div![C!["error"],
|
||||
view_content_tree(&content_tree),
|
||||
]
|
||||
],
|
||||
ShowThreadQueryThreadMessagesBody::PlainText(
|
||||
ShowThreadQueryThreadMessagesBodyOnPlainText {
|
||||
contents,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user