Skip to content

Commit

Permalink
Ignore space between two encoded words (as per RFC 2047)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtimberlake committed Oct 2, 2024
1 parent 807d1db commit 5492610
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/mail/parsers/rfc_2822.ex
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,9 @@ defmodule Mail.Parsers.RFC2822 do
Mail.Encoders.Base64.decode(encoded_string)
end

# Remove space if immediately followed by another encoded word string
remainder = Regex.replace(~r/\s+\=\?/, remainder, "=?")

decoded_string <> parse_encoded_word(remainder)

_ ->
Expand Down
13 changes: 13 additions & 0 deletions test/mail/parsers/rfc_2822_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,19 @@ defmodule Mail.Parsers.RFC2822Test do
assert message.headers["x-reallylongheadernamethatcausesbodytowrap"] == "BodyOnNewLine"
end

test "parse header with folded encoded word" do
# This is seen in the examples in https://www.rfc-editor.org/rfc/rfc2047.html#section-8
message =
parse_email("""
X-Encoded-Word: =?utf-8?Q?h=CE=B5=C5=82=C5=82=C3=B8=20w=C3=B8?=
=?utf-8?Q?r=C5=82d?=
Body
""")

assert message.headers["x-encoded-word"] == "hεłłø wørłd"
end

test "allow empty body (RFC2822 §3.5)" do
message =
parse_email("""
Expand Down

0 comments on commit 5492610

Please sign in to comment.