From 5701b20541935f11123f484babbeced3d8f1d385 Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Fri, 16 Nov 2001 22:55:45 +0000 Subject: If we get a BYE response, call camel_service_disconnect() and set an 2001-11-14 Jeffrey Stedfast * providers/imap/camel-imap-command.c (camel_imap_command_response): If we get a BYE response, call camel_service_disconnect() and set an exception. Also do the check for "* BYE" first instead of passing it off imap_read_untagged() since we'll just waste time in there mallocing left and right only to arrive at the single response line "* BYE" again :-) svn path=/trunk/; revision=14735 --- camel/providers/imap/camel-imap-command.c | 33 +++++++++++++++++++------------ 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'camel/providers/imap') diff --git a/camel/providers/imap/camel-imap-command.c b/camel/providers/imap/camel-imap-command.c index 5639741a42..3afb9af82f 100644 --- a/camel/providers/imap/camel-imap-command.c +++ b/camel/providers/imap/camel-imap-command.c @@ -267,18 +267,25 @@ camel_imap_command_response (CamelImapStore *store, char **response, switch (*respbuf) { case '*': - type = CAMEL_IMAP_RESPONSE_UNTAGGED; - - /* Read the rest of the response if it is multi-line. */ - respbuf = imap_read_untagged (store, respbuf, ex); - if (!respbuf) - type = CAMEL_IMAP_RESPONSE_ERROR; - else if (!g_strncasecmp (respbuf, "* BYE", 5)) { + if (!g_strncasecmp (respbuf, "* BYE", 5)) { /* Connection was lost, no more data to fetch */ + camel_service_disconnect (CAMEL_SERVICE (store), FALSE, NULL); + camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, + _("Server unexpectedly disconnected: %s"), + _("Unknown error")); /* g_strerror (104)); FIXME after 1.0 is released */ store->connected = FALSE; g_free (respbuf); + respbuf = NULL; type = CAMEL_IMAP_RESPONSE_ERROR; + break; } + + /* Read the rest of the response. */ + type = CAMEL_IMAP_RESPONSE_UNTAGGED; + respbuf = imap_read_untagged (store, respbuf, ex); + if (!respbuf) + type = CAMEL_IMAP_RESPONSE_ERROR; + break; case '+': type = CAMEL_IMAP_RESPONSE_CONTINUATION; @@ -292,6 +299,7 @@ camel_imap_command_response (CamelImapStore *store, char **response, if (type == CAMEL_IMAP_RESPONSE_ERROR || type == CAMEL_IMAP_RESPONSE_TAGGED) CAMEL_IMAP_STORE_UNLOCK (store, command_lock); + return type; } @@ -398,17 +406,16 @@ imap_read_untagged (CamelImapStore *store, char *line, CamelException *ex) str->str + 1, length); if (nread == -1) { if (errno == EINTR) - camel_exception_set(ex, CAMEL_EXCEPTION_USER_CANCEL, _("Operation cancelled")); + camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL, _("Operation cancelled")); else - camel_exception_set(ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, strerror(errno)); + camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, g_strerror (errno)); camel_service_disconnect (CAMEL_SERVICE (store), FALSE, NULL); goto lose; } if (nread < length) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - _("Server response ended too soon.")); - camel_service_disconnect (CAMEL_SERVICE (store), - FALSE, NULL); + camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, + _("Server response ended too soon.")); + camel_service_disconnect (CAMEL_SERVICE (store), FALSE, NULL); goto lose; } str->str[length + 1] = '\0'; -- cgit v1.2.3