-
Notifications
You must be signed in to change notification settings - Fork 322
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Format From, To, Cc & Bcc for RFC1342 (#115)
* Format From, To, Cc & Bcc for RFC1342 * Fixed seperator & added tests
- Loading branch information
Showing
3 changed files
with
62 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,6 @@ _cgo_export.* | |
_testmain.go | ||
|
||
*.exe | ||
|
||
# IDEs | ||
.idea |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package email | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
|
@@ -317,6 +318,52 @@ func TestEmailAttachment(t *testing.T) { | |
} | ||
} | ||
|
||
func TestHeaderEncoding(t *testing.T) { | ||
cases := []struct { | ||
field string | ||
have string | ||
want string | ||
}{ | ||
{ | ||
field: "From", | ||
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]>", | ||
want: "Keith Moore <[email protected]>, =?UTF-8?q?Keld_J=C3=B8rn_Simonsen?= <[email protected]>\r\n", | ||
}, | ||
{ | ||
field: "Cc", | ||
have: "Needs Encóding <[email protected]>", | ||
want: "=?UTF-8?q?Needs_Enc=C3=B3ding?= <[email protected]>\r\n", | ||
}, | ||
{ | ||
field: "Subject", | ||
have: "Subject with a 🐟", | ||
want: "=?UTF-8?q?Subject_with_a_=F0=9F=90=9F?=\r\n", | ||
}, | ||
{ | ||
field: "Subject", | ||
have: "Subject with only ASCII", | ||
want: "Subject with only ASCII\r\n", | ||
}, | ||
} | ||
buff := &bytes.Buffer{} | ||
for _, c := range cases { | ||
header := make(textproto.MIMEHeader) | ||
header.Add(c.field, c.have) | ||
buff.Reset() | ||
headerToBytes(buff, header) | ||
want := fmt.Sprintf("%s: %s", c.field, c.want) | ||
got := buff.String() | ||
if got != want { | ||
t.Errorf("invalid utf-8 header encoding. \nwant:%#v\ngot: %#v", want, got) | ||
} | ||
} | ||
} | ||
|
||
func TestEmailFromReader(t *testing.T) { | ||
ex := &Email{ | ||
Subject: "Test Subject", | ||
|