[PATCH 16/18] Fix saving and loading of namespaces in the summary.



Fix saving and loading of namespaces in the summary.
---
 .../providers/imap/camel-imap-store-summary.c      |   19 ++--
 .../providers/imap/camel-imap-store-summary.h      |   14 ++-
.../camel/providers/imap/camel-imap-store.c | 98 ++++++++++++++++----
 3 files changed, 99 insertions(+), 32 deletions(-)

--
Rob Taylor, Codethink Ltd. - http://codethink.co.uk
diff --git a/libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-store-summary.c b/libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-store-summary.c
index f816e5a..eb5d6b1 100644
--- a/libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-store-summary.c
+++ b/libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-store-summary.c
@@ -96,7 +96,6 @@ camel_imap_store_summary_init (CamelImapStoreSummary *s)
 	((CamelStoreSummary *)s)->store_info_size = sizeof(CamelImapStoreInfo);
 	s->version = CAMEL_IMAP_STORE_SUMMARY_VERSION;
 	s->namespaces = NULL;
-	s->namespace = NULL;
 }
 
 static void
@@ -423,7 +422,7 @@ camel_imap_store_summary_full_from_path(CamelImapStoreSummary *s, const char *pa
 }
 
 /* TODO: this api needs some more work */
-CamelImapStoreNamespace *camel_imap_store_summary_namespace_new(CamelImapStoreSummary *s, const char *full_name, char dir_sep)
+CamelImapStoreNamespace *camel_imap_store_summary_namespace_new(CamelImapStoreSummary *s, const char *full_name, char dir_sep, CamelImapStoreNamespaceType type)
 {
 	CamelImapStoreNamespace *ns;
 	char *p, *o, c;
@@ -435,6 +434,7 @@ CamelImapStoreNamespace *camel_imap_store_summary_namespace_new(CamelImapStoreSu
 	if (len >= 0 && ns->full_name[len] == dir_sep)
 		ns->full_name[len] = 0;
 	ns->sep = dir_sep;
+	ns->type = type;
 
 	o = p = ns->path = camel_imap_store_summary_full_to_path(s, ns->full_name, dir_sep);
 	while ((c = *p++)) {
@@ -474,12 +474,6 @@ CamelImapStoreNamespace * camel_imap_store_summary_namespace_add(CamelImapStoreS
 	return ret;
 }
 
-void camel_imap_store_summary_namespace_set(CamelImapStoreSummary *s, CamelImapStoreNamespace *ns)
-{
-	s->namespace = ns;
-	return;
-}
-
 CamelImapStoreNamespace *
 camel_imap_store_summary_namespace_find_path(CamelImapStoreSummary *s, const char *path)
 {
@@ -569,6 +563,7 @@ namespace_load(CamelStoreSummary *s, FILE *in)
 
 	for (i=0 ; i< count; i++) {
 		guint32 sep = '/';
+		guint32 type = CAMEL_IMAP_STORE_NAMESPACE_TYPE_NONE;
 		ns = g_malloc0(sizeof(*ns));
 		if (camel_file_util_decode_string(in, &ns->path) == -1) {
 			namespace_free(s, ns);
@@ -583,6 +578,11 @@ namespace_load(CamelStoreSummary *s, FILE *in)
 			goto nserror;
 		}
 		ns->sep = sep;
+		if (camel_file_util_decode_uint32(in, &type) == -1) {
+			namespace_free(s, ns);
+			goto nserror;
+		}
+		ns->type = type;
 		is->namespaces = g_list_prepend (is->namespaces, ns);
 	}
 
@@ -617,6 +617,9 @@ namespace_save(CamelStoreSummary *s, FILE *in)
 		if (camel_file_util_encode_uint32(in, (guint32)ns->sep) == -1)
 			goto serr;
 
+		if (camel_file_util_encode_uint32(in, (guint32)ns->type) == -1)
+			goto serr;
+
 		list = list->next;
 	}
 
diff --git a/libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-store-summary.h b/libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-store-summary.h
index e886736..a9b7a74 100644
--- a/libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-store-summary.h
+++ b/libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-store-summary.h
@@ -42,6 +42,13 @@ enum {
 	CAMEL_IMAP_STORE_INFO_LAST
 };
 
+typedef enum _CamelImapStoreNamespaceType {
+	CAMEL_IMAP_STORE_NAMESPACE_TYPE_NONE,
+	CAMEL_IMAP_STORE_NAMESPACE_TYPE_PERSONAL,
+	CAMEL_IMAP_STORE_NAMESPACE_TYPE_OTHER,
+	CAMEL_IMAP_STORE_NAMESPACE_TYPE_SHARED
+} CamelImapStoreNamespaceType;
+
 struct _CamelImapStoreInfo {
 	CamelStoreInfo info;
 	char *full_name;
@@ -53,6 +60,7 @@ struct _CamelImapStoreNamespace {
 	char *path;		/* display path */
 	char *full_name;	/* real name */
 	char sep;		/* directory separator */
+	CamelImapStoreNamespaceType type; /* type of namespace */
 };
 
 struct _CamelImapStoreSummary {
@@ -63,8 +71,7 @@ struct _CamelImapStoreSummary {
 	/* header info */
 	guint32 version;	/* version of base part of file */
 	guint32 capabilities;
-	GList *namespaces; /* eventually to be a list */
-	CamelImapStoreNamespace *namespace;
+	GList *namespaces; /*list of CamelImapStoreNamespace */
 };
 
 struct _CamelImapStoreSummaryClass {
@@ -75,8 +82,7 @@ CamelType			 camel_imap_store_summary_get_type	(void);
 CamelImapStoreSummary      *camel_imap_store_summary_new	(void);
 
 /* TODO: this api needs some more work, needs to support lists */
-CamelImapStoreNamespace *camel_imap_store_summary_namespace_new(CamelImapStoreSummary *s, const char *full_name, char dir_sep);
-void camel_imap_store_summary_namespace_set(CamelImapStoreSummary *s, CamelImapStoreNamespace *ns);
+CamelImapStoreNamespace *camel_imap_store_summary_namespace_new(CamelImapStoreSummary *s, const char *full_name, char dir_sep, CamelImapStoreNamespaceType type);
 CamelImapStoreNamespace *camel_imap_store_summary_namespace_add(CamelImapStoreSummary *s, CamelImapStoreNamespace *ns);
 CamelImapStoreNamespace *camel_imap_store_summary_namespace_find_path(CamelImapStoreSummary *s, const char *path);
 CamelImapStoreNamespace *camel_imap_store_summary_namespace_find_full(CamelImapStoreSummary *s, const char *full_name);
diff --git a/libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-store.c b/libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-store.c
index 96d59e9..5c720f3 100644
--- a/libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-store.c
+++ b/libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-store.c
@@ -595,7 +595,61 @@ construct (CamelService *service, CamelSession *session,
 	if (camel_store_summary_load((CamelStoreSummary *)imap_store->summary) == 0) {
 		CamelImapStoreSummary *is = imap_store->summary;
 
-		if (is->namespace) {
+		imap_store->capabilities = is->capabilities;
+		imap_set_server_level(imap_store);
+
+		if ((imap_store->capabilities & IMAP_CAPABILITY_NAMESPACE) &&
+			!(imap_store->parameters & IMAP_PARAM_OVERRIDE_NAMESPACE))
+		{
+			CamelImapStoreNamespace *ns;
+			GList *lst = is->namespaces;
+
+			imap_store->namespaces = g_new0 (struct _namespaces, 1);
+
+			/* down in imap_connect_online we added the name spaces in the order:
+			 * personal
+			 * other
+			 * shared
+			 * so go through them backwards. This is all a bunch of crap.
+			 */
+			while (lst) {
+				struct _namespace **namespace = NULL;
+
+				ns = lst->data;
+				switch (ns->type) {
+					case CAMEL_IMAP_STORE_NAMESPACE_TYPE_NONE:
+						break;
+					case CAMEL_IMAP_STORE_NAMESPACE_TYPE_PERSONAL:
+						namespace = &imap_store->namespaces->personal;
+						break;
+					case CAMEL_IMAP_STORE_NAMESPACE_TYPE_OTHER:
+						namespace = &imap_store->namespaces->other;
+						break;
+					case CAMEL_IMAP_STORE_NAMESPACE_TYPE_SHARED:
+						namespace = &imap_store->namespaces->shared;
+						break;
+				}
+				if (namespace) {
+					struct _namespace *old = *namespace;
+					*namespace = g_new (struct _namespace, 1);
+					(*namespace)->prefix = strdup(ns->full_name);
+					(*namespace)->delim = ns->sep;
+					(*namespace)->next = old;
+				}
+				lst = lst->next;
+			}
+
+			if (imap_store->namespaces && imap_store->namespaces->personal) {
+				imap_store->namespace = imap_store->namespaces->personal->prefix;
+				imap_store->dir_sep = imap_store->namespaces->personal->delim;
+			} else {
+				imap_store->namespace = NULL;
+				imap_store->dir_sep = 0;
+			}
+
+		}
+#if 0
+		else if (is->namespace) {
 			/* if namespace has changed, clear folder list */
 			if (imap_store->namespace && strcmp(imap_store->namespace, is->namespace->full_name) != 0) {
 				camel_store_summary_clear((CamelStoreSummary *)is);
@@ -604,9 +658,9 @@ construct (CamelService *service, CamelSession *session,
 				imap_store->dir_sep = is->namespace->sep;
 			}
 		}
+#endif
+
 
-		imap_store->capabilities = is->capabilities;
-		imap_set_server_level(imap_store);
 	}
 	g_static_rec_mutex_unlock (imap_store->sum_lock);
 
@@ -1903,6 +1957,19 @@ can_work_offline (CamelDiscoStore *disco_store)
 	return camel_store_summary_count((CamelStoreSummary *)store->summary) != 0;
 }
 
+
+static void
+save_namespace_in_summary (CamelImapStore *store, struct _namespace *namespace, CamelImapStoreNamespaceType type)
+{
+	CamelImapStoreNamespace *ns;
+	while (namespace) {
+		ns = camel_imap_store_summary_namespace_new(store->summary, namespace->prefix, namespace->delim, type);
+		ns = camel_imap_store_summary_namespace_add(store->summary,ns);
+
+		namespace = namespace->next;
+	}
+}
+
 static gboolean
 imap_connect_online (CamelService *service, CamelException *ex)
 {
@@ -1957,6 +2024,9 @@ imap_connect_online (CamelService *service, CamelException *ex)
 		if (!result)
 			goto done;
 
+		if (store->namespaces)
+			imap_namespaces_destroy (store->namespaces);
+
 		store->namespaces = imap_parse_namespace_response (result);
 		namespaces = store->namespaces;
 
@@ -1968,28 +2038,16 @@ imap_connect_online (CamelService *service, CamelException *ex)
 			store->dir_sep = 0;
 		}
 
-		if (namespaces && namespaces->personal) {
-			ns = camel_imap_store_summary_namespace_new(store->summary, namespaces->personal->prefix, namespaces->personal->delim);
-			ns = camel_imap_store_summary_namespace_add(store->summary,ns);
-			camel_imap_store_summary_namespace_set(store->summary, ns);
-		}
-
-		if (namespaces && namespaces->other) {
-			ns = camel_imap_store_summary_namespace_new(store->summary, namespaces->other->prefix, namespaces->other->delim);
-			ns = camel_imap_store_summary_namespace_add(store->summary,ns);
+		if (namespaces) {
+			save_namespace_in_summary (store, namespaces->personal, CAMEL_IMAP_STORE_NAMESPACE_TYPE_PERSONAL);
+			save_namespace_in_summary (store, namespaces->other, CAMEL_IMAP_STORE_NAMESPACE_TYPE_OTHER);
+			save_namespace_in_summary (store, namespaces->shared, CAMEL_IMAP_STORE_NAMESPACE_TYPE_SHARED);
 		}
 
-		if (namespaces && namespaces->shared) {
-			ns = camel_imap_store_summary_namespace_new(store->summary, namespaces->shared->prefix, namespaces->shared->delim);
-			ns = camel_imap_store_summary_namespace_add(store->summary,ns);
-		}
-
-
 		g_free (result);
 	} else {
-		ns = camel_imap_store_summary_namespace_new(store->summary, store->namespace, store->dir_sep);
+		ns = camel_imap_store_summary_namespace_new(store->summary, store->namespace, store->dir_sep, CAMEL_IMAP_STORE_NAMESPACE_TYPE_NONE);
 		camel_imap_store_summary_namespace_add(store->summary,ns);
-		camel_imap_store_summary_namespace_set(store->summary, ns);
 	}
 
 	if (store->namespace && strlen (store->namespace) == 0)



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