From 684ceed2cdc66b34f8dcae97c641778c7117bb66 Mon Sep 17 00:00:00 2001 From: Koni Marti Date: Wed, 28 Sep 2022 23:18:42 +0200 Subject: lib: parse address header fields to utf-8 When parsing address header fields, the field charset is automatically decoded to UTF-8. If the charset is unknown, use the raw field value. Fixes: https://todo.sr.ht/~rjarry/aerc/91 Signed-off-by: Koni Marti Tested-by: Tim Culverhouse --- worker/lib/parse.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'worker/lib/parse.go') diff --git a/worker/lib/parse.go b/worker/lib/parse.go index 3eaa2aef..616784c6 100644 --- a/worker/lib/parse.go +++ b/worker/lib/parse.go @@ -225,15 +225,18 @@ func parseReceivedHeader(h *mail.Header) (time.Time, error) { } func parseAddressList(h *mail.Header, key string) ([]*mail.Address, error) { - addrs, err := h.AddressList(key) - if err == nil { - return addrs, nil - } hdr, err := h.Text(key) - if err != nil { + if err != nil && !message.IsUnknownCharset(err) { return nil, err } - return []*mail.Address{{Name: hdr}}, nil + if hdr == "" { + return nil, nil + } + add, err := mail.ParseAddressList(hdr) + if err != nil { + return []*mail.Address{{Name: hdr}}, nil + } + return add, err } // RawMessage is an interface that describes a raw message -- cgit