let get_html() return first instead of last text

usually, there is at most one text/html and one text/plain part.

multiple text/plain parts,
are known only by mailinglist software that wants to add a footer
but cannot alter the original content part -
maybe because it is html and things are hard to stitch
or maybe because the content part is cryptographically signed
and cannot be altered therefore.
This commit is contained in:
B. Petersen
2021-03-03 23:11:21 +01:00
committed by bjoern
parent cd3c2a6c6c
commit 29cbbf9ce8

View File

@@ -108,9 +108,12 @@ impl HtmlMsgParser {
/// Function iterates over all mime-parts
/// and searches for text/plain and text/html parts and saves the
/// last one found
/// first one found.
/// in the corresponding structure fields.
/// Usually, there is at most one plain-text and one HTML-text part.
///
/// Usually, there is at most one plain-text and one HTML-text part,
/// multiple plain-text parts might be used for mailinglist-footers,
/// therefore we use the first one.
fn collect_texts_recursive<'a>(
&'a mut self,
context: &'a Context,
@@ -135,12 +138,11 @@ impl HtmlMsgParser {
}
MimeMultipartType::Single => {
let mimetype = mail.ctype.mimetype.parse::<Mime>()?;
if mimetype == mime::TEXT_HTML {
if mimetype == mime::TEXT_HTML && self.html.is_empty() {
if let Ok(decoded_data) = mail.get_body() {
self.html = decoded_data;
return Ok(());
}
} else if mimetype == mime::TEXT_PLAIN {
} else if mimetype == mime::TEXT_PLAIN && self.plain.is_none() {
if let Ok(decoded_data) = mail.get_body() {
self.plain = Some(PlainText {
text: decoded_data,
@@ -155,7 +157,6 @@ impl HtmlMsgParser {
false
},
});
return Ok(());
}
}
Ok(())