imap: fix error when server returns a message without body section

When opening unread emails from certain people (I won't name any names,
sorry), an annoying error message is displayed on the status line:

 could not get section &imap.BodySectionName{BodyPartName:
 imap.BodyPartName{Specifier:"", Path:[]int(nil), Fields:[]string(nil),
 NotFields:false}, Peek:false, Partial:[]int(nil), value}

This does not occur for already read messages. This issue is similar to
the one that was fixed in commit 8ed95b0d2a ("imap: avoid crash when
replying to unread message").

This happens because the flags are updated in the callback that receives
the message itself. It causes the flag update to arrive in the same
channel/request. Ignore the messages that have an empty body (i.e. only
containing flag updates). This is inherently racy but there seems no way
to get rid of these extra messages.

Signed-off-by: Robin Jarry <robin@jarry.cc>
Acked-by: Koni Marti <koni.marti@gmail.com>
This commit is contained in:
Robin Jarry 2022-07-21 11:47:30 +02:00
parent 52f7d3f900
commit 5dec1f09b1
1 changed files with 4 additions and 0 deletions

View File

@ -158,6 +158,10 @@ func (imapw *IMAPWorker) handleFetchFullMessages(
} }
imapw.handleFetchMessages(msg, msg.Uids, items, imapw.handleFetchMessages(msg, msg.Uids, items,
func(_msg *imap.Message) error { func(_msg *imap.Message) error {
if len(_msg.Body) == 0 {
// ignore duplicate messages with only flag updates
return nil
}
r := _msg.GetBody(section) r := _msg.GetBody(section)
if r == nil { if r == nil {
return fmt.Errorf("could not get section %#v", section) return fmt.Errorf("could not get section %#v", section)