]> granicus.if.org Git - mutt/commitdiff
IMAP logout patch from Brendan Cully.
authorThomas Roessler <roessler@does-not-exist.org>
Mon, 3 Jul 2000 10:16:10 +0000 (10:16 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Mon, 3 Jul 2000 10:16:10 +0000 (10:16 +0000)
curs_main.c
imap/BUGS
imap/command.c
imap/imap.c
imap/imap.h
imap/imap_socket.h
imap/socket.c
imap/util.c

index a794f9b42048923ef3832749c27969c1ae44a0c9..e114f14d52f3f294b0795ee9589c4a6516906398 100644 (file)
@@ -773,11 +773,6 @@ int mutt_index_menu (void)
        {
          int check;
          
-#ifdef USE_IMAP
-          /* logout gracefully from the IMAP server */
-          if (Context && Context->magic == M_IMAP)
-            imap_set_logout (Context);
-#endif
          oldcount = Context ? Context->msgcount : 0;
 
          if (!Context || (check = mx_close_mailbox (Context, &index_hint)) == 0)
@@ -790,6 +785,11 @@ int mutt_index_menu (void)
            menu->redraw = REDRAW_FULL; /* new mail arrived? */
            set_option (OPTSEARCHINVALID);
          }
+
+#ifdef USE_IMAP
+         /* Close all remaining open connections (frees server resources) */
+         imap_logout_all ();
+#endif
        }
        break;
 
@@ -1032,14 +1032,14 @@ int mutt_index_menu (void)
        {
          if (Context)
          {
-#ifdef USE_IMAP
-            if (Context->magic == M_IMAP)
-              imap_set_logout (Context);
-#endif
            mx_fastclose_mailbox (Context);
            safe_free ((void **) &Context);
          }
          done = 1;
+#ifdef USE_IMAP
+         /* Close all open IMAP connections */
+         imap_logout_all ();
+#endif
        }
        break;
 
index 4952f13321edf0b009a93628aca72ccc33680b6a..04d2e1a0dc5bb458191cbac7fcf421f79b20b308 100644 (file)
--- a/imap/BUGS
+++ b/imap/BUGS
@@ -29,13 +29,6 @@ In no particular order:
   result of spurious mx_close_mailbox calls handling the untagged
   BYE response.
 
-* Mutt marks your connection for logout as soon as you say quit, even if
-  you bail out with ^G later.
-  --> This should be fixed by not using imap_set_logout. Instead there
-      should be a function which loops through all connections and logs
-      out of them one at a time. Multiple connections haven't gotten much
-      testing.
-
 * Mutt is uninterruptible during socket calls. We should handle SIGINT.
 
 * Server copy currently doesn't take into account uncommitted changes in
index d95bcd7bec40b9ae3a3d4e1844d70f88b37e1ea2..cfa7debae720d40d8b7919359a53abd71acdef68 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright (C) 1996-8 Michael R. Elkins <me@cs.hmc.edu>
  * Copyright (C) 1996-9 Brandon Long <blong@fiction.net>
- * Copyright (C) 1999 Brendan Cully <brendan@kublai.com>
+ * Copyright (C) 1999-2000 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
@@ -111,7 +111,7 @@ int imap_exec (char* buf, size_t buflen, IMAP_DATA* idata, const char* cmd,
 {
   char* out;
   int outlen;
-  char seq[8];
+  char seq[SEQLEN+1];
 
   /* create sequence for command */
   imap_make_sequence (seq, sizeof (seq));
@@ -154,7 +154,7 @@ int imap_exec (char* buf, size_t buflen, IMAP_DATA* idata, const char* cmd,
   return 0;
 }
 
-/* imap_handle_untagged: fallback parser for otherwise unhandled messages */
+/* imap_handle_untagged: fallback parser for otherwise unhandled messages. */
 int imap_handle_untagged (IMAP_DATA *idata, char *s)
 {
   char *pn;
index e742802c84b1edc1d08c7af164dea2f117793207..a532353807213541f538100b2654311283aec528 100644 (file)
@@ -70,12 +70,6 @@ int imap_delete_mailbox (CONTEXT* ctx, char* mailbox)
   return 0;
 }
 
-void imap_set_logout (CONTEXT *ctx)
-{
-  if (CTX_DATA)
-    CTX_DATA->status = IMAP_LOGOUT;
-}
-
 /* imap_parse_date: date is of the form: DD-MMM-YYYY HH:MM:SS +ZZzz */
 time_t imap_parse_date (char *s)
 {
@@ -846,7 +840,6 @@ int imap_close_connection (CONTEXT *ctx)
   }
   mutt_socket_close_connection (CTX_DATA->conn);
   CTX_DATA->state = IMAP_DISCONNECTED;
-  CTX_DATA->conn->uses = 0;
   CTX_DATA->conn->data = NULL;
   return 0;
 }
@@ -1295,9 +1288,6 @@ int imap_mailbox_check (char *path, int new)
 
   imap_cmd_finish (seq, idata);
 
-  /* what does this do? */
-  conn->uses--;
-
   return msgcount;
 }
 
index 5161b9d315f5fa43d13fe82f1ad7bf233829b29d..2b0b5b744dfcef7c7db689e89fe3c01e48ae4b70 100644 (file)
@@ -43,7 +43,6 @@ int imap_delete_mailbox (CONTEXT* idata, char* mailbox);
 int imap_open_mailbox (CONTEXT *ctx);
 int imap_open_mailbox_append (CONTEXT *ctx);
 int imap_select_mailbox (CONTEXT *ctx, const char* path);
-void imap_set_logout (CONTEXT *ctx);
 int imap_sync_mailbox (CONTEXT *ctx, int expunge, int *index_hint);
 void imap_fastclose_mailbox (CONTEXT *ctx);
 int imap_buffy_check (char *path);
@@ -62,6 +61,9 @@ int imap_append_message (CONTEXT* ctx, MESSAGE* msg);
 int imap_copy_messages (CONTEXT* ctx, HEADER* h, char* dest, int delete);
 int imap_fetch_message (MESSAGE* msg, CONTEXT* ctx, int msgno);
 
+/* socket.c */
+void imap_logout_all (void);
+
 /* util.c */
 int imap_parse_path (const char* path, IMAP_MBOX *mx);
 void imap_qualify_path (char* dest, size_t len, const IMAP_MBOX *mx,
index da7f50eba8c2d92458f874fd1cb78df6b056f2ab..8a1649289b2995122602eab2dedd7135f5367a70 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 1998 Brandon Long <blong@fiction.net>
- * Copyright (C) 1999 Brendan Cully <brendan@kublai.com>
+ * Copyright (C) 1999-2000 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
@@ -24,7 +24,6 @@ typedef struct _connection
 {
   IMAP_MBOX mx;
   char *preconnect; /* Actually specific to server, not connection */
-  int uses;
   int fd;
   char inbuf[LONG_STRING];
   int bufpos;
index fc2e1db1b1a284cd09d7eae37d50e88271f42a80..faa6d8e1aec9ca31144a3e9c1db1f7a0c626855b 100644 (file)
@@ -129,7 +129,6 @@ CONNECTION *mutt_socket_select_connection (const IMAP_MBOX *mx, int newconn)
   conn = (CONNECTION *) safe_calloc (1, sizeof (CONNECTION));
   conn->bufpos = 0;
   conn->available = 0;
-  conn->uses = 0;
   memcpy (&conn->mx, mx, sizeof (conn->mx));
   conn->mx.mbox = 0;
   conn->preconnect = safe_strdup (ImapPreconnect); 
@@ -153,6 +152,54 @@ CONNECTION *mutt_socket_select_connection (const IMAP_MBOX *mx, int newconn)
   return conn;
 }
 
+/* imap_logout_all: close all open connections. Quick and dirty until we can
+ *   make sure we've got all the context we need. */
+void imap_logout_all (void) 
+{
+  CONNECTION* conn, *tmp;
+  char buf[LONG_STRING];
+  char seq[SEQLEN+1];
+  
+  conn = Connections;
+
+  while (conn)
+  {
+    /* what's up here? the last connection doesn't seem to be used */
+    if (conn->fd)
+    {
+      snprintf (buf, sizeof (buf), _("Closing connection to %s..."),
+        conn->mx.host);
+      mutt_message (buf);
+
+      imap_make_sequence (seq, sizeof (seq));
+      snprintf (buf, sizeof (buf), "%s LOGOUT\r\n", seq);
+
+      mutt_socket_write (conn, buf);
+
+      do
+      {
+       if (mutt_socket_read_line_d (buf, sizeof (buf), conn) < 0)
+         break;
+      }
+      while (mutt_strncmp (buf, seq, SEQLEN) != 0);
+      mutt_clear_error ();
+    }
+    
+    tmp = conn;
+    conn = conn->next;
+
+    mutt_socket_close_connection (tmp);
+
+    if (tmp->data) {
+      dprint (2, (debugfile,
+        "imap_logout_all: Connection still has valid CONTEXT?!\n"));
+    }
+
+    free (tmp);
+  }
+}
+
+
 static int try_socket_and_connect (CONNECTION *conn, struct sockaddr_in sin,
                            int verbose)
 {
index d189366279f7721266400ad3d04b9854800fff33..6e959fc4c796b609b4275ea98e2bc1a554b711fb 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright (C) 1996-8 Michael R. Elkins <me@cs.hmc.edu>
  * Copyright (C) 1996-9 Brandon Long <blong@fiction.net>
- * Copyright (C) 1999 Brendan Cully <brendan@kublai.com>
+ * Copyright (C) 1999-2000 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