Index: plugins/groupwise-features/share-folder-common.c
===================================================================
--- plugins/groupwise-features/share-folder-common.c	(revision 37007)
+++ plugins/groupwise-features/share-folder-common.c	(working copy)
@@ -246,8 +246,6 @@ users_dialog_response(GtkWidget *dialog,
 	struct _EMFolderTreeModelStoreInfo *si;
 	EMFolderSelector *emfs = ssi->emfs;
 	const char *uri, *path;
-	CamelException ex;
-	CamelStore *store;
 
 	if (response != GTK_RESPONSE_OK) {
 		gtk_widget_destroy ((GtkWidget *) emfs);
@@ -260,19 +258,11 @@ users_dialog_response(GtkWidget *dialog,
 
 	d(printf ("Creating new folder: %s (%s)\n", path, uri));
 
-	camel_exception_init (&ex);
-	if (!(store = (CamelStore *) camel_session_get_service (session, uri, CAMEL_PROVIDER_STORE, &ex))) {
-		camel_exception_clear (&ex);
+	si = em_folder_tree_model_get_store_info_for_uri (ssi->model, uri);
+	if (!si || !si->store)
 		return;
-	}
-
-	if (!(si = g_hash_table_lookup ((ssi->model)->store_hash, store))) {
-		g_assert_not_reached ();
-		camel_object_unref (store);
-		return;
-	}
 
-	if (CAMEL_IS_VEE_STORE(store)) {
+	if (CAMEL_IS_VEE_STORE (si->store)) {
 		EMVFolderRule *rule;
 
 		/* ensures vfolder is running */
@@ -288,7 +278,6 @@ users_dialog_response(GtkWidget *dialog,
 		create_folder (si->store, path, new_folder_created_cb, ssi);
 
 	}
-	camel_object_unref (store);
 }
 
 static void
@@ -299,10 +288,8 @@ new_folder_response (EMFolderSelector *e
 	struct ShareInfo *ssi;
 	const char *uri;
 	EGwConnection *cnc;
-	CamelException ex;
-	CamelStore *store;
+	EMFolderTreeModelStoreInfo *si;
 
-	ssi = g_new0(struct ShareInfo, 1);
 	if (response != GTK_RESPONSE_OK) {
 		gtk_widget_destroy ((GtkWidget *) emfs);
 		return;
@@ -310,13 +297,15 @@ new_folder_response (EMFolderSelector *e
 
 	/* i want store at this point to get cnc not sure proper or not*/
 	uri = em_folder_selector_get_selected_uri (emfs);
-	camel_exception_init (&ex);
-	if (!(store = (CamelStore *) camel_session_get_service (session, uri, CAMEL_PROVIDER_STORE, &ex))) {
-		camel_exception_clear (&ex);
+	si = em_folder_tree_get_model_storeinfo_for_uri (emfs->emft, uri);
+	if (!si || !si->store) {
+		gtk_widget_destroy ((GtkWidget *) emfs);
 		return;
 	}
 
-	cnc = get_cnc (store);
+	ssi = g_new0 (struct ShareInfo, 1);
+
+	cnc = get_cnc (si->store);
 	users_dialog = gtk_dialog_new_with_buttons (
 			_("Users"), NULL, GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
 	w = gtk_label_new_with_mnemonic (_("Enter the users and set permissions"));
@@ -331,10 +320,6 @@ new_folder_response (EMFolderSelector *e
 	gtk_window_resize (GTK_WINDOW (users_dialog), 350, 300);
 	gtk_widget_show(users_dialog);
 	g_signal_connect (users_dialog, "response", G_CALLBACK (users_dialog_response), ssi);
-
-	camel_object_unref (store);
-	return ;
-
 }
 
 static EPopupItem popup_items[] = {
Index: plugins/groupwise-features/install-shared.c
===================================================================
--- plugins/groupwise-features/install-shared.c	(revision 37007)
+++ plugins/groupwise-features/install-shared.c	(working copy)
@@ -69,11 +69,11 @@ install_folder_response (EMFolderSelecto
 	gchar *container_id;
 	const char *item_id;
 	CamelException ex;
-	CamelStore *store;
 	CamelFolder *folder;
 	EAccount *account;
 	CamelProvider *provider;
 	EGwConnection *cnc;
+	EMFolderTreeModelStoreInfo *si;
 
 	if (response == GTK_RESPONSE_CANCEL){
 		gtk_widget_destroy (GTK_WIDGET (emfs));
@@ -95,19 +95,20 @@ install_folder_response (EMFolderSelecto
 			else
 				parent_name = NULL;
 		}
-		camel_exception_init (&ex);
-		if (!(store = (CamelStore *) camel_session_get_service (mail_component_peek_session(NULL), uri, CAMEL_PROVIDER_STORE, &ex))) {
-			camel_exception_clear (&ex);
+
+		si = em_folder_tree_get_model_storeinfo_for_uri (emfs->emft, uri);
+		if (!si || !si->store || !si->account) {
 			g_strfreev (names);
 			return;
 		}
 
-		cnc = get_cnc (store);
+		cnc = get_cnc (si->store);
 		if(E_IS_GW_CONNECTION (cnc)) {
 			container_id = get_container_id (cnc, parent_name);
 
 			if(e_gw_connection_accept_shared_folder (cnc, folder_name, container_id, (char *)item_id, NULL) == E_GW_CONNECTION_STATUS_OK) {
-
+				CamelStore *store = si->store;
+				camel_object_ref (store);
 
 				folder = camel_store_get_folder (store, "Mailbox", 0, NULL);
 				/*changes = camel_folder_change_info_new ();
@@ -117,12 +118,17 @@ install_folder_response (EMFolderSelecto
 				camel_folder_set_message_flags (folder, item_id, CAMEL_MESSAGE_DELETED, CAMEL_MESSAGE_DELETED);
 				camel_folder_summary_touch (folder->summary);
 				//camel_object_trigger_event (CAMEL_OBJECT (folder), "folder_changed", changes);
-				uri = camel_url_to_string (((CamelService *) store)->url, CAMEL_URL_HIDE_ALL);
-				account = mail_config_get_account_by_source_url (uri);
+				
+				account = si->account;
 				uri = account->source->url;
+				g_object_ref (account);
+				
+				/* 'si' will be freed after this call */
 				em_folder_tree_model_remove_store (model, store);
 				camel_exception_init (&ex);
 				if (!(provider = camel_provider_get(uri, &ex))) {
+					camel_object_unref (store);
+					g_object_unref (account);
 					camel_exception_clear (&ex);
 					g_strfreev (names);
 					return;
@@ -130,6 +136,8 @@ install_folder_response (EMFolderSelecto
 
 				/* make sure the new store belongs in the tree */
 				if (!(provider->flags & CAMEL_PROVIDER_IS_STORAGE)) {
+					camel_object_unref (store);
+					g_object_unref (account);
 					g_strfreev (names);
 					return;
 				}
Index: mail/em-folder-utils.c
===================================================================
--- mail/em-folder-utils.c	(revision 37007)
+++ mail/em-folder-utils.c	(working copy)
@@ -624,8 +624,6 @@ emfu_popup_new_folder_response (EMFolder
 {
 	EMFolderTreeModelStoreInfo *si;
 	const char *uri, *path;
-	CamelException ex;
-	CamelStore *store;
 	struct _EMCreateFolderTempData  *emcftd;
 
 	if (response != GTK_RESPONSE_OK) {
@@ -640,19 +638,13 @@ emfu_popup_new_folder_response (EMFolder
 
 	g_print ("DEBUG: %s (%s)\n", path, uri);
 
-	camel_exception_init (&ex);
-	if (!(store = (CamelStore *) camel_session_get_service (session, uri, CAMEL_PROVIDER_STORE, &ex))) {
-		camel_exception_clear (&ex);
-		return;
-	}
-
-	if (!(si = em_folder_tree_get_model_storeinfo (emfs->emft, store))) {
-		camel_object_unref (store);
-		g_return_if_reached();
+	si = em_folder_tree_get_model_storeinfo_for_uri (emfs->emft, uri);
+	if (!si) {
+		g_return_if_reached ();
 	}
 
 	/* HACK: we need to create vfolders using the vfolder editor */
-	if (CAMEL_IS_VEE_STORE(store)) {
+	if (CAMEL_IS_VEE_STORE(si->store)) {
 		EMVFolderRule *rule;
 
 		/* ensures vfolder is running */
@@ -672,9 +664,6 @@ emfu_popup_new_folder_response (EMFolder
 		g_object_ref (emfs);
 		emfu_create_folder_real (si->store, path, new_folder_created_cb, emcftd);
 	}
-
-	camel_object_unref (store);
-	camel_exception_clear (&ex);
 }
 
 /* FIXME: these functions must be documented */
Index: mail/em-folder-tree.c
===================================================================
--- mail/em-folder-tree.c	(revision 37007)
+++ mail/em-folder-tree.c	(working copy)
@@ -678,7 +678,6 @@ emft_maybe_expand_row (EMFolderTreeModel
 	struct _EMFolderTreeModelStoreInfo *si;
 	gboolean is_store;
 	CamelStore *store;
-	EAccount *account;
 	char *full_name;
 	char *key;
 	struct _selected_uri *u;
@@ -691,8 +690,8 @@ emft_maybe_expand_row (EMFolderTreeModel
 			    -1);
 
 	si = g_hash_table_lookup (model->store_hash, store);
-	if ((account = mail_config_get_account_by_name (si->display_name))) {
-	        key = g_strdup_printf ("%s/%s", account->uid, full_name ? full_name : "");
+	if (si && si->account) {
+	        key = g_strdup_printf ("%s/%s", si->account->uid, full_name ? full_name : "");
 	} else if (CAMEL_IS_VEE_STORE (store)) {
 		/* vfolder store */
 		key = g_strdup_printf ("vfolder/%s", full_name ? full_name : "");
@@ -1618,11 +1617,18 @@ em_folder_tree_set_selected_list (EMFold
 	for (;list;list = list->next) {
 		struct _selected_uri *u = g_malloc0(sizeof(*u));
 		CamelURL *url;
-		CamelException ex = { 0 };
+		EMFolderTreeModelStoreInfo *si;
+
+		si = em_folder_tree_get_model_storeinfo_for_uri (emft, list->data);
+		if (!si || !si->store) {
+			g_warning ("%s: Cannot find uri '%s' in tree.", G_STRFUNC, (const char *)list->data);
+			g_free (u);
+			continue;
+		}
 
 		u->uri = g_strdup(list->data);
-		u->store = (CamelStore *)camel_session_get_service (session, u->uri, CAMEL_PROVIDER_STORE, &ex);
-		camel_exception_clear(&ex);
+		u->store = si->store;
+		camel_object_ref (u->store);
 
 		url = camel_url_new(u->uri, NULL);
 		if (u->store == NULL || url == NULL) {
@@ -1634,7 +1640,6 @@ em_folder_tree_set_selected_list (EMFold
 		} else {
 			const char *path;
 			char *expand_key, *end;
-			EAccount *account;
 
 			if (((CamelService *)u->store)->provider->url_flags & CAMEL_URL_FRAGMENT_IS_PATH)
 				path = url->fragment;
@@ -1645,8 +1650,8 @@ em_folder_tree_set_selected_list (EMFold
 
 			/* This makes sure all our parents up to the root are expanded */
 			/* FIXME: Why does the expanded state store this made up path rather than the euri? */
-			if ( (account = mail_config_get_account_by_source_url(u->uri)) )
-				expand_key = g_strdup_printf ("%s/%s", account->uid, path);
+			if (si->account)
+				expand_key = g_strdup_printf ("%s/%s", si->account->uid, path);
 			else if (CAMEL_IS_VEE_STORE (u->store))
 				expand_key = g_strdup_printf ("vfolder/%s", path);
 			else
@@ -1844,7 +1849,6 @@ emft_update_model_expanded_state (struct
 	struct _EMFolderTreeModelStoreInfo *si;
 	gboolean is_store;
 	CamelStore *store;
-	EAccount *account;
 	char *full_name;
 	char *key;
 
@@ -1855,8 +1859,9 @@ emft_update_model_expanded_state (struct
 			    -1);
 
 	si = g_hash_table_lookup (priv->model->store_hash, store);
-	if ((account = mail_config_get_account_by_name (si->display_name))) {
-	        key = g_strdup_printf ("%s/%s", account->uid, full_name ? full_name : "");
+	printf ("%s: old:%p, new:%p\n", __FUNCTION__, mail_config_get_account_by_name (si->display_name), si ? si->account : NULL);
+	if (si && si->account) {
+	        key = g_strdup_printf ("%s/%s", si->account->uid, full_name ? full_name : "");
 	} else if (CAMEL_IS_VEE_STORE (store)) {
 		/* vfolder store */
 		key = g_strdup_printf ("vfolder/%s", full_name ? full_name : "");
@@ -2621,6 +2626,16 @@ em_folder_tree_get_model_storeinfo (EMFo
 	return si;
 }
 
+/* uri is a folder uri, for example same as returned by em_folder_tree_get_selected_uri */
+EMFolderTreeModelStoreInfo *
+em_folder_tree_get_model_storeinfo_for_uri (EMFolderTree *emft, const char *uri)
+{
+	g_return_val_if_fail (emft != NULL, NULL);
+	g_return_val_if_fail (uri != NULL, NULL);
+
+	return em_folder_tree_model_get_store_info_for_uri (emft->priv->model, uri);
+}
+
 static gboolean
 emft_save_state (EMFolderTree *emft)
 {
Index: mail/em-folder-tree.h
===================================================================
--- mail/em-folder-tree.h	(revision 37007)
+++ mail/em-folder-tree.h	(working copy)
@@ -92,6 +92,7 @@ CamelFolderInfo *em_folder_tree_get_sele
 
 EMFolderTreeModel *em_folder_tree_get_model (EMFolderTree *emft);
 EMFolderTreeModelStoreInfo *em_folder_tree_get_model_storeinfo (EMFolderTree *emft, CamelStore *store);
+EMFolderTreeModelStoreInfo *em_folder_tree_get_model_storeinfo_for_uri (EMFolderTree *emft, const char *uri);
 
 gboolean em_folder_tree_create_folder (EMFolderTree *emft, const char *full_name, const char *uri);
 
Index: mail/em-folder-tree-model.c
===================================================================
--- mail/em-folder-tree-model.c	(revision 37007)
+++ mail/em-folder-tree-model.c	(working copy)
@@ -1068,38 +1068,34 @@ em_folder_tree_model_set_expanded (EMFol
  * @return Key of the uri or NULL, if failed. Returned value should be clear by g_free.
  **/
 static gchar *
-emftm_uri_to_key (const char *uri)
+emftm_uri_to_key (EMFolderTreeModel *model, const char *uri)
 {
-	CamelException ex = { 0 };
-	CamelStore *store;
+	EMFolderTreeModelStoreInfo *si;
 	CamelURL *url;
 	gchar *key;
 
 	if (!uri)
 		return NULL;
 
-	store = (CamelStore *)camel_session_get_service (session, uri, CAMEL_PROVIDER_STORE, &ex);
-	camel_exception_clear(&ex);
-
+	si = em_folder_tree_model_get_store_info_for_uri (model, uri);
 	url = camel_url_new (uri, NULL);
 
-	if (store == NULL || url == NULL) {
+	if (si == NULL || !si->store || url == NULL) {
 		key = NULL;
 	} else {
 		const char *path;
-		EAccount *account;
 
-		if (((CamelService *)store)->provider->url_flags & CAMEL_URL_FRAGMENT_IS_PATH)
+		if (((CamelService *)si->store)->provider->url_flags & CAMEL_URL_FRAGMENT_IS_PATH)
 			path = url->fragment;
 		else
-			path = url->path && url->path[0]=='/' ? url->path+1:url->path;
+			path = url->path && url->path[0]=='/' ? url->path + 1 : url->path;
 
 		if (path == NULL)
 			path = "";
 
-		if ( (account = mail_config_get_account_by_source_url (uri)) )
-			key = g_strdup_printf ("%s/%s", account->uid, path);
-		else if (CAMEL_IS_VEE_STORE (store))
+		if (si->account)
+			key = g_strdup_printf ("%s/%s", si->account->uid, path);
+		else if (CAMEL_IS_VEE_STORE (si->store))
 			key = g_strdup_printf ("vfolder/%s", path);
 		else
 			key = g_strdup_printf ("local/%s", path);
@@ -1108,9 +1104,6 @@ emftm_uri_to_key (const char *uri)
 	if (url)
 		camel_url_free (url);
 
-	if (store)
-		camel_object_unref (store);
-
 	return key;
 }
 
@@ -1127,7 +1120,7 @@ em_folder_tree_model_get_expanded_uri (E
 	g_return_val_if_fail (model != NULL, FALSE);
 	g_return_val_if_fail (uri != NULL, FALSE);
 
-	key = emftm_uri_to_key (uri);
+	key = emftm_uri_to_key (model, uri);
 	expanded = key && em_folder_tree_model_get_expanded (model, key);
 
 	g_free (key);
@@ -1147,13 +1140,53 @@ em_folder_tree_model_set_expanded_uri (E
 	g_return_if_fail (model != NULL);
 	g_return_if_fail (uri != NULL);
 
-	key = emftm_uri_to_key (uri);
+	key = emftm_uri_to_key (model, uri);
 	if (key)
 		em_folder_tree_model_set_expanded (model, key, expanded);
 
 	g_free (key);
 }
 
+/**
+ * em_folder_tree_model_get_store_info_for_uri:
+ * Returns model's store info for uri of the folder.
+ **/
+EMFolderTreeModelStoreInfo *
+em_folder_tree_model_get_store_info_for_uri (EMFolderTreeModel *model, const char *uri)
+{
+	GtkTreeRowReference *row;
+	GtkTreePath *path;
+	GtkTreeIter iter;
+	CamelStore *store;
+
+	if (!uri)
+		return NULL;
+
+	row = g_hash_table_lookup (model->uri_hash, uri);
+	if (!row)
+		return NULL;
+
+	path = gtk_tree_row_reference_get_path (row);
+	if (!path)
+		return NULL;
+
+	if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path)) {
+		gtk_tree_path_free (path);
+		return NULL;
+	}
+
+	gtk_tree_model_get ((GtkTreeModel *) model, &iter,
+			    COL_POINTER_CAMEL_STORE, &store,
+			    -1);
+
+	gtk_tree_path_free (path);
+
+	if (!store)
+		return NULL;
+
+	return g_hash_table_lookup (model->store_hash, store);
+}
+
 void
 em_folder_tree_model_save_state (EMFolderTreeModel *model)
 {
Index: mail/em-folder-tree-model.h
===================================================================
--- mail/em-folder-tree-model.h	(revision 37007)
+++ mail/em-folder-tree-model.h	(working copy)
@@ -137,6 +137,7 @@ void em_folder_tree_model_set_expanded (
 
 gboolean em_folder_tree_model_get_expanded_uri (EMFolderTreeModel *model, const char *uri);
 void em_folder_tree_model_set_expanded_uri (EMFolderTreeModel *model, const char *uri, gboolean expanded);
+EMFolderTreeModelStoreInfo *em_folder_tree_model_get_store_info_for_uri (EMFolderTreeModel *model, const char *uri);
 
 void em_folder_tree_model_save_state (EMFolderTreeModel *model);
 
