Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#147 Proper handling of utf-8 characters in reply-to headers #148

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 <[email protected]>, Only ASCII <[email protected]>",
want: "=?utf-8?q?Needs_Enc=C3=B3ding?= <[email protected]>, \"Only ASCII\" <[email protected]>\r\n",
},
{
field: "Reply-To",
have: "Needs Encóding <[email protected]>, Only ASCII <[email protected]>",
want: "=?utf-8?q?Needs_Enc=C3=B3ding?= <[email protected]>, \"Only ASCII\" <[email protected]>\r\n",
},
{
field: "To",
have: "Keith Moore <[email protected]>, Keld Jørn Simonsen <[email protected]>",
Expand Down Expand Up @@ -523,6 +528,7 @@ func TestNonAsciiEmailFromReader(t *testing.T) {
ex := &Email{
Subject: "Test Subject",
To: []string{"Anaïs <[email protected]>"},
ReplyTo: []string{"Anaïs <[email protected]>"},
Cc: []string{"Patrik Fältström <[email protected]>"},
From: "Mrs Valérie Dupont <[email protected]>",
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?= <[email protected]>
To: =?utf-8?q?Ana=C3=AFs?= <[email protected]>
Reply-To: =?utf-8?q?Ana=C3=AFs?= <[email protected]>
Cc: =?ISO-8859-1?Q?Patrik_F=E4ltstr=F6m?= <[email protected]>
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