]> Sergey Matveev's repositories - sgblog.git/blobdiff - cmd/sgblog-comment-add/mail.go
io/ioutil is deprecated since Go 1.16
[sgblog.git] / cmd / sgblog-comment-add / mail.go
index 1a347fcb5cdfa07cd85f130494e15dde00809e91..6d1aa5452eb0a9c8a99bcd9c141db4c6218096a8 100644 (file)
@@ -1,6 +1,6 @@
 /*
-SGBlog -- Git-based CGI blogging engine
-Copyright (C) 2020 Sergey Matveev <stargrave@stargrave.org>
+SGBlog -- Git-backed CGI/UCSPI blogging/phlogging/gemlogging engine
+Copyright (C) 2020-2022 Sergey Matveev <stargrave@stargrave.org>
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU Affero General Public License as
@@ -22,7 +22,6 @@ import (
        "encoding/base64"
        "errors"
        "io"
-       "io/ioutil"
        "mime"
        "mime/multipart"
        "mime/quotedprintable"
@@ -62,18 +61,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"
@@ -92,7 +83,7 @@ func parseEmail(msg *mail.Message) (subj string, body io.Reader, err error) {
                err = errors.New("no boundary string")
                return
        }
-       data, err := ioutil.ReadAll(msg.Body)
+       data, err := io.ReadAll(msg.Body)
        if err != nil {
                return
        }