[PATCH] base: select first text part as the best one
Export this patch
As soon as we have found a "best" part to display, stop recursing into
the whole bodystructure
---
plugins/base/imap.go | 6 +++++ -
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/plugins/base/imap.go b/plugins/base/imap.go
index e9636e3..2e85287 100644
--- a/plugins/base/imap.go
+++ b/plugins/base/imap.go
@@ -211,6 +211,10 @@ func (msg *IMAPMessage) TextPart() *IMAPPartNode {
var best *IMAPPartNode
isTextPlain := false
msg.BodyStructure.Walk(func(path []int, part imap.BodyStructure) bool {
+ if best != nil {
+ return false
+ }
+
singlePart, ok := part.(*imap.BodyStructureSinglePart)
if !ok {
return true
@@ -232,7 +236,7 @@ func (msg *IMAPMessage) TextPart() *IMAPPartNode {
best = newIMAPPartNode(msg, path, singlePart)
}
}
- return true
+ return best == nil
})
return best
--
2.43.0
Hm, but with this we'd stop iterating at the first text/html part even
if there is a text/plain part after…
We probably want to add isTextPlain to the check as well.