From: Sergey Matveev Date: Wed, 20 May 2020 08:37:50 +0000 (+0300) Subject: Simplify RFC 2047 decoding X-Git-Tag: v0.6.0~2 X-Git-Url: http://www.git.stargrave.org/?p=sgblog.git;a=commitdiff_plain;h=9188303ab732c6b370fea39c21f4552422035806 Simplify RFC 2047 decoding --- diff --git a/cmd/sgblog-comment-add/mail.go b/cmd/sgblog-comment-add/mail.go index 88d95d8..ccb35da 100644 --- a/cmd/sgblog-comment-add/mail.go +++ b/cmd/sgblog-comment-add/mail.go @@ -62,18 +62,10 @@ func parseEmail(msg *mail.Message) (subj string, body io.Reader, err error) { err = errors.New("no Subject") return } - words := strings.Fields(subj) - for i, word := range words { - if strings.HasPrefix(word, "=?") && strings.HasSuffix(word, "?=") { - word, err = new(mime.WordDecoder).Decode(word) - if err != nil { - return - } - words[i] = word - } + subj, err = new(mime.WordDecoder).DecodeHeader(subj) + if err != nil { + return } - subj = strings.Join(words, " ") - ct := msg.Header.Get(CT) if ct == "" { ct = "text/plain"