From 368c0e3fc13d42e94d8b595fa7b72013bf00cff0 Mon Sep 17 00:00:00 2001 From: Thomas Roessler Date: Mon, 3 Jul 2000 10:16:10 +0000 Subject: IMAP logout patch from Brendan Cully. --- imap/BUGS | 7 ------- imap/command.c | 6 +++--- imap/imap.c | 10 ---------- imap/imap.h | 4 +++- imap/imap_socket.h | 3 +-- imap/socket.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- imap/util.c | 2 +- 7 files changed, 56 insertions(+), 25 deletions(-) (limited to 'imap') diff --git a/imap/BUGS b/imap/BUGS index 4952f133..04d2e1a0 100644 --- 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 diff --git a/imap/command.c b/imap/command.c index d95bcd7b..cfa7deba 100644 --- a/imap/command.c +++ b/imap/command.c @@ -1,7 +1,7 @@ /* * Copyright (C) 1996-8 Michael R. Elkins * Copyright (C) 1996-9 Brandon Long - * Copyright (C) 1999 Brendan Cully + * Copyright (C) 1999-2000 Brendan Cully * * 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; diff --git a/imap/imap.c b/imap/imap.c index e742802c..a5323538 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -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; } diff --git a/imap/imap.h b/imap/imap.h index 5161b9d3..2b0b5b74 100644 --- a/imap/imap.h +++ b/imap/imap.h @@ -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, diff --git a/imap/imap_socket.h b/imap/imap_socket.h index da7f50eb..8a164928 100644 --- a/imap/imap_socket.h +++ b/imap/imap_socket.h @@ -1,6 +1,6 @@ /* * Copyright (C) 1998 Brandon Long - * Copyright (C) 1999 Brendan Cully + * Copyright (C) 1999-2000 Brendan Cully * * 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; diff --git a/imap/socket.c b/imap/socket.c index fc2e1db1..faa6d8e1 100644 --- a/imap/socket.c +++ b/imap/socket.c @@ -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) { diff --git a/imap/util.c b/imap/util.c index d1893662..6e959fc4 100644 --- a/imap/util.c +++ b/imap/util.c @@ -1,7 +1,7 @@ /* * Copyright (C) 1996-8 Michael R. Elkins * Copyright (C) 1996-9 Brandon Long - * Copyright (C) 1999 Brendan Cully + * Copyright (C) 1999-2000 Brendan Cully * * 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 -- cgit v1.2.3