Skip to content

Commit

Permalink
Fix SA1019: "io/ioutil" has been deprecated since Go 1.19 in favour o…
Browse files Browse the repository at this point in the history
…f "io"
  • Loading branch information
mnako committed Sep 22, 2024
1 parent c3f63c9 commit 4ce9c4d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
15 changes: 7 additions & 8 deletions decoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/base64"
"fmt"
"io"
"io/ioutil"
"mime"
"mime/multipart"
"mime/quotedprintable"
Expand Down Expand Up @@ -47,7 +46,7 @@ func decodeContent(
cte ContentTransferEncoding,
) (io.Reader, error) {
var contentReader io.Reader
contentBytes, err := ioutil.ReadAll(content)
contentBytes, err := io.ReadAll(content)
if err != nil && err != io.ErrUnexpectedEOF {
return nil, fmt.Errorf(
"letters.decoders.decodeContent: cannot decode content: %w",
Expand All @@ -57,10 +56,10 @@ func decodeContent(
switch cte {
case cteBase64:
decoded := base64.NewDecoder(base64.StdEncoding, bytes.NewReader(contentBytes))
b, err := ioutil.ReadAll(decoded)
b, err := io.ReadAll(decoded)
if err == io.ErrUnexpectedEOF {
decoded = base64.NewDecoder(base64.RawStdEncoding, bytes.NewReader(contentBytes))
b, err = ioutil.ReadAll(decoded)
b, err = io.ReadAll(decoded)
if err != nil {
return nil, fmt.Errorf(
"letters.decoders.decodeContent: cannot decode raw-std-base64-encoded content: %w",
Expand All @@ -74,7 +73,7 @@ func decodeContent(
contentReader = bytes.NewReader(b)
case cteQuotedPrintable:
decoded := quotedprintable.NewReader(bytes.NewReader(contentBytes))
b, err := ioutil.ReadAll(decoded)
b, err := io.ReadAll(decoded)
if err != nil {
return nil, fmt.Errorf(
"letters.decoders.decodeContent: cannot decode quoted-printable-encoded content: %w",
Expand Down Expand Up @@ -113,7 +112,7 @@ func decodeInlineFile(part *multipart.Part, cte ContentTransferEncoding) (Inline
}

ifl.ContentID = strings.Trim(cid, "<>")
ifl.Data, err = ioutil.ReadAll(decoded)
ifl.Data, err = io.ReadAll(decoded)
if err != nil {
return ifl, fmt.Errorf(
"letters.decoders.decodeInlineFile: cannot read inline attachment data: %w",
Expand Down Expand Up @@ -149,7 +148,7 @@ func decodeAttachmentFileFromBody(body io.Reader, headers Headers, cte ContentTr

afl.ContentType = headers.ContentType
afl.ContentDisposition = headers.ContentDisposition
afl.Data, err = ioutil.ReadAll(decoded)
afl.Data, err = io.ReadAll(decoded)
if err != nil {
return afl, fmt.Errorf(
"letters.decoders.decodeAttachmentFileFromBody: cannot read attached file data: %w",
Expand Down Expand Up @@ -183,7 +182,7 @@ func decodeAttachedFileFromPart(part *multipart.Part, cte ContentTransferEncodin
err)
}

afl.Data, err = ioutil.ReadAll(decoded)
afl.Data, err = io.ReadAll(decoded)
if err != nil {
return afl, fmt.Errorf(
"letters.decoders.decodeAttachedFileFromPart: cannot read attached file data: %w",
Expand Down
3 changes: 1 addition & 2 deletions parsers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package letters
import (
"fmt"
"io"
"io/ioutil"
"mime"
"mime/multipart"
"net/mail"
Expand Down Expand Up @@ -358,7 +357,7 @@ func parseText(t io.Reader, e encoding.Encoding, cte ContentTransferEncoding) (s
err)
}

textBody, err := ioutil.ReadAll(reader)
textBody, err := io.ReadAll(reader)
if err != nil {
return "", fmt.Errorf(
"letters.parsers.parseText: cannot read plain text content: %w",
Expand Down

0 comments on commit 4ce9c4d

Please sign in to comment.