]> granicus.if.org Git - mutt/commitdiff
More IMAP folder update hacks. Brendan says it works.
authorThomas Roessler <roessler@does-not-exist.org>
Tue, 29 Feb 2000 22:27:08 +0000 (22:27 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Tue, 29 Feb 2000 22:27:08 +0000 (22:27 +0000)
curs_main.c
imap/imap.c
mx.c

index 5936a53de4ecd37407193fd4f1b180b714490fdc..32b2a3c9de0c003c45b0c0fc39a657ab99376b7f 100644 (file)
@@ -458,11 +458,11 @@ int mutt_index_menu (void)
 
        set_option (OPTSEARCHINVALID);
       }
-      
+    }
+
 #ifdef USE_IMAP
-      imap_disallow_reopen (Context);
+    imap_disallow_reopen (Context);
 #endif
-    }
 
     check_lock = 0;
     
index 63de926a79e11fcb5a2ba244ed6efaefb1b0e270..711eaa545883924266b483f5cb458460cfd8b47f 100644 (file)
@@ -954,7 +954,9 @@ int imap_make_msg_set (char* buf, size_t buflen, CONTEXT* ctx, int flag,
 /* update the IMAP server to reflect message changes done within mutt.
  * Arguments
  *   ctx: the current context
- *   expunge: 0 or 1 - do expunge? */
+ *   expunge: 0 or 1 - do expunge? 
+ */
+
 int imap_sync_mailbox (CONTEXT* ctx, int expunge)
 {
   char buf[HUGE_STRING];
@@ -963,13 +965,21 @@ int imap_sync_mailbox (CONTEXT* ctx, int expunge)
   int deleted;
   int n;
   int err_continue = M_NO;     /* continue on error? */
+  int rc;
 
   if (CTX_DATA->state != IMAP_SELECTED)
   {
     dprint (2, (debugfile, "imap_sync_mailbox: no mailbox selected\n"));
     return -1;
   }
-  
+
+  imap_allow_reopen (ctx);     /* This function is only called when the calling code
+                                * expects the context to be changed.
+                                */
+
+  if ((rc = imap_check_mailbox (ctx, NULL)) != 0)
+    return rc;
+
   /* if we are expunging anyway, we can do deleted messages very quickly... */
   if (expunge && mutt_bit_isset (CTX_DATA->rights, IMAP_ACL_DELETE))
   {
@@ -1087,9 +1097,6 @@ int imap_sync_mailbox (CONTEXT* ctx, int expunge)
     }
   }
 
-  /* clear IMAP_REOPEN_PENDING, which may have been set during exec */
-  CTX_DATA->reopen &= ~IMAP_REOPEN_PENDING;
-
   return 0;
 }
 
@@ -1101,6 +1108,8 @@ void imap_fastclose_mailbox (CONTEXT *ctx)
   if (!ctx->data)
     return;
 
+  CTX_DATA->reopen &= IMAP_REOPEN_ALLOW;
+
   if ((CTX_DATA->state == IMAP_SELECTED) && (ctx == CTX_DATA->selected_ctx))
     CTX_DATA->state = IMAP_AUTHENTICATED;
 
@@ -1145,27 +1154,37 @@ int imap_check_mailbox (CONTEXT *ctx, int *index_hint)
 {
   char buf[LONG_STRING];
   static time_t checktime=0;
+  time_t t;
 
+  /* 
+   * gcc thinks it has to warn about uninitialized use
+   * of t.  This is wrong.
+   */
+  
   if (ImapCheckTimeout)
-  {
-    time_t k=time(NULL);
-    if (k-checktime < ImapCheckTimeout)
-      return 0;
-    checktime=k;
+  { 
+    t = time(NULL);
+    t -= checktime;
   }
 
-  CTX_DATA->check_status = 0;
-  if (imap_exec (buf, sizeof (buf), CTX_DATA, "NOOP", 0) != 0)
+  if ((ImapCheckTimeout && t >= ImapCheckTimeout)
+      || ((CTX_DATA->reopen & IMAP_REOPEN_ALLOW) && (CTX_DATA->reopen & ~IMAP_REOPEN_ALLOW)))
   {
-    imap_error ("imap_check_mailbox()", buf);
-    return -1;
-  }
-
-  if (CTX_DATA->check_status == IMAP_NEW_MAIL)
-    return M_NEW_MAIL;
-  if (CTX_DATA->check_status == IMAP_REOPENED)
-    return M_REOPENED;
+    if (ImapCheckTimeout) checktime += t;
 
+    CTX_DATA->check_status = 0;
+    if (imap_exec (buf, sizeof (buf), CTX_DATA, "NOOP", 0) != 0)
+    {
+      imap_error ("imap_check_mailbox()", buf);
+      return -1;
+    }
+    
+    if (CTX_DATA->check_status == IMAP_NEW_MAIL)
+      return M_NEW_MAIL;
+    if (CTX_DATA->check_status == IMAP_REOPENED)
+      return M_REOPENED;
+  }
+  
   return 0;
 }
 
diff --git a/mx.c b/mx.c
index fdefa123f368fd563fb2cfc022da40e5833cc57e..e6375e07c47a2fa2cf5aa245d3d94adac6017961 100644 (file)
--- a/mx.c
+++ b/mx.c
@@ -892,7 +892,7 @@ int mx_close_mailbox (CONTEXT *ctx)
   /* allow IMAP to preserve the deleted flag across sessions */
   if (ctx->magic == M_IMAP)
   {
-    if (imap_sync_mailbox (ctx, purge) == -1)
+    if (imap_sync_mailbox (ctx, purge) != 0)
       return -1;
   }
   else
@@ -1072,7 +1072,7 @@ int mx_sync_mailbox (CONTEXT *ctx)
     rc = imap_sync_mailbox (ctx, purge);
   else
 #endif
-  rc = sync_mailbox (ctx);
+    rc = sync_mailbox (ctx);
   if (rc == 0)
   {
 #ifdef USE_IMAP