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)]
|
#[derive(Debug)]
|
||||||
pub struct UnhandledContentType {
|
pub struct UnhandledContentType {
|
||||||
text: String,
|
text: String,
|
||||||
|
content_tree: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Object]
|
#[Object]
|
||||||
@ -111,6 +112,9 @@ impl UnhandledContentType {
|
|||||||
async fn contents(&self) -> &str {
|
async fn contents(&self) -> &str {
|
||||||
&self.text
|
&self.text
|
||||||
}
|
}
|
||||||
|
async fn content_tree(&self) -> &str {
|
||||||
|
&self.content_tree
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -368,6 +372,23 @@ impl QueryRoot {
|
|||||||
content_tree
|
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,
|
b => b,
|
||||||
};
|
};
|
||||||
let headers = m
|
let headers = m
|
||||||
@ -508,7 +529,8 @@ fn extract_unhandled(m: &ParsedMail) -> Result<Body, Error> {
|
|||||||
render_content_type_tree(m)
|
render_content_type_tree(m)
|
||||||
);
|
);
|
||||||
Ok(Body::UnhandledContentType(UnhandledContentType {
|
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::Html(Html { html, .. }) => html.clone(),
|
||||||
Body::UnhandledContentType(UnhandledContentType { text }) => {
|
Body::UnhandledContentType(UnhandledContentType { text, .. }) => {
|
||||||
format!(r#"<p class="view-part-unhandled">{text}</p>"#)
|
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<_>>()
|
.collect::<Vec<_>>()
|
||||||
|
|||||||
@ -1505,6 +1505,22 @@
|
|||||||
"ofType": null
|
"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,
|
"inputFields": null,
|
||||||
|
|||||||
@ -23,6 +23,7 @@ query ShowThreadQuery($threadId: String!) {
|
|||||||
__typename
|
__typename
|
||||||
... on UnhandledContentType {
|
... on UnhandledContentType {
|
||||||
contents
|
contents
|
||||||
|
contentTree
|
||||||
}
|
}
|
||||||
... on PlainText {
|
... on PlainText {
|
||||||
contents
|
contents
|
||||||
|
|||||||
@ -691,8 +691,13 @@ fn message_render(msg: &ShowThreadQueryThreadMessages, open: bool) -> Node<Msg>
|
|||||||
C!["body"],
|
C!["body"],
|
||||||
match &msg.body {
|
match &msg.body {
|
||||||
ShowThreadQueryThreadMessagesBody::UnhandledContentType(
|
ShowThreadQueryThreadMessagesBody::UnhandledContentType(
|
||||||
ShowThreadQueryThreadMessagesBodyOnUnhandledContentType { contents },
|
ShowThreadQueryThreadMessagesBodyOnUnhandledContentType { contents ,content_tree},
|
||||||
) => pre![C!["error"], contents],
|
) => div![
|
||||||
|
raw_text_message(&contents),
|
||||||
|
div![C!["error"],
|
||||||
|
view_content_tree(&content_tree),
|
||||||
|
]
|
||||||
|
],
|
||||||
ShowThreadQueryThreadMessagesBody::PlainText(
|
ShowThreadQueryThreadMessagesBody::PlainText(
|
||||||
ShowThreadQueryThreadMessagesBodyOnPlainText {
|
ShowThreadQueryThreadMessagesBodyOnPlainText {
|
||||||
contents,
|
contents,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user