Skip to content

Commit

Permalink
fix: image/*, audio/*, video/* are not attachments when found in both…
Browse files Browse the repository at this point in the history
… text and html parts

RFC8621 section 4.1.4
The additional is_multipart heuristic is to prevent the current malformed .eml
tests from failing.
  • Loading branch information
sftse committed Dec 12, 2023
1 parent 9e19132 commit 4948503
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/parsers/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,20 +323,19 @@ impl MessageParser {
}
(Cow::Borrowed(bytes), None) => String::from_utf8_lossy(bytes),
};

let is_html = mime_type == MimeType::TextHtml;

if add_to_html && !is_html {
if add_to_html {
message.html_body.push(message.parts.len());
} else if add_to_text && is_html {
}
if add_to_text {
message.text_body.push(message.parts.len());
}

if add_to_html && is_html {
message.html_body.push(message.parts.len());
} else if add_to_text && !is_html {
message.text_body.push(message.parts.len());
} else {
if !is_multipart && !(add_to_text || add_to_html)
|| (mime_type == MimeType::Inline || is_multipart)
&& (!add_to_text || !add_to_html)
{
message.attachments.push(message.parts.len());
}

Expand All @@ -352,8 +351,12 @@ impl MessageParser {
if add_to_text {
message.text_body.push(message.parts.len());
}

message.attachments.push(message.parts.len());
if !is_multipart && !(add_to_text || add_to_html)
|| (mime_type == MimeType::Inline || is_multipart)
&& (!add_to_text || !add_to_html)
{
message.attachments.push(message.parts.len());
}

if !is_inline {
PartType::Binary(bytes)
Expand Down

0 comments on commit 4948503

Please sign in to comment.