remove additional text parts if we think they belong to a mailinglist footer

This commit is contained in:
B. Petersen
2021-02-28 01:06:55 +01:00
committed by bjoern
parent 40d7f3ff71
commit 5c2d6c22a0

View File

@@ -259,6 +259,7 @@ impl MimeMessage {
};
parser.parse_mime_recursive(context, &mail).await?;
parser.maybe_remove_bad_parts();
parser.maybe_remove_inline_mailinglist_footer();
parser.heuristically_parse_ndn(context).await;
parser.parse_headers(context);
@@ -1084,6 +1085,28 @@ impl MimeMessage {
}
}
/// Remove unwanted, additional text parts used for mailing list footer.
/// Some mailinglist software add footers as separate mimeparts
/// eg. when the user-edited-content is html.
/// As these footers would appear as repeated, separate text-bubbles,
/// we remove them.
fn maybe_remove_inline_mailinglist_footer(&mut self) {
if self.is_mailinglist_message() {
let text_part_cnt = self
.parts
.iter()
.filter(|p| p.typ == Viewtype::Text)
.count();
if text_part_cnt == 2 {
if let Some(last_part) = self.parts.last() {
if last_part.typ == Viewtype::Text {
self.parts.pop();
}
}
}
}
}
/// Some providers like GMX and Yahoo do not send standard NDNs (Non Delivery notifications).
/// If you improve heuristics here you might also have to change prefetch_should_download() in imap/mod.rs.
/// Also you should add a test in dc_receive_imf.rs (there already are lots of test_parse_ndn_* tests).