Skip to content

Commit

Permalink
rfc822: properly parse address lists
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Robin Jarry <[email protected]>
Tested-by: Inwit <[email protected]>
Reviewed-by: Tristan Partin <[email protected]>
  • Loading branch information
rjarry committed Jun 29, 2024
1 parent 446d530 commit 0efcf2b
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions lib/rfc822/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0efcf2b

Please sign in to comment.