Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep original order of text parts #133

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/mail/renderers/rfc_2822.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Mail.Renderers.RFC2822 do
import Mail.Message, only: [match_content_type?: 2]
import Mail.Message, only: [match_content_type?: 2, is_attachment?: 1]

@days ~w(Mon Tue Wed Thu Fri Sat Sun)
@months ~w(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)
Expand Down Expand Up @@ -256,8 +256,10 @@ defmodule Mail.Renderers.RFC2822 do

if Mail.Message.has_attachment?(message) do
text_parts =
Enum.filter(message.parts, &match_content_type?(&1, ~r/text\/(plain|html)/))
|> Enum.sort(&(&1 > &2))
Enum.filter(
message.parts,
&(match_content_type?(&1, ~r/text\/(plain|html)/) and not is_attachment?(&1))
)

content_type = List.replace_at(content_type, 0, "multipart/mixed")
message = Mail.Message.put_content_type(message, content_type)
Expand Down
Loading