Commit 76e66e04 authored by Brendan Cully's avatar Brendan Cully

The attached patch cleans up some bugs in switching IMAP mailboxes:

* free current flags on mailbox close
* reset reopen state
* don't parse the same untagged SELECT response for multiple options
* call mx_update_context after reading the whole mailbox, not after
  each message
* reset new mail flag if mail arrives in the middle of opening the
  mailbox. This should close 1139

939 is most likely unaffected. I discovered these problems while
investigating 939.
parent ad792d1e
......@@ -257,8 +257,7 @@ void imap_cmd_finish (IMAP_DATA* idata)
/* check_status: curs_main uses imap_check_mailbox to detect
* whether the index needs updating */
idata->check_status = IMAP_NEWMAIL_PENDING;
idata->reopen &= ~IMAP_NEWMAIL_PENDING;
count = imap_read_headers (idata, idata->ctx->msgcount, count-1)+1;
imap_read_headers (idata, idata->ctx->msgcount, count-1);
}
else if (idata->reopen & IMAP_EXPUNGE_PENDING)
{
......
......@@ -560,17 +560,6 @@ int imap_open_mailbox (CONTEXT* ctx)
if ((rc = imap_cmd_step (idata)) != IMAP_CMD_CONTINUE)
break;
pc = idata->cmd.buf + 2;
pc = imap_next_word (pc);
if (!ascii_strncasecmp ("EXISTS", pc, 6))
{
/* imap_handle_untagged will have picked up the EXISTS message and
* set the NEW_MAIL flag. We clear it here. */
idata->reopen &= ~IMAP_NEWMAIL_PENDING;
count = idata->newMailCount;
idata->newMailCount = 0;
}
pc = idata->cmd.buf + 2;
/* Obtain list of available flags here, may be overridden by a
......@@ -596,6 +585,15 @@ int imap_open_mailbox (CONTEXT* ctx)
if ((pc = imap_get_flags (&(idata->flags), pc)) == NULL)
goto fail;
}
else
{
pc = imap_next_word (pc);
if (!ascii_strncasecmp ("EXISTS", pc, 6))
{
count = idata->newMailCount;
idata->newMailCount = 0;
}
}
}
while (rc == IMAP_CMD_CONTINUE);
......@@ -1079,6 +1077,7 @@ void imap_close_mailbox (CONTEXT* ctx)
idata->reopen &= IMAP_REOPEN_ALLOW;
idata->state = IMAP_AUTHENTICATED;
FREE (&(idata->mailbox));
mutt_free_list (&idata->flags);
}
/* free IMAP part of headers */
......
......@@ -91,6 +91,10 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend)
while ((msgend) >= idata->ctx->hdrmax)
mx_alloc_memory (idata->ctx);
oldmsgcount = ctx->msgcount;
idata->reopen &= ~IMAP_NEWMAIL_PENDING;
idata->newMailCount = 0;
for (msgno = msgbegin; msgno <= msgend ; msgno++)
{
if (ReadInc && (!msgno || ((msgno+1) % ReadInc == 0)))
......@@ -120,8 +124,6 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend)
memset (&h, 0, sizeof (h));
h.data = safe_calloc (1, sizeof (IMAP_HEADER_DATA));
oldmsgcount = ctx->msgcount;
/* this DO loop does two things:
* 1. handles untagged messages, so we can try again on the same msg
* 2. fetches the tagged response at the end of the last message.
......@@ -173,9 +175,6 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend)
while ((rc != IMAP_CMD_OK) && ((mfhrc == -1) ||
((msgno + 1) >= fetchlast)));
if (ctx->msgcount > oldmsgcount)
mx_update_context (ctx, ctx->msgcount - oldmsgcount);
if ((mfhrc < -1) || ((rc != IMAP_CMD_CONTINUE) && (rc != IMAP_CMD_OK)))
{
imap_free_header_data ((void**) &h.data);
......@@ -184,20 +183,22 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend)
return -1;
}
/* h.data shouldn't be freed here, it is kept in ctx->headers */
/* in case we get new mail while fetching the headers */
if (idata->reopen & IMAP_NEWMAIL_PENDING)
{
msgend = idata->newMailCount - 1;
while ((msgend) >= ctx->hdrmax)
mx_alloc_memory (ctx);
idata->status &= ~IMAP_NEWMAIL_PENDING;
idata->reopen &= ~IMAP_NEWMAIL_PENDING;
idata->newMailCount = 0;
}
}
fclose(fp);
if (ctx->msgcount > oldmsgcount)
mx_update_context (ctx, ctx->msgcount - oldmsgcount);
return msgend;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment