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

Format From, To, Cc & Bcc for RFC1342 #115

Merged
merged 2 commits into from
Jun 2, 2020
Merged

Format From, To, Cc & Bcc for RFC1342 #115

merged 2 commits into from
Jun 2, 2020

Conversation

Fank
Copy link
Contributor

@Fank Fank commented May 28, 2020

EMails needed to be formated like this:

   From: =?US-ASCII?Q?Keith_Moore?= <[email protected]>
   To: =?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= <[email protected]>
   CC: =?ISO-8859-1?Q?Andr=E9_?= Pirard <[email protected]>

Right now the complete content of the field will be encoded which results in

   From: =?US-ASCII?Q?Keith_Moore <[email protected]>?=
   To: =?ISO-8859-1?Q?Keld_J=F8rn_Simonsen <[email protected]>?=
   CC: =?ISO-8859-1?Q?Andr=E9_ Pirard <[email protected]>?= 

which causes following in mail clients:

unknown
image

https://tools.ietf.org/html/rfc1342

Copy link
Owner

@jordan-wright jordan-wright left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for sending this in! The only thing I'd recommend changing is the delimiter used to separate addresses as noted in the comments.

Additionally, could you please add a test to ensure the correct behavior is happening? Here's one that I came up with that seems to work, but please double-check it:

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: "Subject",
			have:  "Subject with a 🐟",
			want:  "=?UTF-8?q?Subject_with_a_=F0=9F=90=9F?=\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)
		}
	}
}

email.go Outdated Show resolved Hide resolved
email.go Outdated Show resolved Hide resolved
@Fank
Copy link
Contributor Author

Fank commented Jun 2, 2020

Added more tests to ensure everything works as intended

@jordan-wright
Copy link
Owner

This LGTM. Thanks @Fank!

@jordan-wright jordan-wright merged commit fd8a762 into jordan-wright:master Jun 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants