attachment.go 560 B

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