diff --git a/mail/mailer.go b/mail/mailer.go index e34042878..43fafeb24 100644 --- a/mail/mailer.go +++ b/mail/mailer.go @@ -17,6 +17,7 @@ import ( "strconv" "strings" "time" + "unicode" "github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/jmhodges/clock" ) @@ -52,6 +53,15 @@ type MailerImpl struct { csprgSource idGenerator } +func isASCII(str string) bool { + for _, r := range str { + if r > unicode.MaxASCII { + return false + } + } + return true +} + // New constructs a Mailer to represent an account on a particular mail // transfer agent. func New(server, port, username, password string) MailerImpl { @@ -71,6 +81,9 @@ func (m *MailerImpl) generateMessage(to []string, subject, body string) ([]byte, now := m.clk.Now().UTC() addrs := []string{} for _, a := range to { + if !isASCII(a) { + return nil, fmt.Errorf("Non-ASCII email address") + } addrs = append(addrs, strconv.Quote(a)) } headers := []string{ diff --git a/mail/mailer_test.go b/mail/mailer_test.go index 2b09d7c3e..a0bc2226b 100644 --- a/mail/mailer_test.go +++ b/mail/mailer_test.go @@ -42,3 +42,10 @@ func TestGenerateMessage(t *testing.T) { test.AssertEquals(t, fields[8], "") test.AssertEquals(t, fields[9], "this is the body") } + +func TestFailNonASCIIAddress(t *testing.T) { + fc := clock.NewFake() + m := MailerImpl{From: "send@email.com", clk: fc, csprgSource: fakeSource{}} + _, err := m.generateMessage([]string{"遗憾@email.com"}, "test subject", "this is the body\n") + test.AssertError(t, err, "Allowed a non-ASCII to address incorrectly") +}