From 8589228c73a8abb5de890bfbd3fa8ab2807dfda0 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 20 May 2020 16:25:25 +0200 Subject: [PATCH] Replace IMAPMessage.TextPartName with TextPart --- plugins/base/imap.go | 39 +++++++++++++------------------- plugins/base/public/mailbox.html | 2 +- themes/alps/mailbox.html | 2 +- themes/alps/message.html | 6 ++--- themes/sourcehut/mailbox.html | 2 +- 5 files changed, 22 insertions(+), 29 deletions(-) diff --git a/plugins/base/imap.go b/plugins/base/imap.go index 06e6e20..04ce8d7 100755 --- a/plugins/base/imap.go +++ b/plugins/base/imap.go @@ -158,12 +158,22 @@ func (msg *IMAPMessage) URL() *url.URL { } } -func (msg *IMAPMessage) TextPartName() string { +func newIMAPPartNode(msg *IMAPMessage, path []int, part *imap.BodyStructure) *IMAPPartNode { + filename, _ := part.Filename() + return &IMAPPartNode{ + Path: path, + MIMEType: strings.ToLower(part.MIMEType + "/" + part.MIMESubType), + Filename: filename, + Message: msg, + } +} + +func (msg *IMAPMessage) TextPart() *IMAPPartNode { if msg.BodyStructure == nil { - return "" + return nil } - var best []int + var best *IMAPPartNode isTextPlain := false msg.BodyStructure.Walk(func(path []int, part *imap.BodyStructure) bool { if !strings.EqualFold(part.MIMEType, "text") { @@ -176,33 +186,16 @@ func (msg *IMAPMessage) TextPartName() string { switch strings.ToLower(part.MIMESubType) { case "plain": isTextPlain = true - best = path + best = newIMAPPartNode(msg, path, part) case "html": if !isTextPlain { - best = path + best = newIMAPPartNode(msg, path, part) } } return true }) - if best == nil { - return "" - } - l := make([]string, len(best)) - for i, partNum := range best { - l[i] = strconv.Itoa(partNum) - } - return strings.Join(l, ".") -} - -func newIMAPPartNode(msg *IMAPMessage, path []int, part *imap.BodyStructure) *IMAPPartNode { - filename, _ := part.Filename() - return &IMAPPartNode{ - Path: path, - MIMEType: strings.ToLower(part.MIMEType + "/" + part.MIMESubType), - Filename: filename, - Message: msg, - } + return best } func (msg *IMAPMessage) Attachments() []IMAPPartNode { diff --git a/plugins/base/public/mailbox.html b/plugins/base/public/mailbox.html index 45729d1..ff2e3a9 100644 --- a/plugins/base/public/mailbox.html +++ b/plugins/base/public/mailbox.html @@ -27,7 +27,7 @@