]> granicus.if.org Git - mutt/commitdiff
The attached patch cleans up some bugs in switching IMAP mailboxes:
authorBrendan Cully <brendan@kublai.com>
Sun, 7 Apr 2002 19:21:45 +0000 (19:21 +0000)
committerBrendan Cully <brendan@kublai.com>
Sun, 7 Apr 2002 19:21:45 +0000 (19:21 +0000)
* 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
imap/imap.c
imap/message.c

index 2d475bf6f3371a59d5bba7e894bc41b84e5de96d..bd01aa0e8ffa0bdcdabc7edc609aba9495920c60 100644 (file)
@@ -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)
     {
index 983a51b4b85a4d8cff69b52759eb34cedf36f449..cfb2e354c87fc9838256a23c3bfa2e7902e59414 100644 (file)
@@ -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 */
index b41bdf43649b8a52819faa8a47f479ba55533f5e..289fc0d43158f0885946b2755de347c4a890f4a5 100644 (file)
@@ -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;
 }