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 <robin@jarry.cc>
This commit is contained in:
Robin Jarry 2022-02-04 09:14:53 +01:00
parent 9fba8d9cbd
commit a46468521b

View file

@ -38,7 +38,13 @@ func (imapw *IMAPWorker) handleFetchMessageHeaders(
reader := _msg.GetBody(section) reader := _msg.GetBody(section)
textprotoHeader, err := textproto.ReadHeader(bufio.NewReader(reader)) textprotoHeader, err := textproto.ReadHeader(bufio.NewReader(reader))
if err != nil { 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}} header := &mail.Header{message.Header{textprotoHeader}}
imapw.worker.PostMessage(&types.MessageInfo{ imapw.worker.PostMessage(&types.MessageInfo{