Skip to content

Commit

Permalink
filter attachment text parts
Browse files Browse the repository at this point in the history
  • Loading branch information
Awlex committed Jul 5, 2021
1 parent a839f66 commit c0d91b7
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 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 @@ -119,7 +119,8 @@ defmodule Mail.Renderers.RFC2822 do
end

defp render_header_value(_key, [value | subtypes]),
do: Enum.join([encode_header_value(value, :quoted_printable) | render_subtypes(subtypes)], "; ")
do:
Enum.join([encode_header_value(value, :quoted_printable) | render_subtypes(subtypes)], "; ")

defp render_header_value(key, value),
do: render_header_value(key, List.wrap(value))
Expand Down Expand Up @@ -210,7 +211,12 @@ defmodule Mail.Renderers.RFC2822 do
content_type = Mail.Message.get_content_type(message)

if Mail.Message.has_attachment?(message) do
text_parts = Enum.filter(message.parts, &match_content_type?(&1, ~r/text\/(plain|html)/))
text_parts =
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

0 comments on commit c0d91b7

Please sign in to comment.