From 4f592807c036cf22a6045b7bc7710c10b97488c7 Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Mon, 16 Oct 2000 21:00:59 +0000 Subject: [PATCH] Only send the LOGOUT command if the store is connected. (imap_connect): 2000-10-16 Jeffrey Stedfast * providers/imap/camel-imap-store.c (imap_disconnect): Only send the LOGOUT command if the store is connected. (imap_connect): Set the 'connected' state to TRUE when we successfully connect. (get_folder_info): if (!topfi), 'topfi' was allocated but then 'fi' was set. I think Dan meant to set topfi since fi is an uninitialized value at this point. * providers/imap/camel-imap-command.c (imap_read_response): Check for the untagged BYE response and set the 'connected' state to FALSE if we receive the BYE response. Return NULL if we get a BYE response. --- camel/ChangeLog | 21 +++++++++++++++++++-- camel/providers/imap/camel-imap-command.c | 11 ++++++++++- camel/providers/imap/camel-imap-store.c | 25 ++++++++++++++++--------- camel/providers/imap/camel-imap-store.h | 2 ++ 4 files changed, 47 insertions(+), 12 deletions(-) diff --git a/camel/ChangeLog b/camel/ChangeLog index d2e8bc5..34cf859 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,3 +1,18 @@ +2000-10-16 Jeffrey Stedfast + + * providers/imap/camel-imap-store.c (imap_disconnect): Only send + the LOGOUT command if the store is connected. + (imap_connect): Set the 'connected' state to TRUE when we + successfully connect. + (get_folder_info): if (!topfi), 'topfi' was allocated but then + 'fi' was set. I think Dan meant to set topfi since fi is an + uninitialized value at this point. + + * providers/imap/camel-imap-command.c (imap_read_response): Check + for the untagged BYE response and set the 'connected' state to + FALSE if we receive the BYE response. Return NULL if we get a BYE + response. + 2000-10-16 Dan Winship * providers/imap/camel-imap-store.c (get_folder_info): Deal with @@ -70,7 +85,8 @@ Fix camel_summary_* function rename (imap_get_message_info_internal): Likewise. - * camel-mime-parser.c (camel_mime_parser_finalise): Fixed a spelling mistake. + * camel-mime-parser.c (camel_mime_parser_finalise): Fixed a + spelling mistake. * camel-folder-summary.c (camel_summary_format_address): Uh, why do we encode and then decode here ... sigh. This is not the way @@ -82,7 +98,8 @@ 2000-10-11 Chris Toshok - * providers/nntp/camel-nntp-store.c (nntp_store_unsubscribe_folder): remove the leading '/'. + * providers/nntp/camel-nntp-store.c + (nntp_store_unsubscribe_folder): remove the leading '/'. (nntp_store_subscribe_folder): same. (nntp_store_folder_subscribed): same. diff --git a/camel/providers/imap/camel-imap-command.c b/camel/providers/imap/camel-imap-command.c index ea1f3aa..7a6045d 100644 --- a/camel/providers/imap/camel-imap-command.c +++ b/camel/providers/imap/camel-imap-command.c @@ -170,6 +170,15 @@ imap_read_response (CamelImapStore *store, CamelException *ex) g_free (respbuf); goto next; } + } else { + p = imap_next_word (respbuf); + if (!g_strncasecmp (p, "BYE", 3)) { + /* connection was lost, no more data to fetch */ + store->connected = FALSE; + g_free (respbuf); + respbuf = NULL; + break; + } } g_ptr_array_add (response->untagged, respbuf); @@ -187,7 +196,7 @@ imap_read_response (CamelImapStore *store, CamelException *ex) if (expunged) g_array_free (expunged, TRUE); - if (camel_exception_is_set (ex)) { + if (!respbuf || camel_exception_is_set (ex)) { camel_imap_response_free (response); return NULL; } diff --git a/camel/providers/imap/camel-imap-store.c b/camel/providers/imap/camel-imap-store.c index a561cab..6ad4810 100644 --- a/camel/providers/imap/camel-imap-store.c +++ b/camel/providers/imap/camel-imap-store.c @@ -108,11 +108,13 @@ camel_imap_store_init (gpointer object, gpointer klass) CAMEL_SERVICE_URL_NEED_HOST | CAMEL_SERVICE_URL_ALLOW_PATH | CAMEL_SERVICE_URL_ALLOW_AUTH); - + remote_store->default_port = 143; imap_store->dir_sep = NULL; imap_store->current_folder = NULL; + + imap_store->connected = FALSE; } CamelType @@ -259,6 +261,9 @@ imap_connect (CamelService *service, CamelException *ex) } } + /* At this point we know we're connected... */ + store->connected = TRUE; + /* Now lets find out the IMAP capabilities */ response = camel_imap_command (store, NULL, ex, "CAPABILITY"); if (!response) @@ -324,11 +329,13 @@ imap_disconnect (CamelService *service, CamelException *ex) { CamelImapStore *store = CAMEL_IMAP_STORE (service); CamelImapResponse *response; - - /* send the logout command */ - response = camel_imap_command (store, NULL, ex, "LOGOUT"); - camel_imap_response_free (response); - + + if (store->connected) { + /* send the logout command */ + response = camel_imap_command (store, NULL, ex, "LOGOUT"); + camel_imap_response_free (response); + } + g_free (store->dir_sep); store->dir_sep = NULL; @@ -416,7 +423,7 @@ static CamelFolder * get_folder (CamelStore *store, const char *folder_name, gboolean create, CamelException *ex) { CamelImapStore *imap_store = CAMEL_IMAP_STORE (store); - CamelFolder *new_folder; + CamelFolder *new_folder = NULL; char *folder_path, *summary_file, *p; gboolean selectable; @@ -554,8 +561,8 @@ get_folder_info (CamelStore *store, const char *top, gboolean fast, if (!topfi) { camel_exception_clear (ex); topfi = g_new0 (CamelFolderInfo, 1); - fi->full_name = g_strdup (namespace); - fi->name = g_strdup (namespace); + topfi->full_name = g_strdup (namespace); + topfi->name = g_strdup (namespace); } response = camel_imap_command (imap_store, NULL, ex, diff --git a/camel/providers/imap/camel-imap-store.h b/camel/providers/imap/camel-imap-store.h index a211457..3c492c5 100644 --- a/camel/providers/imap/camel-imap-store.h +++ b/camel/providers/imap/camel-imap-store.h @@ -57,6 +57,8 @@ typedef struct { gboolean has_status_capability; gchar *dir_sep, *storage_path; + + gboolean connected; } CamelImapStore; -- 2.7.4