Skip to content

Commit

Permalink
jordan-wright#147 Proper handling of utf-8 characters in reply-to hea…
Browse files Browse the repository at this point in the history
…ders
  • Loading branch information
Tarmo Randma committed Aug 16, 2021
1 parent 943e75f commit 7c4c797
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
build:
name: Build
runs-on: ubuntu-latest
env:
GO111MODULE: auto
steps:

- name: Set up Go 1.x
Expand Down
2 changes: 1 addition & 1 deletion email.go
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ func headerToBytes(buff io.Writer, header textproto.MIMEHeader) {
switch {
case field == "Content-Type" || field == "Content-Disposition":
buff.Write([]byte(subval))
case field == "From" || field == "To" || field == "Cc" || field == "Bcc":
case field == "From" || field == "To" || field == "Cc" || field == "Bcc" || field == "Reply-To":
participants := strings.Split(subval, ",")
for i, v := range participants {
addr, err := mail.ParseAddress(v)
Expand Down
10 changes: 10 additions & 0 deletions email_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,11 @@ func TestHeaderEncoding(t *testing.T) {
have: "Needs Encóding <encoding@example.com>, Only ASCII <foo@example.com>",
want: "=?utf-8?q?Needs_Enc=C3=B3ding?= <encoding@example.com>, \"Only ASCII\" <foo@example.com>\r\n",
},
{
field: "Reply-To",
have: "Needs Encóding <encoding@example.com>, Only ASCII <foo@example.com>",
want: "=?utf-8?q?Needs_Enc=C3=B3ding?= <encoding@example.com>, \"Only ASCII\" <foo@example.com>\r\n",
},
{
field: "To",
have: "Keith Moore <moore@cs.utk.edu>, Keld Jørn Simonsen <keld@dkuug.dk>",
Expand Down Expand Up @@ -523,6 +528,7 @@ func TestNonAsciiEmailFromReader(t *testing.T) {
ex := &Email{
Subject: "Test Subject",
To: []string{"Anaïs <anais@example.org>"},
ReplyTo: []string{"Anaïs <anais@example.org>"},
Cc: []string{"Patrik Fältström <paf@example.com>"},
From: "Mrs Valérie Dupont <valerie.dupont@example.com>",
Text: []byte("This is a test message!"),
Expand All @@ -532,6 +538,7 @@ func TestNonAsciiEmailFromReader(t *testing.T) {
Subject: =?UTF-8?Q?Test Subject?=
From: Mrs =?ISO-8859-1?Q?Val=C3=A9rie=20Dupont?= <valerie.dupont@example.com>
To: =?utf-8?q?Ana=C3=AFs?= <anais@example.org>
Reply-To: =?utf-8?q?Ana=C3=AFs?= <anais@example.org>
Cc: =?ISO-8859-1?Q?Patrik_F=E4ltstr=F6m?= <paf@example.com>
Content-type: text/plain; charset=ISO-8859-1
Expand All @@ -549,6 +556,9 @@ This is a test message!`)
if e.To[0] != ex.To[0] {
t.Fatalf("Incorrect \"To\": %#q != %#q", e.To, ex.To)
}
if e.ReplyTo[0] != ex.ReplyTo[0] {
t.Fatalf("Incorrect \"Reply-To\": %#q != %#q", e.ReplyTo, ex.ReplyTo)
}
if e.Cc[0] != ex.Cc[0] {
t.Fatalf("Incorrect \"Cc\": %#q != %#q", e.Cc, ex.Cc)
}
Expand Down

0 comments on commit 7c4c797

Please sign in to comment.