From c96903f3f1e0ed365b0ff4d56e4c423b4a7902e5 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Tue, 25 Feb 2020 16:38:29 +0100 Subject: [PATCH] plugins/base: replace MessageRenderData.PartPath with Part --- plugins/base/imap.go | 27 +++++++++++++++++++++++++++ plugins/base/public/message.html | 20 ++++++++++---------- plugins/base/routes.go | 8 ++++---- themes/sourcehut/message.html | 20 ++++++++++---------- 4 files changed, 51 insertions(+), 24 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 diff --git a/plugins/base/public/message.html b/plugins/base/public/message.html index 5457627..f019acf 100644 --- a/plugins/base/public/message.html +++ b/plugins/base/public/message.html @@ -16,7 +16,7 @@ {{end}} -
+
-
+
{{if .Flags}} -
+

Flags:

{{range $name, $has := .Flags}} {{if ismutableflag $name}} @@ -85,14 +85,14 @@ {{with index . 1}} - {{if eq $.PartPath .PathString}}{{end}} + {{if eq $.Part.PathString .PathString}}{{end}} {{.String}} - {{if eq $.PartPath .PathString}}{{end}} + {{if eq $.Part.PathString .PathString}}{{end}} {{if .Children}}