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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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