~sircmpwn/aerc

worker/lib/parse: decode address headers v1 PROPOSED

Reto Brunner: 1
 worker/lib/parse: decode address headers

 1 files changed, 7 insertions(+), 1 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/aerc/patches/7401/mbox | git am -3
Learn more about email & git

[PATCH] worker/lib/parse: decode address headers Export this patch

from,cc,bcc etc are sometimes send encoded in an uncommon charset.
We first need to decode the header before we try to parse it.
---
Emmersions mail.Header.AddressList doesn't decode, it assumes things to be
utf8.

The function isn't complicated however so we can simply manually do the exercise

 worker/lib/parse.go | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/worker/lib/parse.go b/worker/lib/parse.go
index 9f9fa62..9e3b877 100644
--- a/worker/lib/parse.go
+++ b/worker/lib/parse.go
@@ -8,6 +8,8 @@ import (
	"mime/quotedprintable"
	"strings"

	gomail "net/mail"

	"git.sr.ht/~sircmpwn/aerc/models"
	"github.com/emersion/go-message"
	_ "github.com/emersion/go-message/charset"
@@ -171,7 +173,11 @@ func parseEnvelope(h *mail.Header) (*models.Envelope, error) {

func parseAddressList(h *mail.Header, key string) ([]*models.Address, error) {
	var converted []*models.Address
	addrs, err := h.AddressList(key)
	decoded, err := h.Text(key)
	if err != nil || decoded == "" {
		return nil, err
	}
	addrs, err := gomail.ParseAddressList(decoded)
	if err != nil {
		if hdr, err := h.Text(key); err != nil && strings.Index(hdr, "@") < 0 {
			return []*models.Address{&models.Address{
-- 
2.22.0
I think this might be better solved in go-message rather than in aerc.
View this thread in the archives