From 7acecd99c9998ff09bf561c211f2d3d566d384c9 Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Wed, 13 Sep 2000 22:13:09 +0000 Subject: Rewrote to take a third argument (gboolean *selectable) so that we can 2000-09-13 Jeffrey Stedfast * providers/imap/camel-imap-store.c (imap_folder_exists): Rewrote to take a third argument (gboolean *selectable) so that we can find out if the folder is selectable or not as we look to see if it exists. Also, don't use EXAMINE because that will not work on non-selectable folders, so use LIST instead. (get_folder): Check to see if the folder exists even vefore calling imap_create as this will save time. If the folder does exist, find out if it's selectable. Moved the call to refresh_info here. * providers/imap/camel-imap-folder.c (imap_get_uids): Check for a NULL summary. (camel_imap_folder_new): Don't call refresh_info here - call it in get_folder() because we don't know if this folder even exists on the server yet! And even if it does, we don't know if it can hold messages or not yet. svn path=/trunk/; revision=5412 --- camel/providers/imap/camel-imap-folder.c | 13 ++-- camel/providers/imap/camel-imap-store.c | 103 ++++++++++++++++++++++++++----- 2 files changed, 95 insertions(+), 21 deletions(-) (limited to 'camel/providers') diff --git a/camel/providers/imap/camel-imap-folder.c b/camel/providers/imap/camel-imap-folder.c index 5b55f6bf9a..643587bbe7 100644 --- a/camel/providers/imap/camel-imap-folder.c +++ b/camel/providers/imap/camel-imap-folder.c @@ -195,17 +195,17 @@ camel_imap_folder_new (CamelStore *parent, char *folder_name, CamelException *ex camel_object_unref (CAMEL_OBJECT (folder)); return NULL; } - + if (!strcmp (folder_name, url->path + 1)) folder->can_hold_messages = FALSE; - CF_CLASS (folder)->refresh_info (folder, ex); - + /*CF_CLASS (folder)->refresh_info (folder, ex);*/ + if (camel_exception_is_set (ex)) { camel_object_unref (CAMEL_OBJECT (folder)); return NULL; } - + return folder; } @@ -531,7 +531,7 @@ imap_get_unread_message_count (CamelFolder *folder) if (!imap_folder->summary) return 0; - infolist = imap_get_summary (folder); + infolist = imap_folder->summary; for (i = 0; i < infolist->len; i++) { info = (CamelMessageInfo *) g_ptr_array_index (infolist, i); @@ -679,7 +679,8 @@ imap_get_uids (CamelFolder *folder) gint i, count; infolist = imap_get_summary (folder); - count = infolist->len; + + count = infolist ? infolist->len : 0; array = g_ptr_array_new (); g_ptr_array_set_size (array, count); diff --git a/camel/providers/imap/camel-imap-store.c b/camel/providers/imap/camel-imap-store.c index 5ffdd51d4b..209b8a6fbb 100644 --- a/camel/providers/imap/camel-imap-store.c +++ b/camel/providers/imap/camel-imap-store.c @@ -319,6 +319,64 @@ camel_imap_store_get_toplevel_dir (CamelImapStore *store) return url->path; } +static gboolean +imap_folder_exists (CamelFolder *folder, gboolean *selectable, CamelException *ex) +{ + CamelStore *store = CAMEL_STORE (folder->parent_store); + CamelURL *url = CAMEL_SERVICE (store)->url; + gchar *result, *folder_path, *dir_sep; + char *flags, *sep, *dirname; + gint status; + + dir_sep = CAMEL_IMAP_STORE (folder->parent_store)->dir_sep; + + g_return_val_if_fail (dir_sep, FALSE); + + if (url && url->path && *(url->path + 1) && g_strcasecmp (folder->full_name, "INBOX")) + folder_path = g_strdup_printf ("%s%s%s", url->path + 1, dir_sep, folder->full_name); + else + folder_path = g_strdup (folder->full_name); + + if (!g_strcasecmp (folder_path, "INBOX")) { + g_free (folder_path); + if (selectable) + *selectable = TRUE; + return TRUE; + } + + /* it's always gonna be FALSE unless it's true - how's that for a comment? ;-) */ + if (selectable) + *selectable = FALSE; + + status = camel_imap_command_extended (CAMEL_IMAP_STORE (store), NULL, + &result, ex, "LIST \"\" %s", folder_path); + + g_free (folder_path); + + if (status != CAMEL_IMAP_OK) { + g_free (result); + return FALSE; + } + + if (imap_parse_list_response (result, "", &flags, &sep, &dirname)) { + if (selectable) + *selectable = !e_strstrcase (flags, "NoSelect"); + + g_free (flags); + g_free (sep); + g_free (dirname); + + return TRUE; + } + + g_free (flags); + g_free (sep); + g_free (dirname); + + return FALSE; +} + +#if 0 static gboolean imap_folder_exists (CamelFolder *folder, CamelException *ex) { @@ -331,7 +389,7 @@ imap_folder_exists (CamelFolder *folder, CamelException *ex) g_return_val_if_fail (dir_sep, FALSE); - if (url && url->path && *(url->path + 1) && strcmp (folder->full_name, "INBOX")) + if (url && url->path && *(url->path + 1) && g_strcasecmp (folder->full_name, "INBOX")) folder_path = g_strdup_printf ("%s%s%s", url->path + 1, dir_sep, folder->full_name); else folder_path = g_strdup (folder->full_name); @@ -348,6 +406,7 @@ imap_folder_exists (CamelFolder *folder, CamelException *ex) return TRUE; } +#endif static gboolean imap_create (CamelFolder *folder, CamelException *ex) @@ -365,10 +424,10 @@ imap_create (CamelFolder *folder, CamelException *ex) return FALSE; } - if (!strcmp (folder->full_name, "INBOX")) + if (!g_strcasecmp (folder->full_name, "INBOX")) return TRUE; - if (imap_folder_exists (folder, ex)) + if (imap_folder_exists (folder, NULL, ex)) return TRUE; /* create the directory for the subfolder */ @@ -376,7 +435,7 @@ imap_create (CamelFolder *folder, CamelException *ex) g_return_val_if_fail (dir_sep, FALSE); - if (url && url->path && *(url->path + 1) && strcmp (folder->full_name, "INBOX")) + if (url && url->path && *(url->path + 1) && g_strcasecmp (folder->full_name, "INBOX")) folder_path = g_strdup_printf ("%s%s%s", url->path + 1, dir_sep, folder->full_name); else folder_path = g_strdup (folder->full_name); @@ -391,13 +450,14 @@ imap_create (CamelFolder *folder, CamelException *ex) return TRUE; } +#if 0 static gboolean folder_is_selectable (CamelStore *store, const char *folder_path, CamelException *ex) { char *result, *flags, *sep, *folder; int status; - if (!strcmp (folder_path, "INBOX")) + if (!g_strcasecmp (folder_path, "INBOX")) return TRUE; status = camel_imap_command_extended (CAMEL_IMAP_STORE (store), NULL, @@ -421,6 +481,7 @@ folder_is_selectable (CamelStore *store, const char *folder_path, CamelException return FALSE; } +#endif static CamelFolder * get_folder (CamelStore *store, const char *folder_name, gboolean create, CamelException *ex) @@ -428,6 +489,8 @@ get_folder (CamelStore *store, const char *folder_name, gboolean create, CamelEx CamelURL *url = CAMEL_SERVICE (store)->url; CamelFolder *new_folder; char *folder_path, *dir_sep; + gboolean exists = FALSE; + gboolean selectable; g_return_val_if_fail (store != NULL, NULL); g_return_val_if_fail (folder_name != NULL, NULL); @@ -444,23 +507,33 @@ get_folder (CamelStore *store, const char *folder_name, gboolean create, CamelEx if (camel_exception_is_set (ex)) return NULL; - + /* this is the top-level dir, we already know it exists - it has to! */ - if (!strcmp (folder_name, dir_sep)) + if (!strcmp (folder_name, dir_sep)) { + camel_folder_refresh_info (new_folder, ex); return new_folder; + } - if (create && !imap_create (new_folder, ex)) { - if (!folder_is_selectable (store, folder_path, ex)) { + if (imap_folder_exists (new_folder, &selectable, ex)) { + /* ah huh, so the folder *does* exist... */ + exists = TRUE; + + /* now lets see if it's selectable... */ + if (!selectable) { camel_exception_clear (ex); new_folder->can_hold_messages = FALSE; - return new_folder; - } else { - g_free (folder_path); - camel_object_unref (CAMEL_OBJECT (new_folder)); - return NULL; } } + if (!exists && create && !imap_create (new_folder, ex)) { + g_free (folder_path); + camel_object_unref (CAMEL_OBJECT (new_folder)); + return NULL; + } + + /* this is where we *should refresh_info, not in imap_folder_new() */ + camel_folder_refresh_info (new_folder, ex); + return new_folder; } @@ -535,7 +608,7 @@ check_current_folder (CamelImapStore *store, CamelFolder *folder, char *fmt, Cam dir_sep = store->dir_sep; - if (url && url->path && *(url->path + 1) && strcmp (folder->full_name, "INBOX")) + if (url && url->path && *(url->path + 1) && g_strcasecmp (folder->full_name, "INBOX")) folder_path = g_strdup_printf ("%s%s%s", url->path + 1, dir_sep, folder->full_name); else folder_path = g_strdup (folder->full_name); -- cgit v1.2.3