evolution-exchange r1718 - in trunk: . camel mail



Author: abharath
Date: Mon Aug  4 04:50:20 2008
New Revision: 1718
URL: http://svn.gnome.org/viewvc/evolution-exchange?rev=1718&view=rev

Log:
Committing on behalf of  Veerapuram Varadhan <vvaradhan novell com>

2008-08-04  Veerapuram Varadhan <vvaradhan novell com>

        ** Part of fix for bug #467586

        * camel/camel-exchange-store.c: (exchange_rename_folder),
        (stub_notification):
        * mail/mail-stub-exchange.c: (get_folder_info_data), (get_folder_info), 
        (rename_folder): Get the folder hierarchy once renamed.



Modified:
   trunk/ChangeLog
   trunk/camel/camel-exchange-store.c
   trunk/mail/mail-stub-exchange.c

Modified: trunk/camel/camel-exchange-store.c
==============================================================================
--- trunk/camel/camel-exchange-store.c	(original)
+++ trunk/camel/camel-exchange-store.c	Mon Aug  4 04:50:20 2008
@@ -837,17 +837,75 @@
 exchange_rename_folder (CamelStore *store, const char *old_name,
 			const char *new_name, CamelException *ex)
 {
+	GPtrArray *folders = NULL, *folder_names = NULL, *folder_uris = NULL;
+	GArray *unread_counts = NULL;
+	GArray *folder_flags = NULL;
+	CamelFolderInfo *info;
+	int i;
+	CamelRenameInfo reninfo;
+	CamelFolder *folder;
+
 	CamelExchangeStore *exch = CAMEL_EXCHANGE_STORE (store);
 
 	if (!camel_exchange_store_connected (exch, ex)) {
 		camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, _("Cannot rename folder in offline mode."));
 		return;
 	}
+	if (!camel_stub_send (exch->stub, ex, CAMEL_STUB_CMD_RENAME_FOLDER,
+			      CAMEL_STUB_ARG_STRING, old_name,
+			      CAMEL_STUB_ARG_STRING, new_name,
+			      CAMEL_STUB_ARG_RETURN,
+			      CAMEL_STUB_ARG_STRINGARRAY, &folder_names,
+			      CAMEL_STUB_ARG_STRINGARRAY, &folder_uris,
+			      CAMEL_STUB_ARG_UINT32ARRAY, &unread_counts,
+			      CAMEL_STUB_ARG_UINT32ARRAY, &folder_flags,
+			      CAMEL_STUB_ARG_END)) {
+		return;
+	}
+
+	if (!folder_names) {
+		/* This means the storage hasn't finished scanning yet.
+		 * We return NULL for now and will emit folder_created
+		 * events later.
+		 */
+		return;
+	}
+
+	folders = g_ptr_array_new ();
+	for (i = 0; i < folder_names->len; i++) {
+		info = make_folder_info (exch, folder_names->pdata[i],
+					 folder_uris->pdata[i],
+					 g_array_index (unread_counts, int, i),
+					 g_array_index (folder_flags, int, i));
+		if (info)
+			g_ptr_array_add (folders, info);
+	}
+	g_ptr_array_free (folder_names, TRUE);
+	g_ptr_array_free (folder_uris, TRUE);
+	g_array_free (unread_counts, TRUE);
+	g_array_free (folder_flags, TRUE);
+
+	info = camel_folder_info_build (folders, new_name, '/', TRUE);
+	
+	if (info)
+		info = postprocess_tree (info);
+	g_ptr_array_free (folders, TRUE);
+
+	reninfo.new = info;
+	reninfo.old_base = (char *)old_name;
+
+	g_mutex_lock (exch->folders_lock);
+	folder = g_hash_table_lookup (exch->folders, reninfo.old_base);
+	if (folder) {
+		g_hash_table_remove (exch->folders, reninfo.old_base);
+		camel_object_unref (CAMEL_OBJECT (folder));
+	}
+	g_mutex_unlock (exch->folders_lock);
+		
+	camel_object_trigger_event (CAMEL_OBJECT (exch),
+				    "folder_renamed", &reninfo);
+	camel_folder_info_free (reninfo.new);
 
-	camel_stub_send (exch->stub, ex, CAMEL_STUB_CMD_RENAME_FOLDER,
-			 CAMEL_STUB_ARG_FOLDER, old_name,
-			 CAMEL_STUB_ARG_FOLDER, new_name,
-			 CAMEL_STUB_ARG_END);
 }
 
 static void
@@ -1080,34 +1138,6 @@
 		break;
 	}
 
-	case CAMEL_STUB_RETVAL_FOLDER_RENAMED:
-	{
-		char *new_name, *new_uri;
-		CamelFolder *folder;
-		CamelRenameInfo reninfo;
-
-		if (camel_stub_marshal_decode_folder (stub->status, &reninfo.old_base) == -1 ||
-		    camel_stub_marshal_decode_folder (stub->status, &new_name) == -1 ||
-		    camel_stub_marshal_decode_string (stub->status, &new_uri) == -1)
-			break;
-
-		reninfo.new = make_folder_info (exch, new_name, new_uri, -1, 0);
-
-		g_mutex_lock (exch->folders_lock);
-		folder = g_hash_table_lookup (exch->folders, reninfo.old_base);
-		if (folder) {
-			g_hash_table_remove (exch->folders, reninfo.old_base);
-			camel_object_unref (CAMEL_OBJECT (folder));
-		}
-		g_mutex_unlock (exch->folders_lock);
-
-		camel_object_trigger_event (CAMEL_OBJECT (exch),
-					    "folder_renamed", &reninfo);
-		camel_folder_info_free (reninfo.new);
-		g_free (reninfo.old_base);
-		break;
-	}
-
 	case CAMEL_STUB_RETVAL_FOLDER_SET_READONLY:
 	{
 		CamelFolder *folder;

Modified: trunk/mail/mail-stub-exchange.c
==============================================================================
--- trunk/mail/mail-stub-exchange.c	(original)
+++ trunk/mail/mail-stub-exchange.c	Mon Aug  4 04:50:20 2008
@@ -134,6 +134,9 @@
 static void folder_update_linestatus (gpointer key, gpointer value, gpointer data);
 static void free_folder (gpointer value);
 static gboolean get_folder_online (MailStubExchangeFolder *mfld, gboolean background);
+static void  get_folder_info_data (MailStub *stub, const char *top, guint32 store_flags,
+				   GPtrArray **names, GPtrArray **uris,
+				   GArray **unread, GArray **flags);
 
 static GStaticRecMutex g_changed_msgs_mutex = G_STATIC_REC_MUTEX_INIT;
 
@@ -2730,12 +2733,13 @@
 	mail_stub_push_changes (stub);
 }
 
-static void
-get_folder_info (MailStub *stub, const char *top, guint32 store_flags)
+static void 
+get_folder_info_data (MailStub *stub, const char *top, guint32 store_flags,
+		      GPtrArray **names, GPtrArray **uris,
+		      GArray **unread, GArray **flags)
 {
 	MailStubExchange *mse = MAIL_STUB_EXCHANGE (stub);
-	GPtrArray *folders = NULL, *names, *uris;
-	GArray *unread, *flags;
+	GPtrArray *folders = NULL;
 	ExchangeHierarchy *hier;
 	EFolder *folder;
 	const char *type, *name, *uri, *path, *inbox_uri = NULL, *trash_uri = NULL, *sent_items_uri = NULL;
@@ -2764,7 +2768,8 @@
 			d(g_print ("%s(%d):%s: NOT SUBSCRIBED - open_folder returned = [%d]\n", __FILE__, __LINE__, __GNUC_PRETTY_FUNCTION__, result));
 	}
 
-	if (!recursive && toplen) {
+	/* No need to check for recursive flag, as I will always be returning a tree, instead of a single folder info object */
+	if (toplen) {
 		d(g_print ("%s(%d):%s: NOT RECURSIVE and toplen top = [%s]\n", __FILE__, __LINE__, __GNUC_PRETTY_FUNCTION__, top));
 		full_path = g_strdup_printf ("/%s", top);
 		folders = exchange_account_get_folder_tree (mse->account, full_path);
@@ -2775,10 +2780,10 @@
 		folders = exchange_account_get_folders (mse->account);
 	}
 
-	names = g_ptr_array_new ();
-	uris = g_ptr_array_new ();
-	unread = g_array_new (FALSE, FALSE, sizeof (int));
-	flags = g_array_new (FALSE, FALSE, sizeof (int));
+	*names = g_ptr_array_new ();
+	*uris = g_ptr_array_new ();
+	*unread = g_array_new (FALSE, FALSE, sizeof (int));
+	*flags = g_array_new (FALSE, FALSE, sizeof (int));
 	/* Can be NULL if started in offline mode */
 	if (mse->inbox) {
 		inbox_uri = e_folder_get_physical_uri (mse->inbox);
@@ -2808,13 +2813,6 @@
 					continue;
 			}
 
-			if (recursive && toplen) {
-				path = e_folder_exchange_get_path (folder);
-				if (strncmp (path + 1, top, toplen) != 0 ||
-				    path[toplen + 1] != '\0')
-					continue;
-			}
-
 			type = e_folder_get_type_string (folder);
 			name = e_folder_get_name (folder);
 			uri = e_folder_get_physical_uri (folder);
@@ -2879,14 +2877,25 @@
 
 			d(g_print ("folder flags is : %d\n", folder_flags));
 
-			g_ptr_array_add (names, (char *)name);
-			g_ptr_array_add (uris, (char *)uri);
-			g_array_append_val (unread, unread_count);
-			g_array_append_val (flags, folder_flags);
+			g_ptr_array_add (*names, (char *)name);
+			g_ptr_array_add (*uris, (char *)uri);
+			g_array_append_val (*unread, unread_count);
+			g_array_append_val (*flags, folder_flags);
 		}
 
 		g_ptr_array_free (folders, TRUE);
 	}
+}
+
+static void
+get_folder_info (MailStub *stub, const char *top, guint32 store_flags)
+{
+	MailStubExchange *mse = MAIL_STUB_EXCHANGE (stub);
+	GPtrArray *names, *uris;
+	GArray *unread, *flags;
+
+	get_folder_info_data (stub, top, store_flags, &names, &uris, 
+			      &unread, &flags);
 
 	mail_stub_return_data (stub, CAMEL_STUB_RETVAL_RESPONSE,
 			       CAMEL_STUB_ARG_STRINGARRAY, names,
@@ -3070,6 +3079,8 @@
 	ExchangeAccountFolderResult result;
 	EFolder *folder;
 	char *old_path, *new_path;
+	GPtrArray *names, *uris;
+	GArray *unread, *flags;
 
 	old_path = g_build_filename ("/", old_name, NULL);
 	folder = exchange_account_get_folder (mse->account, old_path);
@@ -3101,11 +3112,20 @@
 		g_hash_table_steal (mse->folders_by_name, old_name);
 		g_hash_table_insert (mse->folders_by_name, (char *)mfld->name, mfld);
 
-		mail_stub_return_data (stub, CAMEL_STUB_RETVAL_FOLDER_RENAMED,
-				       CAMEL_STUB_ARG_FOLDER, old_name,
-				       CAMEL_STUB_ARG_FOLDER, e_folder_get_name (folder),
-				       CAMEL_STUB_ARG_STRING, e_folder_get_physical_uri (folder),
+		get_folder_info_data (stub, new_name, CAMEL_STUB_STORE_FOLDER_INFO_SUBSCRIBED,
+				      &names, &uris, &unread, &flags);
+
+		mail_stub_return_data (stub, CAMEL_STUB_RETVAL_RESPONSE,
+				       CAMEL_STUB_ARG_STRINGARRAY, names,
+				       CAMEL_STUB_ARG_STRINGARRAY, uris,
+				       CAMEL_STUB_ARG_UINT32ARRAY, unread,
+				       CAMEL_STUB_ARG_UINT32ARRAY, flags,
 				       CAMEL_STUB_ARG_END);
+
+		g_ptr_array_free (names, TRUE);
+		g_ptr_array_free (uris, TRUE);
+		g_array_free (unread, TRUE);
+		g_array_free (flags, TRUE);
 		break;
 
 	case EXCHANGE_ACCOUNT_FOLDER_DOES_NOT_EXIST:



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