Skip to content

Commit 1610034

Browse files
Alex Wieserandrewtimberlake
Alex Wieser
authored andcommitted
Add test for character encoding in address headers
1 parent a5e0628 commit 1610034

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

test/mail/message_test.exs

+18-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ defmodule Mail.MessageTest do
225225
assert %Mail.Message{headers: %{"subject" => ^subject}} = Mail.Parsers.RFC2822.parse(txt)
226226
end
227227

228-
test "UTF-8 in subject (quoted printable with spaces, RFC 2047§4.2 (2)" do
228+
test "UTF-8 in subject (quoted printable with spaces, RFC 2047§4.2 (2))" do
229229
subject = "test 😀 test"
230230

231231
mail =
@@ -234,6 +234,23 @@ defmodule Mail.MessageTest do
234234
assert %Mail.Message{headers: %{"subject" => ^subject}} = Mail.Parsers.RFC2822.parse(mail)
235235
end
236236

237+
test "UTF-8 in addresses" do
238+
from = {"Joachim Löw", "[email protected]"}
239+
to = {"Wolfgang Schüler", "[email protected]"}
240+
241+
txt =
242+
Mail.build()
243+
|> Mail.put_from(from)
244+
|> Mail.put_to(to)
245+
|> Mail.render()
246+
247+
encoded_from = ~s(From: =?UTF-8?Q?"#{Mail.Encoders.QuotedPrintable.encode(elem(from, 0))}"?= <#{elem(from, 1)}>)
248+
encoded_to = ~s(To: =?UTF-8?Q?"#{Mail.Encoders.QuotedPrintable.encode(elem(to, 0))}"?= <#{elem(to, 1)}>)
249+
250+
assert txt =~ encoded_from
251+
assert txt =~ encoded_to
252+
end
253+
237254
test "UTF-8 in other header" do
238255
file_name = "READMEüä.md"
239256

0 commit comments

Comments
 (0)