* be reopened at our earliest convenience */
static void cmd_parse_expunge (IMAP_DATA* idata, const char* s)
{
- int expno, cur;
+ unsigned int exp_msn;
+ int cur;
HEADER* h;
dprint (2, (debugfile, "Handling EXPUNGE\n"));
- expno = atoi (s);
+ exp_msn = atoi (s);
/* walk headers, zero seqno of expunged message, decrement seqno of those
* above. Possibly we could avoid walking the whole list by resorting
{
h = idata->ctx->hdrs[cur];
- if (h->index+1 == expno)
- h->index = -1;
- else if (h->index+1 > expno)
- h->index--;
+ if (HEADER_DATA(h)->msn == exp_msn)
+ {
+ /* imap_expunge_mailbox() will rewrite h->index.
+ * It needs to resort using SORT_ORDER anyway, so setting to INT_MAX
+ * makes the code simpler and possibly more efficient. */
+ h->index = INT_MAX;
+ HEADER_DATA(h)->msn = 0;
+ }
+ else if (HEADER_DATA(h)->msn > exp_msn)
+ HEADER_DATA(h)->msn--;
}
idata->reopen |= IMAP_EXPUNGE_PENDING;
{
HEADER* h;
int i, cacheno;
+ short old_sort;
#ifdef USE_HCACHE
idata->hcache = imap_hcache_open (idata, NULL);
#endif
+ old_sort = Sort;
+ Sort = SORT_ORDER;
+ mutt_sort_headers (idata->ctx, 0);
+
for (i = 0; i < idata->ctx->msgcount; i++)
{
h = idata->ctx->hdrs[i];
- if (h->index == -1)
+ if (h->index == INT_MAX)
{
dprint (2, (debugfile, "Expunging message UID %d.\n", HEADER_DATA (h)->uid));
imap_free_header_data ((IMAP_HEADER_DATA**)&h->data);
}
+ else
+ h->index = i;
}
#if USE_HCACHE
/* We may be called on to expunge at any time. We can't rely on the caller
* to always know to rethread */
mx_update_tables (idata->ctx, 0);
+ Sort = old_sort;
mutt_sort_headers (idata->ctx, 1);
}