Re: [Evolution-hackers] Introduction and Questions



On Thu, 2007-05-31 at 17:18 -0400, Jeffrey Stedfast wrote:
[snip]
> > Single namespace.  It's all INBOX.folder.subfolder.
> > The one wrinkle is that in some cases 'folder' exists in the namespace,
> > but is not an actual box or folder (whatever the right term is) on the
> > server: INBOX.folder.subfolder is a real folder; INBOX.folder is not.
> 
> I guess just a bug
> 

I don't have a build environment anymore so I can't easily test this
patch, but perhaps i will fix your missing folder troubles.


Jeff

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 7792)
+++ ChangeLog	(working copy)
@@ -1,5 +1,9 @@
 2007-05-31  Jeffrey Stedfast  <fejj novell com>
 
+	* camel-imap4-store.c (imap4_build_folder_info): Add "ghost"
+	folder info's if needed in order to make sure the folder-info tree
+	is complete.
+
 	* camel-imap4-utils.c (camel_imap4_parse_flags_list): Handle
 	Junk/NonJunk flags.
 
Index: camel-imap4-store.c
===================================================================
--- camel-imap4-store.c	(revision 7791)
+++ camel-imap4-store.c	(working copy)
@@ -1169,7 +1169,85 @@
 	}
 }
 
+static char *
+list_parent (camel_imap4_list_t *mbox)
+{
+	const char *d;
+	
+	if (!(d = strrchr (mbox->name, mbox->delim)))
+		return NULL;
+	
+	return g_strndup (mbox->name, d - mbox->name);
+}
+
+/* bloody glib... GPtrArray doesn't have an insert method */
 static void
+array_insert (GPtrArray *array, int index, void *data)
+{
+	int i;
+	
+	if ((index + 1) == array->len) {
+		/* special case, adding to the end of the array */
+		g_ptr_array_add (array, data);
+		return;
+	}
+	
+	if (index >= array->len) {
+		/* special case, adding past the end of the array */
+		g_ptr_array_set_size (array, index + 1);
+		array->pdata[index] = data;
+		return;
+	}
+	
+	g_ptr_array_set_size (array, array->len + 1);
+	
+	/* shift all elements starting at @index 1 position to the right */
+	for (i = array->len - 2; i >= index; i--)
+		array->pdata[i + 1] = array->pdata[i];
+	
+	array->pdata[index] = data;
+}
+
+static void
+list_add_ghosts (GPtrArray *array)
+{
+	camel_imap4_list_t *mbox;
+	GHashTable *list_hash;
+	char delim, *parent;
+	int i = 0;
+	
+	list_hash = g_hash_table_new (g_str_hash, g_str_equal);
+	
+	while (i < array->len) {
+		mbox = array->pdata[i];
+		if ((parent = list_parent (mbox))) {
+			if (!g_hash_table_lookup (list_hash, parent)) {
+				/* ghost folder, insert a fake LIST info w/ a \NoSelect flag */
+				delim = mbox->delim;
+				mbox = g_new (camel_imap4_list_t, 1);
+				mbox->flags = CAMEL_FOLDER_NOSELECT;
+				mbox->name = parent;
+				mbox->delim = delim;
+				
+				g_hash_table_insert (list_hash, parent, mbox);
+				
+				array_insert (array, i, mbox);
+				continue;
+			} else {
+				/* already exists */
+				g_free (parent);
+			}
+		}
+		
+		g_hash_table_insert (list_hash, mbox->name, mbox);
+		
+		i++;
+	}
+	
+	g_hash_table_destroy (list_hash);
+}
+
+static void
 imap4_status (CamelStore *store, CamelFolderInfo *fi)
 {
 	CamelIMAP4Engine *engine = ((CamelIMAP4Store *) store)->engine;
@@ -1269,6 +1347,7 @@
 	g_ptr_array_sort (array, (GCompareFunc) list_sort);
 	
 	list_remove_duplicates (array);
+	list_add_ghosts (array);
 	
 	url = camel_url_copy (engine->url);
 	


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