From fafcee2534111ee2f1353201837ca8cd42850e26 Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Tue, 22 Nov 2022 11:09:57 +0100 Subject: imap: fix error with empty flag updates Fix the following error occurring when fetching new headers after IDLE: panic: runtime error: invalid memory address or nil pointer dereference bufio.(*Reader).fill(0xc00029af00) bufio/bufio.go:106 +0xd8 bufio.(*Reader).Peek(0xc0006e1f00, 0x1) bufio/bufio.go:144 +0x5d github.com/emersion/go-message/textproto.ReadHeader(0x0?) github.com/emersion/go-message@v0.15.0/textproto/header.go:525 +0x5f git.sr.ht/~rjarry/aerc/worker/imap.(*IMAPWorker).handleFetchMessageHeaders.func1(0xc00026e980) git.sr.ht/~rjarry/aerc/worker/imap/fetch.go:49 +0x1ab git.sr.ht/~rjarry/aerc/worker/imap.(*IMAPWorker).handleFetchMessages.func1() git.sr.ht/~rjarry/aerc/worker/imap/fetch.go:222 +0xa2 created by git.sr.ht/~rjarry/aerc/worker/imap.(*IMAPWorker).handleFetchMessages git.sr.ht/~rjarry/aerc/worker/imap/fetch.go:217 +0x10a Some IMAP messages only contain flag updates, ignore them. Reuse the same logic than handleFetchMessageBodyPart() and handleFechFullMessages(). Fixes: https://todo.sr.ht/~rjarry/aerc/111 Signed-off-by: Robin Jarry Tested-by: normen --- worker/imap/fetch.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'worker/imap') diff --git a/worker/imap/fetch.go b/worker/imap/fetch.go index f3aad36e..f5407087 100644 --- a/worker/imap/fetch.go +++ b/worker/imap/fetch.go @@ -45,13 +45,17 @@ func (imapw *IMAPWorker) handleFetchMessageHeaders( } imapw.handleFetchMessages(msg, toFetch, items, func(_msg *imap.Message) error { + if len(_msg.Body) == 0 { + // ignore duplicate messages with only flag updates + return nil + } reader := _msg.GetBody(section) + if reader == nil { + return fmt.Errorf("failed to find part: %v", section) + } textprotoHeader, err := textproto.ReadHeader(bufio.NewReader(reader)) if err != nil { - logging.Errorf( - "message %d: could not read header: %v", _msg.Uid, err) - imapw.worker.PostMessageInfoError(msg, _msg.Uid, err) - return nil + return fmt.Errorf("failed to read part header: %w", err) } header := &mail.Header{Header: message.Header{Header: textprotoHeader}} info := &models.MessageInfo{ -- cgit