From 55cb331c8edfca81e57d133a98ef194dd1c18e82 Mon Sep 17 00:00:00 2001 From: Joey Pabalinas Date: Fri, 6 Apr 2018 02:40:27 -1000 Subject: [PATCH] message.c: retry message parse if first attempt is zero-length On IMAP failure the message body can sometimes be truncated, which leaves an empty message in the cache that must be manually deleted to be properly re-fetched. If the cached message body is zero-length, retry the message parse once to be sure that the message body actually *is* empty. --- imap/message.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/imap/message.c b/imap/message.c index 18f08348c..088895e2d 100644 --- a/imap/message.c +++ b/imap/message.c @@ -989,6 +989,7 @@ int imap_fetch_message(struct Context *ctx, struct Message *msg, int msgno) unsigned int uid; int cacheno; struct ImapCache *cache = NULL; + bool retried = false; bool read; int rc; @@ -1178,6 +1179,14 @@ parsemsg: rewind(msg->fp); HEADER_DATA(h)->parsed = true; + /* retry message parse if cached message is empty */ + if (!retried && ((h->lines == 0) || (h->content->length == 0))) + { + imap_cache_del(idata, h); + retried = true; + goto parsemsg; + } + return 0; bail: -- 2.40.0