]> granicus.if.org Git - mutt/commitdiff
Don't do Context updates from the background.
authorThomas Roessler <roessler@does-not-exist.org>
Mon, 28 Feb 2000 17:27:21 +0000 (17:27 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Mon, 28 Feb 2000 17:27:21 +0000 (17:27 +0000)
imap/command.c
imap/imap.c
imap/imap.h
imap/imap_private.h
imap/util.c

index 964e4d6cff052d32a0261b8e7433ae3f6a37b183..3fab7abe7557e999f59cd6d7c497823faf33a75a 100644 (file)
@@ -42,14 +42,23 @@ static char *Capabilities[] = {"IMAP4", "IMAP4rev1", "STATUS", "ACL",
  *   detected, do expunge) */
 void imap_cmd_finish (const char* seq, IMAP_DATA* idata)
 {
-  if ((idata->state == IMAP_SELECTED) && 
-      !idata->selected_ctx->closing && 
-      (idata->status == IMAP_NEW_MAIL || 
-       idata->status == IMAP_EXPUNGE))
+  if (!(idata->state == IMAP_SELECTED) || idata->selected_ctx->closing)
+  {
+    idata->status = 0;
+    mutt_clear_error ();
+    return;
+  }
+  
+  if ((idata->status == IMAP_NEW_MAIL || 
+       idata->status == IMAP_EXPUNGE ||
+       (idata->reopen & (IMAP_REOPEN_PENDING|IMAP_NEWMAIL_PENDING)))
+      && (idata->reopen & IMAP_REOPEN_ALLOW))
   {
     int count = idata->newMailCount;
 
-    if (idata->status == IMAP_NEW_MAIL && count > idata->selected_ctx->msgcount)
+    if (!(idata->reopen & IMAP_REOPEN_PENDING) &&
+       ((idata->status == IMAP_NEW_MAIL) || (idata->reopen & IMAP_NEWMAIL_PENDING))  
+       && count > idata->selected_ctx->msgcount)
     {
       /* read new mail messages */
       dprint (1, (debugfile, "imap_cmd_finish: fetching new mail\n"));
@@ -60,17 +69,27 @@ void imap_cmd_finish (const char* seq, IMAP_DATA* idata)
       count = imap_read_headers (idata->selected_ctx, 
         idata->selected_ctx->msgcount, count - 1) + 1;
       idata->check_status = IMAP_NEW_MAIL;
+      idata->reopen &= ~IMAP_NEWMAIL_PENDING;
     }
     else
     {
       imap_reopen_mailbox (idata->selected_ctx, NULL);
       idata->check_status = IMAP_REOPENED;
+      idata->reopen &= ~(IMAP_REOPEN_PENDING|IMAP_NEWMAIL_PENDING);
     }
 
-    idata->status = 0;
-
-    mutt_clear_error ();
   }
+  else if (!(idata->reopen & IMAP_REOPEN_ALLOW))
+  {
+    if (idata->status == IMAP_NEW_MAIL)
+      idata->reopen |= IMAP_NEWMAIL_PENDING;
+    
+    if (idata->status == IMAP_EXPUNGE)
+      idata->reopen |= IMAP_REOPEN_PENDING;
+  }
+
+  idata->status = 0;
+  mutt_clear_error ();
 }
 
 /* imap_code: returns 1 if the command result was OK, or 0 if NO or BAD */
index 36cda2bc0e2b6195484ad9a76a4b43bb337956b8..63de926a79e11fcb5a2ba244ed6efaefb1b0e270 100644 (file)
@@ -1087,6 +1087,9 @@ 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;
 }
 
@@ -1162,6 +1165,7 @@ int imap_check_mailbox (CONTEXT *ctx, int *index_hint)
     return M_NEW_MAIL;
   if (CTX_DATA->check_status == IMAP_REOPENED)
     return M_REOPENED;
+
   return 0;
 }
 
index a88479f222eec3c3bdd88d82fe346e1ee58fcf63..3d90d2f196ab3a7a2886e172d094a4e54be639ad 100644 (file)
@@ -51,6 +51,9 @@ int imap_mailbox_check (char *path, int new);
 int imap_subscribe (char *path, int subscribe);
 int imap_complete (char* dest, size_t dlen, char* path);
 
+void imap_allow_reopen (CONTEXT *ctx);
+void imap_disallow_reopen (CONTEXT *ctx);
+
 /* browse.c */
 int imap_init_browse (char *path, struct browser_state *state);
 
index a116a0b04c3c17ec2b6c28f2b37b527317d1d1cc..2d7b4085352359525ec5cde79250e8757fbb1b4f 100644 (file)
 #define M_IMAP_PASS (1<<3)
 #define M_IMAP_CRAM (1<<4)
 
+#define IMAP_REOPEN_ALLOW    (1<<0)
+#define IMAP_REOPEN_PENDING  (1<<1)
+#define IMAP_NEWMAIL_PENDING (1<<2)
+
 enum
 {
   IMAP_FATAL = 1,
@@ -145,6 +149,8 @@ typedef struct
   unsigned char rights[(RIGHTSMAX + 7)/8];
   unsigned int newMailCount;
   IMAP_CACHE cache[IMAP_CACHE_LEN];
+  short reopen;
+  
   /* all folder flags - system flags AND keywords */
   LIST *flags;
 } IMAP_DATA;
index 720c7cf37449893aff34d7819181d3655ea1d9d8..12fad71d81af4b01fbd69ec2aa35bad600a2c18a 100644 (file)
@@ -21,6 +21,7 @@
 /* general IMAP utility functions */
 
 #include "mutt.h"
+#include "mx.h"        /* for M_IMAP */
 #include "imap_private.h"
 
 #include <stdlib.h>
@@ -359,3 +360,16 @@ int imap_wait_keepalive (pid_t pid)
   return rc;
 }
 
+/* Allow/disallow re-opening a folder upon expunge. */
+
+void imap_allow_reopen (CONTEXT *ctx)
+{
+  if (ctx->magic == M_IMAP)
+    CTX_DATA->reopen |= IMAP_REOPEN_ALLOW;
+}
+
+void imap_disallow_reopen (CONTEXT *ctx)
+{
+  if (ctx->magic == M_IMAP)
+    CTX_DATA->reopen &= ~IMAP_REOPEN_ALLOW;
+}