From b7157573f2a829d9c30689bdee747113e6233e5c Mon Sep 17 00:00:00 2001 From: fabrixxm Date: Sat, 7 May 2022 22:13:08 +0200 Subject: [PATCH] default Content-Type to text/plain for not multipart messages (#357) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Default Content-Type to text/plain for not multipart messages Parse body of messages without subparts as text/plain if Content-Type header is not set. * narrow check for defaulting to `text/plain` take message body as `text/plain` only if message has only one part and has no `Content-Type` header Co-authored-by: Clément DOUIN --- cli/src/msg/parts_entity.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cli/src/msg/parts_entity.rs b/cli/src/msg/parts_entity.rs index d4d0640..8c30f4f 100644 --- a/cli/src/msg/parts_entity.rs +++ b/cli/src/msg/parts_entity.rs @@ -55,7 +55,12 @@ impl Parts { part: &'a mailparse::ParsedMail<'a>, ) -> Result { let mut parts = vec![]; - build_parts_map_rec(account, part, &mut parts)?; + if part.subparts.is_empty() && part.get_headers().get_first_value("content-type").is_none() { + let content = part.get_body().unwrap_or_default(); + parts.push(Part::TextPlain(TextPlainPart { content })) + } else { + build_parts_map_rec(account, part, &mut parts)?; + } Ok(Self(parts)) } } @@ -105,7 +110,7 @@ fn build_parts_map_rec( } else if ctype.starts_with("text/html") { parts.push(Part::TextHtml(TextHtmlPart { content })) } - }; + } } }; } else {