aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2024-06-28 22:49:58 +0200
committerRobin Jarry <robin@jarry.cc>2024-06-29 21:21:27 +0200
commit0efcf2b3b08de22bcd5994a671c2b276db3488eb (patch)
tree4a21074ac6826c4edfb2208cfb7dbbfbad0411b1 /lib
parent446d5303b9c7e7100261fe444bf42319e25e228e (diff)
downloadaerc-0efcf2b3b08de22bcd5994a671c2b276db3488eb.tar.gz
rfc822: properly parse address lists
h.Text() parses blobs of encoded text without taking into account specific handling for email addresses. h.AddressList(key) uses mail.ParseAddressList(h.Get(key)) already deals with charsets and quoted-printable stuff. Pass it the raw header value. In some cases, mail.ParseAddressList will return a list of addresses *and* an UnknownCharset error. In this specific case, ignore the error. Fixes: https://todo.sr.ht/~rjarry/aerc/257 Reported-by: Inwit <inwit@sindominio.net> Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Inwit <inwit@sindominio.net> Reviewed-by: Tristan Partin <tristan@partin.io>
Diffstat (limited to 'lib')
-rw-r--r--lib/rfc822/message.go17
1 files changed, 7 insertions, 10 deletions
diff --git a/lib/rfc822/message.go b/lib/rfc822/message.go
index f511ea19..391ab3e5 100644
--- a/lib/rfc822/message.go
+++ b/lib/rfc822/message.go
@@ -277,18 +277,15 @@ func parseReceivedHeader(h *mail.Header) (time.Time, error) {
}
func parseAddressList(h *mail.Header, key string) ([]*mail.Address, error) {
- hdr, err := h.Text(key)
- if err != nil && !message.IsUnknownCharset(err) {
+ addrs, err := h.AddressList(key)
+ if len(addrs) == 0 {
+ // Only consider the error if the returned address list is empty
+ // Sometimes, we get a list of addresses and unknown charset
+ // errors which are not fatal.
return nil, err
}
- if hdr == "" {
- return nil, nil
- }
- add, err := mail.ParseAddressList(hdr)
- if err != nil {
- return []*mail.Address{{Name: hdr}}, nil
- }
- return add, err
+ // If we got at least one address, ignore any returned error.
+ return addrs, nil
}
// RawMessage is an interface that describes a raw message