-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update header parsing to decode encoded words after parsing the heade…
…r (RFC 2047)
- Loading branch information
1 parent
68ab800
commit f8a1565
Showing
2 changed files
with
163 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -939,6 +939,76 @@ defmodule Mail.Parsers.RFC2822Test do | |
assert message.headers["content-type"] == ["text/html", {"charset", "us-ascii"}] | ||
end | ||
|
||
test "parses encoded word cotaining 'special' characters RFC 2047§6.2" do | ||
message = | ||
parse_email(""" | ||
From: =?UTF-8?B?am9obi5kb2VAcmVkYWN0ZS4uLg==?= <[email protected]> | ||
""") | ||
|
||
assert message.headers["from"] == {"john.doe@redacte...", "[email protected]"} | ||
end | ||
|
||
test "correct handling of encoded words according to RFC 2047 (examples)" do | ||
message = | ||
parse_email(""" | ||
From: =?US-ASCII?Q?Keith_Moore?= <[email protected]> | ||
To: =?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= <[email protected]> | ||
CC: =?ISO-8859-1?Q?Andr=E9?= Pirard <[email protected]> | ||
Subject: =?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?= | ||
=?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?= | ||
""") | ||
|
||
assert message.headers["from"] == {"Keith Moore", "[email protected]"} | ||
assert message.headers["to"] == [{"Keld J\xF8rn Simonsen", "[email protected]"}] | ||
assert message.headers["cc"] == [{"Andr\xE9 Pirard", "[email protected]"}] | ||
assert message.headers["subject"] == "If you can read this you understand the example." | ||
|
||
message = | ||
parse_email(""" | ||
From: =?ISO-8859-1?Q?Olle_J=E4rnefors?= <[email protected]> | ||
To: [email protected], [email protected] | ||
Subject: Time for ISO 10646? | ||
""") | ||
|
||
assert message.headers["from"] == {"Olle J\xE4rnefors", "[email protected]"} | ||
assert message.headers["to"] == ["[email protected]", "[email protected]"] | ||
assert message.headers["subject"] == "Time for ISO 10646?" | ||
|
||
message = | ||
parse_email(""" | ||
To: Dave Crocker <[email protected]> | ||
Cc: [email protected], [email protected] | ||
From: =?ISO-8859-1?Q?Patrik_F=E4ltstr=F6m?= <[email protected]> | ||
Subject: Re: RFC-HDR care and feeding | ||
""") | ||
|
||
assert message.headers["from"] == {"Patrik F\xE4ltstr\xF6m", "[email protected]"} | ||
assert message.headers["to"] == [{"Dave Crocker", "[email protected]"}] | ||
assert message.headers["cc"] == ["[email protected]", "[email protected]"] | ||
assert message.headers["subject"] == "Re: RFC-HDR care and feeding" | ||
|
||
message = | ||
parse_email(""" | ||
From: Nathaniel Borenstein <[email protected]> | ||
(=?iso-8859-8?b?7eXs+SDv4SDp7Oj08A==?=) | ||
To: Greg Vaudreuil <[email protected]>, Ned Freed | ||
<[email protected]>, Keith Moore <[email protected]> | ||
Subject: Test of new header generator | ||
MIME-Version: 1.0 | ||
Content-type: text/plain; charset=ISO-8859-1 | ||
""") | ||
|
||
assert message.headers["from"] == {"Nathaniel Borenstein", "[email protected]"} | ||
|
||
assert message.headers["to"] == [ | ||
{"Greg Vaudreuil", "[email protected]"}, | ||
{"Ned Freed", "[email protected]"}, | ||
{"Keith Moore", "[email protected]"} | ||
] | ||
|
||
assert message.headers["subject"] == "Test of new header generator" | ||
end | ||
|
||
defp parse_email(email, opts \\ []), | ||
do: email |> convert_crlf |> Mail.Parsers.RFC2822.parse(opts) | ||
|
||
|