~sircmpwn/aerc

aerc: Added nil checks before reading header. v1 PROPOSED

Michael Clancy: 1
 Added nil checks before reading header.

 1 files changed, 8 insertions(+), 2 deletions(-)
Hi,

Thanks for getting back to me!
Next
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/~sircmpwn/aerc/patches/11252/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH aerc] Added nil checks before reading header. Export this patch

textProto.ReadHeader expects a non-nil section reader passed to it, and
panics otherwise.
---
 worker/imap/fetch.go | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/worker/imap/fetch.go b/worker/imap/fetch.go
index def0da8..6a56cfb 100644
--- a/worker/imap/fetch.go
+++ b/worker/imap/fetch.go
@@ -3,7 +3,6 @@ package imap
import (
	"bufio"
	"fmt"

	"github.com/emersion/go-imap"
	"github.com/emersion/go-message"
	_ "github.com/emersion/go-message/charset"
@@ -36,6 +35,9 @@ func (imapw *IMAPWorker) handleFetchMessageHeaders(
	imapw.handleFetchMessages(msg, msg.Uids, items,
		func(_msg *imap.Message) error {
			reader := _msg.GetBody(section)
			if reader == nil {
				return fmt.Errorf("could not get section %#v", section)
			}
			textprotoHeader, err := textproto.ReadHeader(bufio.NewReader(reader))
			if err != nil {
				return fmt.Errorf("could not read header: %v", err)
@@ -88,7 +90,11 @@ func (imapw *IMAPWorker) handleFetchMessageBodyPart(
	}
	imapw.handleFetchMessages(msg, []uint32{msg.Uid}, items,
		func(_msg *imap.Message) error {
			headerReader := bufio.NewReader(_msg.GetBody(&partHeaderSection))
			headerSection := _msg.GetBody(&partHeaderSection)
			if headerSection == nil {
				return fmt.Errorf("could not get header section")
			}
			headerReader := bufio.NewReader(headerSection)
			h, err := textproto.ReadHeader(headerReader)
			if err != nil {
				return fmt.Errorf("failed to read part header: %v", err)
-- 
2.27.0
Hi,
Thanks for the patch.
However I think this is the wrong approach.

Aerc does something invalid in that it often fallsback to the []int{1} path or however the bodypart path is called.

This however only applies to multipart messages, not to simpler ones.

Emersion suggested the proper solution and actually I'm already working on the patch.

I can sent the wip out to you if you'd like to take over.

Your patch (while it probably resolves your issue) only patches the symptoms, not the underlying cause.

Greetings,
Reto