From: Kevin McCarthy Date: Sun, 21 May 2017 17:51:38 +0000 (-0700) Subject: Properly adjust fetch ranges when handling new mail. (see #3942) X-Git-Tag: neomutt-20170707^2^2~40 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a9141e1a672671b8c3177c6aa87339f4ad73c807;p=neomutt Properly adjust fetch ranges when handling new mail. (see #3942) When pulling down headers, it is possible for expunge responses to happen too. If we get a new mail count, we need to take into account changes to the max_msn due to the expunges. --- diff --git a/imap/message.c b/imap/message.c index 85d8f408e..b18dc2695 100644 --- a/imap/message.c +++ b/imap/message.c @@ -325,7 +325,7 @@ int imap_read_headers (IMAP_DATA* idata, unsigned int msn_begin, unsigned int ms /* make sure we don't get remnants from older larger message headers */ fputs ("\n\n", fp); - if (h.data->msn < msn_begin || h.data->msn > fetch_msn_end) + if (h.data->msn < 1 || h.data->msn > fetch_msn_end) { dprint (1, (debugfile, "imap_read_headers: skipping FETCH response for " "unknown message number %d\n", h.data->msn)); @@ -392,10 +392,17 @@ int imap_read_headers (IMAP_DATA* idata, unsigned int msn_begin, unsigned int ms } } - /* in case we get new mail while fetching the headers */ + /* In case we get new mail while fetching the headers. + * + * Note: it is possible to handle EXPUNGE responses while pulling + * down the headers. Therefore, we need to use the current state + * of max_msn, not fetch_msn_end to set the start range. + */ if (idata->reopen & IMAP_NEWMAIL_PENDING) { - msn_begin = fetch_msn_end + 1; + /* update to the last value we actually pulled down */ + fetch_msn_end = idata->max_msn; + msn_begin = idata->max_msn + 1; msn_end = idata->newMailCount; while (msn_end > ctx->hdrmax) mx_alloc_memory (ctx);