[evolution-mapi] Bug #568424 - Copy/Move mails with public folders fails



commit 7e3c00fdb18d30ca3a74a2f513293b670afdac1a
Author: Milan Crha <mcrha redhat com>
Date:   Thu Jun 10 13:01:52 2010 +0200

    Bug #568424 - Copy/Move mails with public folders fails

 .../exchange-mapi-account-setup.c                  |    2 +-
 src/addressbook/e-book-backend-mapi.c              |    4 +-
 src/calendar/e-cal-backend-mapi.c                  |    4 +-
 src/camel/camel-mapi-folder.c                      |   47 ++++--
 src/camel/camel-mapi-store.c                       |    8 +-
 src/libexchangemapi/exchange-mapi-cal-utils.c      |    6 +-
 src/libexchangemapi/exchange-mapi-connection.c     |  195 +++++++++-----------
 src/libexchangemapi/exchange-mapi-connection.h     |   20 +-
 8 files changed, 143 insertions(+), 143 deletions(-)
---
diff --git a/src/account-setup-eplugin/exchange-mapi-account-setup.c b/src/account-setup-eplugin/exchange-mapi-account-setup.c
index 829fc82..a3c6f16 100644
--- a/src/account-setup-eplugin/exchange-mapi-account-setup.c
+++ b/src/account-setup-eplugin/exchange-mapi-account-setup.c
@@ -835,7 +835,7 @@ exchange_mapi_cal_commit (EPlugin *epl, EConfigTarget *target)
 	conn = exchange_mapi_connection_find (e_source_get_property (source, "profile"));
 	g_return_if_fail (conn != NULL);
 
-	fid = exchange_mapi_connection_create_folder (conn, type, pfid, e_source_peek_name (source));
+	fid = exchange_mapi_connection_create_folder (conn, type, pfid, 0, e_source_peek_name (source));
 	g_object_unref (conn);
 
 	sfid = exchange_mapi_util_mapi_id_to_string (fid);
diff --git a/src/addressbook/e-book-backend-mapi.c b/src/addressbook/e-book-backend-mapi.c
index dc78e57..d20e509 100644
--- a/src/addressbook/e-book-backend-mapi.c
+++ b/src/addressbook/e-book-backend-mapi.c
@@ -783,7 +783,7 @@ e_book_backend_mapi_remove_contacts (EBookBackend *backend,
 			tmp = tmp->next;
 		}
 
-		exchange_mapi_connection_remove_items (priv->conn, olFolderContacts, priv->fid, list);
+		exchange_mapi_connection_remove_items (priv->conn, olFolderContacts, priv->fid, 0, list);
 		if (priv->marked_for_offline && priv->is_cache_ready) {
 			tmp = id_list;
 			while (tmp) {
@@ -1637,7 +1637,7 @@ e_book_backend_mapi_remove (EBookBackend *backend,
 
 	case GNOME_Evolution_Addressbook_MODE_REMOTE:
 
-		status = exchange_mapi_connection_remove_folder (priv->conn, priv->fid);
+		status = exchange_mapi_connection_remove_folder (priv->conn, priv->fid, 0);
 		if (!status) {
 			e_data_book_respond_remove (book, opid, GNOME_Evolution_Addressbook_OtherError);
 			return;
diff --git a/src/calendar/e-cal-backend-mapi.c b/src/calendar/e-cal-backend-mapi.c
index 7ac4aaf..c70fc9d 100644
--- a/src/calendar/e-cal-backend-mapi.c
+++ b/src/calendar/e-cal-backend-mapi.c
@@ -346,7 +346,7 @@ e_cal_backend_mapi_remove (ECalBackendSync *backend, EDataCal *cal)
 	if (priv->mode == CAL_MODE_LOCAL || !priv->conn || !exchange_mapi_connection_connected (priv->conn))
 		return GNOME_Evolution_Calendar_RepositoryOffline;
 
-	status = exchange_mapi_connection_remove_folder (priv->conn, priv->fid);
+	status = exchange_mapi_connection_remove_folder (priv->conn, priv->fid, 0);
 	if (!status)
 		return GNOME_Evolution_Calendar_OtherError;
 
@@ -1920,7 +1920,7 @@ e_cal_backend_mapi_remove_object (ECalBackendSync *backend, EDataCal *cal,
 				list = g_slist_prepend (list, (gpointer) data);
 //			}
 
-			if (exchange_mapi_connection_remove_items (priv->conn, priv->olFolder, priv->fid, list)) {
+			if (exchange_mapi_connection_remove_items (priv->conn, priv->olFolder, priv->fid, 0, list)) {
 				for (l = comp_list; l; l = l->next) {
 					ECalComponent *comp = E_CAL_COMPONENT (l->data);
 					ECalComponentId *id = e_cal_component_get_id (comp);
diff --git a/src/camel/camel-mapi-folder.c b/src/camel/camel-mapi-folder.c
index a544714..c657a6b 100644
--- a/src/camel/camel-mapi-folder.c
+++ b/src/camel/camel-mapi-folder.c
@@ -831,13 +831,13 @@ mapi_sync (CamelFolder *folder, gboolean expunge, CamelException *ex)
 
 	if (read_items) {
 		camel_service_lock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
-		exchange_mapi_connection_set_flags (camel_mapi_store_get_exchange_connection (mapi_store), 0, fid, read_items, 0, options);
+		exchange_mapi_connection_set_flags (camel_mapi_store_get_exchange_connection (mapi_store), 0, fid, options, read_items, 0);
 		camel_service_unlock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 	}
 
 	if (unread_items) {
 		camel_service_lock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
-		exchange_mapi_connection_set_flags (camel_mapi_store_get_exchange_connection (mapi_store), 0, fid, unread_items, CLEAR_READ_FLAG, options);
+		exchange_mapi_connection_set_flags (camel_mapi_store_get_exchange_connection (mapi_store), 0, fid, options, unread_items, CLEAR_READ_FLAG);
 		camel_service_unlock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 	}
 
@@ -845,10 +845,10 @@ mapi_sync (CamelFolder *folder, gboolean expunge, CamelException *ex)
 	if (deleted_items) {
 		camel_service_lock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 		if ((mapi_folder->type & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_TRASH) {
-			exchange_mapi_connection_remove_items (camel_mapi_store_get_exchange_connection (mapi_store), 0, fid, deleted_items);
+			exchange_mapi_connection_remove_items (camel_mapi_store_get_exchange_connection (mapi_store), 0, fid, options, deleted_items);
 		} else {
 			exchange_mapi_util_mapi_id_from_string (camel_mapi_store_system_folder_fid (mapi_store, olFolderDeletedItems), &deleted_items_fid);
-			exchange_mapi_connection_move_items (camel_mapi_store_get_exchange_connection (mapi_store), fid, deleted_items_fid, deleted_items);
+			exchange_mapi_connection_move_items (camel_mapi_store_get_exchange_connection (mapi_store), fid, options, deleted_items_fid, 0, deleted_items);
 		}
 
 		camel_service_unlock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
@@ -860,7 +860,7 @@ mapi_sync (CamelFolder *folder, gboolean expunge, CamelException *ex)
 
 		camel_service_lock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 		exchange_mapi_util_mapi_id_from_string (camel_mapi_store_system_folder_fid (mapi_store, olFolderJunk), &junk_fid);
-		exchange_mapi_connection_move_items (camel_mapi_store_get_exchange_connection (mapi_store), fid, junk_fid, junk_items);
+		exchange_mapi_connection_move_items (camel_mapi_store_get_exchange_connection (mapi_store), fid, options, junk_fid, 0, junk_items);
 		camel_service_unlock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 
 		/* in junk_items are only emails which are not deleted */
@@ -1323,7 +1323,7 @@ mapi_expunge (CamelFolder *folder, CamelException *ex)
 
 	if ((mapi_folder->type & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_TRASH) {
 		camel_service_lock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
-		status = exchange_mapi_connection_empty_folder (camel_mapi_store_get_exchange_connection (mapi_store), fid);
+		status = exchange_mapi_connection_empty_folder (camel_mapi_store_get_exchange_connection (mapi_store), fid, 0);
 		camel_service_unlock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 
 		if (status) {
@@ -1367,7 +1367,7 @@ mapi_expunge (CamelFolder *folder, CamelException *ex)
 	if (deleted_items) {
 		camel_service_lock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 
-		status = exchange_mapi_connection_remove_items (camel_mapi_store_get_exchange_connection (mapi_store), 0, fid, deleted_items);
+		status = exchange_mapi_connection_remove_items (camel_mapi_store_get_exchange_connection (mapi_store), 0, fid, 0, deleted_items);
 
 		camel_service_unlock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 
@@ -1404,6 +1404,7 @@ mapi_transfer_messages_to (CamelFolder *source, GPtrArray *uids,
 		gboolean delete_originals, CamelException *ex)
 {
 	mapi_id_t src_fid, dest_fid;
+	guint32 src_fid_options, dest_fid_options;
 
 	CamelOfflineStore *offline;
 	CamelMapiStore *mapi_store;
@@ -1414,9 +1415,21 @@ mapi_transfer_messages_to (CamelFolder *source, GPtrArray *uids,
 	const gchar *source_full_name;
 	const gchar *destination_full_name;
 	gint i = 0;
-
 	GSList *src_msg_ids = NULL;
 
+	if (!CAMEL_IS_MAPI_FOLDER (source) || !CAMEL_IS_MAPI_FOLDER (destination) ||
+	    (CAMEL_MAPI_FOLDER (source)->type & CAMEL_MAPI_FOLDER_PUBLIC) != 0 ||
+	    (CAMEL_MAPI_FOLDER (destination)->type & CAMEL_MAPI_FOLDER_PUBLIC) != 0) {
+		CamelFolderClass *folder_class;
+
+		/* because cannot use MAPI to copy/move messages with public folders,
+		   thus fallback to per-message copy/move */
+		folder_class = CAMEL_FOLDER_CLASS (camel_mapi_folder_parent_class);
+		return folder_class->transfer_messages_to (
+			source, uids, destination, transferred_uids,
+			delete_originals, ex);
+	}
+
 	source_full_name = camel_folder_get_full_name (source);
 	source_parent_store = camel_folder_get_parent_store (source);
 
@@ -1428,13 +1441,15 @@ mapi_transfer_messages_to (CamelFolder *source, GPtrArray *uids,
 
 	/* check for offline operation */
 	if (offline->state == CAMEL_OFFLINE_STORE_NETWORK_UNAVAIL)
-		return TRUE;
+		return FALSE;
 
 	folder_id =  camel_mapi_store_folder_id_lookup (mapi_store, source_full_name);
 	exchange_mapi_util_mapi_id_from_string (folder_id, &src_fid);
+	src_fid_options = (CAMEL_MAPI_FOLDER (source)->type & CAMEL_MAPI_FOLDER_PUBLIC) != 0 ? MAPI_OPTIONS_USE_PFSTORE : 0;
 
 	folder_id = camel_mapi_store_folder_id_lookup (mapi_store, destination_full_name);
 	exchange_mapi_util_mapi_id_from_string (folder_id, &dest_fid);
+	dest_fid_options = (CAMEL_MAPI_FOLDER (destination)->type & CAMEL_MAPI_FOLDER_PUBLIC) != 0 ? MAPI_OPTIONS_USE_PFSTORE : 0;
 
 	for (i=0; i < uids->len; i++) {
 		mapi_id_t *mid = g_new0 (mapi_id_t, 1); /* FIXME : */
@@ -1445,8 +1460,11 @@ mapi_transfer_messages_to (CamelFolder *source, GPtrArray *uids,
 	}
 
 	if (delete_originals) {
-		if (!exchange_mapi_connection_move_items (camel_mapi_store_get_exchange_connection (mapi_store), src_fid, dest_fid, src_msg_ids)) {
-			//TODO : Set exception.
+		enum MAPISTATUS retval = exchange_mapi_connection_move_items (camel_mapi_store_get_exchange_connection (mapi_store), src_fid, src_fid_options, dest_fid, dest_fid_options, src_msg_ids);
+		if (retval != MAPI_E_SUCCESS) {
+			const gchar *err_str = mapi_get_errstr (retval);
+
+			camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, err_str ? err_str : _("Unknown error"));
 		} else {
 			changes = camel_folder_change_info_new ();
 
@@ -1459,8 +1477,11 @@ mapi_transfer_messages_to (CamelFolder *source, GPtrArray *uids,
 
 		}
 	} else {
-		if (!exchange_mapi_connection_copy_items (camel_mapi_store_get_exchange_connection (mapi_store), src_fid, dest_fid, src_msg_ids)) {
-			//TODO : Set exception.
+		enum MAPISTATUS retval = exchange_mapi_connection_copy_items (camel_mapi_store_get_exchange_connection (mapi_store), src_fid, src_fid_options, dest_fid, dest_fid_options, src_msg_ids);
+		if (retval != MAPI_E_SUCCESS) {
+			const gchar *err_str = mapi_get_errstr (retval);
+
+			camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, err_str ? err_str : _("Unknown error"));
 		}
 	}
 
diff --git a/src/camel/camel-mapi-store.c b/src/camel/camel-mapi-store.c
index 7dbbc10..93b1d0b 100644
--- a/src/camel/camel-mapi-store.c
+++ b/src/camel/camel-mapi-store.c
@@ -571,7 +571,7 @@ mapi_create_folder(CamelStore *store, const gchar *parent_name, const gchar *fol
 	camel_service_lock (CAMEL_SERVICE (store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 
 	exchange_mapi_util_mapi_id_from_string (parent_id, &parent_fid);
-	new_folder_id = exchange_mapi_connection_create_folder (priv->conn, olFolderInbox, parent_fid, folder_name);
+	new_folder_id = exchange_mapi_connection_create_folder (priv->conn, olFolderInbox, parent_fid, 0, folder_name);
 	if (new_folder_id != 0) {
 		CamelMapiStoreInfo *si;
 		gchar *fid = g_strdup_printf ("%016" G_GINT64_MODIFIER "X", new_folder_id);
@@ -647,7 +647,7 @@ mapi_delete_folder(CamelStore *store, const gchar *folder_name, CamelException *
 
 	folder_id = g_hash_table_lookup (priv->name_hash, folder_name);
 	exchange_mapi_util_mapi_id_from_string (folder_id, &folder_fid);
-	status = exchange_mapi_connection_remove_folder (priv->conn, folder_fid);
+	status = exchange_mapi_connection_remove_folder (priv->conn, folder_fid, 0);
 
 	if (status) {
 		/* Fixme ??  */
@@ -785,7 +785,7 @@ mapi_rename_folder(CamelStore *store, const gchar *old_name, const gchar *new_na
 		gchar *folder_id;
 
 		/* renaming in the same folder, thus no MoveFolder necessary */
-		if (!exchange_mapi_connection_rename_folder (priv->conn, old_fid, tmp ? tmp : new_name)) {
+		if (!exchange_mapi_connection_rename_folder (priv->conn, old_fid, 0, tmp ? tmp : new_name)) {
 			/*To translators : '%s to %s' is current name of the folder  and
 			new name of the folder.*/
 			camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
@@ -838,7 +838,7 @@ mapi_rename_folder(CamelStore *store, const gchar *old_name, const gchar *new_na
 		} else if (!old_parent_fid_str || !new_parent_fid_str ||
 			   !exchange_mapi_util_mapi_id_from_string (old_parent_fid_str, &old_parent_fid) ||
 			   !exchange_mapi_util_mapi_id_from_string (new_parent_fid_str, &new_parent_fid) ||
-			   !exchange_mapi_connection_move_folder (priv->conn, old_fid, old_parent_fid, new_parent_fid, tmp)) {
+			   !exchange_mapi_connection_move_folder (priv->conn, old_fid, old_parent_fid, 0, new_parent_fid, 0, tmp)) {
 			camel_service_unlock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 			camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, _("Cannot rename MAPI folder '%s' to '%s'"), old_name, new_name);
 			g_free (old_parent);
diff --git a/src/libexchangemapi/exchange-mapi-cal-utils.c b/src/libexchangemapi/exchange-mapi-cal-utils.c
index 33fe867..28b4a24 100644
--- a/src/libexchangemapi/exchange-mapi-cal-utils.c
+++ b/src/libexchangemapi/exchange-mapi-cal-utils.c
@@ -1182,7 +1182,7 @@ update_server_object (ExchangeMapiConnection *conn, struct mapi_SPropValue_array
 			idlist.id = *mid;
 			ids = g_slist_append (ids, &idlist);
 
-			exchange_mapi_connection_remove_items (conn, olFolderCalendar, fid, ids);
+			exchange_mapi_connection_remove_items (conn, olFolderCalendar, fid, 0, ids);
 			g_slist_free (ids);
 		} else
 			create_new = FALSE;
@@ -1256,7 +1256,7 @@ check_server_for_object (ExchangeMapiConnection *conn, struct mapi_SPropValue_ar
 	set_SPropValue_proptag (&sprop, proptag, (gconstpointer ) sb);
 	cast_mapi_SPropValue (&(res.res.resProperty.lpProp), &sprop);
 
-	ids = exchange_mapi_connection_check_restriction (conn, fid, &res);
+	ids = exchange_mapi_connection_check_restriction (conn, fid, 0, &res);
 
 	if (ids && g_slist_length(ids) == 1) {
 		struct id_list *idlist = (struct id_list *)(ids->data);
@@ -2112,7 +2112,7 @@ exchange_mapi_cal_util_get_new_appt_id (ExchangeMapiConnection *conn, mapi_id_t
 			GSList *ids = NULL;
 			set_SPropValue_proptag (&sprop, PR_OWNER_APPT_ID, (gconstpointer ) &id);
 			cast_mapi_SPropValue (&(res.res.resProperty.lpProp), &sprop);
-			ids = exchange_mapi_connection_check_restriction (conn, fid, &res);
+			ids = exchange_mapi_connection_check_restriction (conn, fid, 0, &res);
 			if (ids) {
 				GSList *l;
 				for (l = ids; l; l = l->next)
diff --git a/src/libexchangemapi/exchange-mapi-connection.c b/src/libexchangemapi/exchange-mapi-connection.c
index 5de210f..f66ac2c 100644
--- a/src/libexchangemapi/exchange-mapi-connection.c
+++ b/src/libexchangemapi/exchange-mapi-connection.c
@@ -1293,8 +1293,32 @@ cleanup:
 	return TRUE;
 }
 
+static enum MAPISTATUS
+open_folder (ExchangeMapiConnection *conn, uint32_t olFolder, mapi_id_t fid, guint32 fid_options, mapi_object_t *obj_folder)
+{
+	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, MAPI_E_INVALID_PARAMETER);
+	g_return_val_if_fail (obj_folder != NULL, MAPI_E_INVALID_PARAMETER);
+
+	if (fid == 0) {
+		enum MAPISTATUS retval;
+
+		retval = GetDefaultFolder (&priv->msg_store, &fid, olFolder);
+		if (retval != MAPI_E_SUCCESS)
+			return retval;
+
+		fid_options = 0;
+	}
+
+	if ((fid_options & MAPI_OPTIONS_USE_PFSTORE) != 0) {
+		if (!ensure_public_store (priv))
+			return MAPI_E_CALL_FAILED;
+	}
+
+	return OpenFolder (((fid_options & MAPI_OPTIONS_USE_PFSTORE) != 0 ? &priv->public_store : &priv->msg_store), fid, obj_folder);
+}
+
 GSList *
-exchange_mapi_connection_check_restriction (ExchangeMapiConnection *conn, mapi_id_t fid, struct mapi_SRestriction *res)
+exchange_mapi_connection_check_restriction (ExchangeMapiConnection *conn, mapi_id_t fid, guint32 fid_options, struct mapi_SRestriction *res)
 {
 	enum MAPISTATUS retval;
 	TALLOC_CTX *mem_ctx;
@@ -1316,9 +1340,9 @@ exchange_mapi_connection_check_restriction (ExchangeMapiConnection *conn, mapi_i
 	mapi_object_init(&obj_table);
 
 	/* Attempt to open the folder */
-	retval = OpenFolder(&priv->msg_store, fid, &obj_folder);
+	retval = open_folder (conn, 0, fid, fid_options, &obj_folder);
 	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("OpenFolder", GetLastError());
+		mapi_errstr("open_folder", GetLastError());
 		goto cleanup;
 	}
 
@@ -1420,15 +1444,10 @@ exchange_mapi_connection_fetch_items   (ExchangeMapiConnection *conn, mapi_id_t
 	mapi_object_init(&obj_folder);
 	mapi_object_init(&obj_table);
 
-	if ((options & MAPI_OPTIONS_USE_PFSTORE) != 0) {
-		if (!ensure_public_store (priv))
-			goto cleanup;
-	}
-
 	/* Attempt to open the folder */
-	retval = OpenFolder (((options & MAPI_OPTIONS_USE_PFSTORE) != 0 ? &priv->public_store : &priv->msg_store), fid, &obj_folder);
+	retval = open_folder (conn, 0, fid, options, &obj_folder);
 	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("OpenFolder", GetLastError());
+		mapi_errstr("open_folder", GetLastError());
 		goto cleanup;
 	}
 
@@ -1768,15 +1787,10 @@ exchange_mapi_connection_fetch_item (ExchangeMapiConnection *conn, mapi_id_t fid
 	mapi_object_init(&obj_folder);
 	mapi_object_init(&obj_message);
 
-	if ((options & MAPI_OPTIONS_USE_PFSTORE) != 0) {
-		if (!ensure_public_store (priv))
-			goto cleanup;
-	}
-
 	/* Attempt to open the folder */
-	retval = OpenFolder (((options & MAPI_OPTIONS_USE_PFSTORE) != 0 ? &priv->public_store : &priv->msg_store), fid, &obj_folder);
+	retval = open_folder (conn, 0, fid, options, &obj_folder);
 	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("OpenFolder", GetLastError());
+		mapi_errstr("open_folder", GetLastError());
 		goto cleanup;
 	}
 
@@ -1803,7 +1817,7 @@ cleanup:
 }
 
 mapi_id_t
-exchange_mapi_connection_create_folder (ExchangeMapiConnection *conn, uint32_t olFolder, mapi_id_t pfid, const gchar *name)
+exchange_mapi_connection_create_folder (ExchangeMapiConnection *conn, uint32_t olFolder, mapi_id_t pfid, guint32 fid_options, const gchar *name)
 {
 	enum MAPISTATUS retval;
 	mapi_object_t obj_folder;
@@ -1822,9 +1836,9 @@ exchange_mapi_connection_create_folder (ExchangeMapiConnection *conn, uint32_t o
 	mapi_object_init(&obj_folder);
 
 	/* We now open the top/parent folder */
-	retval = OpenFolder (&priv->msg_store, pfid, &obj_top);
+	retval = open_folder (conn, olFolder, pfid, fid_options, &obj_top);
 	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("OpenFolder", GetLastError());
+		mapi_errstr("open_folder", GetLastError());
 		goto cleanup;
 	}
 
@@ -1880,7 +1894,7 @@ cleanup:
 }
 
 gboolean
-exchange_mapi_connection_empty_folder (ExchangeMapiConnection *conn, mapi_id_t fid)
+exchange_mapi_connection_empty_folder (ExchangeMapiConnection *conn, mapi_id_t fid, guint32 fid_options)
 {
 	enum MAPISTATUS retval;
 	mapi_object_t obj_folder;
@@ -1895,9 +1909,9 @@ exchange_mapi_connection_empty_folder (ExchangeMapiConnection *conn, mapi_id_t f
 	mapi_object_init (&obj_folder);
 
 	/* Attempt to open the folder to be emptied */
-	retval = OpenFolder(&priv->msg_store, fid, &obj_folder);
+	retval = open_folder (conn, 0, fid, fid_options, &obj_folder);
 	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("OpenFolder", GetLastError());
+		mapi_errstr("open_folder", GetLastError());
 		goto cleanup;
 	}
 
@@ -1922,7 +1936,7 @@ cleanup:
 }
 
 gboolean
-exchange_mapi_connection_remove_folder (ExchangeMapiConnection *conn, mapi_id_t fid)
+exchange_mapi_connection_remove_folder (ExchangeMapiConnection *conn, mapi_id_t fid, guint32 fid_options)
 {
 	enum MAPISTATUS retval;
 	mapi_object_t obj_top;
@@ -1955,9 +1969,9 @@ exchange_mapi_connection_remove_folder (ExchangeMapiConnection *conn, mapi_id_t
 	 */
 
 	/* Attempt to open the folder to be removed */
-	retval = OpenFolder(&priv->msg_store, fid, &obj_folder);
+	retval = open_folder (conn, 0, fid, fid_options, &obj_folder);
 	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("OpenFolder", GetLastError());
+		mapi_errstr("open_folder", GetLastError());
 		goto cleanup;
 	}
 
@@ -1971,9 +1985,9 @@ exchange_mapi_connection_remove_folder (ExchangeMapiConnection *conn, mapi_id_t
 	g_debug("Folder with id %016" G_GINT64_MODIFIER "X was emptied ", fid);
 
 	/* Attempt to open the top/parent folder */
-	retval = OpenFolder (&priv->msg_store, folder->parent_folder_id, &obj_top);
+	retval = open_folder (conn, 0, folder->parent_folder_id, fid_options, &obj_top);
 	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("OpenFolder", GetLastError());
+		mapi_errstr("open_folder", GetLastError());
 		goto cleanup;
 	}
 
@@ -2003,7 +2017,7 @@ cleanup:
 }
 
 gboolean
-exchange_mapi_connection_rename_folder (ExchangeMapiConnection *conn, mapi_id_t fid, const gchar *new_name)
+exchange_mapi_connection_rename_folder (ExchangeMapiConnection *conn, mapi_id_t fid, guint32 fid_options, const gchar *new_name)
 {
 	enum MAPISTATUS retval;
 	mapi_object_t obj_folder;
@@ -2021,9 +2035,9 @@ exchange_mapi_connection_rename_folder (ExchangeMapiConnection *conn, mapi_id_t
 	mapi_object_init(&obj_folder);
 
 	/* Open the folder to be renamed */
-	retval = OpenFolder (&priv->msg_store, fid, &obj_folder);
+	retval = open_folder (conn, 0, fid, fid_options, &obj_folder);
 	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("OpenFolder", GetLastError());
+		mapi_errstr("open_folder", GetLastError());
 		goto cleanup;
 	}
 
@@ -2051,7 +2065,7 @@ cleanup:
 /* moves folder 'src_fid' to folder 'des_fid' under name 'new_name' (no path in a new_name),
    'src_parent_fid' is folder ID of a parent of the src_fid */
 gboolean
-exchange_mapi_connection_move_folder (ExchangeMapiConnection *conn, mapi_id_t src_fid, mapi_id_t src_parent_fid, mapi_id_t des_fid, const gchar *new_name)
+exchange_mapi_connection_move_folder (ExchangeMapiConnection *conn, mapi_id_t src_fid, mapi_id_t src_parent_fid, guint32 src_fid_options, mapi_id_t des_fid, guint32 des_fid_options, const gchar *new_name)
 {
 	enum MAPISTATUS retval;
 	mapi_object_t obj_src, obj_src_parent, obj_des;
@@ -2072,21 +2086,21 @@ exchange_mapi_connection_move_folder (ExchangeMapiConnection *conn, mapi_id_t sr
 	mapi_object_init (&obj_src_parent);
 	mapi_object_init (&obj_des);
 
-	retval = OpenFolder (&priv->msg_store, src_fid, &obj_src);
+	retval = open_folder (conn, 0, src_fid, src_fid_options, &obj_src);
 	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr ("OpenFolder src_fid", GetLastError());
+		mapi_errstr ("open_folder src_fid", GetLastError());
 		goto cleanup;
 	}
 
-	retval = OpenFolder (&priv->msg_store, src_parent_fid, &obj_src_parent);
+	retval = open_folder (conn, 0, src_parent_fid, src_fid_options, &obj_src_parent);
 	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr ("OpenFolder src_parent_fid", GetLastError());
+		mapi_errstr ("open_folder src_parent_fid", GetLastError());
 		goto cleanup;
 	}
 
-	retval = OpenFolder (&priv->msg_store, des_fid, &obj_des);
+	retval = open_folder (conn, 0, des_fid, des_fid_options, &obj_des);
 	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr ("OpenFolder des_fid", GetLastError());
+		mapi_errstr ("open_folder des_fid", GetLastError());
 		goto cleanup;
 	}
 
@@ -2163,9 +2177,9 @@ exchange_mapi_connection_resolve_named_props (ExchangeMapiConnection *conn, mapi
 	SPropTagArray = talloc_zero (mem_ctx, struct SPropTagArray);
 
 	/* Attempt to open the folder */
-	retval = OpenFolder (&priv->msg_store, fid, &obj_folder);
+	retval = open_folder (conn, 0, fid, 0, &obj_folder);
 	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("OpenFolder", GetLastError());
+		mapi_errstr("open_folder", GetLastError());
 		goto cleanup;
 	}
 
@@ -2283,9 +2297,9 @@ exchange_mapi_connection_resolve_named_prop (ExchangeMapiConnection *conn, mapi_
 	SPropTagArray = talloc_zero(mem_ctx, struct SPropTagArray);
 
 	/* Attempt to open the folder */
-	retval = OpenFolder (&priv->msg_store, fid, &obj_folder);
+	retval = open_folder (conn, 0, fid, 0, &obj_folder);
 	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("OpenFolder", GetLastError());
+		mapi_errstr("open_folder", GetLastError());
 		goto cleanup;
 	}
 
@@ -2380,19 +2394,10 @@ exchange_mapi_connection_create_item (ExchangeMapiConnection *conn, uint32_t olF
 	mapi_object_init(&obj_folder);
 	mapi_object_init(&obj_message);
 
-	/* If fid not present then we'll use olFolder. Document this in API doc. */
-	if (fid == 0) {
-		retval = GetDefaultFolder (&priv->msg_store, &fid, olFolder);
-		if (retval != MAPI_E_SUCCESS) {
-			mapi_errstr("GetDefaultFolder", GetLastError());
-			goto cleanup;
-		}
-	}
-
 	/* Attempt to open the folder */
-	retval = OpenFolder (&priv->msg_store, fid, &obj_folder);
+	retval = open_folder (conn, olFolder, fid, options, &obj_folder);
 	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("OpenFolder", GetLastError());
+		mapi_errstr("open_folder", GetLastError());
 		goto cleanup;
 	}
 
@@ -2511,19 +2516,10 @@ exchange_mapi_connection_modify_item (ExchangeMapiConnection *conn, uint32_t olF
 	mapi_object_init(&obj_folder);
 	mapi_object_init(&obj_message);
 
-	/* If fid not present then we'll use olFolder. Document this in API doc. */
-	if (fid == 0) {
-		retval = GetDefaultFolder (&priv->msg_store, &fid, olFolder);
-		if (retval != MAPI_E_SUCCESS) {
-			mapi_errstr("GetDefaultFolder", GetLastError());
-			goto cleanup;
-		}
-	}
-
 	/* Attempt to open the folder */
-	retval = OpenFolder (&priv->msg_store, fid, &obj_folder);
+	retval = open_folder (conn, olFolder, fid, options, &obj_folder);
 	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("OpenFolder", GetLastError());
+		mapi_errstr("open_folder", GetLastError());
 		goto cleanup;
 	}
 
@@ -2596,7 +2592,7 @@ cleanup:
 }
 
 gboolean
-exchange_mapi_connection_set_flags (ExchangeMapiConnection *conn, uint32_t olFolder, mapi_id_t fid, GSList *mids, uint32_t flag, guint32 options)
+exchange_mapi_connection_set_flags (ExchangeMapiConnection *conn, uint32_t olFolder, mapi_id_t fid, guint32 fid_options, GSList *mids, uint32_t flag)
 {
 	enum MAPISTATUS retval;
 	TALLOC_CTX *mem_ctx;
@@ -2619,15 +2615,10 @@ exchange_mapi_connection_set_flags (ExchangeMapiConnection *conn, uint32_t olFol
 	for (i=0; tmp; tmp=tmp->next, i++)
 		id_messages[i] = *((mapi_id_t *)tmp->data);
 
-	if ((options & MAPI_OPTIONS_USE_PFSTORE) != 0) {
-		if (!ensure_public_store (priv))
-			goto cleanup;
-	}
-
 	/* Attempt to open the folder */
-	retval = OpenFolder (((options & MAPI_OPTIONS_USE_PFSTORE) != 0 ? &priv->public_store : &priv->msg_store), fid, &obj_folder);
+	retval = open_folder (conn, olFolder, fid, fid_options, &obj_folder);
 	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("OpenFolder", GetLastError());
+		mapi_errstr("open_folder", GetLastError());
 		goto cleanup;
 	}
 
@@ -2651,16 +2642,15 @@ cleanup:
 }
 
 static gboolean
-mapi_move_items (mapi_object_t *msg_store, mapi_id_t src_fid, mapi_id_t dest_fid, GSList *mid_list, gboolean do_copy)
+mapi_move_items (ExchangeMapiConnection *conn, mapi_id_t src_fid, guint32 src_fid_options, mapi_id_t dest_fid, guint32 dest_fid_options, GSList *mid_list, gboolean do_copy)
 {
 	enum MAPISTATUS	retval;
 	mapi_object_t obj_folder_src;
 	mapi_object_t obj_folder_dst;
 	mapi_id_array_t msg_id_array;
 	GSList *l;
-	gboolean result = FALSE;
 
-	g_return_val_if_fail (msg_store != NULL, FALSE);
+	g_return_val_if_fail (conn != NULL, MAPI_E_INVALID_PARAMETER);
 
 	mapi_object_init(&obj_folder_src);
 	mapi_object_init(&obj_folder_dst);
@@ -2669,15 +2659,15 @@ mapi_move_items (mapi_object_t *msg_store, mapi_id_t src_fid, mapi_id_t dest_fid
 	for (l = mid_list; l != NULL; l = g_slist_next (l))
 		mapi_id_array_add_id (&msg_id_array, *((mapi_id_t *)l->data));
 
-	retval = OpenFolder (msg_store, src_fid, &obj_folder_src);
+	retval = open_folder (conn, 0, src_fid, src_fid_options, &obj_folder_src);
 	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("OpenFolder - source folder", GetLastError());
+		mapi_errstr("open_folder - source folder", GetLastError());
 		goto cleanup;
 	}
 
-	retval = OpenFolder (msg_store, dest_fid, &obj_folder_dst);
+	retval = open_folder (conn, 0, dest_fid, dest_fid_options, &obj_folder_dst);
 	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("OpenFolder - destination folder", GetLastError());
+		mapi_errstr("open_folder - destination folder", GetLastError());
 		goto cleanup;
 	}
 
@@ -2687,56 +2677,54 @@ mapi_move_items (mapi_object_t *msg_store, mapi_id_t src_fid, mapi_id_t dest_fid
 		goto cleanup;
 	}
 
-	result = TRUE;
-
 cleanup:
 	mapi_id_array_release(&msg_id_array);
 	mapi_object_release(&obj_folder_dst);
 	mapi_object_release(&obj_folder_src);
 
-	return result;
+	return retval;
 }
 
-gboolean
-exchange_mapi_connection_copy_items (ExchangeMapiConnection *conn, mapi_id_t src_fid, mapi_id_t dest_fid, GSList *mids)
+enum MAPISTATUS
+exchange_mapi_connection_copy_items (ExchangeMapiConnection *conn, mapi_id_t src_fid, guint32 src_fid_options, mapi_id_t dest_fid, guint32 dest_fid_options, GSList *mids)
 {
-	gboolean result = FALSE;
+	enum MAPISTATUS retval;
 
-	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, FALSE);
-	g_return_val_if_fail (priv->session != NULL, FALSE);
+	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, MAPI_E_INVALID_PARAMETER);
+	g_return_val_if_fail (priv->session != NULL, MAPI_E_INVALID_PARAMETER);
 
 	g_debug("%s: Entering %s ", G_STRLOC, G_STRFUNC);
 
 	LOCK ();
-	result = mapi_move_items (&priv->msg_store, src_fid, dest_fid, mids, TRUE);
+	retval = mapi_move_items (conn, src_fid, src_fid_options, dest_fid, dest_fid_options, mids, TRUE);
 	UNLOCK ();
 
 	g_debug("%s: Leaving %s ", G_STRLOC, G_STRFUNC);
 
-	return result;
+	return retval;
 }
 
-gboolean
-exchange_mapi_connection_move_items (ExchangeMapiConnection *conn, mapi_id_t src_fid, mapi_id_t dest_fid, GSList *mids)
+enum MAPISTATUS
+exchange_mapi_connection_move_items (ExchangeMapiConnection *conn, mapi_id_t src_fid, guint32 src_fid_options, mapi_id_t dest_fid, guint32 dest_fid_options, GSList *mids)
 {
-	gboolean result = FALSE;
+	enum MAPISTATUS retval;
 
-	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, FALSE);
-	g_return_val_if_fail (priv->session != NULL, FALSE);
+	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, MAPI_E_INVALID_PARAMETER);
+	g_return_val_if_fail (priv->session != NULL, MAPI_E_INVALID_PARAMETER);
 
 	g_debug("%s: Entering %s ", G_STRLOC, G_STRFUNC);
 
 	LOCK ();
-	result = mapi_move_items (&priv->msg_store, src_fid, dest_fid, mids, FALSE);
+	retval = mapi_move_items (conn, src_fid, src_fid_options, dest_fid, dest_fid_options, mids, FALSE);
 	UNLOCK ();
 
 	g_debug("%s: Leaving %s ", G_STRLOC, G_STRFUNC);
 
-	return result;
+	return retval;
 }
 
 gboolean
-exchange_mapi_connection_remove_items (ExchangeMapiConnection *conn, uint32_t olFolder, mapi_id_t fid, GSList *mids)
+exchange_mapi_connection_remove_items (ExchangeMapiConnection *conn, uint32_t olFolder, mapi_id_t fid, guint32 fid_options, GSList *mids)
 {
 	enum MAPISTATUS retval;
 	TALLOC_CTX *mem_ctx;
@@ -2762,19 +2750,10 @@ exchange_mapi_connection_remove_items (ExchangeMapiConnection *conn, uint32_t ol
 		id_messages[i] = data->id;
 	}
 
-	/* If fid not present then we'll use olFolder. Document this in API doc. */
-	if (fid == 0) {
-		retval = GetDefaultFolder (&priv->msg_store, &fid, olFolder);
-		if (retval != MAPI_E_SUCCESS) {
-			mapi_errstr("GetDefaultFolder", GetLastError());
-			goto cleanup;
-		}
-	}
-
 	/* Attempt to open the folder */
-	retval = OpenFolder (&priv->msg_store, fid, &obj_folder);
+	retval = open_folder (conn, olFolder, fid, fid_options, &obj_folder);
 	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("OpenFolder", GetLastError());
+		mapi_errstr("open_folder", GetLastError());
 		goto cleanup;
 	}
 
diff --git a/src/libexchangemapi/exchange-mapi-connection.h b/src/libexchangemapi/exchange-mapi-connection.h
index ff83637..8d733d7 100644
--- a/src/libexchangemapi/exchange-mapi-connection.h
+++ b/src/libexchangemapi/exchange-mapi-connection.h
@@ -178,12 +178,12 @@ gboolean		exchange_mapi_connection_fetch_gal (ExchangeMapiConnection *conn,
 
 gboolean		exchange_mapi_connection_get_public_folder (ExchangeMapiConnection *conn, mapi_object_t *obj_object);
 
-mapi_id_t		exchange_mapi_connection_create_folder (ExchangeMapiConnection *conn, uint32_t olFolder, mapi_id_t pfid, const gchar *name);
-gboolean		exchange_mapi_connection_remove_folder (ExchangeMapiConnection *conn, mapi_id_t fid);
-gboolean		exchange_mapi_connection_empty_folder (ExchangeMapiConnection *conn, mapi_id_t fid);
-gboolean		exchange_mapi_connection_rename_folder (ExchangeMapiConnection *conn, mapi_id_t fid, const gchar *new_name);
-gboolean		exchange_mapi_connection_move_folder (ExchangeMapiConnection *conn, mapi_id_t src_fid, mapi_id_t src_parent_fid, mapi_id_t des_fid, const gchar *new_name);
-GSList *		exchange_mapi_connection_check_restriction (ExchangeMapiConnection *conn, mapi_id_t fid, struct mapi_SRestriction *res);
+mapi_id_t		exchange_mapi_connection_create_folder (ExchangeMapiConnection *conn, uint32_t olFolder, mapi_id_t pfid, guint32 fid_options, const gchar *name);
+gboolean		exchange_mapi_connection_remove_folder (ExchangeMapiConnection *conn, mapi_id_t fid, guint32 fid_options);
+gboolean		exchange_mapi_connection_empty_folder (ExchangeMapiConnection *conn, mapi_id_t fid, guint32 fid_options);
+gboolean		exchange_mapi_connection_rename_folder (ExchangeMapiConnection *conn, mapi_id_t fid, guint32 fid_options, const gchar *new_name);
+gboolean		exchange_mapi_connection_move_folder (ExchangeMapiConnection *conn, mapi_id_t src_fid, mapi_id_t src_parent_fid, guint32 src_fid_options, mapi_id_t des_fid, guint32 des_fid_options, const gchar *new_name);
+GSList *		exchange_mapi_connection_check_restriction (ExchangeMapiConnection *conn, mapi_id_t fid, guint32 fid_options, struct mapi_SRestriction *res);
 mapi_id_t		exchange_mapi_connection_get_default_folder_id (ExchangeMapiConnection *conn, uint32_t olFolder);
 mapi_id_t		exchange_mapi_connection_create_item (ExchangeMapiConnection *conn, uint32_t olFolder, mapi_id_t fid,
 					BuildWritePropsCB build_props, gpointer bwp_data,
@@ -195,10 +195,10 @@ gboolean		exchange_mapi_connection_modify_item (ExchangeMapiConnection *conn, ui
 					GSList *recipients, GSList *attachments, GSList *generic_streams,
 					uint32_t options);
 
-gboolean		exchange_mapi_connection_set_flags (ExchangeMapiConnection *conn, uint32_t olFolder, mapi_id_t fid, GSList *mid_list, uint32_t flag, guint32 options);
-gboolean		exchange_mapi_connection_remove_items (ExchangeMapiConnection *conn, uint32_t olFolder, mapi_id_t fid, GSList *mids);
-gboolean		exchange_mapi_connection_copy_items (ExchangeMapiConnection *conn, mapi_id_t src_fid, mapi_id_t dest_fid, GSList *mids);
-gboolean		exchange_mapi_connection_move_items (ExchangeMapiConnection *conn, mapi_id_t src_fid, mapi_id_t dest_fid, GSList *mids);
+gboolean		exchange_mapi_connection_set_flags (ExchangeMapiConnection *conn, uint32_t olFolder, mapi_id_t fid, guint32 fid_options, GSList *mid_list, uint32_t flag);
+gboolean		exchange_mapi_connection_remove_items (ExchangeMapiConnection *conn, uint32_t olFolder, mapi_id_t fid, guint32 fid_options, GSList *mids);
+enum MAPISTATUS		exchange_mapi_connection_copy_items (ExchangeMapiConnection *conn, mapi_id_t src_fid, guint32 src_fid_options, mapi_id_t dest_fid, guint32 dest_fid_options, GSList *mids);
+enum MAPISTATUS		exchange_mapi_connection_move_items (ExchangeMapiConnection *conn, mapi_id_t src_fid, guint32 src_fid_options, mapi_id_t dest_fid, guint32 dest_fid_options, GSList *mids);
 gboolean 		exchange_mapi_connection_get_folders_list (ExchangeMapiConnection *conn, GSList **mapi_folders);
 gboolean		exchange_mapi_connection_get_pf_folders_list (ExchangeMapiConnection *conn, GSList **mapi_folders);
 GSList *		exchange_mapi_connection_peek_folders_list (ExchangeMapiConnection *conn);



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