Andreas Krennmair:
authorak1 <ak1@e385b8ad-14ed-0310-8656-cc95a2468c6d>
Sun, 30 Jan 2005 18:03:34 +0000 (18:03 +0000)
committerak1 <ak1@e385b8ad-14ed-0310-8656-cc95a2468c6d>
Sun, 30 Jan 2005 18:03:34 +0000 (18:03 +0000)
implemented IMAP reconnecting when connection is lost or closed from the server side.

git-svn-id: svn://svn.berlios.de/mutt-ng/trunk@40 e385b8ad-14ed-0310-8656-cc95a2468c6d

ChangeLog.mutt-ng
imap/command.c
imap/imap.c

index 76fd78f..46b9c72 100644 (file)
@@ -1,5 +1,8 @@
 Changes specific to mutt-ng:
 
+2005-01-30:
+  * (Partially?) implemented IMAP reconnecting, needs more testing
+
 2005-01-29:
   * Fixed bugs #3149 and #3161: declarations within functions don't work with gcc 2.95
   * Rename helper programs new names and install documentation into 
index c2d29fa..e10de38 100644 (file)
@@ -115,7 +115,7 @@ int imap_cmd_step (IMAP_DATA* idata)
     if (c <= 0)
     {
       dprint (1, (debugfile, "imap_cmd_step: Error reading server response.\n"));
-      cmd_handle_fatal (idata);
+      /* cmd_handle_fatal (idata); */
       return IMAP_CMD_BAD;
     }
 
@@ -206,6 +206,13 @@ int imap_exec (IMAP_DATA* idata, const char* cmd, int flags)
     rc = imap_cmd_step (idata);
   while (rc == IMAP_CMD_CONTINUE);
 
+  if (rc == IMAP_CMD_BAD) {
+    if (imap_reconnect(idata->ctx)!=0) {
+      return -1;
+    }
+    return 0;
+  }
+
   if (rc == IMAP_CMD_NO && (flags & IMAP_CMD_FAIL_OK))
     return -2;
 
@@ -286,12 +293,12 @@ static void cmd_handle_fatal (IMAP_DATA* idata)
       (idata->reopen & IMAP_REOPEN_ALLOW) &&
       !idata->ctx->closing)
   {
-    mx_fastclose_mailbox (idata->ctx);
-    /*mutt_error (_("Mailbox closed"));
+    /*mx_fastclose_mailbox (idata->ctx);*/
+    mutt_error (_("Mailbox closed"));
     mutt_sleep (1);
-    */
     idata->state = IMAP_DISCONNECTED;
-    imap_reconnect(idata->ctx);
+    if (imap_reconnect(idata->ctx)!=0)
+      mx_fastclose_mailbox(idata->ctx);
   }
 
   if (idata->state != IMAP_SELECTED)
@@ -375,12 +382,16 @@ static int cmd_handle_untagged (IMAP_DATA* idata)
     SKIPWS (s);
     mutt_error ("%s", s);
     idata->status = IMAP_BYE;
-    if (idata->state == IMAP_SELECTED)
-      mx_fastclose_mailbox (idata->ctx);
-    mutt_socket_close (idata->conn);
-    idata->state = IMAP_DISCONNECTED;
 
-    return -1;
+    /*if (imap_reconnect(idata->ctx)!=0) {
+        if (idata->state == IMAP_SELECTED)
+        mx_fastclose_mailbox (idata->ctx); */ /* XXX memleak? */
+      mutt_socket_close (idata->conn);
+      idata->state = IMAP_DISCONNECTED;
+      return -1;
+    /*} else {
+        return 0;
+      } */
   }
   else if (option (OPTIMAPSERVERNOISE) && (ascii_strncasecmp ("NO", s, 2) == 0))
   {
index 0ad54d1..9bc7e86 100644 (file)
@@ -1485,20 +1485,19 @@ int imap_complete(char* dest, size_t dlen, char* path) {
   return -1;
 }
 
-/* reconnect and verify indexes if connection was lost */
+/* reconnect if connection was lost */
 int imap_reconnect(CONTEXT* ctx) {
   IMAP_DATA* imap_data = (IMAP_DATA *)ctx->data;
 
-  if (imap_data->status == IMAP_CONNECTED)
-    return -1;
-  if (imap_data->status == IMAP_BYE)
-    return 0;
-
-  mutt_socket_close(imap_data->conn);
+  if (imap_data) {
+    if (imap_data->status == IMAP_CONNECTED)
+      return -1;
+  }
 
   if (query_quadoption(OPT_IMAPRECONNECT,_("Connection lost. Reconnect to IMAP server?")) != M_YES)
     return -1;
 
-  return imap_open_mailbox(ctx);
+  mx_open_mailbox(ctx->path,0,ctx);
+  return 0;
 }