attachment.go

 1package message
 2
 3import (
 4	"slices"
 5	"strings"
 6)
 7
 8type Attachment struct {
 9	FilePath string
10	FileName string
11	MimeType string
12	Content  []byte
13}
14
15func (a Attachment) IsText() bool     { return strings.HasPrefix(a.MimeType, "text/") }
16func (a Attachment) IsImage() bool    { return strings.HasPrefix(a.MimeType, "image/") }
17func (a Attachment) IsMarkdown() bool { return a.MimeType == "text/markdown" }
18
19// ContainsTextAttachment returns true if any of the attachments is a text attachment.
20func ContainsTextAttachment(attachments []Attachment) bool {
21	return slices.ContainsFunc(attachments, func(a Attachment) bool {
22		return a.IsText()
23	})
24}