Disallow non-ASCII addresses
This commit is contained in:
parent
aa94f07081
commit
4e569184d5
|
@ -17,6 +17,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
"unicode"
|
||||||
|
|
||||||
"github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/jmhodges/clock"
|
"github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/jmhodges/clock"
|
||||||
)
|
)
|
||||||
|
@ -52,6 +53,15 @@ type MailerImpl struct {
|
||||||
csprgSource idGenerator
|
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
|
// New constructs a Mailer to represent an account on a particular mail
|
||||||
// transfer agent.
|
// transfer agent.
|
||||||
func New(server, port, username, password string) MailerImpl {
|
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()
|
now := m.clk.Now().UTC()
|
||||||
addrs := []string{}
|
addrs := []string{}
|
||||||
for _, a := range to {
|
for _, a := range to {
|
||||||
|
if !isASCII(a) {
|
||||||
|
return nil, fmt.Errorf("Non-ASCII email address")
|
||||||
|
}
|
||||||
addrs = append(addrs, strconv.Quote(a))
|
addrs = append(addrs, strconv.Quote(a))
|
||||||
}
|
}
|
||||||
headers := []string{
|
headers := []string{
|
||||||
|
|
|
@ -42,3 +42,10 @@ func TestGenerateMessage(t *testing.T) {
|
||||||
test.AssertEquals(t, fields[8], "")
|
test.AssertEquals(t, fields[8], "")
|
||||||
test.AssertEquals(t, fields[9], "this is the body")
|
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")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue