]> Sergey Matveev's repositories - sgblog.git/blobdiff - cmd/sgblog-comment-add/mail.go
Do not omit errors
[sgblog.git] / cmd / sgblog-comment-add / mail.go
index 3ffc1e84ac83df06c6cf52445984ff4a8953b325..98ee1626b785a48012724230ccd1be0d10b672a6 100644 (file)
@@ -1,6 +1,6 @@
 /*
 SGBlog -- Git-backed CGI/UCSPI blogging/phlogging/gemlogging engine
-Copyright (C) 2020-2021 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2020-2023 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
@@ -21,8 +21,8 @@ import (
        "bytes"
        "encoding/base64"
        "errors"
+       "fmt"
        "io"
-       "io/ioutil"
        "mime"
        "mime/multipart"
        "mime/quotedprintable"
@@ -75,6 +75,10 @@ func parseEmail(msg *mail.Message) (subj string, body io.Reader, err error) {
                return
        }
        ct, params, err := mime.ParseMediaType(ct)
+       if err != nil {
+               err = fmt.Errorf("can not ParseMediaType: %w", err)
+               return
+       }
        if ct != "multipart/signed" {
                err = errors.New("only text/plain and multipart/signed+text/plain Content-Type supported")
                return
@@ -84,7 +88,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
        }
@@ -109,7 +113,11 @@ func parseEmail(msg *mail.Message) (subj string, body io.Reader, err error) {
                        return
                }
                if strings.HasPrefix(ct, "multipart/mixed") {
-                       ct, params, err = mime.ParseMediaType(ct)
+                       _, params, err = mime.ParseMediaType(ct)
+                       if err != nil {
+                               err = fmt.Errorf("can not ParseMediaType: %w", err)
+                               return
+                       }
                        boundary = params["boundary"]
                        if len(boundary) == 0 {
                                err = errors.New("no boundary string")