From 9188303ab732c6b370fea39c21f4552422035806 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Wed, 20 May 2020 11:37:50 +0300 Subject: [PATCH] Simplify RFC 2047 decoding --- cmd/sgblog-comment-add/mail.go | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) 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" -- 2.48.1