From e816fe2f60e9cf232c4a54c4457f92f5df4fe341 Mon Sep 17 00:00:00 2001 From: Alexander Weinhold Date: Tue, 15 Aug 2017 16:58:04 +0200 Subject: [PATCH] handle non-ascii subjects --- libUnreadMail.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libUnreadMail.go b/libUnreadMail.go index 63a6222..d551911 100644 --- a/libUnreadMail.go +++ b/libUnreadMail.go @@ -84,6 +84,11 @@ func normalize(m []byte, encoding string) ([]byte, error) { return s, err } +func decodeSubject(subject string) (string, error) { + dec := new(mime.WordDecoder) + return dec.DecodeHeader(subject) +} + func getPlainParts(mail *mail.Message) ([]string, []error) { parts := make([]string, 0) errs := make([]error, 0) @@ -156,7 +161,10 @@ func FetchPlaintext(p *Parameters) ([]string, []error) { date := mail.Header.Get("Date") from := mail.Header.Get("From") to := mail.Header.Get("To") - subject := mail.Header.Get("Subject") + subject, sErr := decodeSubject(mail.Header.Get("Subject")) + if sErr != nil { + errs = append(errs, sErr) + } m := fmt.Sprintf("Date: %s\nFrom: %s\nTo: %s\nSubject: %s\n\n%s", date, from, to, subject, strings.Join(parts, "\n\n")) mailsPlain = append(mailsPlain, m) }