default Content-Type to text/plain for not multipart messages (#357)

* 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 <soywod@users.noreply.github.com>
This commit is contained in:
fabrixxm 2022-05-07 22:13:08 +02:00 committed by GitHub
parent 6d154abcb5
commit b7157573f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -55,7 +55,12 @@ impl Parts {
part: &'a mailparse::ParsedMail<'a>,
) -> Result<Self> {
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 {