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:
Mechiel Lukkien
2024-08-22 17:36:49 +02:00
parent 0bb4501472
commit 5678b03324
6 changed files with 64 additions and 15 deletions

View File

@ -9,7 +9,6 @@ import (
"io"
"log"
"net"
"net/mail"
"os"
"path/filepath"
"slices"
@ -19,6 +18,7 @@ import (
"github.com/mjl-/sconf"
"github.com/mjl-/mox/dns"
"github.com/mjl-/mox/message"
"github.com/mjl-/mox/mox-"
"github.com/mjl-/mox/sasl"
"github.com/mjl-/mox/smtp"
@ -196,16 +196,12 @@ binary should be setgid that group:
}
recipient = submitconf.DefaultDestination
} else {
addrs, err := mail.ParseAddressList(s)
addrs, err := message.ParseAddressList(s)
xcheckf(err, "parsing To address list")
if len(addrs) != 1 {
log.Fatalf("only single address allowed in To header")
}
addr, err := smtp.ParseNetMailAddress(addrs[0].Address)
if err != nil {
log.Fatalf("parsing address: %v", err)
}
recipient = addr.Pack(false)
recipient = addrs[0].User + "@" + addrs[0].Host
}
}
if k == "to" {