server: use same html cleanup idiom in nm as we do in newreader
This commit is contained in:
parent
b8c1710a83
commit
100865c923
@ -17,7 +17,7 @@ use crate::{
|
|||||||
Attachment, Body, DispositionType, Email, EmailThread, Header, Html, Message, PlainText,
|
Attachment, Body, DispositionType, Email, EmailThread, Header, Html, Message, PlainText,
|
||||||
Tag, Thread, ThreadSummary, UnhandledContentType,
|
Tag, Thread, ThreadSummary, UnhandledContentType,
|
||||||
},
|
},
|
||||||
linkify_html, sanitize_html,
|
linkify_html, InlineStyle, SanitizeHtml, Transformer,
|
||||||
};
|
};
|
||||||
|
|
||||||
const TEXT_PLAIN: &'static str = "text/plain";
|
const TEXT_PLAIN: &'static str = "text/plain";
|
||||||
@ -169,17 +169,29 @@ pub async fn thread(
|
|||||||
};
|
};
|
||||||
|
|
||||||
Body::Html(Html {
|
Body::Html(Html {
|
||||||
html: format!(
|
html: {
|
||||||
r#"<p class="view-part-text-plain">{}</p>"#,
|
let body_tranformers: Vec<Box<dyn Transformer>> = vec![
|
||||||
// Trim newlines to prevent excessive white space at the beginning/end of
|
Box::new(InlineStyle),
|
||||||
// presenation. Leave tabs and spaces incase plain text attempts to center a
|
Box::new(SanitizeHtml {
|
||||||
// header on the first line.
|
cid_prefix: &cid_prefix,
|
||||||
sanitize_html(
|
base_url: &base_url,
|
||||||
&linkify_html(&text.trim_matches('\n')),
|
}),
|
||||||
&cid_prefix,
|
];
|
||||||
&base_url
|
let mut html = linkify_html(&text.trim_matches('\n'));
|
||||||
)?
|
for t in body_tranformers.iter() {
|
||||||
),
|
if t.should_run(&None, &html) {
|
||||||
|
html = t.transform(&None, &html).await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
format!(
|
||||||
|
r#"<p class="view-part-text-plain">{}</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.
|
||||||
|
html
|
||||||
|
)
|
||||||
|
},
|
||||||
content_tree: if debug_content_tree {
|
content_tree: if debug_content_tree {
|
||||||
render_content_type_tree(&m)
|
render_content_type_tree(&m)
|
||||||
} else {
|
} else {
|
||||||
@ -187,8 +199,27 @@ pub async fn thread(
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Body::Html(Html { html, content_tree }) => Body::Html(Html {
|
Body::Html(Html {
|
||||||
html: sanitize_html(&html, &cid_prefix, &base_url)?,
|
mut html,
|
||||||
|
content_tree,
|
||||||
|
}) => Body::Html(Html {
|
||||||
|
html: {
|
||||||
|
let body_tranformers: Vec<Box<dyn Transformer>> = vec![
|
||||||
|
// TODO: this breaks things like emails from calendar
|
||||||
|
//Box::new(InlineStyle),
|
||||||
|
Box::new(SanitizeHtml {
|
||||||
|
cid_prefix: &cid_prefix,
|
||||||
|
base_url: &base_url,
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
for t in body_tranformers.iter() {
|
||||||
|
if t.should_run(&None, &html) {
|
||||||
|
html = t.transform(&None, &html).await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
html
|
||||||
|
},
|
||||||
|
|
||||||
content_tree: if debug_content_tree {
|
content_tree: if debug_content_tree {
|
||||||
render_content_type_tree(&m)
|
render_content_type_tree(&m)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user