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) }