diff options
author | Simon Ser <contact@emersion.fr> | 2020-02-25 16:38:29 +0100 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2020-02-25 16:38:29 +0100 |
commit | c96903f3f1e0ed365b0ff4d56e4c423b4a7902e5 (patch) | |
tree | 2e2e6905769cc72d0077127d0b6894d347aca0f7 /plugins/base/imap.go | |
parent | b3f98de1da11e13dea5c08af4f80520258c120cf (diff) | |
download | alps-c96903f3f1e0ed365b0ff4d56e4c423b4a7902e5.tar.gz alps-c96903f3f1e0ed365b0ff4d56e4c423b4a7902e5.zip |
plugins/base: replace MessageRenderData.PartPath with Part
Diffstat (limited to 'plugins/base/imap.go')
-rwxr-xr-x | plugins/base/imap.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/plugins/base/imap.go b/plugins/base/imap.go index eadb098..177fefc 100755 --- a/plugins/base/imap.go +++ b/plugins/base/imap.go @@ -180,6 +180,33 @@ func (msg *IMAPMessage) Attachments() []IMAPPartNode { return attachments } +func pathsEqual(a, b []int) bool { + if len(a) != len(b) { + return false + } + for i := range a { + if a[i] != b[i] { + return false + } + } + return true +} + +func (msg *IMAPMessage) PartByPath(path []int) *IMAPPartNode { + if msg.BodyStructure == nil { + return nil + } + + var result *IMAPPartNode + msg.BodyStructure.Walk(func(p []int, part *imap.BodyStructure) bool { + if result == nil && pathsEqual(path, p) { + result = newIMAPPartNode(msg, p, part) + } + return result == nil + }) + return result +} + func (msg *IMAPMessage) PartByID(id string) *IMAPPartNode { if msg.BodyStructure == nil || id == "" { return nil |