Skip to content

Commit

Permalink
hoist common if condition out of if-else
Browse files Browse the repository at this point in the history
  • Loading branch information
sftse committed Dec 6, 2023
1 parent e9b8d78 commit e0030a2
Showing 1 changed file with 13 additions and 25 deletions.
38 changes: 13 additions & 25 deletions src/parsers/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,19 @@ impl MessageParser {
(false, false)
};

if add_to_html {
message.html_body.push(message.parts.len());
}
if add_to_text {
message.text_body.push(message.parts.len());
}

if !is_multipart && !(add_to_text || add_to_html)
|| (is_media || is_multipart) && (!add_to_text || !add_to_html)
{
message.attachments.push(message.parts.len());
}

if is_text {
let text = match (
bytes,
Expand All @@ -325,37 +338,12 @@ impl MessageParser {
(Cow::Borrowed(bytes), None) => String::from_utf8_lossy(bytes),
};

if add_to_html {
message.html_body.push(message.parts.len());
}
if add_to_text {
message.text_body.push(message.parts.len());
}

if !is_multipart && !(add_to_text || add_to_html)
|| (is_media || is_multipart) && (!add_to_text || !add_to_html)
{
message.attachments.push(message.parts.len());
}

if mime_type == MimeType::TextHtml {
PartType::Html(text)
} else {
PartType::Text(text)
}
} else {
if add_to_html {
message.html_body.push(message.parts.len());
}
if add_to_text {
message.text_body.push(message.parts.len());
}
if !is_multipart && !(add_to_text || add_to_html)
|| (is_media || is_multipart) && (!add_to_text || !add_to_html)
{
message.attachments.push(message.parts.len());
}

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

0 comments on commit e0030a2

Please sign in to comment.