fix(mail): propagate io.ReadAll errors when parsing parts
This commit is contained in:
@@ -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,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user