]> granicus.if.org Git - mutt/commitdiff
The attached patch should keep all opened IMAP connections alive, no
authorBrendan Cully <brendan@kublai.com>
Tue, 15 Jul 2003 11:41:32 +0000 (11:41 +0000)
committerBrendan Cully <brendan@kublai.com>
Tue, 15 Jul 2003 11:41:32 +0000 (11:41 +0000)
matter what mailbox you are currently in. With the patch that got
committed yesterday, this should close bug 1523.

(There was a typo in that patch. This one supersedes it.)

curs_main.c
globals.h
imap/command.c
imap/imap.c
imap/imap.h
imap/imap_private.h
imap/util.c
mx.c

index cf6188957b25ebae93851e6dcdfc8ee161864270..4506c29c297ff3eb32dbdde2e4ef38e80a77d0d2 100644 (file)
@@ -509,6 +509,7 @@ int mutt_index_menu (void)
     }
 
 #ifdef USE_IMAP
+    imap_keepalive ();
     imap_disallow_reopen (Context);
 #endif
 
@@ -976,7 +977,8 @@ CHECK_IMAP_ACL(IMAP_ACL_DELETE);
 
 #ifdef USE_IMAP
       case OP_MAIN_IMAP_FETCH:
-       ImapLastCheck = 0;
+       if (Context->magic == M_IMAP)
+         imap_check_mailbox (Context, &index_hint, 1);
         break;
 #endif
       
index 445611ca60e3b3e944e8cbbdd6df86f5ad12664a..dca04c1d15062e47b628ff4bf7a1cf7551ccd5af 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -124,10 +124,6 @@ WHERE LIST *UnIgnore INITVAL(0);
 WHERE LIST *MailLists INITVAL(0);
 WHERE LIST *SubscribedLists INITVAL(0);
 
-#ifdef USE_IMAP
-WHERE time_t ImapLastCheck INITVAL(0);
-#endif
-
 /* bit vector for boolean variables */
 #ifdef MAIN_C
 unsigned char Options[(OPTMAX + 7)/8];
index 71b4b87980bd08a677197a6db53f49dc2bdecd2b..fb01bd209d252a49d9698a097b71405539a00093 100644 (file)
@@ -133,7 +133,9 @@ int imap_cmd_step (IMAP_DATA* idata)
     cmd->blen = IMAP_CMD_BUFSIZE;
     dprint (3, (debugfile, "imap_cmd_step: shrank buffer to %u bytes\n", cmd->blen));
   }
-  
+
+  idata->lastread = time(NULL);
+
   /* handle untagged messages. The caller still gets its shot afterwards. */
   if (!ascii_strncmp (cmd->buf, "* ", 2) &&
       cmd_handle_untagged (idata))
index 36fde9e12c0371de5f0b6139dd6d97bac5b16f60..a70d223231da2eddff1fe583cf108550d4ecdac7 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright (C) 1996-8 Michael R. Elkins <me@mutt.org>
  * Copyright (C) 1996-9 Brandon Long <blong@fiction.net>
- * Copyright (C) 1999-2002 Brendan Cully <brendan@kublai.com>
+ * Copyright (C) 1999-2003 Brendan Cully <brendan@kublai.com>
  * 
  *     This program is free software; you can redistribute it and/or modify
  *     it under the terms of the GNU General Public License as published by
@@ -525,9 +525,6 @@ int imap_open_mailbox (CONTEXT* ctx)
   /* once again the context is new */
   ctx->data = idata;
 
-  if (idata->status == IMAP_FATAL)
-    goto fail;
-
   /* Clean up path and replace the one in the ctx */
   imap_fix_path (idata, mx.mbox, buf, sizeof (buf));
   FREE(&(idata->mailbox));
@@ -918,7 +915,7 @@ int imap_sync_mailbox (CONTEXT* ctx, int expunge, int* index_hint)
    * to be changed. */
   imap_allow_reopen (ctx);
 
-  if ((rc = imap_check_mailbox (ctx, index_hint)) != 0)
+  if ((rc = imap_check_mailbox (ctx, index_hint, 0)) != 0)
     return rc;
 
   memset (&cmd, 0, sizeof (cmd));
@@ -1085,6 +1082,7 @@ void imap_close_mailbox (CONTEXT* ctx)
     idata->state = IMAP_AUTHENTICATED;
     FREE (&(idata->mailbox));
     mutt_free_list (&idata->flags);
+    idata->ctx = NULL;
   }
 
   /* free IMAP part of headers */
@@ -1109,25 +1107,18 @@ void imap_close_mailbox (CONTEXT* ctx)
  *     0               no change
  *     -1              error
  */
-int imap_check_mailbox (CONTEXT *ctx, int *index_hint)
+int imap_check_mailbox (CONTEXT *ctx, int *index_hint, int force)
 {
   /* overload keyboard timeout to avoid many mailbox checks in a row.
    * Most users don't like having to wait exactly when they press a key. */
-
   IMAP_DATA* idata;
-  time_t now;
   int result = 0;
 
   idata = (IMAP_DATA*) ctx->data;
 
-  now = time(NULL);
-  if (now > ImapLastCheck + Timeout)
-  {
-    ImapLastCheck = now;
-
-    if (imap_exec (idata, "NOOP", 0) != 0)
-      return -1;
-  }
+  if ((force || time(NULL) > idata->lastread + Timeout)
+      && imap_exec (idata, "NOOP", 0) != 0)
+    return -1;
 
   /* We call this even when we haven't run NOOP in case we have pending
    * changes to process, since we can reopen here. */
index 3a374255798265b3551675fb62e26320e89851ab..4a3608d0a354a6797150dc4254eac27067137ff4 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 1996-8 Michael R. Elkins <me@mutt.org>
- * Copyright (C) 2000-1 Brendan Cully <brendan@kublai.com>
+ * Copyright (C) 2000-3 Brendan Cully <brendan@kublai.com>
  * 
  *     This program is free software; you can redistribute it and/or modify
  *     it under the terms of the GNU General Public License as published by
@@ -33,7 +33,7 @@ typedef struct
 
 /* imap.c */
 int imap_access (const char*, int);
-int imap_check_mailbox (CONTEXT *ctx, int *index_hint);
+int imap_check_mailbox (CONTEXT *ctx, int *index_hint, int force);
 int imap_close_connection (CONTEXT *ctx);
 int imap_delete_mailbox (CONTEXT* idata, IMAP_MBOX mx);
 int imap_open_mailbox (CONTEXT *ctx);
index 7efd9c552b2602695226f9f720b0893b95c0a6e3..0a554097178b6c418b7128c6a6d635975509805e 100644 (file)
@@ -165,6 +165,7 @@ typedef struct
   char* capstr;
   unsigned char capabilities[(CAPMAX + 7)/8];
   unsigned int seqno;
+  time_t lastread; /* last time we read a command for the server */
   /* who knows, one day we may run multiple commands in parallel */
   IMAP_COMMAND cmd;
 
index 6fd13e73f2bdb6d0ba750b6b185e47ce7d6a9c4b..ae72edb70301242fe414616651d7adb78af856a6 100644 (file)
@@ -249,22 +249,7 @@ void imap_error (const char *where, const char *msg)
 /* imap_new_idata: Allocate and initialise a new IMAP_DATA structure.
  *   Returns NULL on failure (no mem) */
 IMAP_DATA* imap_new_idata (void) {
-  IMAP_DATA* idata;
-
-  idata = safe_calloc (1, sizeof (IMAP_DATA));
-  if (!idata)
-    return NULL;
-
-  idata->conn = NULL;
-  idata->capstr = NULL;
-  idata->state = IMAP_DISCONNECTED;
-  idata->seqno = 0;
-
-  idata->cmd.buf = NULL;
-  idata->cmd.blen = 0;
-  idata->cmd.state = IMAP_CMD_OK;
-
-  return idata;
+  return safe_calloc (1, sizeof (IMAP_DATA));
 }
 
 /* imap_free_idata: Release and clear storage in an IMAP_DATA structure. */
@@ -562,12 +547,35 @@ static RETSIGTYPE alrm_handler (int sig)
 
 void imap_keepalive (void)
 {
-  CONTEXT *ctx = Context;
-  
-  if (ctx == NULL || ctx->magic != M_IMAP || CTX_DATA->ctx != ctx)
-    return;
+  CONNECTION *conn;
+  CONTEXT *ctx = NULL;
+  IMAP_DATA *idata;
+
+  conn = mutt_socket_head ();
+  while (conn)
+  {
+    if (conn->account.type == M_ACCT_TYPE_IMAP)
+    {
+      idata = (IMAP_DATA*) conn->data;
 
-  imap_check_mailbox (ctx, NULL);
+      if (idata->state >= IMAP_AUTHENTICATED
+         && time(NULL) >= idata->lastread + ImapKeepalive)
+      {
+       if (idata->ctx)
+         ctx = idata->ctx;
+       else
+       {
+         ctx = safe_calloc (1, sizeof (CONTEXT));
+         ctx->data = idata;
+       }
+       imap_check_mailbox (ctx, NULL, 1);
+       if (!idata->ctx)
+         FREE (&ctx);
+      }
+    }
+
+    conn = conn->next;
+  }
 }
 
 int imap_wait_keepalive (pid_t pid)
diff --git a/mx.c b/mx.c
index c00444f02b5d6598ec0c02f7cbc6411b2f615f0a..bc7b8ffcce36d279f9835d4dd619c8a7a3f4e48e 100644 (file)
--- a/mx.c
+++ b/mx.c
@@ -1360,7 +1360,7 @@ int mx_check_mailbox (CONTEXT *ctx, int *index_hint, int lock)
 
 #ifdef USE_IMAP
       case M_IMAP:
-       return (imap_check_mailbox (ctx, index_hint));
+       return (imap_check_mailbox (ctx, index_hint, 0));
 #endif /* USE_IMAP */
 
 #ifdef USE_POP