From 087b331d2e97411b945b95e4f0bb379f0ad7d1ae Mon Sep 17 00:00:00 2001 From: Moritz Poldrack Date: Fri, 22 Dec 2023 21:12:55 +0100 Subject: imap: show parseable messages on error Currently if there are mails aerc can not properly handle, listing the mailbox is aborted. This is especially bothersome if the message one is looking for would be parseable without issue. Show an error if parsing of a message fails, but handle all other messages as normal. This leads to those messages showing up as still loading. Signed-off-by: Moritz Poldrack Acked-by: Robin Jarry --- worker/imap/fetch.go | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'worker/imap/fetch.go') diff --git a/worker/imap/fetch.go b/worker/imap/fetch.go index 0c923bf0..12e2fbdd 100644 --- a/worker/imap/fetch.go +++ b/worker/imap/fetch.go @@ -239,22 +239,19 @@ func (imapw *IMAPWorker) handleFetchMessages( msg types.WorkerMessage, uids []uint32, items []imap.FetchItem, procFunc func(*imap.Message) error, ) { + var err error messages := make(chan *imap.Message) - done := make(chan error) + done := make(chan []error) go func() { defer log.PanicHandler() - var reterr error - for _msg := range messages { - err := procFunc(_msg) + var reterr []error + for msg := range messages { + err := procFunc(msg) if err != nil { - if reterr == nil { - reterr = err - } - // drain the channel upon error - for range messages { - } + log.Errorf("failed to process message <%d>: %v", msg.Uid, err) + reterr = append(reterr, err) } } done <- reterr @@ -268,11 +265,15 @@ func (imapw *IMAPWorker) handleFetchMessages( } set := toSeqSet(uids) - if err := imapw.client.UidFetch(set, items, messages); err != nil { + if err = imapw.client.UidFetch(set, items, messages); err != nil { emitErr(err) return } - if err := <-done; err != nil { + if errs := <-done; len(errs) != 0 { + err = errs[0] + if len(errs) > 1 { + err = fmt.Errorf("parsing of %d messages failed", len(errs)) + } emitErr(err) return } -- cgit