{
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)
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;
{
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;
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
/*
* 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
{
char* out;
int outlen;
- char seq[8];
+ char seq[SEQLEN+1];
/* create sequence for command */
imap_make_sequence (seq, sizeof (seq));
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;
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)
{
}
mutt_socket_close_connection (CTX_DATA->conn);
CTX_DATA->state = IMAP_DISCONNECTED;
- CTX_DATA->conn->uses = 0;
CTX_DATA->conn->data = NULL;
return 0;
}
imap_cmd_finish (seq, idata);
- /* what does this do? */
- conn->uses--;
-
return msgcount;
}
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);
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,
/*
* 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
{
IMAP_MBOX mx;
char *preconnect; /* Actually specific to server, not connection */
- int uses;
int fd;
char inbuf[LONG_STRING];
int bufpos;
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);
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)
{
/*
* 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