From c96903f3f1e0ed365b0ff4d56e4c423b4a7902e5 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Tue, 25 Feb 2020 16:38:29 +0100 Subject: plugins/base: replace MessageRenderData.PartPath with Part --- plugins/base/imap.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'plugins/base/imap.go') 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 -- cgit v1.2.3-59-g8ed1b