Re: [Fwd: First attempt at support for NAMESPACE]



Hi guys,

This is a cleaned up version of that patch.

I hope people will test this, a lot.

It would be very nice to have this in the first release, but the amount
of code that I changed and that can be tricky among different IMAP
servers is large enough to be a (little) bit worried.

(any change is enough to be a little bit worried, nowadays :p)


On Fri, 2007-12-21 at 00:26 +0100, Philip Van Hoof wrote:
> email message attachment, "Forwarded message - First attempt at
> support for NAMESPACE"
> > -------- Forwarded Message --------
> > From: Philip Van Hoof <spam pvanhoof be>
> > To: Evolution Hackers <Evolution-hackers gnome org>
> > Cc: Matthew Barnes <mbarnes redhat com>
> > Subject: First attempt at support for NAMESPACE
> > Date: Fri, 21 Dec 2007 00:26:11 +0100
> > 
> > Here's a first attempt. This is not a official patch proposal because it
> > ain't finished yet (I made quite a few shortcuts in the code, and I need
> > to cleanup some stuff too).
> > 
> > http://pvanhoof.be/files/camel-lite-shared-folders.diff
> > 
> > ps. NAMESPACE means: support for company-wide shared folders.
> > ps. I'm using `LIST "" *', this is indeed not a good idea. I also have
> > the list of namespaces in a parsed way, so I can ask the folder lists in
> > a better way too .. (as I said, shortcuts in the code).
> > 
> > 
> _______________________________________________
> tinymail-devel-list mailing list
> tinymail-devel-list gnome org
> http://mail.gnome.org/mailman/listinfo/tinymail-devel-list
-- 
Philip Van Hoof, freelance software developer
home: me at pvanhoof dot be 
gnome: pvanhoof at gnome dot org 
http://pvanhoof.be/blog
http://codeminded.be



Index: libtinymail-camel/camel-lite/camel/camel-store.c
===================================================================
--- libtinymail-camel/camel-lite/camel/camel-store.c	(revision 3166)
+++ libtinymail-camel/camel-lite/camel/camel-store.c	(working copy)
@@ -1044,6 +1044,7 @@
 				camel_url_set_param (url, "noselect", "yes");
 				pfi->uri = camel_url_to_string (url, 0);
 				camel_url_free (url);
+				pfi->flags |= CAMEL_FOLDER_SUBSCRIBED | CAMEL_FOLDER_NOSELECT;
 
 				g_hash_table_insert (hash, pname, pfi);
 				g_ptr_array_add (folders, pfi);
Index: libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-store.c
===================================================================
--- libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-store.c	(revision 3166)
+++ libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-store.c	(working copy)
@@ -415,6 +415,9 @@
 		disco->diary = NULL;
 	}
 
+	if (imap_store->namespaces)
+		imap_namespaces_destroy (imap_store->namespaces);
+
 	/* g_static_rec_mutex_free (imap_store->idle_prefix_lock); */
 	g_free (imap_store->idle_prefix_lock);
 	imap_store->idle_prefix_lock = NULL;
@@ -1863,6 +1866,8 @@
 	if ((store->capabilities & IMAP_CAPABILITY_NAMESPACE) &&
 		!(store->parameters & IMAP_PARAM_OVERRIDE_NAMESPACE))
 	{
+		struct _namespaces *namespaces;
+
 		response = camel_imap_command (store, NULL, ex, "NAMESPACE");
 		if (!response)
 			goto done;
@@ -1871,34 +1876,43 @@
 		if (!result)
 			goto done;
 
-#if 0
-		/* new code... */
-		namespaces = imap_parse_namespace_response (result);
-		imap_namespaces_destroy (namespaces);
-		/* end new code */
-#endif
+		store->namespaces = imap_parse_namespace_response (result);
+		namespaces = store->namespaces;
 
-		name = camel_strstrcase (result, "NAMESPACE ((");
-		if (name) {
-			char *sep;
+		if (namespaces && namespaces->personal) {
+			store->namespace = namespaces->personal->prefix;
+			store->dir_sep = namespaces->personal->delim;
+		} else {
+			store->namespace = NULL;
+			store->dir_sep = 0;
+		}
 
-			name += 12;
-			store->namespace = imap_parse_string ((const char **) &name, &len);
-			if (name && *name++ == ' ') {
-				sep = imap_parse_string ((const char **) &name, &len);
-				if (sep) {
-					store->dir_sep = *sep;
-					g_free (sep);
-				}
-			}
+		if (namespaces && namespaces->personal) {
+			ns = camel_imap_store_summary_namespace_new(store->summary, namespaces->personal->prefix, namespaces->personal->delim);
+			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);
+			camel_imap_store_summary_namespace_add(store->summary,ns);
+		}
+
+		if (namespaces && namespaces->shared) {
+			ns = camel_imap_store_summary_namespace_new(store->summary, namespaces->shared->prefix, namespaces->shared->delim);
+			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);
+		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) {
-		g_free (store->namespace);
+	if (store->namespace && strlen (store->namespace) == 0)
 		store->namespace = NULL;
-	}
 
 	if (store->namespace && !store->dir_sep) {
 		if (FALSE && store->server_level >= IMAP_LEVEL_IMAP4REV1) {
@@ -1938,7 +1952,6 @@
 	len = strlen (store->namespace);
 	if (len && store->namespace[len - 1] != store->dir_sep) {
 		gchar *tmp;
-
 		tmp = g_strdup_printf ("%s%c", store->namespace, store->dir_sep);
 		g_free (store->namespace);
 		store->namespace = tmp;
@@ -1946,8 +1959,6 @@
 
 	g_static_rec_mutex_lock (store->sum_lock);
 
-	ns = camel_imap_store_summary_namespace_new(store->summary, store->namespace, store->dir_sep);
-	camel_imap_store_summary_namespace_set(store->summary, ns);
 
 	if ((store->parameters & IMAP_PARAM_SUBSCRIPTIONS)
 	    && camel_store_summary_count((CamelStoreSummary *)store->summary) == 0)
@@ -2054,10 +2065,8 @@
 		store->authtypes = NULL;
 	}
 
-	if (store->namespace && !(store->parameters & IMAP_PARAM_OVERRIDE_NAMESPACE)) {
-		g_free (store->namespace);
+	if (store->namespace && !(store->parameters & IMAP_PARAM_OVERRIDE_NAMESPACE))
 		store->namespace = NULL;
-	}
 
 	return TRUE;
 }
@@ -2452,106 +2461,7 @@
 	return (CamelMessageInfo *) mi;
 }
 
-GPtrArray*
-_camel_imap_store_get_recent_messages (CamelImapStore *imap_store, const char *folder_name, int *unseen, int *messages, gboolean withthem)
-{
-	guint32 uidnext=-1;
-	struct imap_status_item *items, *item;
-	guint ounseen, omessages, ouidnext;
-	GPtrArray *retval = NULL;
-	CamelException ex = CAMEL_EXCEPTION_INITIALISER;
-	CamelImapResponse *response;
-	CamelException tex = CAMEL_EXCEPTION_INITIALISER;
 
-	if (!camel_disco_store_check_online (CAMEL_DISCO_STORE (imap_store), &ex))
-		return NULL;
-
-/*
-      Example:    C: A042 STATUS blurdybloop (UIDNEXT MESSAGES)
-                  S: * STATUS blurdybloop (MESSAGES 231 UIDNEXT 44292)
-                  S: A042 OK STATUS completed
-*/
-
-	camel_operation_uncancel (NULL);
-
-
-	/* On for example courier, the selected's STATUS is cached (kill that cache) */
-	if (withthem)
-	{
-	    response = camel_imap_command (imap_store, NULL, &tex,
-			    "SELECT"/*, folder_name*/);
-
-printf ("SELECT %s\n", folder_name);
-
-	    if (response)
-		    camel_imap_response_free (imap_store, response);
-	}
-
-	item = items = get_folder_status (imap_store, folder_name, "MESSAGES UNSEEN UIDNEXT", FALSE);
-	while (item != NULL) {
-		if (!g_ascii_strcasecmp (item->name, "MESSAGES"))
-			*messages = item->value;
-		if (!g_ascii_strcasecmp (item->name, "UNSEEN"))
-			*unseen = item->value;
-		if (!g_ascii_strcasecmp (item->name, "UIDNEXT"))
-			uidnext = item->value;
-		item = item->next;
-	}
-	imap_status_item_free (items);
-printf ("%d %d %d\n", *messages, *unseen, uidnext);
-
-	if (withthem)
-	{
-		camel_imap_store_get_status_for (imap_store, folder_name, &omessages, &ounseen, &ouidnext);
-
-		if (ouidnext != uidnext)
-		{
-			CamelImapResponseType type;
-			char *resp;
-
-			camel_exception_clear (&tex);
-
-			if (!camel_imap_command_start (imap_store, NULL, &tex,
-				"UID FETCH %d:* (FLAGS RFC822.SIZE INTERNALDATE BODY.PEEK[HEADER])", ouidnext-1))
-				goto done;
-
-			while ((type = camel_imap_command_response (imap_store, &resp, &tex))
-				== CAMEL_IMAP_RESPONSE_UNTAGGED)
-			{
-			   if (resp)
-			   {
-				CamelMessageInfo *mi = parse_message_header (resp);
-				g_free (resp);
-
-				if (mi)
-				{
-					if (retval == NULL)
-						retval = g_ptr_array_new ();
-					g_ptr_array_add (retval, mi);
-				}
-			   }
-			}
-
-			/* Restore the original folder selection */
-			if (imap_store->current_folder != NULL && imap_store->current_folder->full_name != NULL)
-			{
-				response = camel_imap_command (imap_store, NULL, &tex,
-						"SELECT %F", imap_store->current_folder->full_name);
-				if (response)
-					camel_imap_response_free (imap_store, response);
-			}
-		}
-	}
-
-done:
-
-	camel_imap_store_set_status_for (imap_store, folder_name, *messages, *unseen, uidnext);
-
-	camel_imap_store_start_idle (imap_store);
-
-	return retval;
-}
-
 static void
 imap_get_folder_status (CamelStore *store, const char *folder_name, int *unseen, int *messages, int *uidnext)
 {
@@ -3445,12 +3355,6 @@
 	if (imap_store->capabilities & IMAP_CAPABILITY_LISTEXT)
 		loops = 1;
 
-	/* We do a LIST followed by LSUB, and merge the results.  LSUB may not be a strict
-	   subset of LIST for some servers, so we can't use either or separately */
-
-	/* TNY TODO! It used to loop until 2, but I think it's just wrong to
-	   merge with LSUB?! (It doesn't make any sense) */
-
 	present = g_hash_table_new(folder_hash, folder_eq);
 
 	for (j = 0; j < loops; j++) {
@@ -3465,6 +3369,7 @@
 			response = camel_imap_command (imap_store, NULL, ex,
 				"%s \"\" %G", j==1 ? "LSUB" : "LIST",
 				pattern);
+
 		if (!response)
 			goto fail;
 
@@ -3473,19 +3378,6 @@
 			fi = parse_list_response_as_folder_info (imap_store, list);
 
 			if (fi) {
-				if (FALSE && j == 0) {
-					struct imap_status_item *item, *items;
-					item = items = get_folder_status (imap_store, fi->full_name, "MESSAGES UNSEEN", TRUE);
-					while (item != NULL) {
-						if (!g_ascii_strcasecmp (item->name, "MESSAGES"))
-							fi->total = item->value;
-						if (!g_ascii_strcasecmp (item->name, "UNSEEN"))
-							fi->unread = item->value;
-						item = item->next;
-					}
-					imap_status_item_free (items);
-				}
-
 				if (fi->flags & CAMEL_FOLDER_NONEXISTENT) {
 					camel_folder_info_free(fi);
 					continue;
@@ -3497,7 +3389,6 @@
 
 					if (j == 1) {
 						/* It's in LSUB but not in LIST? */
-
 						fi->flags |= CAMEL_FOLDER_SUBSCRIBED;
 						if ((fi->flags & (CAMEL_IMAP_FOLDER_MARKED | CAMEL_IMAP_FOLDER_UNMARKED)))
 							imap_store->capabilities |= IMAP_CAPABILITY_useful_lsub;
@@ -3514,12 +3405,10 @@
 						fi->flags |= CAMEL_FOLDER_SUBSCRIBED;
 						hfi->flags |= CAMEL_STORE_INFO_FOLDER_SUBSCRIBED;
 					}
-					if (j == 0)
-					{
+					if (j == 0) {
 						hfi->unread = fi->unread;
 						hfi->total = fi->total;
 					}
-					camel_folder_info_free(fi);
 				}
 			}
 		}
@@ -3613,60 +3502,7 @@
 	g_free (folder_dir);
 }
 
-struct _refresh_msg {
-	CamelSessionThreadMsg msg;
 
-	CamelStore *store;
-	CamelException ex;
-};
-
-static void
-refresh_refresh(CamelSession *session, CamelSessionThreadMsg *msg)
-{
-	struct _refresh_msg *m = (struct _refresh_msg *)msg;
-	CamelImapStore *store = (CamelImapStore *)m->store;
-	CamelException nex = CAMEL_EXCEPTION_INITIALISER;
-
-	CAMEL_SERVICE_REC_LOCK(m->store, connect_lock);
-
-	if (!camel_disco_store_check_online((CamelDiscoStore *)m->store, &m->ex))
-		goto done;
-
-	if (store->namespace && store->namespace[0]) {
-		char *pattern;
-
-		get_folders_sync(store, "INBOX", &m->ex);
-		if (camel_exception_is_set(&m->ex))
-			goto done;
-		get_folders_sync(store, store->namespace, &m->ex);
-		if (camel_exception_is_set(&m->ex))
-			goto done;
-		pattern = imap_concat(store, store->namespace, "*");
-		get_folders_sync(store, pattern, &m->ex);
-		g_free(pattern);
-	} else {
-		get_folders_sync((CamelImapStore *)m->store, "*", &m->ex);
-	}
-	camel_store_summary_touch((CamelStoreSummary *)((CamelImapStore *)m->store)->summary);
-	camel_store_summary_save((CamelStoreSummary *)((CamelImapStore *)m->store)->summary, &nex);
-done:
-	CAMEL_SERVICE_REC_UNLOCK(m->store, connect_lock);
-}
-
-static void
-refresh_free(CamelSession *session, CamelSessionThreadMsg *msg)
-{
-	struct _refresh_msg *m = (struct _refresh_msg *)msg;
-
-	camel_object_unref(m->store);
-	camel_exception_clear(&m->ex);
-}
-
-static CamelSessionThreadOps refresh_ops = {
-	refresh_refresh,
-	refresh_free,
-};
-
 static CamelFolderInfo *
 get_folder_info_online (CamelStore *store, const char *top, guint32 flags, CamelException *ex)
 {
@@ -3675,10 +3511,6 @@
 
 	g_static_rec_mutex_lock (imap_store->sum_lock);
 
-	/* If we have a list of folders already, use that, but if we haven't
-	   updated for a while, then trigger an asynchronous rescan.  Otherwise
-	   we update the list first, and then build it from that */
-
 	if (top == NULL)
 		top = "";
 
@@ -3688,71 +3520,27 @@
 	if (camel_debug("imap:folder_info"))
 		printf("get folder info online\n");
 
-	if (FALSE && (flags & CAMEL_STORE_FOLDER_INFO_SUBSCRIBED)
-	    && camel_store_summary_count((CamelStoreSummary *)imap_store->summary) > 0) {
-		time_t now;
-		int ref;
+	CAMEL_SERVICE_REC_LOCK(store, connect_lock);
 
-		now = time(NULL);
-		ref = now > imap_store->refresh_stamp+60*60*1;
-		if (ref) {
-			CAMEL_SERVICE_REC_LOCK(store, connect_lock);
-			ref = now > imap_store->refresh_stamp+60*60*1;
-			if (ref) {
-				struct _refresh_msg *m;
+	if (!camel_disco_store_check_online((CamelDiscoStore *)imap_store, ex))
+		goto fail;
 
-				imap_store->refresh_stamp = now;
-
-				m = camel_session_thread_msg_new(((CamelService *)store)->session, &refresh_ops, sizeof(*m));
-				m->store = store;
-				camel_object_ref(store);
-				camel_exception_init(&m->ex);
-				camel_session_thread_queue(((CamelService *)store)->session, &m->msg, 0);
-			}
-			CAMEL_SERVICE_REC_UNLOCK(store, connect_lock);
-		}
+	if (top[0] == 0) {
+		get_folders_sync (imap_store, "*", ex);
+		if (camel_exception_is_set(ex))
+			goto fail;
 	} else {
 		char *pattern;
 		int i;
-
-		CAMEL_SERVICE_REC_LOCK(store, connect_lock);
-
-		if (!camel_disco_store_check_online((CamelDiscoStore *)imap_store, ex))
-			goto fail;
-
-		if (top[0] == 0) {
-			if (imap_store->namespace && imap_store->namespace[0]) {
-				get_folders_sync (imap_store, "INBOX", ex);
-				if (camel_exception_is_set(ex))
-					goto fail;
-
-				i = strlen(imap_store->namespace)-1;
-				pattern = g_alloca(i+5);
-				strcpy(pattern, imap_store->namespace);
-				while (i>0 && pattern[i] == imap_store->dir_sep)
-					pattern[i--] = 0;
-				i++;
-			} else {
-				pattern = g_alloca(2);
-				pattern[0] = '*';
-				pattern[1] = 0;
-				i=0;
-			}
-		} else {
-			char *name;
-
-			name = camel_imap_store_summary_full_from_path(imap_store->summary, top);
-			if (name == NULL)
-				name = camel_imap_store_summary_path_to_full(imap_store->summary, top, imap_store->dir_sep);
-
-			i = strlen(name);
-			pattern = g_alloca(i+5);
-			strcpy(pattern, name);
-			g_free(name);
-		}
-
-		
-		if (pattern[0] != '*' && imap_store->dir_sep) {
+		char *name;
+		name = camel_imap_store_summary_full_from_path(imap_store->summary, top);
+		if (name == NULL)
+			name = camel_imap_store_summary_path_to_full(imap_store->summary, top, imap_store->dir_sep);
+		i = strlen(name);
+		pattern = g_alloca(i+5);
+		strcpy(pattern, name);
+		g_free(name);
+		if (imap_store->dir_sep) {
 			pattern[i] = imap_store->dir_sep;
 			pattern[i+1] = (flags & CAMEL_STORE_FOLDER_INFO_RECURSIVE)?'*':'%';
 			pattern[i+2] = 0;
@@ -3762,12 +3550,12 @@
 
 		if (camel_exception_is_set(ex))
 			goto fail;
+	}
 
-		camel_store_summary_touch((CamelStoreSummary *)imap_store->summary);
-		camel_store_summary_save((CamelStoreSummary *)imap_store->summary, ex);
+	camel_store_summary_touch((CamelStoreSummary *)imap_store->summary);
+	camel_store_summary_save((CamelStoreSummary *)imap_store->summary, ex);
 
-		CAMEL_SERVICE_REC_UNLOCK(store, connect_lock);
-	}
+	CAMEL_SERVICE_REC_UNLOCK(store, connect_lock);
 
 	tree = get_folder_info_offline(store, top, flags, ex);
 
@@ -3810,11 +3598,7 @@
 
 	/* get starting point */
 	if (top[0] == 0) {
-		if (imap_store->namespace && imap_store->namespace[0]) {
-			name = g_strdup(imap_store->summary->namespace->full_name);
-			top = imap_store->summary->namespace->path;
-		} else
-			name = g_strdup("");
+		name = g_strdup("");
 	} else {
 		name = camel_imap_store_summary_full_from_path(imap_store->summary, top);
 		if (name == NULL)
Index: libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-store-summary.h
===================================================================
--- libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-store-summary.h	(revision 3166)
+++ libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-store-summary.h	(working copy)
@@ -63,7 +63,8 @@
 	/* header info */
 	guint32 version;	/* version of base part of file */
 	guint32 capabilities;
-	CamelImapStoreNamespace *namespace; /* eventually to be a list */
+	GList *namespaces; /* eventually to be a list */
+	CamelImapStoreNamespace *namespace;
 };
 
 struct _CamelImapStoreSummaryClass {
@@ -76,6 +77,7 @@
 /* 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);
+void 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);
 
Index: libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-store.h
===================================================================
--- libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-store.h	(revision 3166)
+++ libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-store.h	(working copy)
@@ -160,6 +160,7 @@
 	/* NB: namespace should be handled by summary->namespace */
 	char *namespace, dir_sep, *base_url, *storage_path;
 	GHashTable *authtypes;
+	struct _namespaces *namespaces;
 
 	time_t refresh_stamp;
 	gchar *idle_prefix;
Index: libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-folder.c
===================================================================
--- libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-folder.c	(revision 3166)
+++ libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-folder.c	(working copy)
@@ -171,7 +171,6 @@
 static void camel_imap_folder_changed_for_idle (CamelFolder *folder, int exists,
 			   GArray *expunged, CamelException *ex, CamelFolderChangeInfo *changes, gboolean exists_happened);
 
-GPtrArray* _camel_imap_store_get_recent_messages (CamelImapStore *imap_store, const char *folder_name, int *messages, int *unseen, gboolean withthem);
 
 static void imap_delete_attachments (CamelFolder *folder, const char *uid);
 static void imap_rewrite_cache (CamelFolder *folder, const char *uid, CamelMimeMessage *msg);
Index: libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-store-summary.c
===================================================================
--- libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-store-summary.c	(revision 3166)
+++ libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-store-summary.c	(working copy)
@@ -42,9 +42,9 @@
 #define d(x)
 #define io(x)			/* io debug */
 
-#define CAMEL_IMAP_STORE_SUMMARY_VERSION_0 (0)
+#define CAMEL_IMAP_STORE_SUMMARY_VERSION_0 (1)
 
-#define CAMEL_IMAP_STORE_SUMMARY_VERSION (0)
+#define CAMEL_IMAP_STORE_SUMMARY_VERSION (1)
 
 #define _PRIVATE(o) (((CamelImapStoreSummary *)(o))->priv)
 
@@ -93,14 +93,20 @@
 
 	((CamelStoreSummary *)s)->store_info_size = sizeof(CamelImapStoreInfo);
 	s->version = CAMEL_IMAP_STORE_SUMMARY_VERSION;
+	s->namespaces = NULL;
+	s->namespace = NULL;
 }
 
 static void
 camel_imap_store_summary_finalise (CamelObject *obj)
 {
 	/*struct _CamelImapStoreSummaryPrivate *p;*/
-	/*CamelImapStoreSummary *s = (CamelImapStoreSummary *)obj;*/
+	CamelImapStoreSummary *is = (CamelImapStoreSummary *)obj;
+	CamelStoreSummary *s = (CamelStoreSummary *) s;
 
+	if (is->namespaces)
+		namespace_clear (s);
+
 	/*p = _PRIVATE(obj);
 	  g_free(p);*/
 }
@@ -395,57 +401,67 @@
 	return ns;
 }
 
+void camel_imap_store_summary_namespace_add(CamelImapStoreSummary *s, CamelImapStoreNamespace *ns)
+{
+	s->namespaces = g_list_prepend (s->namespaces, ns);
+}
+
 void camel_imap_store_summary_namespace_set(CamelImapStoreSummary *s, CamelImapStoreNamespace *ns)
 {
-	d(printf("Setting namesapce to '%s' '%c' -> '%s'\n", ns->full_name, ns->sep, ns->path));
-	namespace_clear((CamelStoreSummary *)s);
 	s->namespace = ns;
-	camel_store_summary_touch((CamelStoreSummary *)s);
+	return;
 }
 
 CamelImapStoreNamespace *
 camel_imap_store_summary_namespace_find_path(CamelImapStoreSummary *s, const char *path)
 {
 	int len;
-	CamelImapStoreNamespace *ns;
+	GList *list;
+	CamelImapStoreNamespace *nsf = NULL;
 
-	/* NB: this currently only compares against 1 namespace, in future compare against others */
-	ns = s->namespace;
-	while (ns) {
+	list = s->namespaces;
+	while (list) {
+		CamelImapStoreNamespace *ns = list->data;
 		len = strlen(ns->path);
 		if (len == 0
 		    || (strncmp(ns->path, path, len) == 0
-			&& (path[len] == '/' || path[len] == 0)))
+			&& (path[len] == '/' || path[len] == 0))) {
+			nsf = ns;
 			break;
-		ns = NULL;
+		}
+		list = list->next;
 	}
 
-	/* have a default? */
-	return ns;
+	return nsf;
 }
 
 CamelImapStoreNamespace *
 camel_imap_store_summary_namespace_find_full(CamelImapStoreSummary *s, const char *full)
 {
 	int len;
-	CamelImapStoreNamespace *ns;
+	GList *list;
+	CamelImapStoreNamespace *nsf = NULL;
 
 	/* NB: this currently only compares against 1 namespace, in future compare against others */
-	ns = s->namespace;
-	while (ns) {
+	list = s->namespaces;
+	while (list) {
+		CamelImapStoreNamespace *ns = list->data;
 		len = strlen(ns->full_name);
 		d(printf("find_full: comparing namespace '%s' to name '%s'\n", ns->full_name, full));
 		if (len == 0
 		    || (strncmp(ns->full_name, full, len) == 0
-			&& (full[len] == ns->sep || full[len] == 0)))
+			&& (full[len] == ns->sep || full[len] == 0))) {
+			nsf = ns;
 			break;
-		ns = NULL;
+		}
+		list = list->next;
 	}
 
 	/* have a default? */
-	return ns;
+	return nsf;
 }
 
+
 static void
 namespace_free(CamelStoreSummary *s, CamelImapStoreNamespace *ns)
 {
@@ -458,51 +474,84 @@
 namespace_clear(CamelStoreSummary *s)
 {
 	CamelImapStoreSummary *is = (CamelImapStoreSummary *)s;
+	GList *list = is->namespaces;
 
-	if (is->namespace)
-		namespace_free(s, is->namespace);
-	is->namespace = NULL;
+	while (list) {
+		CamelImapStoreNamespace *ns = list->data;
+		namespace_free(s, ns);
+		list=list->next;
+	}
+	g_list_free (is->namespaces);
+	is->namespaces = NULL;
 }
 
-static CamelImapStoreNamespace *
+static int
 namespace_load(CamelStoreSummary *s, FILE *in)
 {
+	CamelImapStoreSummary *is = (CamelImapStoreSummary *) s;
+
 	CamelImapStoreNamespace *ns;
-	guint32 sep = '/';
+	int count = 0, i = 0;
 
-	ns = g_malloc0(sizeof(*ns));
+	if (is->namespaces)
+		namespace_clear (s);
 
-	if (camel_file_util_decode_string(in, &ns->path) == -1)
+	if (camel_file_util_decode_uint32(in, &count) == -1)
 		goto nserror;
 
-	if (camel_file_util_decode_string(in, &ns->full_name) == -1)
-		goto nserror;
+	for (i=0 ; i< count; i++) {
+		guint32 sep = '/';
+		ns = g_malloc0(sizeof(*ns));
+		if (camel_file_util_decode_string(in, &ns->path) == -1) {
+			namespace_free(s, ns);
+			goto nserror;
+		}
+		if (camel_file_util_decode_string(in, &ns->full_name) == -1) {
+			namespace_free(s, ns);
+			goto nserror;
+		}
+		if (camel_file_util_decode_uint32(in, &sep) == -1) {
+			namespace_free(s, ns);
+			goto nserror;
+		}
+		ns->sep = sep;
+		is->namespaces = g_list_prepend (is->namespaces, ns);
+	}
 
-	if (camel_file_util_decode_uint32(in, &sep) == -1)
-		goto nserror;
+	return 0;
 
-	ns->sep = sep;
-
-	return ns;
-
  nserror:
 
-	namespace_free(s, ns);
-	return NULL;
+	return -1;
 }
 
 static int
-namespace_save(CamelStoreSummary *s, FILE *in, CamelImapStoreNamespace *ns)
+namespace_save(CamelStoreSummary *s, FILE *in)
 {
-	if (camel_file_util_encode_string(in, ns->path) == -1)
-		goto serr;
+	CamelImapStoreSummary *is = (CamelImapStoreSummary *) s;
 
-	if (camel_file_util_encode_string(in, ns->full_name) == -1)
-		goto serr;
+	GList *list;
 
-	if (camel_file_util_encode_uint32(in, (guint32)ns->sep) == -1)
+	if (camel_file_util_encode_uint32(in, (guint32) g_list_length (is->namespaces)) == -1)
 		goto serr;
 
+	list = is->namespaces;
+
+	while (list) {
+		CamelImapStoreNamespace *ns = list->data;
+
+		if (camel_file_util_encode_string(in, ns->path) == -1)
+			goto serr;
+
+		if (camel_file_util_encode_string(in, ns->full_name) == -1)
+			goto serr;
+
+		if (camel_file_util_encode_uint32(in, (guint32)ns->sep) == -1)
+			goto serr;
+
+		list = list->next;
+	}
+
 	return 0;
 
  serr:
@@ -531,18 +580,12 @@
 	}
 
 	/* note file format can be expanded to contain more namespaces, but only 1 at the moment */
-	if (camel_file_util_decode_fixed_int32(in, &capabilities) == -1
-	    || camel_file_util_decode_fixed_int32(in, &count) == -1
-	    || count > 1)
+	if (camel_file_util_decode_fixed_int32(in, &capabilities) == -1)
 		return -1;
 
 	is->capabilities = capabilities;
-	if (count == 1) {
-		if ((is->namespace = namespace_load(s, in)) == NULL)
-			return -1;
-	}
 
-	return 0;
+	return namespace_load (s, in);
 }
 
 static int
@@ -551,16 +594,13 @@
 	CamelImapStoreSummary *is = (CamelImapStoreSummary *)s;
 	guint32 count;
 
-	count = is->namespace?1:0;
-
 	/* always write as latest version */
 	if (camel_imap_store_summary_parent->summary_header_save((CamelStoreSummary *)s, out) == -1
 	    || camel_file_util_encode_fixed_int32(out, CAMEL_IMAP_STORE_SUMMARY_VERSION) == -1
-	    || camel_file_util_encode_fixed_int32(out, is->capabilities) == -1
-	    || camel_file_util_encode_fixed_int32(out, count) == -1)
+	    || camel_file_util_encode_fixed_int32(out, is->capabilities) == -1)
 		return -1;
 
-	if (is->namespace && namespace_save(s, out, is->namespace) == -1)
+	if (namespace_save(s, out) == -1)
 		return -1;
 
 	return 0;
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 3166)
+++ ChangeLog	(working copy)
@@ -1,7 +1,13 @@
+2007-12-21  Philip Van Hoof <pvanhoof gnome org>
+
+	* Experimental support for NAMESPACE in IMAP accounts
+	* Better handling of LIST and LSUB requests
+
 2007-12-20  Alberto Garcia Gonzalez  <agarcia igalia com>
 
-	* libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-command.c:
-	(camel_imap_command_response): Set an initial value to variable len
+	* libtinymail-camel/camel-lite/camel/providers/imap/camel-
+	imap-command.c: (camel_imap_command_response): Set an initial 
+	value to variable len
 
 2007-12-20 Dirk-Jan C. Binnema <dirk-jan binnema nokia com>
 


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