aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/base/imap.go
diff options
context:
space:
mode:
authorLibravatarLibravatar Simon Ser <[email protected]> 2020-01-28 12:30:07 +0100
committerLibravatarLibravatar Simon Ser <[email protected]> 2020-01-28 12:30:07 +0100
commit85c01b87a99233fcc273e810b4ad48bb0d33096f (patch)
tree18c2bf279602f684db34ae5a0180f1f6b07a94b0 /plugins/base/imap.go
parent50046b62ac61a985f82bfc22b4e7b39b334d030c (diff)
downloadalps-85c01b87a99233fcc273e810b4ad48bb0d33096f.tar.gz
alps-85c01b87a99233fcc273e810b4ad48bb0d33096f.tar.bz2
alps-85c01b87a99233fcc273e810b4ad48bb0d33096f.zip
plugins/base: support attachments in drafts
References: https://todo.sr.ht/~sircmpwn/koushin/16
Diffstat (limited to 'plugins/base/imap.go')
-rwxr-xr-xplugins/base/imap.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/plugins/base/imap.go b/plugins/base/imap.go
index 1b41265..0c36baa 100755
--- a/plugins/base/imap.go
+++ b/plugins/base/imap.go
@@ -144,6 +144,28 @@ func (msg *IMAPMessage) TextPartName() string {
return strings.Join(l, ".")
}
+func (msg *IMAPMessage) Attachments() []IMAPPartNode {
+ if msg.BodyStructure == nil {
+ return nil
+ }
+
+ var attachments []IMAPPartNode
+ msg.BodyStructure.Walk(func(path []int, part *imap.BodyStructure) bool {
+ if !strings.EqualFold(part.Disposition, "attachment") {
+ return true
+ }
+
+ filename, _ := part.Filename()
+ attachments = append(attachments, IMAPPartNode{
+ Path: path,
+ MIMEType: strings.ToLower(part.MIMEType + "/" + part.MIMESubType),
+ Filename: filename,
+ })
+ return true
+ })
+ return attachments
+}
+
type IMAPPartNode struct {
Path []int
MIMEType string