fix parsing message headers with addresses that need double quotes

we are using Go's net/mail to parse message headers. it can parse addresses,
and properly decodes email addresses with double quotes (e.g. " "@example.com).
however, it gives us an address without the double quotes in the localpart,
effectively an invalid address. we now have a workaround to parse such
not-quite-addresses.

for issue #199 reported by gene-hightower, thanks for reporting!
This commit is contained in:
Mechiel Lukkien
2024-08-22 16:03:52 +02:00
parent 79b641cdc6
commit 016fde8d78
4 changed files with 29 additions and 3 deletions

View File

@ -596,3 +596,10 @@ func TestEmbedded2(t *testing.T) {
_, err = EnsurePart(pkglog.Logger, false, bytes.NewReader(buf), int64(len(buf)))
tfail(t, err, nil)
}
func TestNetMailAddress(t *testing.T) {
const s = "From: \" \"@example.com\r\n\r\nbody\r\n"
p, err := EnsurePart(pkglog.Logger, false, strings.NewReader(s), int64(len(s)))
tcheck(t, err, "parse")
tcompare(t, p.Envelope.From, []Address{{"", `" "`, "example.com"}})
}