[evolution-data-server] Use LIST-EXTENDED to return subscribed status from LIST



commit 9445941f962f42cc513903a12d3036d9607bae4c
Author: David Woodhouse <David Woodhouse intel com>
Date:   Fri Jun 25 00:01:36 2010 +0100

    Use LIST-EXTENDED to return subscribed status from LIST
    
    If the server supports LIST-EXTENDED, we don't have to follow the initial
    LIST with an LSUB command to see which folders are subscribed -- we can
    just ask it to tell us the subscribed status in the LIST responses.

 camel/providers/imapx/camel-imapx-server.c |   10 +++++++++-
 camel/providers/imapx/camel-imapx-server.h |    1 +
 camel/providers/imapx/camel-imapx-store.c  |   26 ++++++++++++++++----------
 camel/providers/imapx/camel-imapx-utils.c  |    1 +
 4 files changed, 27 insertions(+), 11 deletions(-)
---
diff --git a/camel/providers/imapx/camel-imapx-server.c b/camel/providers/imapx/camel-imapx-server.c
index 7104bf4..a2f83ff 100644
--- a/camel/providers/imapx/camel-imapx-server.c
+++ b/camel/providers/imapx/camel-imapx-server.c
@@ -267,6 +267,7 @@ struct _CamelIMAPXJob {
 		struct {
 			gchar *pattern;
 			guint32 flags;
+			const gchar *ext;
 			GHashTable *folders;
 		} list;
 
@@ -3818,6 +3819,11 @@ imapx_job_list_start(CamelIMAPXServer *is, CamelIMAPXJob *job)
 	ic = camel_imapx_command_new(is, "LIST", NULL, "%s \"\" %s",
 				     (job->u.list.flags & CAMEL_STORE_FOLDER_INFO_SUBSCRIBED)?"LSUB":"LIST",
 				     job->u.list.pattern);
+	if (job->u.list.ext) {
+		/* Hm, we need a way to add atoms _without_ quoting or using literals */
+		camel_imapx_command_add(ic, " ");
+		camel_imapx_command_add(ic, job->u.list.ext);
+	}
 	ic->pri = job->pri;
 	ic->job = job;
 	ic->complete = imapx_command_list_done;
@@ -5066,7 +5072,8 @@ imapx_list_cmp(gconstpointer ap, gconstpointer bp)
 }
 
 GPtrArray *
-camel_imapx_server_list(CamelIMAPXServer *is, const gchar *top, guint32 flags, CamelException *ex)
+camel_imapx_server_list(CamelIMAPXServer *is, const gchar *top, guint32 flags,
+			const gchar *ext, CamelException *ex)
 {
 	CamelIMAPXJob *job;
 	GPtrArray *folders = NULL;
@@ -5079,6 +5086,7 @@ camel_imapx_server_list(CamelIMAPXServer *is, const gchar *top, guint32 flags, C
 	job->start = imapx_job_list_start;
 	job->pri = IMAPX_PRIORITY_LIST;
 	job->ex = ex;
+	job->u.list.ext = ext;
 	job->u.list.flags = flags;
 	job->u.list.folders = g_hash_table_new(imapx_name_hash, imapx_name_equal);
 	job->u.list.pattern = g_alloca(strlen(encoded_name)+5);
diff --git a/camel/providers/imapx/camel-imapx-server.h b/camel/providers/imapx/camel-imapx-server.h
index eb2aad8..0f63d94 100644
--- a/camel/providers/imapx/camel-imapx-server.h
+++ b/camel/providers/imapx/camel-imapx-server.h
@@ -142,6 +142,7 @@ gboolean	imapx_connect_to_server		(CamelIMAPXServer *is,
 GPtrArray *	camel_imapx_server_list		(CamelIMAPXServer *is,
 						 const gchar *top,
 						 guint32 flags,
+						 const gchar *ext,
 						 CamelException *ex);
 void		camel_imapx_server_refresh_info	(CamelIMAPXServer *is,
 						 CamelFolder *folder,
diff --git a/camel/providers/imapx/camel-imapx-store.c b/camel/providers/imapx/camel-imapx-store.c
index b03fdc6..af619b5 100644
--- a/camel/providers/imapx/camel-imapx-store.c
+++ b/camel/providers/imapx/camel-imapx-store.c
@@ -1006,11 +1006,11 @@ imapx_get_folders_free(gpointer k, gpointer v, gpointer d)
 }
 
 static void
-fetch_folders_for_pattern (CamelIMAPXStore *istore, const gchar *pattern, guint32 flags, GHashTable *table, CamelException *ex)
+fetch_folders_for_pattern (CamelIMAPXStore *istore, const gchar *pattern, guint32 flags, const gchar *ext, GHashTable *table, CamelException *ex)
 {
 	GPtrArray *folders = NULL;
 
-	folders = camel_imapx_server_list (istore->server, pattern, flags, ex);
+	folders = camel_imapx_server_list (istore->server, pattern, flags, ext, ex);
 	if (camel_exception_is_set (ex))
 		return;
 
@@ -1054,6 +1054,7 @@ fetch_folders_for_namespaces (CamelIMAPXStore *istore, const gchar *pattern, gbo
 		while (ns) {
 			guint32 flags = 0;
 			gchar *pat = NULL;
+			const gchar *list_ext = NULL;
 
 			if (!pattern) {
 				if (!*ns->path)
@@ -1066,20 +1067,25 @@ fetch_folders_for_namespaces (CamelIMAPXStore *istore, const gchar *pattern, gbo
 			if (sync)
 				flags |= CAMEL_STORE_FOLDER_INFO_SUBSCRIPTION_LIST;
 
+			if (istore->server->cinfo->capa & IMAPX_CAPABILITY_LIST_EXTENDED)
+				list_ext = "RETURN (SUBSCRIBED)";
+
 			flags |= CAMEL_STORE_FOLDER_INFO_RECURSIVE;
-			fetch_folders_for_pattern (istore, pat, flags, folders, ex);
+			fetch_folders_for_pattern (istore, pat, flags, list_ext, folders, ex);
 			if (camel_exception_is_set (ex)) {
 				g_free (pat);
 				goto exception;
 			}
-
-			flags |= CAMEL_STORE_FOLDER_INFO_SUBSCRIBED;
-			fetch_folders_for_pattern (istore, pat, flags, folders, ex);
-			if (camel_exception_is_set (ex)) {
-				g_free (pat);
-				goto exception;
+			if (!list_ext) {
+				/* If the server doesn't support LIST-EXTENDED then we have to
+				   issue LSUB to list the subscribed folders separately */
+				flags |= CAMEL_STORE_FOLDER_INFO_SUBSCRIBED;
+				fetch_folders_for_pattern (istore, pat, flags, NULL, folders, ex);
+				if (camel_exception_is_set (ex)) {
+					g_free (pat);
+					goto exception;
+				}
 			}
-
 			g_free (pat);
 
 			if (pattern)
diff --git a/camel/providers/imapx/camel-imapx-utils.c b/camel/providers/imapx/camel-imapx-utils.c
index e3f14f1..b7cbb26 100644
--- a/camel/providers/imapx/camel-imapx-utils.c
+++ b/camel/providers/imapx/camel-imapx-utils.c
@@ -1788,6 +1788,7 @@ static struct {
 	{ "\\NOSELECT", CAMEL_FOLDER_NOSELECT },
 	{ "\\MARKED", 1<< 16},
 	{ "\\UNMARKED", 1<< 17},
+	{ "\\SUBSCRIBED", CAMEL_FOLDER_SUBSCRIBED },
 };
 
 struct _list_info *



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]