handle non-ascii subjects

This commit is contained in:
Alexander Weinhold 2017-08-15 16:58:04 +02:00
parent ca1e6261e9
commit e816fe2f60

View File

@ -84,6 +84,11 @@ func normalize(m []byte, encoding string) ([]byte, error) {
return s, err return s, err
} }
func decodeSubject(subject string) (string, error) {
dec := new(mime.WordDecoder)
return dec.DecodeHeader(subject)
}
func getPlainParts(mail *mail.Message) ([]string, []error) { func getPlainParts(mail *mail.Message) ([]string, []error) {
parts := make([]string, 0) parts := make([]string, 0)
errs := make([]error, 0) errs := make([]error, 0)
@ -156,7 +161,10 @@ func FetchPlaintext(p *Parameters) ([]string, []error) {
date := mail.Header.Get("Date") date := mail.Header.Get("Date")
from := mail.Header.Get("From") from := mail.Header.Get("From")
to := mail.Header.Get("To") 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")) 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) mailsPlain = append(mailsPlain, m)
} }