fix(mail): propagate io.ReadAll errors when parsing parts
This commit is contained in:
@@ -3,6 +3,7 @@ package mail
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
@@ -72,13 +73,19 @@ func ParseMessage(uid uint32, raw []byte) (Message, error) {
|
||||
case *mail.InlineHeader:
|
||||
ct, _, _ := hdr.ContentType()
|
||||
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)
|
||||
}
|
||||
case *mail.AttachmentHeader:
|
||||
name, _ := hdr.Filename()
|
||||
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{
|
||||
Name: name, Size: len(b), MIME: ct, Content: b,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user