~migadu/alps-devel

base: select first text part as the best one v1 NEEDS REVISION

Matthieu Rakotojaona: 1
 base: select first text part as the best one

 1 files changed, 5 insertions(+), 1 deletions(-)
Simon Ser <contact@emersion.fr> wrote:
Next
I don't think this can work with the way we render HTML vs plaintext.
I'd rather avoid multipart/mixed rendering for now.
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~migadu/alps-devel/patches/47973/mbox | git am -3
Learn more about email & git

[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.