From 34ea072e455300005a9831cf833cf11663720f7f Mon Sep 17 00:00:00 2001 From: Brendan Cully Date: Sun, 7 Apr 2002 19:21:45 +0000 Subject: [PATCH] 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. --- imap/command.c | 3 +-- imap/imap.c | 21 ++++++++++----------- imap/message.c | 17 +++++++++-------- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/imap/command.c b/imap/command.c index 2d475bf6..bd01aa0e 100644 --- a/imap/command.c +++ b/imap/command.c @@ -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) { diff --git a/imap/imap.c b/imap/imap.c index 983a51b4..cfb2e354 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -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 */ diff --git a/imap/message.c b/imap/message.c index b41bdf43..289fc0d4 100644 --- a/imap/message.c +++ b/imap/message.c @@ -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; } -- 2.40.0