From a46468521bf8a6d7f6f0d8f0728eb99d599d2ccf Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Fri, 4 Feb 2022 09:14:53 +0100 Subject: [PATCH] imap: do not abort on malformed messages Some messages contain invalid headers, textproto.ReadHeader fails with an error: malformed MIME header key: From nobody Fri Jan 14 19 And all other messages of the selected folder are ignored. Return an explicit error message to the UI and continue processing other messages. This is consistent with what the maildir worker does. Signed-off-by: Robin Jarry --- worker/imap/fetch.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/worker/imap/fetch.go b/worker/imap/fetch.go index c63ee42..19f4fa3 100644 --- a/worker/imap/fetch.go +++ b/worker/imap/fetch.go @@ -38,7 +38,13 @@ func (imapw *IMAPWorker) handleFetchMessageHeaders( reader := _msg.GetBody(section) textprotoHeader, err := textproto.ReadHeader(bufio.NewReader(reader)) if err != nil { - return fmt.Errorf("could not read header: %v", err) + imapw.worker.Logger.Printf( + "message %v: could not read header: %v", _msg.Uid, err) + imapw.worker.PostMessage(&types.Error{ + Message: types.RespondTo(msg), + Error: err, + }, nil) + return nil } header := &mail.Header{message.Header{textprotoHeader}} imapw.worker.PostMessage(&types.MessageInfo{