fix(mail): propagate io.ReadAll errors when parsing parts

This commit is contained in:
2026-06-21 23:53:24 +01:00
parent d73aabca96
commit 7df0c95339
+9 -2
View File
@@ -3,6 +3,7 @@ package mail
import ( import (
"bytes" "bytes"
"fmt"
"io" "io"
"strings" "strings"
@@ -72,13 +73,19 @@ func ParseMessage(uid uint32, raw []byte) (Message, error) {
case *mail.InlineHeader: case *mail.InlineHeader:
ct, _, _ := hdr.ContentType() ct, _, _ := hdr.ContentType()
if strings.HasPrefix(ct, "text/plain") && m.BodyText == "" { if strings.HasPrefix(ct, "text/plain") && m.BodyText == "" {
b, _ := io.ReadAll(part.Body) b, err := io.ReadAll(part.Body)
if err != nil {
return Message{}, fmt.Errorf("read message part: %w", err)
}
m.BodyText = string(b) m.BodyText = string(b)
} }
case *mail.AttachmentHeader: case *mail.AttachmentHeader:
name, _ := hdr.Filename() name, _ := hdr.Filename()
ct, _, _ := hdr.ContentType() ct, _, _ := hdr.ContentType()
b, _ := io.ReadAll(part.Body) b, err := io.ReadAll(part.Body)
if err != nil {
return Message{}, fmt.Errorf("read message part: %w", err)
}
m.Attachments = append(m.Attachments, Attachment{ m.Attachments = append(m.Attachments, Attachment{
Name: name, Size: len(b), MIME: ct, Content: b, Name: name, Size: len(b), MIME: ct, Content: b,
}) })