mirror of
https://github.com/mjl-/mox.git
synced 2025-07-12 18:24:35 +03:00
normalize localparts with unicode nfc when parsing
both when parsing our configs, and for incoming on smtp or in messages. so we properly compare things like é and e+accent as equal, and accept the different encodings of that same address.
This commit is contained in:
@ -6,6 +6,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/text/unicode/norm"
|
||||
|
||||
"github.com/mjl-/mox/dns"
|
||||
)
|
||||
|
||||
@ -17,6 +19,7 @@ var ErrBadAddress = errors.New("invalid email address")
|
||||
// Localpart is a decoded local part of an email address, before the "@".
|
||||
// For quoted strings, values do not hold the double quote or escaping backslashes.
|
||||
// An empty string can be a valid localpart.
|
||||
// Localparts are in Unicode NFC.
|
||||
type Localpart string
|
||||
|
||||
// String returns a packed representation of an address, with proper escaping/quoting, for use in SMTP.
|
||||
@ -268,7 +271,7 @@ func (p *parser) xlocalpart() Localpart {
|
||||
// ../rfc/5321:3486
|
||||
p.xerrorf("localpart longer than 64 octets")
|
||||
}
|
||||
return Localpart(s)
|
||||
return Localpart(norm.NFC.String(s))
|
||||
}
|
||||
|
||||
func (p *parser) xquotedString() string {
|
||||
|
Reference in New Issue
Block a user