From 655e2d019941c39b04549766eeb212757c2fcfb5 Mon Sep 17 00:00:00 2001 From: Thomas Roessler Date: Tue, 11 Jul 2000 20:38:49 +0000 Subject: Unify logout stuff in _one_ function. From Vsevolod Volkov. --- imap/imap.c | 25 +++++++++++++++---------- imap/imap_private.h | 1 + imap/socket.c | 15 ++------------- 3 files changed, 18 insertions(+), 23 deletions(-) (limited to 'imap') diff --git a/imap/imap.c b/imap/imap.c index b4015a11..051a32e9 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -816,25 +816,30 @@ int imap_open_mailbox_append (CONTEXT *ctx) return 0; } -int imap_close_connection (CONTEXT *ctx) +void imap_logout (CONNECTION *conn) { char buf[LONG_STRING]; char seq[8]; + imap_make_sequence (seq, sizeof (seq)); + snprintf (buf, sizeof (buf), "%s LOGOUT\r\n", seq); + mutt_socket_write (conn, buf); + do + { + if (mutt_socket_readln (buf, sizeof (buf), conn) < 0) + break; + } + while (mutt_strncmp (seq, buf, SEQLEN) != 0); +} + +int imap_close_connection (CONTEXT *ctx) +{ dprint (1, (debugfile, "imap_close_connection(): closing connection\n")); /* if the server didn't shut down on us, close the connection gracefully */ if (CTX_DATA->status != IMAP_BYE) { mutt_message _("Closing connection to IMAP server..."); - imap_make_sequence (seq, sizeof (seq)); - snprintf (buf, sizeof (buf), "%s LOGOUT\r\n", seq); - mutt_socket_write (CTX_DATA->conn, buf); - do - { - if (mutt_socket_readln (buf, sizeof (buf), CTX_DATA->conn) < 0) - break; - } - while (mutt_strncmp (seq, buf, SEQLEN) != 0); + imap_logout (CTX_DATA->conn); mutt_clear_error (); } mutt_socket_close (CTX_DATA->conn); diff --git a/imap/imap_private.h b/imap/imap_private.h index 08fd3412..1d5cc24e 100644 --- a/imap/imap_private.h +++ b/imap/imap_private.h @@ -178,6 +178,7 @@ int imap_parse_list_response(CONNECTION* conn, char* buf, int buflen, char** name, int* noselect, int* noinferiors, char* delim); int imap_read_bytes (FILE* fp, CONNECTION* conn, long bytes); int imap_reopen_mailbox (CONTEXT *ctx, int *index_hint); +void imap_logout (CONNECTION* conn); /* auth.c */ int imap_authenticate (IMAP_DATA *idata, CONNECTION *conn); diff --git a/imap/socket.c b/imap/socket.c index e752bcf1..0fad0a64 100644 --- a/imap/socket.c +++ b/imap/socket.c @@ -151,8 +151,6 @@ CONNECTION* mutt_socket_find (const IMAP_MBOX* mx, int newconn) void imap_logout_all (void) { CONNECTION* conn; - char buf[SHORT_STRING]; - char seq[SEQLEN+1]; conn = Connections; @@ -163,17 +161,8 @@ void imap_logout_all (void) mutt_message (_("Closing connection to %s..."), conn->mx.host); - imap_make_sequence (seq, sizeof (seq)); - snprintf (buf, sizeof (buf), "%s LOGOUT\r\n", seq); - - mutt_socket_write (conn, buf); - - do - { - if (mutt_socket_readln (buf, sizeof (buf), conn) < 0) - break; - } - while (mutt_strncmp (buf, seq, SEQLEN) != 0); + imap_logout (conn); + mutt_clear_error (); mutt_socket_close (conn); -- cgit v1.2.3