emersion / go-message

✉️ A streaming Go library for the Internet Message Format and mail messages
MIT License
373 stars 108 forks source link

header.AddressList does not decode header Name #133

Closed ahmedkhalf closed 3 years ago

ahmedkhalf commented 3 years ago

Here is the name of the email I am trying to decode: ♟Chess.com My code:

r := msg.GetBody(section) // go-imap
mr, err := mail.CreateReader(r)
header := mr.Header
if from, err := header.AddressList("From"); err == nil {
        log.Println("From:", from)
}

output:

2021/03/15 15:08:53 From: ["=?utf-8?q?=E2=99=9F?=Chess.com" <alert@chess.com>]

I tried use from.Name as suggested here (https://github.com/emersion/go-message/issues/132#issuecomment-788762616). But still doesn't work: (https://github.com/emersion/go-message/issues/132#issuecomment-799321271)

emersion commented 3 years ago

What is the raw header value?

header.Get("From")
ahmedkhalf commented 3 years ago

log.Println(header.Get("From")) 2021/03/15 15:15:59 "=?utf-8?q?=E2=99=9F?=Chess.com" <alert@chess.com>

emersion commented 3 years ago

The name is quoted. UTF-8 escaping can't happen inside of quoted strings. The original header is broken.

ahmedkhalf commented 3 years ago

But what do I do now? This is comes from outlook.. Is there any other alternative in go-imap to fetch the name?

emersion commented 3 years ago

Outlook well known for correctly implementing RFCs as always…

If you really want to work around the issue you can pass the value through textproto.WordDecoder again. This isn't a patch I'd accept upstream though.