mirror of
https://github.com/mjl-/mox.git
synced 2025-07-10 06:34:40 +03:00
recognize more charsets than utf-8/iso-8859-1/us-ascii when parsing message headers with address
as they occur in From/To headers, for example: "From: =?iso-8859-2?Q?Krist=FDna?= <k@example.com>". we are using net/mail to parse such headers. most address-parsing functions in that package will only decode charsets utf-8, iso-8859-1 and us-ascii. we have to be careful to always use net/mail.AddressParser with a WordDecoder that understands more that the basics. for issue #204 by morki, thanks for reporting!
This commit is contained in:
@ -517,13 +517,14 @@ type File struct {
|
||||
// parseAddress expects either a plain email address like "user@domain", or a
|
||||
// single address as used in a message header, like "name <user@domain>".
|
||||
func parseAddress(msghdr string) (message.NameAddress, error) {
|
||||
a, err := mail.ParseAddress(msghdr)
|
||||
// todo: parse more fully according to ../rfc/5322:959
|
||||
parser := mail.AddressParser{WordDecoder: &wordDecoder}
|
||||
a, err := parser.Parse(msghdr)
|
||||
if err != nil {
|
||||
return message.NameAddress{}, err
|
||||
}
|
||||
|
||||
// todo: parse more fully according to ../rfc/5322:959
|
||||
path, err := smtp.ParseAddress(a.Address)
|
||||
path, err := smtp.ParseNetMailAddress(a.Address)
|
||||
if err != nil {
|
||||
return message.NameAddress{}, err
|
||||
}
|
||||
@ -1658,12 +1659,12 @@ func recipientSecurity(ctx context.Context, log mlog.Log, resolver dns.Resolver,
|
||||
SecurityResultUnknown,
|
||||
}
|
||||
|
||||
msgAddr, err := mail.ParseAddress(messageAddressee)
|
||||
parser := mail.AddressParser{WordDecoder: &wordDecoder}
|
||||
msgAddr, err := parser.Parse(messageAddressee)
|
||||
if err != nil {
|
||||
return rs, fmt.Errorf("parsing message addressee: %v", err)
|
||||
return rs, fmt.Errorf("parsing addressee: %v", err)
|
||||
}
|
||||
|
||||
addr, err := smtp.ParseAddress(msgAddr.Address)
|
||||
addr, err := smtp.ParseNetMailAddress(msgAddr.Address)
|
||||
if err != nil {
|
||||
return rs, fmt.Errorf("parsing address: %v", err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user