From 29cbbf9ce8256e5e35a05463479cbddd1493f0f3 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Wed, 3 Mar 2021 23:11:21 +0100 Subject: [PATCH] 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. --- src/html.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/html.rs b/src/html.rs index 1379f10eb..b7cd121ee 100644 --- a/src/html.rs +++ b/src/html.rs @@ -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::()?; - 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(())