[evolution-mapi] Bug #568419 - Crash on "Delete folder"/"Copy to Folder"



commit 55e19ea8c7cecbef597c680e2f3f7eb99f5f85a6
Author: Milan Crha <mcrha redhat com>
Date:   Thu Jan 21 15:47:46 2010 +0100

    Bug #568419 - Crash on "Delete folder"/"Copy to Folder"

 src/camel/camel-mapi-folder.c |    4 +-
 src/camel/camel-mapi-store.c  |   70 +++++++++++++++++++++-------------------
 2 files changed, 39 insertions(+), 35 deletions(-)
---
diff --git a/src/camel/camel-mapi-folder.c b/src/camel/camel-mapi-folder.c
index 2a31af0..8d15113 100644
--- a/src/camel/camel-mapi-folder.c
+++ b/src/camel/camel-mapi-folder.c
@@ -1974,12 +1974,12 @@ mapi_transfer_messages_to (CamelFolder *source, GPtrArray *uids,
 	folder_id =  camel_mapi_store_folder_id_lookup (mapi_store, source->full_name) ;
 	exchange_mapi_util_mapi_id_from_string (folder_id, &src_fid);
 
-	folder_id =  camel_mapi_store_folder_id_lookup (mapi_store, destination->full_name) ;
+	folder_id = camel_mapi_store_folder_id_lookup (mapi_store, destination->full_name);
 	exchange_mapi_util_mapi_id_from_string (folder_id, &dest_fid);
 
 	for (i=0; i < uids->len; i++) {
 		mapi_id_t *mid = g_new0 (mapi_id_t, 1); /* FIXME : */
-		if (!exchange_mapi_util_mapi_ids_from_uid (g_ptr_array_index (uids, i), &src_fid, mid)) 
+		if (!exchange_mapi_util_mapi_ids_from_uid (g_ptr_array_index (uids, i), &src_fid, mid))
 			continue;
 
 		src_msg_ids = g_slist_prepend (src_msg_ids, mid);
diff --git a/src/camel/camel-mapi-store.c b/src/camel/camel-mapi-store.c
index 22cdc8e..d98a300 100644
--- a/src/camel/camel-mapi-store.c
+++ b/src/camel/camel-mapi-store.c
@@ -449,19 +449,38 @@ mapi_get_folder(CamelStore *store, const char *folder_name, guint32 flags, Camel
 {
 	CamelMapiStore *mapi_store = CAMEL_MAPI_STORE (store);
 	CamelMapiStorePrivate *priv = mapi_store->priv;
+	CamelMapiStoreInfo *si;
 	CamelFolder *folder;
-	gchar *folder_dir, *storage_path = NULL;
+	gchar *storage_path;
+
+	si = camel_mapi_store_summary_full_name (mapi_store->summary, folder_name);
+	if (!si && (flags & CAMEL_STORE_FOLDER_CREATE) == CAMEL_STORE_FOLDER_CREATE) {
+		gchar *name, *tmp;
+		const gchar *parent;
+		CamelFolderInfo *folder_info;
+
+		tmp = g_strdup (folder_name);
+		if (!(name = strrchr (tmp, '/'))) {
+			name = tmp;
+			parent = "";
+		} else {
+			*name++ = '\0';
+			parent = tmp;
+		}
+
+		folder_info = mapi_create_folder (store, parent, name, ex);
+		g_free (tmp);
 
-	storage_path = g_strdup_printf("%s/folders", priv->storage_path);
-	folder_dir = g_strdup_printf("%s/folders/%s", storage_path, folder_name);
+		if (!folder_info)
+			return NULL;
 
-	if (!folder_dir || g_access (folder_dir, F_OK) != 0) {
-		g_free (folder_dir);
-		/* camel_exception_setv (ex, CAMEL_EXCEPTION_STORE_NO_FOLDER, */
-		/* 		_("No such folder %s"), folder_name); */
-		/* return NULL; */
+		camel_store_free_folder_info (store, folder_info);
 	}
 
+	if (si)
+		camel_store_summary_info_free ((CamelStoreSummary *)mapi_store->summary, (CamelStoreInfo *)si);
+
+	storage_path = g_strdup_printf ("%s/folders", priv->storage_path);
 	folder = camel_mapi_folder_new (store, folder_name, storage_path, flags, ex);
 	g_free (storage_path);
 
@@ -487,7 +506,7 @@ mapi_create_folder(CamelStore *store, const char *parent_name, const char *folde
 				      folder_name);
 		return NULL;
 	}
-	
+
 	if (parent_name && (strlen(parent_name) > 0) )
 		parent_id = g_strdup (g_hash_table_lookup (priv->name_hash, parent_name));
 	else
@@ -511,7 +530,7 @@ mapi_create_folder(CamelStore *store, const char *parent_name, const char *folde
 		si = camel_mapi_store_summary_add_from_full(mapi_store->summary, root->full_name, '/', fid, parent_id);
 		camel_store_summary_save((CamelStoreSummary *)mapi_store->summary);
 
-		mapi_update_folder_hash_tables (mapi_store, folder_name, fid, parent_id);
+		mapi_update_folder_hash_tables (mapi_store, root->full_name, fid, parent_id);
 
 		camel_object_trigger_event (CAMEL_OBJECT (store), "folder_created", root);
 	}
@@ -1167,15 +1186,10 @@ mapi_folders_update_hash_tables_from_cache (CamelMapiStore *store)
 
 	for (i = 0; i < summary_count; i++) {
 		CamelMapiStoreInfo *si = (CamelMapiStoreInfo *) camel_store_summary_index(summary, i);
-		gchar *name;
 		
 		if (si == NULL) continue;
 
-		name = g_strrstr(si->full_name, "/");
-		name ? ++name : si->full_name;
-
-		mapi_update_folder_hash_tables (store, name, si->folder_id, si->parent_id);
-		
+		mapi_update_folder_hash_tables (store, si->full_name, si->folder_id, si->parent_id);
 	}
 }
 
@@ -1301,14 +1315,14 @@ mapi_folders_sync (CamelMapiStore *store, const char *top, guint32 flags, CamelE
 	
 	/*populate the hash table for finding the mapping from container id <-> folder name*/
 	for (;temp_list != NULL ; temp_list = g_slist_next (temp_list) ) {
-		const char *name;
+		const char *full_name;
 		gchar *fid = NULL, *parent_id = NULL;
 
-		name = exchange_mapi_folder_get_name ((ExchangeMAPIFolder *)(temp_list->data));
+		full_name = exchange_mapi_folder_get_name ((ExchangeMAPIFolder *)(temp_list->data));
 		fid = g_strdup_printf ("%016" G_GINT64_MODIFIER "X", exchange_mapi_folder_get_fid((ExchangeMAPIFolder *)(temp_list->data)));
 		parent_id = g_strdup_printf ("%016" G_GINT64_MODIFIER "X", exchange_mapi_folder_get_parent_id ((ExchangeMAPIFolder *)(temp_list->data)));
 
-		mapi_update_folder_hash_tables (store, name, fid, parent_id);
+		mapi_update_folder_hash_tables (store, full_name, fid, parent_id);
 
 		if (((ExchangeMAPIFolder *)(temp_list->data))->is_default) {
 			guint *type = g_new0 (guint, 1);
@@ -1479,7 +1493,6 @@ mapi_subscribe_folder(CamelStore *store, const char *folder_name, CamelException
 	CamelStoreInfo *si = NULL;
 	gchar *parent_name = NULL;
 	gchar *f_name = NULL;
-	CamelURL *url;
 	/* TODO : exchange_mapi_add_to_favorites (); */
 
 	si = camel_store_summary_path((CamelStoreSummary *)mapi_store->summary, folder_name);
@@ -1502,18 +1515,14 @@ mapi_subscribe_folder(CamelStore *store, const char *folder_name, CamelException
 			return;
 	}
 
-	fi = mapi_build_folder_info(mapi_store, parent_name, g_strdup (folder_name)); /* FIXME */
-
-	url = camel_url_new(mapi_store->priv->base_url,NULL);
-	url->path = g_strdup_printf("/%s", camel_store_info_path((CamelStoreSummary *)mapi_store->summary, si));
-	g_free (fi->uri);
-	fi->uri = camel_url_to_string(url,CAMEL_URL_HIDE_ALL);
+	fi = mapi_build_folder_info (mapi_store, parent_name, folder_name);
 
 	fi->flags |= CAMEL_FOLDER_SUBSCRIBED;
 	fi->flags |= CAMEL_FOLDER_NOCHILDREN;
 	fi->flags |= CAMEL_STORE_INFO_FOLDER_SUBSCRIBED;
 
 	camel_object_trigger_event (CAMEL_OBJECT (store), "folder_subscribed", fi);
+	camel_folder_info_free (fi);
 }
 
 static gboolean
@@ -1538,7 +1547,6 @@ mapi_unsubscribe_folder(CamelStore *store, const char *folder_name, CamelExcepti
 	CamelStoreInfo *si;
 	gchar *parent_name = NULL;
 	gchar *f_name = NULL;
-	CamelURL *url;
 
 	CamelMapiStore *mapi_store = CAMEL_MAPI_STORE (store);
 
@@ -1562,14 +1570,10 @@ mapi_unsubscribe_folder(CamelStore *store, const char *folder_name, CamelExcepti
 			return;
 	}
 
-	fi = mapi_build_folder_info(mapi_store, parent_name, g_strdup (folder_name)); /* FIXME */
-
-	url = camel_url_new(mapi_store->priv->base_url,NULL);
-	url->path = g_strdup_printf("/%s", camel_store_info_path((CamelStoreSummary *)mapi_store->summary, si));
-	g_free (fi->uri);
-	fi->uri = camel_url_to_string(url,CAMEL_URL_HIDE_ALL);
+	fi = mapi_build_folder_info (mapi_store, parent_name, folder_name);
 
 	camel_object_trigger_event (CAMEL_OBJECT (store), "folder_unsubscribed", fi);
+	camel_folder_info_free (fi);
 }
 
 static void



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