[evolution-mapi] Provide GCancellable into EMapiConnection functions and callbacks



commit 4d85abba0f98381a3bea1c7bdbb7793be5b1a7a6
Author: Milan Crha <mcrha redhat com>
Date:   Tue Nov 1 21:28:40 2011 +0100

    Provide GCancellable into EMapiConnection functions and callbacks

 .../e-mapi-account-listener.c                      |    7 +-
 src/account-setup-eplugin/e-mapi-account-setup.c   |    8 +-
 src/addressbook/e-book-backend-mapi-contacts.c     |   73 +-
 src/addressbook/e-book-backend-mapi-gal.c          |   34 +-
 src/addressbook/e-book-backend-mapi.c              |   15 +-
 src/addressbook/e-book-backend-mapi.h              |   10 +-
 src/calendar/e-cal-backend-mapi.c                  |   76 ++-
 src/camel/camel-mapi-folder.c                      |   46 +-
 src/camel/camel-mapi-notifications.c               |    6 +-
 src/camel/camel-mapi-store.c                       |   35 +-
 src/camel/camel-mapi-transport.c                   |    9 +-
 src/libexchangemapi/e-mapi-cal-utils.c             |  105 ++-
 src/libexchangemapi/e-mapi-cal-utils.h             |   35 +-
 src/libexchangemapi/e-mapi-connection.c            |  924 ++++++++++++++++----
 src/libexchangemapi/e-mapi-connection.h            |  365 ++++++--
 src/libexchangemapi/e-mapi-mail-utils.c            |   34 +-
 src/libexchangemapi/e-mapi-mail-utils.h            |   22 +-
 src/libexchangemapi/e-mapi-utils.c                 |   46 +-
 src/libexchangemapi/e-mapi-utils.h                 |   32 +-
 19 files changed, 1420 insertions(+), 462 deletions(-)
---
diff --git a/src/account-setup-eplugin/e-mapi-account-listener.c b/src/account-setup-eplugin/e-mapi-account-listener.c
index c98c113..09793cc 100644
--- a/src/account-setup-eplugin/e-mapi-account-listener.c
+++ b/src/account-setup-eplugin/e-mapi-account-listener.c
@@ -1006,7 +1006,7 @@ update_sources_cb (gpointer data, gboolean cancelled, gpointer user_data)
 	e_mapi_connection_peek_folders_list (conn);
 
 	if (trash_id)
-		*trash_id = e_mapi_connection_get_default_folder_id (conn, olFolderDeletedItems, NULL);
+		*trash_id = e_mapi_connection_get_default_folder_id (conn, olFolderDeletedItems, NULL, NULL);
 }
 
 static void
@@ -1218,8 +1218,7 @@ create_profile_entry (CamelURL *url, EAccount *account, CamelMapiSettings *setti
 		if (empd.password || empd.krb_sso) {
 			GError *error = NULL;
 
-			status = e_mapi_create_profile (&empd, NULL,
-							       NULL, &error);
+			status = e_mapi_create_profile (&empd, NULL, NULL, NULL, &error);
 			if (status) {
 				/* profile was created, try to connect to the server */
 				EMapiConnection *conn;
@@ -1228,7 +1227,7 @@ create_profile_entry (CamelURL *url, EAccount *account, CamelMapiSettings *setti
 				status = FALSE;
 				profname = e_mapi_util_profile_name (&empd, FALSE);
 
-				conn = e_mapi_connection_new (profname, empd.password, &error);
+				conn = e_mapi_connection_new (profname, empd.password, NULL, &error);
 				if (conn) {
 					status = e_mapi_connection_connected (conn);
 					g_object_unref (conn);
diff --git a/src/account-setup-eplugin/e-mapi-account-setup.c b/src/account-setup-eplugin/e-mapi-account-setup.c
index 093009d..bd59f20 100644
--- a/src/account-setup-eplugin/e-mapi-account-setup.c
+++ b/src/account-setup-eplugin/e-mapi-account-setup.c
@@ -319,7 +319,7 @@ validate_credentials (GtkWidget *widget, EConfig *config)
 		gboolean status = e_mapi_create_profile (&empd,
 								(mapi_profile_callback_t) create_profile_callback,
 								empd.username,
-								&error);
+								NULL, &error);
 		if (status) {
 			/* profile was created, try to connect to the server */
 			EMapiConnection *conn;
@@ -329,7 +329,7 @@ validate_credentials (GtkWidget *widget, EConfig *config)
 			profname = e_mapi_util_profile_name (&empd,
 								    FALSE);
 
-			conn = e_mapi_connection_new (profname, empd.password, &error);
+			conn = e_mapi_connection_new (profname, empd.password, NULL, &error);
 			if (conn) {
 				status = e_mapi_connection_connected (conn);
 				g_object_unref (conn);
@@ -853,7 +853,7 @@ e_mapi_book_commit (EPlugin *epl, EConfigTarget *target)
 	conn = e_mapi_connection_find (e_source_get_property (source, "profile"));
 	g_return_if_fail (conn != NULL);
 
-	fid = e_mapi_connection_create_folder (conn, olFolderContacts, pfid, 0, e_source_peek_name (source), &mapi_error);
+	fid = e_mapi_connection_create_folder (conn, olFolderContacts, pfid, 0, e_source_peek_name (source), NULL, &mapi_error);
 	g_object_unref (conn);
 
 	if (!fid) {
@@ -969,7 +969,7 @@ e_mapi_cal_commit (EPlugin *epl, EConfigTarget *target)
 	conn = e_mapi_connection_find (e_source_get_property (source, "profile"));
 	g_return_if_fail (conn != NULL);
 
-	fid = e_mapi_connection_create_folder (conn, type, pfid, 0, e_source_peek_name (source), &mapi_error);
+	fid = e_mapi_connection_create_folder (conn, type, pfid, 0, e_source_peek_name (source), NULL, &mapi_error);
 	g_object_unref (conn);
 
 	if (!fid) {
diff --git a/src/addressbook/e-book-backend-mapi-contacts.c b/src/addressbook/e-book-backend-mapi-contacts.c
index ddc795e..05df282 100644
--- a/src/addressbook/e-book-backend-mapi-contacts.c
+++ b/src/addressbook/e-book-backend-mapi-contacts.c
@@ -147,17 +147,17 @@ build_multiple_restriction_emails_contains (EMapiConnection *conn, mapi_id_t fid
 
 	or_res[3].rt = RES_CONTENT;
 	or_res[3].res.resContent.fuzzy = FL_FULLSTRING | FL_IGNORECASE;
-	or_res[3].res.resContent.ulPropTag = e_mapi_connection_resolve_named_prop (conn, fid, PidLidEmail1OriginalDisplayName, NULL);
+	or_res[3].res.resContent.ulPropTag = e_mapi_connection_resolve_named_prop (conn, fid, PidLidEmail1OriginalDisplayName, NULL, NULL);
 	or_res[3].res.resContent.lpProp.value.lpszA = email;
 
 	or_res[4].rt = RES_CONTENT;
 	or_res[4].res.resContent.fuzzy = FL_FULLSTRING | FL_IGNORECASE;
-	or_res[4].res.resContent.ulPropTag = e_mapi_connection_resolve_named_prop (conn, fid, PidLidEmail2OriginalDisplayName, NULL);
+	or_res[4].res.resContent.ulPropTag = e_mapi_connection_resolve_named_prop (conn, fid, PidLidEmail2OriginalDisplayName, NULL, NULL);
 	or_res[4].res.resContent.lpProp.value.lpszA = email;
 
 	or_res[5].rt = RES_CONTENT;
 	or_res[5].res.resContent.fuzzy = FL_FULLSTRING | FL_IGNORECASE;
-	or_res[5].res.resContent.ulPropTag = e_mapi_connection_resolve_named_prop (conn, fid, PidLidEmail3OriginalDisplayName, NULL);
+	or_res[5].res.resContent.ulPropTag = e_mapi_connection_resolve_named_prop (conn, fid, PidLidEmail3OriginalDisplayName, NULL, NULL);
 	or_res[5].res.resContent.lpProp.value.lpszA = email;
 
 	res = g_new0 (struct mapi_SRestriction, 1);
@@ -229,7 +229,14 @@ typedef struct {
 } MapiCreateitemData;
 
 static gboolean
-mapi_book_write_props (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, struct SPropValue **values, uint32_t *n_values, gpointer data)
+mapi_book_write_props (EMapiConnection *conn,
+		       mapi_id_t fid,
+		       TALLOC_CTX *mem_ctx,
+		       struct SPropValue **values,
+		       uint32_t *n_values,
+		       gpointer data,
+		       GCancellable *cancellable,
+		       GError **perror)
 {
 	/* Do not make this array static, below function modifies it.
 	   The array is used to just ensure named ids are known later. */
@@ -260,7 +267,7 @@ mapi_book_write_props (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx
 		} G_STMT_END
 
 	#define set_str_named_value(named_id, val) G_STMT_START { \
-		if (!e_mapi_utils_add_spropvalue_namedid (conn, fid, mem_ctx, values, n_values, named_id, val ? val : "")) \
+		if (!e_mapi_utils_add_spropvalue_namedid (conn, fid, mem_ctx, values, n_values, named_id, val ? val : "", cancellable, perror)) \
 			return FALSE;	\
 		} G_STMT_END
 
@@ -282,7 +289,7 @@ mapi_book_write_props (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx
 	g_return_val_if_fail (values != NULL, FALSE);
 	g_return_val_if_fail (n_values != NULL, FALSE);
 
-	if (!e_mapi_connection_resolve_named_props (conn, fid, nids, G_N_ELEMENTS (nids), NULL))
+	if (!e_mapi_connection_resolve_named_props (conn, fid, nids, G_N_ELEMENTS (nids), cancellable, perror))
 		return FALSE;
 
 	if (GPOINTER_TO_INT (e_contact_get (mcd->contact, E_CONTACT_IS_LIST))) {
@@ -331,7 +338,7 @@ mapi_book_write_props (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx
 
 		set_str_value (PR_MESSAGE_CLASS, IPM_DISTLIST);
 		u32 = 0xFFFFFFFF;
-		if (!e_mapi_utils_add_spropvalue_namedid (conn, fid, mem_ctx, values, n_values, PidLidFileUnderId, &u32))
+		if (!e_mapi_utils_add_spropvalue_namedid (conn, fid, mem_ctx, values, n_values, PidLidFileUnderId, &u32, cancellable, perror))
 			return FALSE;
 		set_str_named_con_value (PidLidFileUnder, E_CONTACT_FILE_AS);
 		set_str_named_con_value (PidLidDistributionListName, E_CONTACT_FILE_AS);
@@ -398,15 +405,15 @@ mapi_book_write_props (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx
 		g_list_free (local);
 
 		if (!e_mapi_utils_add_spropvalue_namedid (conn, fid, mem_ctx, values, n_values,
-			PidLidDistributionListOneOffMembers, oneoff_members))
+			PidLidDistributionListOneOffMembers, oneoff_members, cancellable, perror))
 			return FALSE;
 
 		if (!e_mapi_utils_add_spropvalue_namedid (conn, fid, mem_ctx, values, n_values,
-			PidLidDistributionListMembers, members))
+			PidLidDistributionListMembers, members, cancellable, perror))
 			return FALSE;
 
 		if (!e_mapi_utils_add_spropvalue_namedid (conn, fid, mem_ctx, values, n_values,
-			PidLidDistributionListChecksum, &crc32))
+			PidLidDistributionListChecksum, &crc32, cancellable, perror))
 			return FALSE;
 
 		/* list_size shouldn't exceed 15000 bytes, is so, use a stream instead of those properties above, but for now... */
@@ -524,7 +531,10 @@ struct FetchContactItemData
 };
 
 static gboolean
-fetch_contact_item_cb (FetchItemsCallbackData *item_data, gpointer data)
+fetch_contact_item_cb (FetchItemsCallbackData *item_data,
+		       gpointer data,
+		       GCancellable *cancellable,
+		       GError **perror)
 {
 	struct FetchContactItemData *fcid = data;
 
@@ -557,7 +567,10 @@ struct CreateContactListData
 };
 
 static gboolean
-create_contact_list_cb (FetchItemsCallbackData *item_data, gpointer data)
+create_contact_list_cb (FetchItemsCallbackData *item_data,
+			gpointer data,
+			GCancellable *cancellable,
+			GError **perror)
 {
 	struct CreateContactListData *ccld = data;
 	EContact *contact;
@@ -591,7 +604,10 @@ struct FetchContactsData
 };
 
 static gboolean
-fetch_contacts_cb (FetchItemsCallbackData *item_data, gpointer data)
+fetch_contacts_cb (FetchItemsCallbackData *item_data,
+		   gpointer data,
+		   GCancellable *cancellable,
+		   GError **perror)
 {
 	struct FetchContactsData *fcd = data;
 	EContact *contact;
@@ -626,12 +642,15 @@ fetch_contacts_cb (FetchItemsCallbackData *item_data, gpointer data)
 
 struct FetchContactsUidsData
 {
-	GCancellable *cancelled;
+	GCancellable *cancellable;
 	GHashTable *uids;
 };
 
 static gboolean
-fetch_contacts_uids_cb (FetchItemsCallbackData *item_data, gpointer data)
+fetch_contacts_uids_cb (FetchItemsCallbackData *item_data,
+			gpointer data,
+			GCancellable *cancellable,
+			GError **perror)
 {
 	struct FetchContactsUidsData *fcud = data;
 	gchar *suid;
@@ -642,7 +661,7 @@ fetch_contacts_uids_cb (FetchItemsCallbackData *item_data, gpointer data)
 	if (suid)
 		g_hash_table_insert (fcud->uids, suid, GINT_TO_POINTER (1));
 
-	return !g_cancellable_is_cancelled (fcud->cancelled);
+	return !g_cancellable_is_cancelled (fcud->cancellable);
 }
 
 static void
@@ -707,7 +726,7 @@ ebbm_contacts_remove (EBookBackendMAPI *ebma, GCancellable *cancellable, GError
 		if (!conn) {
 			g_propagate_error (error, EDB_ERROR (OFFLINE_UNAVAILABLE));
 		} else {
-			e_mapi_connection_remove_folder (conn, priv->fid, 0, &mapi_error);
+			e_mapi_connection_remove_folder (conn, priv->fid, 0, cancellable, &mapi_error);
 
 			if (mapi_error) {
 				mapi_error_to_edb_error (error, mapi_error, E_DATA_BOOK_STATUS_OTHER_ERROR, _("Failed to remove public folder"));
@@ -768,7 +787,7 @@ ebbm_contacts_create_contacts (EBookBackendMAPI *ebma, GCancellable *cancellable
 
 	mid = e_mapi_connection_create_item (conn, olFolderContacts, priv->fid,
 		mapi_book_write_props, &mcd,
-		NULL, NULL, NULL, MAPI_OPTIONS_DONT_SUBMIT | (priv->is_public_folder ? MAPI_OPTIONS_USE_PFSTORE : 0), &mapi_error);
+		NULL, NULL, NULL, MAPI_OPTIONS_DONT_SUBMIT | (priv->is_public_folder ? MAPI_OPTIONS_USE_PFSTORE : 0), cancellable, &mapi_error);
 
 	e_book_backend_mapi_unlock_connection (ebma);
 
@@ -837,7 +856,7 @@ ebbm_contacts_remove_contacts (EBookBackendMAPI *ebma, GCancellable *cancellable
 		*removed_ids = g_slist_prepend (*removed_ids, g_strdup (uid));
 	}
 
-	e_mapi_connection_remove_items (conn, olFolderContacts, priv->fid, priv->is_public_folder ? MAPI_OPTIONS_USE_PFSTORE : 0, to_remove, &mapi_error);
+	e_mapi_connection_remove_items (conn, olFolderContacts, priv->fid, priv->is_public_folder ? MAPI_OPTIONS_USE_PFSTORE : 0, to_remove, cancellable, &mapi_error);
 
 	e_book_backend_mapi_unlock_connection (ebma);
 
@@ -904,7 +923,7 @@ ebbm_contacts_modify_contacts (EBookBackendMAPI *ebma, GCancellable *cancellable
 	e_mapi_util_mapi_ids_from_uid (e_contact_get_const (contact, E_CONTACT_UID), &fid, &mid);
 
 	if (!e_mapi_connection_modify_item (conn, olFolderContacts, priv->fid, mid,
-		mapi_book_write_props, &mcd, NULL, NULL, NULL, priv->is_public_folder ? MAPI_OPTIONS_USE_PFSTORE : 0, &mapi_error)) {
+		mapi_book_write_props, &mcd, NULL, NULL, NULL, priv->is_public_folder ? MAPI_OPTIONS_USE_PFSTORE : 0, cancellable, &mapi_error)) {
 
 		mapi_error_to_edb_error (error, mapi_error, E_DATA_BOOK_STATUS_OTHER_ERROR, _("Failed to modify item on a server"));
 		if (mapi_error)
@@ -972,7 +991,7 @@ ebbm_contacts_get_contact (EBookBackendMAPI *ebma, GCancellable *cancellable, co
 	e_mapi_connection_fetch_item (conn, priv->fid, mid,
 		priv->is_public_folder ? NULL : mapi_book_utils_get_prop_list, GET_ALL_KNOWN_IDS,
 		fetch_contact_item_cb, &fcid,
-		options, &mapi_error);
+		options, cancellable, &mapi_error);
 
 	if (fcid.contact) {
 		*vcard =  e_vcard_to_string (E_VCARD (fcid.contact), EVC_FORMAT_VCARD_30);
@@ -1053,7 +1072,7 @@ ebbm_contacts_get_contact_list (EBookBackendMAPI *ebma, GCancellable *cancellabl
 
 	if (!e_mapi_connection_fetch_items (conn, priv->fid, get_all ? NULL : &res, NULL,
 		priv->is_public_folder ? NULL : mapi_book_utils_get_prop_list, GET_ALL_KNOWN_IDS,
-		create_contact_list_cb, &ccld, options, &mapi_error)) {
+		create_contact_list_cb, &ccld, options, cancellable, &mapi_error)) {
 		mapi_error_to_edb_error (error, mapi_error, E_DATA_BOOK_STATUS_OTHER_ERROR, _("Failed to fetch items from a server"));
 		if (mapi_error)
 			g_error_free (mapi_error);
@@ -1119,7 +1138,7 @@ ebbm_contacts_fetch_contacts (EBookBackendMAPI *ebma, struct mapi_SRestriction *
 
 	if (!e_mapi_connection_fetch_items (conn, priv->fid, restriction, NULL,
 		mapi_book_utils_get_prop_list, GET_ALL_KNOWN_IDS,
-		fetch_contacts_cb, &fcd, options, &mapi_error)) {
+		fetch_contacts_cb, &fcd, options, NULL, &mapi_error)) {
 		mapi_error_to_edb_error (error, mapi_error, E_DATA_BOOK_STATUS_OTHER_ERROR, _("Failed to fetch items from a server"));
 
 		if (mapi_error)
@@ -1130,7 +1149,7 @@ ebbm_contacts_fetch_contacts (EBookBackendMAPI *ebma, struct mapi_SRestriction *
 }
 
 static void
-ebbm_contacts_fetch_known_uids (EBookBackendMAPI *ebma, GCancellable *cancelled, GHashTable *uids, GError **error)
+ebbm_contacts_fetch_known_uids (EBookBackendMAPI *ebma, GCancellable *cancellable, GHashTable *uids, GError **error)
 {
 	EBookBackendMAPIContacts *ebmac;
 	EBookBackendMAPIContactsPrivate *priv;
@@ -1141,7 +1160,7 @@ ebbm_contacts_fetch_known_uids (EBookBackendMAPI *ebma, GCancellable *cancelled,
 
 	e_return_data_book_error_if_fail (ebma != NULL, E_DATA_BOOK_STATUS_INVALID_ARG);
 	e_return_data_book_error_if_fail (E_IS_BOOK_BACKEND_MAPI_CONTACTS (ebma), E_DATA_BOOK_STATUS_INVALID_ARG);
-	e_return_data_book_error_if_fail (cancelled != NULL, E_DATA_BOOK_STATUS_INVALID_ARG);
+	e_return_data_book_error_if_fail (cancellable != NULL, E_DATA_BOOK_STATUS_INVALID_ARG);
 	e_return_data_book_error_if_fail (uids != NULL, E_DATA_BOOK_STATUS_INVALID_ARG);
 
 	ebmac = E_BOOK_BACKEND_MAPI_CONTACTS (ebma);
@@ -1163,12 +1182,12 @@ ebbm_contacts_fetch_known_uids (EBookBackendMAPI *ebma, GCancellable *cancelled,
 	if (priv->is_public_folder)
 		options |= MAPI_OPTIONS_USE_PFSTORE;
 
-	fcud.cancelled = cancelled;
+	fcud.cancellable = cancellable;
 	fcud.uids = uids;
 
 	e_mapi_connection_fetch_items (conn, priv->fid, NULL, NULL,
 		mapi_book_utils_get_prop_list, GET_UIDS_ONLY,
-		fetch_contacts_uids_cb, &fcud, options, &mapi_error);
+		fetch_contacts_uids_cb, &fcud, options, cancellable, &mapi_error);
 
 	if (mapi_error) {
 		mapi_error_to_edb_error (error, mapi_error, E_DATA_BOOK_STATUS_OTHER_ERROR, _("Failed to fetch items from a server"));
diff --git a/src/addressbook/e-book-backend-mapi-gal.c b/src/addressbook/e-book-backend-mapi-gal.c
index 3cc0834..c8ab7d9 100644
--- a/src/addressbook/e-book-backend-mapi-gal.c
+++ b/src/addressbook/e-book-backend-mapi-gal.c
@@ -63,7 +63,13 @@ struct FetchGalData
 };
 
 static gboolean
-fetch_gal_cb (EMapiConnection *conn, uint32_t row_index, uint32_t n_rows, struct SRow *aRow, gpointer data)
+fetch_gal_cb (EMapiConnection *conn,
+	      uint32_t row_index,
+	      uint32_t n_rows,
+	      struct SRow *aRow,
+	      gpointer data,
+	      GCancellable *cancellable,
+	      GError **perror)
 {
 	struct FetchGalData *fgd = data;
 	struct timeval *last_modification = NULL, tv = { 0 };
@@ -104,13 +110,19 @@ fetch_gal_cb (EMapiConnection *conn, uint32_t row_index, uint32_t n_rows, struct
 
 struct FetchGalUidsData
 {
-	GCancellable *cancelled;
+	GCancellable *cancellable;
 	GHashTable *uids;
 	mapi_id_t fid; /* folder ID of contacts */
 };
 
 static gboolean
-fetch_gal_uids_cb (EMapiConnection *conn, uint32_t row_index, uint32_t n_rows, struct SRow *aRow, gpointer data)
+fetch_gal_uids_cb (EMapiConnection *conn,
+		   uint32_t row_index,
+		   uint32_t n_rows,
+		   struct SRow *aRow,
+		   gpointer data,
+		   GCancellable *cancellable,
+		   GError **perror)
 {
 	gchar *uid;
 	struct FetchGalUidsData *fgud = data;
@@ -123,7 +135,7 @@ fetch_gal_uids_cb (EMapiConnection *conn, uint32_t row_index, uint32_t n_rows, s
 	if (uid)
 		g_hash_table_insert (fgud->uids, uid, GINT_TO_POINTER (1));
 
-	return !g_cancellable_is_cancelled (fgud->cancelled);
+	return !g_cancellable_is_cancelled (fgud->cancellable);
 }
 
 static void
@@ -201,11 +213,11 @@ ebbm_gal_fetch_contacts (EBookBackendMAPI *ebma, struct mapi_SRestriction *restr
 	fgd.ebma = ebma;
 	fgd.book_view = book_view;
 	fgd.notify_contact_data = notify_contact_data;
-	fgd.fid = e_mapi_connection_get_default_folder_id (conn, olFolderContacts, NULL);
+	fgd.fid = e_mapi_connection_get_default_folder_id (conn, olFolderContacts, NULL, NULL);
 
 	fetch_successful = e_mapi_connection_fetch_gal (conn, restriction,
 		mapi_book_utils_get_prop_list, GET_ALL_KNOWN_IDS,
-		fetch_gal_cb, &fgd, &mapi_error);
+		fetch_gal_cb, &fgd, NULL, &mapi_error);
 
 	if (mapi_error) {
 		mapi_error_to_edb_error (error, mapi_error, E_DATA_BOOK_STATUS_OTHER_ERROR, _("Failed to fetch GAL entries"));
@@ -228,14 +240,14 @@ ebbm_gal_fetch_contacts (EBookBackendMAPI *ebma, struct mapi_SRestriction *restr
 }
 
 static void
-ebbm_gal_fetch_known_uids (EBookBackendMAPI *ebma, GCancellable *cancelled, GHashTable *uids, GError **error)
+ebbm_gal_fetch_known_uids (EBookBackendMAPI *ebma, GCancellable *cancellable, GHashTable *uids, GError **error)
 {
 	EMapiConnection *conn;
 	GError *mapi_error = NULL;
 	struct FetchGalUidsData fgud = { 0 };
 
 	g_return_if_fail (ebma != NULL);
-	g_return_if_fail (cancelled != NULL);
+	g_return_if_fail (cancellable != NULL);
 	g_return_if_fail (uids != NULL);
 
 	e_book_backend_mapi_lock_connection (ebma);
@@ -247,13 +259,13 @@ ebbm_gal_fetch_known_uids (EBookBackendMAPI *ebma, GCancellable *cancelled, GHas
 		return;
 	}
 
-	fgud.cancelled = cancelled;
+	fgud.cancellable = cancellable;
 	fgud.uids = uids;
-	fgud.fid = e_mapi_connection_get_default_folder_id (conn, olFolderContacts, NULL);
+	fgud.fid = e_mapi_connection_get_default_folder_id (conn, olFolderContacts, cancellable, NULL);
 
 	e_mapi_connection_fetch_gal (conn, NULL,
 		mapi_book_utils_get_prop_list, GET_UIDS_ONLY,
-		fetch_gal_uids_cb, &fgud, &mapi_error);
+		fetch_gal_uids_cb, &fgud, cancellable, &mapi_error);
 
 	if (mapi_error) {
 		mapi_error_to_edb_error (error, mapi_error, E_DATA_BOOK_STATUS_OTHER_ERROR, _("Failed to fetch GAL entries"));
diff --git a/src/addressbook/e-book-backend-mapi.c b/src/addressbook/e-book-backend-mapi.c
index 4d86d1e..5e21a22 100644
--- a/src/addressbook/e-book-backend-mapi.c
+++ b/src/addressbook/e-book-backend-mapi.c
@@ -413,11 +413,12 @@ ebbm_connect_user (EBookBackendMAPI *ebma, GCancellable *cancellable, const gcha
 
 		priv->conn = e_mapi_connection_new (priv->profile,
 							   password,
+							   cancellable,
 							   &mapi_error);
 		if (!priv->conn) {
 			priv->conn = e_mapi_connection_find (priv->profile);
 			if (priv->conn && !e_mapi_connection_connected (priv->conn))
-				e_mapi_connection_reconnect (priv->conn, password, &mapi_error);
+				e_mapi_connection_reconnect (priv->conn, password, cancellable, &mapi_error);
 		}
 
 		if (old_conn)
@@ -1645,7 +1646,13 @@ e_book_backend_mapi_cache_get (EBookBackendMAPI *ebma, const gchar *key)
 
 /* 'data' is one of GET_ALL_KNOWN_IDS or GET_UIDS_ONLY */
 gboolean
-mapi_book_utils_get_prop_list (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, struct SPropTagArray *props, gpointer data)
+mapi_book_utils_get_prop_list (EMapiConnection *conn,
+			       mapi_id_t fid,
+			       TALLOC_CTX *mem_ctx,
+			       struct SPropTagArray *props,
+			       gpointer data,
+			       GCancellable *cancellable,
+			       GError **perror)
 {
 	/* this is a list of all known book MAPI tag IDs;
 	   if you add new add it here too, otherwise it may not be fetched */
@@ -1733,9 +1740,9 @@ mapi_book_utils_get_prop_list (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX
 
 	/* called with fid = 0 from GAL */
 	if (!fid)
-		fid = e_mapi_connection_get_default_folder_id (conn, olFolderContacts, NULL);
+		fid = e_mapi_connection_get_default_folder_id (conn, olFolderContacts, cancellable, NULL);
 
-	return e_mapi_utils_add_named_ids_to_props_array (conn, fid, mem_ctx, props, nids, G_N_ELEMENTS (nids));
+	return e_mapi_utils_add_named_ids_to_props_array (conn, fid, mem_ctx, props, nids, G_N_ELEMENTS (nids), cancellable, perror);
 }
 
 static gchar *
diff --git a/src/addressbook/e-book-backend-mapi.h b/src/addressbook/e-book-backend-mapi.h
index fa2249c..83fc1b3 100644
--- a/src/addressbook/e-book-backend-mapi.h
+++ b/src/addressbook/e-book-backend-mapi.h
@@ -84,7 +84,7 @@ typedef struct
 	/* function to fetch list of known uids (strings) on the server;
 	   it's used to synchronize local cache with deleted items;
 	   uids has the uid key, as a newly allocated string; value should be GINT_TO_POINTER(1) always */
-	void (*op_fetch_known_uids) (EBookBackendMAPI *ebma, GCancellable *cancelled, GHashTable *uids, GError **error);
+	void (*op_fetch_known_uids) (EBookBackendMAPI *ebma, GCancellable *cancellable, GHashTable *uids, GError **error);
 } EBookBackendMAPIClass;
 
 GType e_book_backend_mapi_get_type (void);
@@ -124,7 +124,13 @@ void mapi_error_to_edb_error (GError **perror, const GError *mapi_error, EDataBo
 #define GET_UIDS_ONLY     (GINT_TO_POINTER(2))
 
 /* data is one of GET_ALL_KNOWN_IDS or GET_UIDS_ONLY */
-gboolean mapi_book_utils_get_prop_list (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, struct SPropTagArray *props, gpointer data);
+gboolean mapi_book_utils_get_prop_list (EMapiConnection *conn,
+					mapi_id_t fid,
+					TALLOC_CTX *mem_ctx,
+					struct SPropTagArray *props,
+					gpointer data,
+					GCancellable *cancellable,
+					GError **perror);
 
 /* only one of mapi_properties and aRow can be set */
 EContact *mapi_book_utils_contact_from_props (EMapiConnection *conn, mapi_id_t fid, const gchar *book_uri, struct mapi_SPropValue_array *mapi_properties, struct SRow *aRow);
diff --git a/src/calendar/e-cal-backend-mapi.c b/src/calendar/e-cal-backend-mapi.c
index 545aedf..5b198a9 100644
--- a/src/calendar/e-cal-backend-mapi.c
+++ b/src/calendar/e-cal-backend-mapi.c
@@ -273,7 +273,7 @@ ecbm_remove (ECalBackend *backend, EDataCal *cal, GCancellable *cancellable, GEr
 	if (g_strcmp0 (e_source_get_property (source, "public"), "yes") != 0) {
 		GError *mapi_error = NULL;
 
-		if (!e_mapi_connection_remove_folder (priv->conn, priv->fid, 0, &mapi_error)) {
+		if (!e_mapi_connection_remove_folder (priv->conn, priv->fid, 0, cancellable, &mapi_error)) {
 			mapi_error_to_edc_error (perror, mapi_error, OtherError, _("Failed to remove public folder"));
 			if (mapi_error)
 				g_error_free (mapi_error);
@@ -397,7 +397,10 @@ put_component_to_store (ECalBackendMAPI *cbmapi,
 }
 
 static gboolean
-mapi_cal_get_changes_cb (FetchItemsCallbackData *item_data, gpointer data)
+mapi_cal_get_changes_cb (FetchItemsCallbackData *item_data,
+			 gpointer data,
+			 GCancellable *cancellable,
+			 GError **perror)
 {
 	struct mapi_SPropValue_array *array = item_data->properties;
 	const mapi_id_t mid = item_data->mid;
@@ -515,7 +518,10 @@ struct deleted_items_data {
 };
 
 static gboolean
-handle_deleted_items_cb (FetchItemsCallbackData *item_data, gpointer data)
+handle_deleted_items_cb (FetchItemsCallbackData *item_data,
+			 gpointer data,
+			 GCancellable *cancellable,
+			 GError **perror)
 {
 	const mapi_id_t mid = item_data->mid;
 	struct deleted_items_data *did = data;
@@ -569,7 +575,13 @@ handle_deleted_items_cb (FetchItemsCallbackData *item_data, gpointer data)
 }
 
 static gboolean
-mapi_cal_get_idlist (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, struct SPropTagArray *props, gpointer data)
+mapi_cal_get_idlist (EMapiConnection *conn,
+		     mapi_id_t fid,
+		     TALLOC_CTX *mem_ctx,
+		     struct SPropTagArray *props,
+		     gpointer data,
+		     GCancellable *cancellable,
+		     GError **perror)
 {
 	static const uint32_t cal_IDList[] = {
 		PR_FID,
@@ -658,7 +670,7 @@ get_deltas (gpointer handle)
 	if (!e_mapi_connection_fetch_items (priv->conn, priv->fid, use_restriction ? &res : NULL, NULL,
 					is_public ? NULL : e_mapi_cal_utils_get_props_cb, GINT_TO_POINTER (kind),
 					mapi_cal_get_changes_cb, cbmapi,
-					options, &mapi_error)) {
+					options, NULL, &mapi_error)) {
 		if (mapi_error) {
 			gchar *msg = g_strdup_printf (_("Failed to fetch changes from a server: %s"), mapi_error->message);
 			e_cal_backend_notify_error (E_CAL_BACKEND (cbmapi), msg);
@@ -702,7 +714,7 @@ get_deltas (gpointer handle)
 	if (!e_mapi_connection_fetch_items (priv->conn, priv->fid, NULL, NULL,
 						mapi_cal_get_idlist, NULL,
 						handle_deleted_items_cb, &did,
-						options, &mapi_error)) {
+						options, NULL, &mapi_error)) {
 		if (mapi_error) {
 			gchar *msg = g_strdup_printf (_("Failed to fetch changes from a server: %s"), mapi_error->message);
 			e_cal_backend_notify_error (E_CAL_BACKEND (cbmapi), msg);
@@ -779,7 +791,7 @@ get_deltas (gpointer handle)
 		if (!e_mapi_connection_fetch_items (priv->conn, priv->fid, &res, NULL,
 					is_public ? NULL : e_mapi_cal_utils_get_props_cb, GINT_TO_POINTER (kind),
 					mapi_cal_get_changes_cb, cbmapi,
-					options, &mapi_error)) {
+					options, NULL, &mapi_error)) {
 			if (mapi_error) {
 				gchar *msg = g_strdup_printf (_("Failed to fetch changes from a server: %s"), mapi_error->message);
 				e_cal_backend_notify_error (E_CAL_BACKEND (cbmapi), msg);
@@ -1008,7 +1020,10 @@ start_fetch_deltas (gpointer data)
 }
 
 static gboolean
-mapi_cal_cache_create_cb (FetchItemsCallbackData *item_data, gpointer data)
+mapi_cal_cache_create_cb (FetchItemsCallbackData *item_data,
+			  gpointer data,
+			  GCancellable *cancellable,
+			  GError **perror)
 {
 	struct mapi_SPropValue_array *properties = item_data->properties;
 	const mapi_id_t mid = item_data->mid;
@@ -1122,7 +1137,7 @@ populate_cache (ECalBackendMAPI *cbmapi, GError **perror)
 	if (!e_mapi_connection_fetch_items (priv->conn, priv->fid, NULL, NULL,
 					is_public ? NULL : e_mapi_cal_utils_get_props_cb, GINT_TO_POINTER (kind),
 					mapi_cal_cache_create_cb, cbmapi,
-					options, &mapi_error)) {
+					options, NULL, &mapi_error)) {
 		e_cal_backend_store_thaw_changes (priv->store);
 		g_mutex_lock (priv->mutex);
 		priv->populating_cache = FALSE;
@@ -1235,12 +1250,12 @@ ecbm_connect_user (ECalBackend *backend, GCancellable *cancellable, const gchar
 
 	old_conn = priv->conn;
 
-	priv->conn = e_mapi_connection_new (priv->profile, password, &mapi_error);
+	priv->conn = e_mapi_connection_new (priv->profile, password, cancellable, &mapi_error);
 	if (!priv->conn) {
 		priv->conn = e_mapi_connection_find (priv->profile);
 		if (priv->conn
 		    && !e_mapi_connection_connected (priv->conn)) {
-			e_mapi_connection_reconnect (priv->conn, password, &mapi_error);
+			e_mapi_connection_reconnect (priv->conn, password, cancellable, &mapi_error);
 		}
 	}
 
@@ -1388,7 +1403,13 @@ ecbm_authenticate_user (ECalBackend *backend, GCancellable *cancellable, ECreden
 }
 
 static gboolean
-mapi_cal_get_required_props (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, struct SPropTagArray *props, gpointer data)
+mapi_cal_get_required_props (EMapiConnection *conn,
+			     mapi_id_t fid,
+			     TALLOC_CTX *mem_ctx,
+			     struct SPropTagArray *props,
+			     gpointer data,
+			     GCancellable *cancellable,
+			     GError **perror)
 {
 	static uint32_t req_props_list[] = {
 		PR_OWNER_APPT_ID,
@@ -1409,14 +1430,17 @@ mapi_cal_get_required_props (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *m
 
 	g_return_val_if_fail (props != NULL, FALSE);
 
-	if (!e_mapi_utils_add_named_ids_to_props_array (conn, fid, mem_ctx, props, nids, G_N_ELEMENTS (nids)))
+	if (!e_mapi_utils_add_named_ids_to_props_array (conn, fid, mem_ctx, props, nids, G_N_ELEMENTS (nids), cancellable, perror))
 		return FALSE;
 
 	return e_mapi_utils_add_props_to_props_array (mem_ctx, props, req_props_list, G_N_ELEMENTS (req_props_list));
 }
 
 static gboolean
-capture_req_props (FetchItemsCallbackData *item_data, gpointer data)
+capture_req_props (FetchItemsCallbackData *item_data,
+		   gpointer data,
+		   GCancellable *cancellable,
+		   GError **perror)
 {
 	struct mapi_SPropValue_array *properties = item_data->properties;
 	struct cal_cbdata *cbdata = (struct cal_cbdata *) data;
@@ -1478,11 +1502,11 @@ get_server_data (ECalBackendMAPI *cbmapi, ECalComponent *comp, struct cal_cbdata
 	if (e_mapi_connection_fetch_item (priv->conn, priv->fid, mid,
 					mapi_cal_get_required_props, NULL,
 					capture_req_props, cbdata,
-					MAPI_OPTIONS_FETCH_GENERIC_STREAMS, NULL))
+					MAPI_OPTIONS_FETCH_GENERIC_STREAMS, NULL, NULL))
 
 		return;
 
-	proptag = e_mapi_connection_resolve_named_prop (priv->conn, priv->fid, PidLidCleanGlobalObjectId, NULL);
+	proptag = e_mapi_connection_resolve_named_prop (priv->conn, priv->fid, PidLidCleanGlobalObjectId, NULL, NULL);
 	if (proptag == MAPI_E_RESERVED) proptag = PidLidCleanGlobalObjectId;
 
 	res.rt = RES_PROPERTY;
@@ -1513,7 +1537,7 @@ get_server_data (ECalBackendMAPI *cbmapi, ECalComponent *comp, struct cal_cbdata
 	e_mapi_connection_fetch_items (priv->conn, priv->fid, &res, NULL,
 					mapi_cal_get_required_props, NULL,
 					capture_req_props, cbdata,
-					MAPI_OPTIONS_FETCH_GENERIC_STREAMS, NULL);
+					MAPI_OPTIONS_FETCH_GENERIC_STREAMS, NULL, NULL);
 
 	talloc_free (mem_ctx);
 }
@@ -1605,7 +1629,7 @@ ecbm_create_object (ECalBackend *backend, EDataCal *cal, GCancellable *cancellab
 		if (ba) {
 			ExchangeMAPIStream *stream = g_new0 (ExchangeMAPIStream, 1);
 			stream->value = ba;
-			stream->proptag = e_mapi_connection_resolve_named_prop (priv->conn, priv->fid, PidLidAppointmentRecur, NULL);
+			stream->proptag = e_mapi_connection_resolve_named_prop (priv->conn, priv->fid, PidLidAppointmentRecur, cancellable, NULL);
 			if (stream->proptag != MAPI_E_RESERVED)
 				streams = g_slist_append (streams, stream);
 		}
@@ -1643,7 +1667,7 @@ ecbm_create_object (ECalBackend *backend, EDataCal *cal, GCancellable *cancellab
 
 		mid = e_mapi_connection_create_item (priv->conn, priv->olFolder, priv->fid,
 						e_mapi_cal_utils_write_props_cb, &cbdata,
-						recipients, attachments, streams, MAPI_OPTIONS_DONT_SUBMIT, &mapi_error);
+						recipients, attachments, streams, MAPI_OPTIONS_DONT_SUBMIT, cancellable, &mapi_error);
 		g_free (cbdata.props);
 		if (!mid) {
 			g_object_unref (comp);
@@ -1808,7 +1832,7 @@ ecbm_modify_object (ECalBackend *backend, EDataCal *cal, GCancellable *cancellab
 		if (ba) {
 			ExchangeMAPIStream *stream = g_new0 (ExchangeMAPIStream, 1);
 			stream->value = ba;
-			stream->proptag = e_mapi_connection_resolve_named_prop (priv->conn, priv->fid, PidLidAppointmentRecur, NULL);
+			stream->proptag = e_mapi_connection_resolve_named_prop (priv->conn, priv->fid, PidLidAppointmentRecur, cancellable, NULL);
 			if (stream->proptag != MAPI_E_RESERVED)
 				streams = g_slist_append (streams, stream);
 		}
@@ -1821,7 +1845,7 @@ ecbm_modify_object (ECalBackend *backend, EDataCal *cal, GCancellable *cancellab
 		e_mapi_cal_util_fetch_attachments (comp, &attachments, cache_dir);
 
 	e_cal_component_get_uid (comp, &uid);
-//	rid = e_cal_component_get_recurid_as_string (comp);
+	/* rid = e_cal_component_get_recurid_as_string (comp); */
 
 	cbdata.kind = kind;
 	cbdata.get_timezone = (icaltimezone * (*)(gpointer data, const gchar *tzid)) ecbm_internal_get_timezone;
@@ -1871,7 +1895,7 @@ ecbm_modify_object (ECalBackend *backend, EDataCal *cal, GCancellable *cancellab
 
 		status = e_mapi_connection_modify_item (priv->conn, priv->olFolder, priv->fid, mid,
 						e_mapi_cal_utils_write_props_cb, &cbdata,
-						recipients, attachments, streams, MAPI_OPTIONS_DONT_SUBMIT, &mapi_error);
+						recipients, attachments, streams, MAPI_OPTIONS_DONT_SUBMIT, cancellable, &mapi_error);
 		g_free (cbdata.props);
 		free_server_data (&cbdata);
 		if (!status) {
@@ -1972,7 +1996,7 @@ ecbm_remove_object (ECalBackend *backend, EDataCal *cal, GCancellable *cancellab
 			list = g_slist_prepend (list, (gpointer) data);
 		/* } */
 
-		if (e_mapi_connection_remove_items (priv->conn, priv->olFolder, priv->fid, 0, list, &ri_error)) {
+		if (e_mapi_connection_remove_items (priv->conn, priv->olFolder, priv->fid, 0, list, cancellable, &ri_error)) {
 			for (l = comp_list; l; l = l->next) {
 				ECalComponent *comp = E_CAL_COMPONENT (l->data);
 				ECalComponentId *id = e_cal_component_get_id (comp);
@@ -2064,7 +2088,7 @@ ecbm_send_objects (ECalBackend *backend, EDataCal *cal, GCancellable *cancellabl
 				if (ba) {
 					ExchangeMAPIStream *stream = g_new0 (ExchangeMAPIStream, 1);
 					stream->value = ba;
-					stream->proptag = e_mapi_connection_resolve_named_prop (priv->conn, priv->fid, PidLidAppointmentRecur, NULL);
+					stream->proptag = e_mapi_connection_resolve_named_prop (priv->conn, priv->fid, PidLidAppointmentRecur, cancellable, NULL);
 					if (stream->proptag != MAPI_E_RESERVED)
 						streams = g_slist_append (streams, stream);
 				}
@@ -2172,7 +2196,7 @@ ecbm_send_objects (ECalBackend *backend, EDataCal *cal, GCancellable *cancellabl
 
 			mid = e_mapi_connection_create_item (priv->conn, olFolderSentMail, 0,
 							e_mapi_cal_utils_write_props_cb, &cbdata,
-							recipients, attachments, streams, MAPI_OPTIONS_DELETE_ON_SUBMIT_FAILURE, &mapi_error);
+							recipients, attachments, streams, MAPI_OPTIONS_DELETE_ON_SUBMIT_FAILURE, cancellable, &mapi_error);
 			cbdata.globalid = NULL;
 			cbdata.cleanglobalid = NULL;
 			free_server_data (&cbdata);
@@ -2434,7 +2458,7 @@ ecbm_get_free_busy (ECalBackend *backend, EDataCal *cal, GCancellable *cancellab
 		return;
 	}
 
-	if (!e_mapi_cal_utils_get_free_busy_data (priv->conn, users, start, end, freebusy, &mapi_error)) {
+	if (!e_mapi_cal_utils_get_free_busy_data (priv->conn, users, start, end, freebusy, cancellable, &mapi_error)) {
 		mapi_error_to_edc_error (perror, mapi_error, OtherError, _("Failed to get Free/Busy data"));
 
 		if (mapi_error)
diff --git a/src/camel/camel-mapi-folder.c b/src/camel/camel-mapi-folder.c
index d8c18dc..045d088 100644
--- a/src/camel/camel-mapi-folder.c
+++ b/src/camel/camel-mapi-folder.c
@@ -143,7 +143,10 @@ update_store_summary (CamelFolder *folder, GError **error)
 }
 
 static gboolean
-fetch_items_summary_cb (FetchItemsCallbackData *item_data, gpointer data)
+fetch_items_summary_cb (FetchItemsCallbackData *item_data,
+			gpointer data,
+			GCancellable *cancellable,
+			GError **perror)
 {
 	fetch_items_data *fi_data = (fetch_items_data *)data;
 
@@ -448,7 +451,7 @@ mapi_update_cache (CamelFolder *folder, GSList *list, CamelFolderChangeInfo **ch
 				gchar *from_email;
 
 				camel_service_lock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
-				from_email = e_mapi_connection_ex_to_smtp (camel_mapi_store_get_connection (mapi_store), item->header.from_email, NULL, NULL);
+				from_email = e_mapi_connection_ex_to_smtp (camel_mapi_store_get_connection (mapi_store), item->header.from_email, NULL, cancellable, NULL);
 				camel_service_unlock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 
 				g_free (item->header.from_email);
@@ -515,7 +518,10 @@ struct _SyncDeletedData {
 };
 
 static gboolean
-deleted_items_sync_cb (FetchItemsCallbackData *item_data, gpointer data)
+deleted_items_sync_cb (FetchItemsCallbackData *item_data,
+		       gpointer data,
+		       GCancellable *cancellable,
+		       GError **perror)
 {
 	guint32 msg_flags = CAMEL_MESSAGE_FOLDER_FLAGGED; /* to not have 0 in the hash table */
 	GHashTable *uids = data;
@@ -589,7 +595,7 @@ mapi_sync_deleted (CamelSession *session,
 	e_mapi_connection_fetch_items (camel_mapi_store_get_connection (mapi_store), data->folder_id, NULL, NULL,
 					       NULL, NULL,
 					       deleted_items_sync_cb, server_messages,
-					       options | MAPI_OPTIONS_DONT_OPEN_MESSAGE, NULL);
+					       options | MAPI_OPTIONS_DONT_OPEN_MESSAGE, cancellable, NULL);
 
 	camel_operation_pop_message (cancellable);
 
@@ -696,7 +702,13 @@ mapi_sync_deleted_data_free (SyncDeletedData *data)
 }
 
 static gboolean
-mapi_camel_get_summary_list (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, struct SPropTagArray *props, gpointer data)
+mapi_camel_get_summary_list (EMapiConnection *conn,
+			     mapi_id_t fid,
+			     TALLOC_CTX *mem_ctx,
+			     struct SPropTagArray *props,
+			     gpointer data,
+			     GCancellable *cancellable,
+			     GError **perror)
 {
 	static const uint32_t summary_prop_list[] = {
 		PR_INTERNET_CPID,
@@ -738,7 +750,7 @@ camel_mapi_folder_fetch_summary (CamelStore *store, CamelFolder *folder, const m
 	status = e_mapi_connection_fetch_items  (camel_mapi_store_get_connection (mapi_store), fid, res, sort,
 							mapi_camel_get_summary_list, NULL,
 							fetch_items_summary_cb, fetch_data,
-							options, mapi_error);
+							options, cancellable, mapi_error);
 
 	camel_service_unlock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 
@@ -1128,7 +1140,7 @@ mapi_folder_append_message_sync (CamelFolder *folder,
 	mid = e_mapi_connection_create_item (camel_mapi_store_get_connection (mapi_store), -1, fid,
 					 mapi_mail_utils_create_item_build_props, item,
 					 item->recipients, item->attachments,
-					 item->generic_streams, MAPI_OPTIONS_DONT_SUBMIT, &mapi_error);
+					 item->generic_streams, MAPI_OPTIONS_DONT_SUBMIT, cancellable, &mapi_error);
 
 	if (mid) {
 		CamelFolderChangeInfo *changes = camel_folder_change_info_new ();
@@ -1230,7 +1242,7 @@ mapi_folder_expunge_sync (CamelFolder *folder,
 		g_ptr_array_free (folders, TRUE);
 
 		camel_service_lock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
-		status = e_mapi_connection_empty_folder (camel_mapi_store_get_connection (mapi_store), fid, 0, &mapi_error);
+		status = e_mapi_connection_empty_folder (camel_mapi_store_get_connection (mapi_store), fid, 0, cancellable, &mapi_error);
 		camel_service_unlock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 
 		if (status) {
@@ -1284,7 +1296,7 @@ mapi_folder_expunge_sync (CamelFolder *folder,
 	if (deleted_items) {
 		camel_service_lock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 
-		status = e_mapi_connection_remove_items (camel_mapi_store_get_connection (mapi_store), 0, fid, 0, deleted_items, NULL);
+		status = e_mapi_connection_remove_items (camel_mapi_store_get_connection (mapi_store), 0, fid, 0, deleted_items, cancellable, NULL);
 
 		camel_service_unlock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 
@@ -1428,7 +1440,7 @@ mapi_folder_get_message_sync (CamelFolder *folder,
 	e_mapi_connection_fetch_item (camel_mapi_store_get_connection (mapi_store), id_folder, id_message,
 					mapi_mail_get_item_prop_list, NULL,
 					fetch_props_to_mail_item_cb, &item,
-					options, &mapi_error);
+					options, cancellable, &mapi_error);
 	camel_service_unlock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 
 	if (item == NULL) {
@@ -1631,13 +1643,13 @@ mapi_folder_synchronize_sync (CamelFolder *folder,
 
 	if (read_items) {
 		camel_service_lock (service, CAMEL_SERVICE_REC_CONNECT_LOCK);
-		e_mapi_connection_set_flags (camel_mapi_store_get_connection (mapi_store), 0, fid, options, read_items, 0, NULL);
+		e_mapi_connection_set_flags (camel_mapi_store_get_connection (mapi_store), 0, fid, options, read_items, 0, cancellable, NULL);
 		camel_service_unlock (service, CAMEL_SERVICE_REC_CONNECT_LOCK);
 	}
 
 	if (unread_items) {
 		camel_service_lock (service, CAMEL_SERVICE_REC_CONNECT_LOCK);
-		e_mapi_connection_set_flags (camel_mapi_store_get_connection (mapi_store), 0, fid, options, unread_items, CLEAR_READ_FLAG, NULL);
+		e_mapi_connection_set_flags (camel_mapi_store_get_connection (mapi_store), 0, fid, options, unread_items, CLEAR_READ_FLAG, cancellable, NULL);
 		camel_service_unlock (service, CAMEL_SERVICE_REC_CONNECT_LOCK);
 	}
 
@@ -1645,12 +1657,12 @@ mapi_folder_synchronize_sync (CamelFolder *folder,
 	if (deleted_items) {
 		camel_service_lock (service, CAMEL_SERVICE_REC_CONNECT_LOCK);
 		if ((mapi_folder->camel_folder_flags & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_TRASH) {
-			e_mapi_connection_remove_items (camel_mapi_store_get_connection (mapi_store), 0, fid, options, deleted_items, NULL);
+			e_mapi_connection_remove_items (camel_mapi_store_get_connection (mapi_store), 0, fid, options, deleted_items, cancellable, NULL);
 		} else {
 			GError *err = NULL;
 
 			e_mapi_util_mapi_id_from_string (camel_mapi_store_system_folder_fid (mapi_store, olFolderDeletedItems), &deleted_items_fid);
-			e_mapi_connection_move_items (camel_mapi_store_get_connection (mapi_store), fid, options, deleted_items_fid, 0, deleted_items, &err);
+			e_mapi_connection_move_items (camel_mapi_store_get_connection (mapi_store), fid, options, deleted_items_fid, 0, deleted_items, cancellable, &err);
 
 			if (err) {
 				g_warning ("%s: Failed to move deleted items: %s", G_STRFUNC, err->message);
@@ -1667,7 +1679,7 @@ mapi_folder_synchronize_sync (CamelFolder *folder,
 
 		camel_service_lock (service, CAMEL_SERVICE_REC_CONNECT_LOCK);
 		e_mapi_util_mapi_id_from_string (camel_mapi_store_system_folder_fid (mapi_store, olFolderJunk), &junk_fid);
-		e_mapi_connection_move_items (camel_mapi_store_get_connection (mapi_store), fid, options, junk_fid, 0, junk_items, &err);
+		e_mapi_connection_move_items (camel_mapi_store_get_connection (mapi_store), fid, options, junk_fid, 0, junk_items, cancellable, &err);
 		camel_service_unlock (service, CAMEL_SERVICE_REC_CONNECT_LOCK);
 
 		/* in junk_items are only emails which are not deleted */
@@ -1792,7 +1804,7 @@ mapi_folder_transfer_messages_to_sync (CamelFolder *source,
 	if (delete_originals) {
 		GError *err = NULL;
 
-		if (!e_mapi_connection_move_items (camel_mapi_store_get_connection (mapi_store), src_fid, src_fid_options, dest_fid, dest_fid_options, src_msg_ids, &err)) {
+		if (!e_mapi_connection_move_items (camel_mapi_store_get_connection (mapi_store), src_fid, src_fid_options, dest_fid, dest_fid_options, src_msg_ids, cancellable, &err)) {
 			g_set_error (
 				error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
 				"%s", err ? err->message : _("Unknown error"));
@@ -1813,7 +1825,7 @@ mapi_folder_transfer_messages_to_sync (CamelFolder *source,
 	} else {
 		GError *err = NULL;
 
-		if (!e_mapi_connection_copy_items (camel_mapi_store_get_connection (mapi_store), src_fid, src_fid_options, dest_fid, dest_fid_options, src_msg_ids, &err)) {
+		if (!e_mapi_connection_copy_items (camel_mapi_store_get_connection (mapi_store), src_fid, src_fid_options, dest_fid, dest_fid_options, src_msg_ids, cancellable, &err)) {
 			g_set_error (
 				error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
 				"%s", err ? err->message : _("Unknown error"));
diff --git a/src/camel/camel-mapi-notifications.c b/src/camel/camel-mapi-notifications.c
index 3b1c713..feb6197 100644
--- a/src/camel/camel-mapi-notifications.c
+++ b/src/camel/camel-mapi-notifications.c
@@ -229,14 +229,14 @@ mapi_push_notification_listener_thread (gpointer data)
 
 	g_object_ref (conn);
 
-	if (e_mapi_connection_events_init (conn, NULL)) {
+	if (e_mapi_connection_events_init (conn, NULL, NULL)) {
 		e_mapi_connection_events_subscribe (conn, thread_data->event_options, thread_data->event_mask,
 						&thread_data->connection, mapi_notifications_filter,
-						thread_data->event_data, NULL);
+						thread_data->event_data, NULL, NULL);
 
 		camel_service_unlock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 		e_mapi_connection_events_monitor (conn, cb_data); /*Blocking call. Don't hold locks here*/
-		e_mapi_connection_events_unsubscribe (conn, thread_data->connection, NULL);
+		e_mapi_connection_events_unsubscribe (conn, thread_data->connection, NULL, NULL);
 	} else
 		camel_service_unlock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 
diff --git a/src/camel/camel-mapi-store.c b/src/camel/camel-mapi-store.c
index dabc58f..b719667 100644
--- a/src/camel/camel-mapi-store.c
+++ b/src/camel/camel-mapi-store.c
@@ -361,7 +361,21 @@ remove_path_from_store_summary (const gchar *path, gpointer value, CamelMapiStor
 }
 
 static gboolean
-mapi_folders_sync (CamelMapiStore *store, guint32 flags, GError **error)
+camel_mapi_update_operation_progress_cb (EMapiConnection *conn,
+					 guint32 item_index,
+					 guint32 items_total,
+					 gpointer user_data,
+					 GCancellable *cancellable,
+					 GError **perror)
+{
+	if (items_total > 0)
+		camel_operation_progress (cancellable, 100 * item_index / items_total);
+
+	return TRUE;
+}
+
+static gboolean
+mapi_folders_sync (CamelMapiStore *store, guint32 flags, GCancellable *cancellable, GError **error)
 {
 	CamelMapiStorePrivate  *priv = store->priv;
 	gboolean status;
@@ -381,8 +395,7 @@ mapi_folders_sync (CamelMapiStore *store, guint32 flags, GError **error)
 		return FALSE;
 	}
 
-	status = e_mapi_connection_get_folders_list (priv->conn, &folder_list, &err);
-
+	status = e_mapi_connection_get_folders_list (priv->conn, &folder_list, camel_mapi_update_operation_progress_cb, NULL, cancellable, &err);
 	if (!status) {
 		g_warning ("Could not get folder list (%s)\n", err ? err->message : "Unknown error");
 		if (err)
@@ -412,7 +425,7 @@ mapi_folders_sync (CamelMapiStore *store, guint32 flags, GError **error)
 		GError *err = NULL;
 
 		/*Consult the name <-> fid hash table for a FID.*/
-		status = e_mapi_connection_get_pf_folders_list (priv->conn, &folder_list, &err);
+		status = e_mapi_connection_get_pf_folders_list (priv->conn, &folder_list, camel_mapi_update_operation_progress_cb, NULL, cancellable, &err);
 		if (!status)
 			g_warning ("Could not get Public folder list (%s)\n", err ? err->message : "Unknown error");
 
@@ -942,7 +955,7 @@ mapi_update_folder_info_cb (CamelSession *session,
 		   one every single question on the folder info */
 		status = camel_service_get_connection_status (service);
 		if (check_for_connection (service, NULL) || status == CAMEL_SERVICE_CONNECTING) {
-			if (mapi_folders_sync (mapi_store, CAMEL_STORE_FOLDER_INFO_RECURSIVE, error)) {
+			if (mapi_folders_sync (mapi_store, CAMEL_STORE_FOLDER_INFO_RECURSIVE, cancellable, error)) {
 				camel_store_summary_touch (mapi_store->summary);
 				camel_store_summary_save (mapi_store->summary);
 			}
@@ -984,7 +997,7 @@ mapi_store_get_folder_info_sync (CamelStore *store,
 				camel_service_connect_sync (service, NULL);
 
 			if (check_for_connection (service, NULL) || status == CAMEL_SERVICE_CONNECTING) {
-				if (!mapi_folders_sync (mapi_store, flags, error)) {
+				if (!mapi_folders_sync (mapi_store, flags, cancellable, error)) {
 					camel_service_unlock (service, CAMEL_SERVICE_REC_CONNECT_LOCK);
 					return NULL;
 				}
@@ -1064,7 +1077,7 @@ mapi_store_create_folder_sync (CamelStore *store,
 	camel_service_lock (CAMEL_SERVICE (store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 
 	e_mapi_util_mapi_id_from_string (parent_id, &parent_fid);
-	new_folder_id = e_mapi_connection_create_folder (priv->conn, olFolderInbox, parent_fid, 0, folder_name, &mapi_error);
+	new_folder_id = e_mapi_connection_create_folder (priv->conn, olFolderInbox, parent_fid, 0, folder_name, cancellable, &mapi_error);
 	if (new_folder_id != 0) {
 		gchar *folder_id_str;
 
@@ -1133,7 +1146,7 @@ mapi_store_delete_folder_sync (CamelStore *store,
 
 	folder_id = g_hash_table_lookup (priv->name_hash, folder_name);
 	e_mapi_util_mapi_id_from_string (folder_id, &folder_fid);
-	status = e_mapi_connection_remove_folder (priv->conn, folder_fid, 0, &local_error);
+	status = e_mapi_connection_remove_folder (priv->conn, folder_fid, 0, cancellable, &local_error);
 
 	if (status) {
 		/* Fixme ??  */
@@ -1259,7 +1272,7 @@ mapi_store_rename_folder_sync (CamelStore *store,
 		gchar *folder_id;
 
 		/* renaming in the same folder, thus no MoveFolder necessary */
-		if (!e_mapi_connection_rename_folder (priv->conn, old_fid, 0, tmp ? tmp : new_name, &local_error)) {
+		if (!e_mapi_connection_rename_folder (priv->conn, old_fid, 0, tmp ? tmp : new_name, cancellable, &local_error)) {
 			if (local_error) {
 				g_set_error (
 					error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
@@ -1323,7 +1336,7 @@ mapi_store_rename_folder_sync (CamelStore *store,
 		} else if (!old_parent_fid_str || !new_parent_fid_str ||
 			   !e_mapi_util_mapi_id_from_string (old_parent_fid_str, &old_parent_fid) ||
 			   !e_mapi_util_mapi_id_from_string (new_parent_fid_str, &new_parent_fid) ||
-			   !e_mapi_connection_move_folder (priv->conn, old_fid, old_parent_fid, 0, new_parent_fid, 0, tmp, &local_error)) {
+			   !e_mapi_connection_move_folder (priv->conn, old_fid, old_parent_fid, 0, new_parent_fid, 0, tmp, cancellable, &local_error)) {
 			camel_service_unlock (service, CAMEL_SERVICE_REC_CONNECT_LOCK);
 			if (local_error) {
 				g_set_error (
@@ -1807,7 +1820,7 @@ mapi_authenticate_sync (CamelService *service,
 		return CAMEL_AUTHENTICATION_ERROR;
 	}
 
-	store->priv->conn = e_mapi_connection_new (profile, password, &mapi_error);
+	store->priv->conn = e_mapi_connection_new (profile, password, cancellable, &mapi_error);
 	if (store->priv->conn && e_mapi_connection_connected (store->priv->conn)) {
 		result = CAMEL_AUTHENTICATION_ACCEPTED;
 	} else if (g_error_matches (mapi_error, E_MAPI_ERROR, MAPI_E_LOGON_FAILED)) {
diff --git a/src/camel/camel-mapi-transport.c b/src/camel/camel-mapi-transport.c
index 98df354..419f907 100644
--- a/src/camel/camel-mapi-transport.c
+++ b/src/camel/camel-mapi-transport.c
@@ -58,7 +58,10 @@ G_DEFINE_TYPE (CamelMapiTransport, camel_mapi_transport, CAMEL_TYPE_TRANSPORT)
 
 /*CreateItem would return the MID of the new message or '0' if we fail.*/
 static mapi_id_t
-mapi_message_item_send (EMapiConnection *conn, MailItem *item, GError **perror)
+mapi_message_item_send (EMapiConnection *conn,
+			MailItem *item,
+			GCancellable *cancellable,
+			GError **perror)
 {
 	guint64 fid = 0;
 	mapi_id_t mid = 0;
@@ -75,7 +78,7 @@ mapi_message_item_send (EMapiConnection *conn, MailItem *item, GError **perror)
 
 	mid = e_mapi_connection_create_item (conn, olFolderSentMail, fid,
 					 mapi_mail_utils_create_item_build_props, item,
-					 item->recipients, item->attachments, item->generic_streams, MAPI_OPTIONS_DELETE_ON_SUBMIT_FAILURE, perror);
+					 item->recipients, item->attachments, item->generic_streams, MAPI_OPTIONS_DELETE_ON_SUBMIT_FAILURE, cancellable, perror);
 
 	return mid;
 }
@@ -121,7 +124,7 @@ mapi_send_to_sync (CamelTransport *transport,
 	item = mapi_mime_message_to_mail_item (message, 0, from, cancellable, NULL);
 
 	/* send */
-	st = mapi_message_item_send (conn, item, &mapi_error);
+	st = mapi_message_item_send (conn, item, cancellable, &mapi_error);
 
 	g_object_unref (conn);
 
diff --git a/src/libexchangemapi/e-mapi-cal-utils.c b/src/libexchangemapi/e-mapi-cal-utils.c
index e863e1f..8fc5774 100644
--- a/src/libexchangemapi/e-mapi-cal-utils.c
+++ b/src/libexchangemapi/e-mapi-cal-utils.c
@@ -43,9 +43,9 @@
 
 #define d(x) 
 
-static gboolean appt_build_name_id (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, struct SPropTagArray *props);
-static gboolean task_build_name_id (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, struct SPropTagArray *props);
-static gboolean note_build_name_id (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, struct SPropTagArray *props);
+static gboolean appt_build_name_id (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, struct SPropTagArray *props, GCancellable *cancellable, GError **perror);
+static gboolean task_build_name_id (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, struct SPropTagArray *props, GCancellable *cancellable, GError **perror);
+static gboolean note_build_name_id (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, struct SPropTagArray *props, GCancellable *cancellable, GError **perror);
 
 static icalparameter_role
 get_role_from_type (OlMailRecipientType type)
@@ -873,7 +873,7 @@ e_mapi_cal_util_mapi_props_to_comp (EMapiConnection *conn, mapi_id_t fid, icalco
 						email = "";
 
 					if (g_str_equal (email_type, "EX")) {
-						to_free = e_mapi_connection_ex_to_smtp (conn, email, NULL, NULL);
+						to_free = e_mapi_connection_ex_to_smtp (conn, email, NULL, NULL, NULL);
 						email = to_free;
 					}
 
@@ -905,7 +905,7 @@ e_mapi_cal_util_mapi_props_to_comp (EMapiConnection *conn, mapi_id_t fid, icalco
 						email = "";
 
 					if (g_str_equal (email_type, "EX")) {
-						to_free = e_mapi_connection_ex_to_smtp (conn, email, NULL, NULL);
+						to_free = e_mapi_connection_ex_to_smtp (conn, email, NULL, NULL, NULL);
 						email = to_free;
 					}
 
@@ -934,11 +934,11 @@ e_mapi_cal_util_mapi_props_to_comp (EMapiConnection *conn, mapi_id_t fid, icalco
 				const gchar *sent_email = (const gchar *) e_mapi_util_find_array_propval (properties, PR_SENT_REPRESENTING_EMAIL_ADDRESS_UNICODE);
 
 				if (!g_utf8_collate (sender_email_type, "EX")) {
-					sender_free = e_mapi_connection_ex_to_smtp (conn, sender_email, NULL, NULL);
+					sender_free = e_mapi_connection_ex_to_smtp (conn, sender_email, NULL, NULL, NULL);
 					sender_email = sender_free;
 				}
 				if (!g_utf8_collate (sent_email_type, "EX")) {
-					sent_free = e_mapi_connection_ex_to_smtp (conn, sent_email, NULL, NULL);
+					sent_free = e_mapi_connection_ex_to_smtp (conn, sent_email, NULL, NULL, NULL);
 					sent_email = sent_free;
 				}
 
@@ -1086,7 +1086,10 @@ struct fetch_camel_cal_data {
 };
 
 static gboolean
-fetch_camel_cal_comp_cb (FetchItemsCallbackData *item_data, gpointer data)
+fetch_camel_cal_comp_cb (FetchItemsCallbackData *item_data,
+			 gpointer data,
+			 GCancellable *cancellable,
+			 GError **perror)
 {
 	struct fetch_camel_cal_data *fccd = data;
 	ECalComponent *comp = NULL;
@@ -1171,19 +1174,25 @@ e_mapi_cal_util_camel_helper (EMapiConnection *conn, mapi_id_t orig_fid, mapi_id
 		e_mapi_connection_fetch_object_props (conn, NULL, orig_fid, orig_mid, obj_message,
 					e_mapi_cal_utils_get_props_cb, GINT_TO_POINTER (fccd.kind),
 					fetch_camel_cal_comp_cb, &fccd,
-					MAPI_OPTIONS_FETCH_ALL, NULL);
+					MAPI_OPTIONS_FETCH_ALL, NULL, NULL);
 	else
 		e_mapi_connection_fetch_item (conn, orig_fid, orig_mid,
 					e_mapi_cal_utils_get_props_cb, GINT_TO_POINTER (fccd.kind),
 					fetch_camel_cal_comp_cb, &fccd,
-					MAPI_OPTIONS_FETCH_ALL, NULL);
+					MAPI_OPTIONS_FETCH_ALL, NULL, NULL);
 
 	return fccd.result_data;
 }
 
 /* call with props = NULL to fetch named ids into the connection cache */
 gboolean
-e_mapi_cal_utils_add_named_ids (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, struct SPropTagArray *props, gint pkind)
+e_mapi_cal_utils_add_named_ids (EMapiConnection *conn,
+				mapi_id_t fid,
+				TALLOC_CTX *mem_ctx,
+				struct SPropTagArray *props,
+				gint pkind,
+				GCancellable *cancellable,
+				GError **perror)
 {
 	/* do not make this array static, the function modifies it on run */
 	ResolveNamedIDsData common_nids[] = {
@@ -1204,17 +1213,17 @@ e_mapi_cal_utils_add_named_ids (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX
 	icalcomponent_kind kind = pkind;
 
 	if (!props) {
-		if (!e_mapi_connection_resolve_named_props (conn, fid, common_nids, G_N_ELEMENTS (common_nids), NULL))
+		if (!e_mapi_connection_resolve_named_props (conn, fid, common_nids, G_N_ELEMENTS (common_nids), cancellable, perror))
 			return FALSE;
-	} else if (!e_mapi_utils_add_named_ids_to_props_array (conn, fid, mem_ctx, props, common_nids, G_N_ELEMENTS (common_nids)))
+	} else if (!e_mapi_utils_add_named_ids_to_props_array (conn, fid, mem_ctx, props, common_nids, G_N_ELEMENTS (common_nids), cancellable, perror))
 		return FALSE;
 
 	if (kind == ICAL_VEVENT_COMPONENT)
-		return appt_build_name_id (conn, fid, mem_ctx, props);
+		return appt_build_name_id (conn, fid, mem_ctx, props, cancellable, perror);
 	else if (kind == ICAL_VTODO_COMPONENT)
-		return task_build_name_id (conn, fid, mem_ctx, props);
+		return task_build_name_id (conn, fid, mem_ctx, props, cancellable, perror);
 	else if (kind == ICAL_VJOURNAL_COMPONENT)
-		return note_build_name_id (conn, fid, mem_ctx, props);
+		return note_build_name_id (conn, fid, mem_ctx, props, cancellable, perror);
 
 	return TRUE;
 }
@@ -1222,7 +1231,12 @@ e_mapi_cal_utils_add_named_ids (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX
 #define DEFAULT_APPT_REMINDER_MINS 15
 
 static gboolean
-appt_build_name_id (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, struct SPropTagArray *props)
+appt_build_name_id (EMapiConnection *conn,
+		    mapi_id_t fid,
+		    TALLOC_CTX *mem_ctx,
+		    struct SPropTagArray *props,
+		    GCancellable *cancellable,
+		    GError **perror)
 {
 	/* do not make this array static, the function modifies it on run */
 	ResolveNamedIDsData nids[] = {
@@ -1259,15 +1273,20 @@ appt_build_name_id (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, s
 	};
 
 	if (!props)
-		return e_mapi_connection_resolve_named_props (conn, fid, nids, G_N_ELEMENTS (nids), NULL);
+		return e_mapi_connection_resolve_named_props (conn, fid, nids, G_N_ELEMENTS (nids), cancellable, perror);
 
-	return e_mapi_utils_add_named_ids_to_props_array (conn, fid, mem_ctx, props, nids, G_N_ELEMENTS (nids));
+	return e_mapi_utils_add_named_ids_to_props_array (conn, fid, mem_ctx, props, nids, G_N_ELEMENTS (nids), cancellable, perror);
 }
 
 #define DEFAULT_TASK_REMINDER_MINS 1080
 
 static gboolean
-task_build_name_id (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, struct SPropTagArray *props)
+task_build_name_id (EMapiConnection *conn,
+		    mapi_id_t fid,
+		    TALLOC_CTX *mem_ctx,
+		    struct SPropTagArray *props,
+		    GCancellable *cancellable,
+		    GError **perror)
 {
 	/* do not make this array static, the function modifies it on run */
 	ResolveNamedIDsData nids[] = {
@@ -1288,13 +1307,18 @@ task_build_name_id (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, s
 	};
 
 	if (!props)
-		return e_mapi_connection_resolve_named_props (conn, fid, nids, G_N_ELEMENTS (nids), NULL);
+		return e_mapi_connection_resolve_named_props (conn, fid, nids, G_N_ELEMENTS (nids), cancellable, perror);
 
-	return e_mapi_utils_add_named_ids_to_props_array (conn, fid, mem_ctx, props, nids, G_N_ELEMENTS (nids));
+	return e_mapi_utils_add_named_ids_to_props_array (conn, fid, mem_ctx, props, nids, G_N_ELEMENTS (nids), cancellable, perror);
 }
 
 static gboolean
-note_build_name_id (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, struct SPropTagArray *props)
+note_build_name_id (EMapiConnection *conn,
+		    mapi_id_t fid,
+		    TALLOC_CTX *mem_ctx,
+		    struct SPropTagArray *props,
+		    GCancellable *cancellable,
+		    GError **perror)
 {
 	/* do not make this array static, the function modifies it on run */
 	ResolveNamedIDsData nids[] = {
@@ -1304,9 +1328,9 @@ note_build_name_id (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, s
 	};
 
 	if (!props)
-		return e_mapi_connection_resolve_named_props (conn, fid, nids, G_N_ELEMENTS (nids), NULL);
+		return e_mapi_connection_resolve_named_props (conn, fid, nids, G_N_ELEMENTS (nids), cancellable, perror);
 
-	return e_mapi_utils_add_named_ids_to_props_array (conn, fid, mem_ctx, props, nids, G_N_ELEMENTS (nids));
+	return e_mapi_utils_add_named_ids_to_props_array (conn, fid, mem_ctx, props, nids, G_N_ELEMENTS (nids), cancellable, perror);
 }
 
 /* retrieves timezone location from a timezone ID */
@@ -1343,7 +1367,14 @@ get_tzid_location (const gchar *tzid, struct cal_cbdata *cbdata)
 #define SECS_IN_MINUTE 60
 
 gboolean
-e_mapi_cal_utils_write_props_cb (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, struct SPropValue **values, uint32_t *n_values, gpointer data)
+e_mapi_cal_utils_write_props_cb (EMapiConnection *conn,
+				 mapi_id_t fid,
+				 TALLOC_CTX *mem_ctx,
+				 struct SPropValue **values,
+				 uint32_t *n_values,
+				 gpointer data,
+				 GCancellable *cancellable,
+				 GError **perror)
 {
 	struct cal_cbdata *cbdata = (struct cal_cbdata *) data;
 	ECalComponent *comp;
@@ -1369,7 +1400,7 @@ e_mapi_cal_utils_write_props_cb (EMapiConnection *conn, mapi_id_t fid, TALLOC_CT
 		case ICAL_VEVENT_COMPONENT:
 		case ICAL_VTODO_COMPONENT:
 		case ICAL_VJOURNAL_COMPONENT:
-			if (!e_mapi_cal_utils_add_named_ids (conn, fid, mem_ctx, NULL, cbdata->kind))
+			if (!e_mapi_cal_utils_add_named_ids (conn, fid, mem_ctx, NULL, cbdata->kind, cancellable, perror))
 				return FALSE;
 			break;
 		default:
@@ -1387,7 +1418,7 @@ e_mapi_cal_utils_write_props_cb (EMapiConnection *conn, mapi_id_t fid, TALLOC_CT
 		} G_STMT_END
 
 	#define set_named_value(named_id, val) G_STMT_START { \
-		if (!e_mapi_utils_add_spropvalue_namedid (conn, fid, mem_ctx, values, n_values, named_id, val)) \
+		if (!e_mapi_utils_add_spropvalue_namedid (conn, fid, mem_ctx, values, n_values, named_id, val, cancellable, perror)) \
 			return FALSE;	\
 		} G_STMT_END
 
@@ -1405,7 +1436,7 @@ e_mapi_cal_utils_write_props_cb (EMapiConnection *conn, mapi_id_t fid, TALLOC_CT
 									\
 		e_mapi_util_time_t_to_filetime (dtval, &filetime); \
 									\
-		if (!e_mapi_utils_add_spropvalue_namedid (conn, fid, mem_ctx, values, n_values, named_id, &filetime)) \
+		if (!e_mapi_utils_add_spropvalue_namedid (conn, fid, mem_ctx, values, n_values, named_id, &filetime, cancellable, perror)) \
 			return FALSE;	\
 		} G_STMT_END
 
@@ -2020,7 +2051,7 @@ e_mapi_cal_util_get_new_appt_id (EMapiConnection *conn, mapi_id_t fid)
 			cast_mapi_SPropValue (mem_ctx,
 					      &(res.res.resProperty.lpProp),
 					      &sprop);
-			ids = e_mapi_connection_check_restriction (conn, fid, 0, &res, NULL);
+			ids = e_mapi_connection_check_restriction (conn, fid, 0, &res, NULL, NULL);
 			if (ids) {
 				GSList *l;
 				for (l = ids; l; l = l->next)
@@ -2162,7 +2193,7 @@ populate_freebusy_data (struct Binary_r *bin, uint32_t month, uint32_t year, GSL
 }
 
 gboolean
-e_mapi_cal_utils_get_free_busy_data (EMapiConnection *conn, const GSList *users, time_t start, time_t end, GSList **freebusy, GError **mapi_error)
+e_mapi_cal_utils_get_free_busy_data (EMapiConnection *conn, const GSList *users, time_t start, time_t end, GSList **freebusy, GCancellable *cancellable, GError **mapi_error)
 {
 	struct SRow		aRow;
 	enum MAPISTATUS		ms;
@@ -2189,7 +2220,7 @@ e_mapi_cal_utils_get_free_busy_data (EMapiConnection *conn, const GSList *users,
 
 	*freebusy = NULL;
 
-	if (!e_mapi_connection_get_public_folder (conn, &obj_store, mapi_error)) {
+	if (!e_mapi_connection_get_public_folder (conn, &obj_store, cancellable, mapi_error)) {
 		return FALSE;
 	}
 
@@ -2275,7 +2306,13 @@ e_mapi_cal_utils_get_free_busy_data (EMapiConnection *conn, const GSList *users,
 
 /* beware, the 'data' pointer is an integer of the event kind */
 gboolean
-e_mapi_cal_utils_get_props_cb (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, struct SPropTagArray *props, gpointer data)
+e_mapi_cal_utils_get_props_cb (EMapiConnection *conn,
+			       mapi_id_t fid,
+			       TALLOC_CTX *mem_ctx,
+			       struct SPropTagArray *props,
+			       gpointer data,
+			       GCancellable *cancellable,
+			       GError **perror)
 {
 	static const uint32_t cal_GetPropsList[] = {
 		PR_FID,
@@ -2318,7 +2355,7 @@ e_mapi_cal_utils_get_props_cb (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX
 	if (!e_mapi_utils_add_props_to_props_array (mem_ctx, props, cal_GetPropsList, G_N_ELEMENTS (cal_GetPropsList)))
 		return FALSE;
 
-	return e_mapi_cal_utils_add_named_ids (conn, fid, mem_ctx, props, GPOINTER_TO_INT (data));
+	return e_mapi_cal_utils_add_named_ids (conn, fid, mem_ctx, props, GPOINTER_TO_INT (data), cancellable, perror);
 }
 
 gchar *
diff --git a/src/libexchangemapi/e-mapi-cal-utils.h b/src/libexchangemapi/e-mapi-cal-utils.h
index 02b39d2..2091c0a 100644
--- a/src/libexchangemapi/e-mapi-cal-utils.h
+++ b/src/libexchangemapi/e-mapi-cal-utils.h
@@ -97,11 +97,36 @@ e_mapi_cal_util_camel_helper (EMapiConnection *conn, mapi_id_t fid, mapi_id_t mi
 uint32_t
 e_mapi_cal_util_get_new_appt_id (EMapiConnection *conn, mapi_id_t fid);
 
-gboolean e_mapi_cal_utils_add_named_ids (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, struct SPropTagArray *props, gint pkind);
-gboolean e_mapi_cal_utils_get_props_cb (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, struct SPropTagArray *props, gpointer data);
-gboolean e_mapi_cal_utils_write_props_cb (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, struct SPropValue **values, uint32_t *n_values, gpointer data);
-
-gboolean e_mapi_cal_utils_get_free_busy_data (EMapiConnection *conn, const GSList *users, time_t start, time_t end, GSList **freebusy, GError **mapi_error);
+gboolean	e_mapi_cal_utils_add_named_ids			(EMapiConnection *conn,
+								 mapi_id_t fid,
+								 TALLOC_CTX *mem_ctx,
+								 struct SPropTagArray *props,
+								 gint pkind,
+								 GCancellable *cancellable,
+								 GError **perror);
+gboolean	e_mapi_cal_utils_get_props_cb			(EMapiConnection *conn,
+								 mapi_id_t fid,
+								 TALLOC_CTX *mem_ctx,
+								 struct SPropTagArray *props,
+								 gpointer data,
+								 GCancellable *cancellable,
+								 GError **perror);
+gboolean	e_mapi_cal_utils_write_props_cb			(EMapiConnection *conn,
+								 mapi_id_t fid,
+								 TALLOC_CTX *mem_ctx,
+								 struct SPropValue **values,
+								 uint32_t *n_values,
+								 gpointer data,
+								 GCancellable *cancellable,
+								 GError **perror);
+
+gboolean	e_mapi_cal_utils_get_free_busy_data		(EMapiConnection *conn,
+								 const GSList *users,
+								 time_t start,
+								 time_t end,
+								 GSList **freebusy,
+								 GCancellable *cancellable,
+								 GError **mapi_error);
 
 gchar *e_mapi_cal_utils_get_icomp_x_prop (icalcomponent *comp, const gchar *key);
 
diff --git a/src/libexchangemapi/e-mapi-connection.c b/src/libexchangemapi/e-mapi-connection.c
index 4617d1d..c99e844 100644
--- a/src/libexchangemapi/e-mapi-connection.c
+++ b/src/libexchangemapi/e-mapi-connection.c
@@ -44,8 +44,8 @@
 
 static void register_connection (EMapiConnection *conn);
 static void unregister_connection (EMapiConnection *conn);
-static gboolean mapi_profile_create (const EMapiProfileData *empd, mapi_profile_callback_t callback, gconstpointer data, GError **perror, gboolean use_locking);
-static struct mapi_session *mapi_profile_load (const gchar *profname, const gchar *password, GError **perror);
+static gboolean mapi_profile_create (const EMapiProfileData *empd, mapi_profile_callback_t callback, gconstpointer data, GCancellable *cancellable, GError **perror, gboolean use_locking);
+static struct mapi_session *mapi_profile_load (const gchar *profname, const gchar *password, GCancellable *cancellable, GError **perror);
 static void ema_global_lock (void);
 static void ema_global_unlock (void);
 
@@ -93,7 +93,9 @@ make_mapi_error (GError **perror, const gchar *context, enum MAPISTATUS mapi_sta
 	if (!perror)
 		return;
 
-	g_return_if_fail (*perror == NULL);
+	/* do not overwrite already set error */
+	if (*perror != NULL)
+		return;
 
 	switch (mapi_status) {
 	case MAPI_E_SUCCESS:
@@ -358,7 +360,7 @@ e_mapi_connection_find (const gchar *profile)
 
 /* Creates a new connection object and connects to a server as defined in 'profile' */
 EMapiConnection *
-e_mapi_connection_new (const gchar *profile, const gchar *password, GError **perror)
+e_mapi_connection_new (const gchar *profile, const gchar *password, GCancellable *cancellable, GError **perror)
 {
 	EMapiConnection *conn;
 	EMapiConnectionPrivate *priv;
@@ -367,7 +369,7 @@ e_mapi_connection_new (const gchar *profile, const gchar *password, GError **per
 
 	e_return_val_mapi_error_if_fail (profile != NULL, MAPI_E_INVALID_PARAMETER, NULL);
 
-	session = mapi_profile_load (profile, password, perror);
+	session = mapi_profile_load (profile, password, cancellable, perror);
 	if (!session) {
 		e_mapi_debug_print ("%s: %s: Login failed ", G_STRLOC, G_STRFUNC);
 		return NULL;
@@ -394,6 +396,12 @@ e_mapi_connection_new (const gchar *profile, const gchar *password, GError **per
 		return NULL;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		UNLOCK ();
+		g_object_unref (conn);
+		return NULL;
+	}
+
 	priv->profile = g_strdup (profile);
 	priv->has_public_store = FALSE;
 	UNLOCK ();
@@ -423,7 +431,7 @@ e_mapi_connection_close (EMapiConnection *conn)
 }
 
 gboolean
-e_mapi_connection_reconnect (EMapiConnection *conn, const gchar *password, GError **perror)
+e_mapi_connection_reconnect (EMapiConnection *conn, const gchar *password, GCancellable *cancellable, GError **perror)
 {
 	enum MAPISTATUS ms;
 
@@ -435,7 +443,7 @@ e_mapi_connection_reconnect (EMapiConnection *conn, const gchar *password, GErro
 	if (priv->session)
 		e_mapi_connection_close (conn);
 
-	priv->session = mapi_profile_load (priv->profile, password, perror);
+	priv->session = mapi_profile_load (priv->profile, password, cancellable, perror);
 	if (!priv->session) {
 		e_mapi_debug_print ("%s: %s: Login failed ", G_STRLOC, G_STRFUNC);
 		UNLOCK ();
@@ -458,6 +466,11 @@ e_mapi_connection_reconnect (EMapiConnection *conn, const gchar *password, GErro
 
 	priv->has_public_store = FALSE;
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		UNLOCK ();
+		return FALSE;
+	}
+
 	UNLOCK ();
 
 	e_mapi_debug_print ("%s: %s: Connected ", G_STRLOC, G_STRFUNC);
@@ -1032,7 +1045,7 @@ e_mapi_util_set_attachments (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *m
 				goto cleanup;
 			}
 
-			if (!mapi_mail_utils_create_item_build_props (conn, fid, mem_ctx, &props, &propslen, item)) {
+			if (!mapi_mail_utils_create_item_build_props (conn, fid, mem_ctx, &props, &propslen, item, NULL, perror)) {
 				make_mapi_error (perror, "build_props", MAPI_E_CALL_FAILED);
 				goto cleanup;
 			}
@@ -1119,7 +1132,7 @@ obj_message_to_camel_mime (EMapiConnection *conn, mapi_id_t fid, mapi_object_t *
 
 	if (!e_mapi_connection_fetch_object_props (conn, NULL, fid, 0, obj_msg, mapi_mail_get_item_prop_list, NULL,
 					fetch_props_to_mail_item_cb, &item,
-					MAPI_OPTIONS_FETCH_ALL | MAPI_OPTIONS_GETBESTBODY, NULL)
+					MAPI_OPTIONS_FETCH_ALL | MAPI_OPTIONS_GETBESTBODY, NULL, NULL)
 	    || item == NULL) {
 		if (item)
 			mail_item_free (item);
@@ -1181,7 +1194,11 @@ may_skip_property (uint32_t proptag)
 
 /* Returns TRUE if all attachments were read succcesfully, else returns FALSE */
 static gboolean
-e_mapi_util_get_attachments (EMapiConnection *conn, mapi_id_t fid, mapi_object_t *obj_message, GSList **attach_list, GError **perror)
+e_mapi_util_get_attachments (EMapiConnection *conn,
+			     mapi_id_t fid,
+			     mapi_object_t *obj_message,
+			     GSList **attach_list,
+			     GError **perror)
 {
 	enum MAPISTATUS		ms;
 	TALLOC_CTX		*mem_ctx;
@@ -1328,7 +1345,7 @@ e_mapi_util_get_attachments (EMapiConnection *conn, mapi_id_t fid, mapi_object_t
 		mapi_object_release(&obj_attach);
 	}
 
-cleanup:
+ cleanup:
 	if (ms != MAPI_E_SUCCESS)
 		status = FALSE;
 	mapi_object_release(&obj_tb_attach);
@@ -1340,7 +1357,14 @@ cleanup:
 }
 
 gboolean
-e_mapi_connection_fetch_gal (EMapiConnection *conn, struct mapi_SRestriction *restrictions, BuildReadPropsCB build_props, gpointer brp_data, FetchGALCallback cb, gpointer data, GError **perror)
+e_mapi_connection_fetch_gal (EMapiConnection *conn,
+			     struct mapi_SRestriction *restrictions,
+			     BuildReadPropsCB build_props,
+			     gpointer brp_data,
+			     FetchGALCallback cb,
+			     gpointer data,
+			     GCancellable *cancellable,
+			     GError **perror)
 {
 	struct SPropTagArray	*propsTagArray;
 	struct SRowSet		*aRowSet;
@@ -1364,7 +1388,7 @@ e_mapi_connection_fetch_gal (EMapiConnection *conn, struct mapi_SRestriction *re
 	}
 
 	propsTagArray = set_SPropTagArray (mem_ctx, 0x1, PR_MESSAGE_CLASS);
-	if (!build_props (conn, 0, mem_ctx, propsTagArray, brp_data)) {
+	if (!build_props (conn, 0, mem_ctx, propsTagArray, brp_data, cancellable, perror)) {
 		make_mapi_error (perror, "build_props", MAPI_E_CALL_FAILED);
 		UNLOCK();
 		talloc_free (mem_ctx);
@@ -1384,7 +1408,7 @@ e_mapi_connection_fetch_gal (EMapiConnection *conn, struct mapi_SRestriction *re
 		if (aRowSet->cRows) {
 			ema_global_unlock ();
 			for (i = 0; i < aRowSet->cRows; i++, count++) {
-				if (!cb (conn, count, n_rows, &aRowSet->aRow[i], data)) {
+				if (!cb (conn, count, n_rows, &aRowSet->aRow[i], data, cancellable, perror)) {
 					ms = MAPI_E_RESERVED;
 					break;
 				}
@@ -1410,7 +1434,10 @@ e_mapi_connection_fetch_gal (EMapiConnection *conn, struct mapi_SRestriction *re
 }
 
 gboolean
-e_mapi_connection_get_public_folder (EMapiConnection *conn, mapi_object_t *obj_store, GError **perror)
+e_mapi_connection_get_public_folder (EMapiConnection *conn,
+				     mapi_object_t *obj_store,
+				     GCancellable *cancellable,
+				     GError **perror)
 {
 	enum MAPISTATUS ms;
 
@@ -1487,7 +1514,7 @@ e_mapi_util_get_recipients (EMapiConnection *conn, mapi_object_t *obj_message, G
 				const gchar *addrtype = e_mapi_util_find_row_propval (&(rows_recip.aRow[i_row_recip]), PR_ADDRTYPE_UNICODE);
 
 				if (addrtype && g_ascii_strcasecmp (addrtype, "EX") == 0)
-					recipient->email_id = talloc_strdup (recipient->mem_ctx, e_mapi_connection_ex_to_smtp (conn, recipient->email_id, NULL, NULL));
+					recipient->email_id = talloc_strdup (recipient->mem_ctx, e_mapi_connection_ex_to_smtp (conn, recipient->email_id, NULL, NULL, NULL));
 			}
 		}
 
@@ -1550,6 +1577,7 @@ e_mapi_connection_get_folder_properties (EMapiConnection *conn,
 					 gpointer brp_cb_user_data,
 					 GetFolderPropertiesCB cb,
 					 gpointer cb_user_data,
+					 GCancellable *cancellable,
 					 GError **perror)
 {
 	enum MAPISTATUS ms;
@@ -1572,9 +1600,12 @@ e_mapi_connection_get_folder_properties (EMapiConnection *conn,
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror))
+		goto cleanup;
+
 	spropTagArray = set_SPropTagArray (mem_ctx, 1, PR_FID);
 	if (brp_cb) {
-		if (!brp_cb (conn, fid, mem_ctx, spropTagArray, brp_cb_user_data)) {
+		if (!brp_cb (conn, fid, mem_ctx, spropTagArray, brp_cb_user_data, cancellable, perror)) {
 			goto cleanup;
 		}
 	} else {
@@ -1595,6 +1626,9 @@ e_mapi_connection_get_folder_properties (EMapiConnection *conn,
 			goto cleanup;
 		}
 
+		if (g_cancellable_set_error_if_cancelled (cancellable, perror))
+			goto cleanup;
+
 		/* Conversion from SPropValue to mapi_SPropValue. (no padding here) */
 		properties->cValues = prop_count;
 		properties->lpProps = talloc_zero_array (mem_ctx, struct mapi_SPropValue, prop_count + 1);
@@ -1614,7 +1648,10 @@ e_mapi_connection_get_folder_properties (EMapiConnection *conn,
 		}
 	}
 
-	res = cb (conn, fid, mem_ctx, properties, cb_user_data, perror);
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror))
+		goto cleanup;
+
+	res = cb (conn, fid, mem_ctx, properties, cb_user_data, cancellable, perror);
 
  cleanup:
 	mapi_object_release (&obj_folder);
@@ -1627,7 +1664,12 @@ e_mapi_connection_get_folder_properties (EMapiConnection *conn,
 }
 
 GSList *
-e_mapi_connection_check_restriction (EMapiConnection *conn, mapi_id_t fid, guint32 fid_options, struct mapi_SRestriction *res, GError **perror)
+e_mapi_connection_check_restriction (EMapiConnection *conn,
+				     mapi_id_t fid,
+				     guint32 fid_options,
+				     struct mapi_SRestriction *res,
+				     GCancellable *cancellable,
+				     GError **perror)
 {
 	enum MAPISTATUS ms;
 	TALLOC_CTX *mem_ctx;
@@ -1654,6 +1696,9 @@ e_mapi_connection_check_restriction (EMapiConnection *conn, mapi_id_t fid, guint
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror))
+		goto cleanup;
+
 	/* Get a handle on the container */
 	ms = GetContentsTable (&obj_folder, &obj_table, 0, NULL);
 	if (ms != MAPI_E_SUCCESS) {
@@ -1661,6 +1706,9 @@ e_mapi_connection_check_restriction (EMapiConnection *conn, mapi_id_t fid, guint
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror))
+		goto cleanup;
+
 	GetPropsTagArray = talloc_zero(mem_ctx, struct SPropTagArray);
 	GetPropsTagArray->cValues = 0;
 
@@ -1685,6 +1733,9 @@ e_mapi_connection_check_restriction (EMapiConnection *conn, mapi_id_t fid, guint
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror))
+		goto cleanup;
+
 	if (res) {
 		/* Applying any restriction that are set. */
 		ms = Restrict (&obj_table, res, NULL);
@@ -1692,6 +1743,9 @@ e_mapi_connection_check_restriction (EMapiConnection *conn, mapi_id_t fid, guint
 			make_mapi_error (perror, "Restrict", ms);
 			goto cleanup;
 		}
+
+		if (g_cancellable_set_error_if_cancelled (cancellable, perror))
+			goto cleanup;
 	}
 
 	/* Number of items in the container */
@@ -1701,6 +1755,9 @@ e_mapi_connection_check_restriction (EMapiConnection *conn, mapi_id_t fid, guint
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror))
+		goto cleanup;
+
 	if (!count)
 		goto cleanup;
 
@@ -1718,7 +1775,7 @@ e_mapi_connection_check_restriction (EMapiConnection *conn, mapi_id_t fid, guint
 		mids = g_slist_prepend (mids, id_list);
 	}
 
-cleanup:
+ cleanup:
 	mapi_object_release(&obj_folder);
 	mapi_object_release(&obj_table);
 	talloc_free (mem_ctx);
@@ -1729,10 +1786,10 @@ cleanup:
 	return mids;
 }
 
-typedef gboolean (*ForeachTableRowCB) (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, struct SRow *srow, guint32 row_index, guint32 rows_total, gpointer user_data, GError **perror);
+typedef gboolean (*ForeachTableRowCB) (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, struct SRow *srow, guint32 row_index, guint32 rows_total, gpointer user_data, GCancellable *cancellable, GError **perror);
 
-static gboolean
-foreach_tablerow (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, mapi_object_t *obj_table, ForeachTableRowCB cb, gpointer user_data, GError **perror)
+static enum MAPISTATUS
+foreach_tablerow (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, mapi_object_t *obj_table, ForeachTableRowCB cb, gpointer user_data, GCancellable *cancellable, GError **perror)
 {
 	enum MAPISTATUS ms;
 	struct SRowSet SRowSet;
@@ -1752,6 +1809,11 @@ foreach_tablerow (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, map
 			break;
 		}
 
+		if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+			ms = MAPI_E_USER_CANCEL;
+			break;
+		}
+
 		if (!count)
 			break;
 
@@ -1762,13 +1824,20 @@ foreach_tablerow (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, map
 			break;
 		}
 
+		if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+			ms = MAPI_E_USER_CANCEL;
+			break;
+		}
+
 		for (i = 0; i < SRowSet.cRows && ms == MAPI_E_SUCCESS; i++) {
-			if (!cb (conn, fid, mem_ctx, &SRowSet.aRow[i], cursor_pos + i + 1, count, user_data, perror))
+			if (!cb (conn, fid, mem_ctx, &SRowSet.aRow[i], cursor_pos + i + 1, count, user_data, cancellable, perror))
 				ms = MAPI_E_RESERVED;
+			else if (g_cancellable_set_error_if_cancelled (cancellable, perror))
+				ms = MAPI_E_USER_CANCEL;
 		}
 	} while (cursor_pos < count && ms == MAPI_E_SUCCESS);
 
-	return ms == MAPI_E_SUCCESS;
+	return ms;
 }
 
 struct ListItemsInternalData
@@ -1778,7 +1847,15 @@ struct ListItemsInternalData
 };
 
 static gboolean
-list_items_internal_cb (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, struct SRow *srow, guint32 row_index, guint32 rows_total, gpointer user_data, GError **perror)
+list_items_internal_cb (EMapiConnection *conn,
+			mapi_id_t fid,
+			TALLOC_CTX *mem_ctx,
+			struct SRow *srow,
+			guint32 row_index,
+			guint32 rows_total,
+			gpointer user_data,
+			GCancellable *cancellable,
+			GError **perror)
 {
 	struct ListItemsInternalData *lii_data = user_data;
 	ListItemsData lid;
@@ -1804,17 +1881,23 @@ list_items_internal_cb (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ct
 	else
 		lid.last_modified = 0;
 
-	return lii_data->cb (conn, fid, mem_ctx, &lid, row_index, rows_total, lii_data->user_data, perror);
+	return lii_data->cb (conn, fid, mem_ctx, &lid, row_index, rows_total, lii_data->user_data, cancellable, perror);
 }
 
 gboolean
-e_mapi_connection_list_items (EMapiConnection *conn, mapi_id_t fid, guint32 options, struct mapi_SRestriction *restrictions, ListItemsCB cb, gpointer user_data, GError **perror)
+e_mapi_connection_list_items (EMapiConnection *conn,
+			      mapi_id_t fid,
+			      guint32 options,
+			      struct mapi_SRestriction *restrictions,
+			      ListItemsCB cb,
+			      gpointer user_data,
+			      GCancellable *cancellable,
+			      GError **perror)
 {
 	enum MAPISTATUS ms;
 	TALLOC_CTX *mem_ctx;
 	mapi_object_t obj_folder;
 	mapi_object_t obj_table;
-	gboolean result = FALSE;
 	struct SPropTagArray *propTagArray;
 	struct ListItemsInternalData lii_data;
 
@@ -1833,6 +1916,11 @@ e_mapi_connection_list_items (EMapiConnection *conn, mapi_id_t fid, guint32 opti
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
+
 	/* Get a handle on the container */
 	ms = GetContentsTable (&obj_folder, &obj_table, TableFlags_UseUnicode, NULL);
 	if (ms != MAPI_E_SUCCESS) {
@@ -1852,6 +1940,11 @@ e_mapi_connection_list_items (EMapiConnection *conn, mapi_id_t fid, guint32 opti
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
+
 	if (restrictions) {
 		/* Applying any restriction that are set. */
 		ms = Restrict (&obj_table, restrictions, NULL);
@@ -1859,12 +1952,17 @@ e_mapi_connection_list_items (EMapiConnection *conn, mapi_id_t fid, guint32 opti
 			make_mapi_error (perror, "Restrict", ms);
 			goto cleanup;
 		}
+
+		if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+			ms = MAPI_E_USER_CANCEL;
+			goto cleanup;
+		}
 	}
 
 	lii_data.cb = cb;
 	lii_data.user_data = user_data;
 
-	result = foreach_tablerow (conn, fid, mem_ctx, &obj_table, list_items_internal_cb, &lii_data, perror);
+	ms = foreach_tablerow (conn, fid, mem_ctx, &obj_table, list_items_internal_cb, &lii_data, cancellable, perror);
 
  cleanup:
 	mapi_object_release (&obj_folder);
@@ -1872,15 +1970,21 @@ e_mapi_connection_list_items (EMapiConnection *conn, mapi_id_t fid, guint32 opti
 	talloc_free (mem_ctx);
 	UNLOCK ();
 
-	return result;
+	return ms == MAPI_E_SUCCESS;
 }
 
 gboolean
-e_mapi_connection_fetch_items   (EMapiConnection *conn, mapi_id_t fid,
-					struct mapi_SRestriction *res, struct SSortOrderSet *sort_order,
-					BuildReadPropsCB build_props, gpointer brp_data,
-					FetchCallback cb, gpointer data,
-					guint32 options, GError **perror)
+e_mapi_connection_fetch_items  (EMapiConnection *conn,
+				mapi_id_t fid,
+				struct mapi_SRestriction *res,
+				struct SSortOrderSet *sort_order,
+				BuildReadPropsCB build_props,
+				gpointer brp_data,
+				FetchCallback cb,
+				gpointer data,
+				guint32 options,
+				GCancellable *cancellable,
+				GError **perror)
 {
 	enum MAPISTATUS ms;
 	TALLOC_CTX *mem_ctx;
@@ -1907,6 +2011,11 @@ e_mapi_connection_fetch_items   (EMapiConnection *conn, mapi_id_t fid,
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
+
 	/* Get a handle on the container */
 	ms = GetContentsTable (&obj_folder, &obj_table, TableFlags_UseUnicode, NULL);
 	if (ms != MAPI_E_SUCCESS) {
@@ -1914,6 +2023,11 @@ e_mapi_connection_fetch_items   (EMapiConnection *conn, mapi_id_t fid,
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
+
 	SPropTagArray = set_SPropTagArray(mem_ctx, 0x5,
 					  PR_FID,
 					  PR_MID,
@@ -1928,6 +2042,11 @@ e_mapi_connection_fetch_items   (EMapiConnection *conn, mapi_id_t fid,
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
+
 	if (res) {
 		/* Applying any restriction that are set. */
 		ms = Restrict (&obj_table, res, NULL);
@@ -1935,6 +2054,11 @@ e_mapi_connection_fetch_items   (EMapiConnection *conn, mapi_id_t fid,
 			make_mapi_error (perror, "Restrict", ms);
 			goto cleanup;
 		}
+
+		if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+			ms = MAPI_E_USER_CANCEL;
+			goto cleanup;
+		}
 	}
 
 	if (sort_order) {
@@ -1947,10 +2071,15 @@ e_mapi_connection_fetch_items   (EMapiConnection *conn, mapi_id_t fid,
 
 	if (build_props) {
 		propsTagArray = set_SPropTagArray (mem_ctx, 0x1, PR_MESSAGE_CLASS);
-		if (!build_props (conn, fid, mem_ctx, propsTagArray, brp_data)) {
+		if (!build_props (conn, fid, mem_ctx, propsTagArray, brp_data, cancellable, perror)) {
 			make_mapi_error (perror, "build_props", MAPI_E_CALL_FAILED);
 			goto cleanup;
 		}
+
+		if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+			ms = MAPI_E_USER_CANCEL;
+			goto cleanup;
+		}
 	}
 
 	/* Note : We maintain a cursor position. count parameter in QueryRows */
@@ -2090,7 +2219,7 @@ e_mapi_connection_fetch_items   (EMapiConnection *conn, mapi_id_t fid,
 				item_data->index = cursor_pos + i; //cursor_pos + current_table_index
 
 				ema_global_unlock ();
-				cb_retval = cb (item_data, data);
+				cb_retval = cb (item_data, data, cancellable, perror);
 				ema_global_lock ();
 
 				g_free (item_data);
@@ -2110,6 +2239,10 @@ e_mapi_connection_fetch_items   (EMapiConnection *conn, mapi_id_t fid,
 			if (!cb_retval) break;
 		}
 
+		if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+			ms = MAPI_E_USER_CANCEL;
+			goto cleanup;
+		}
 	} while (cursor_pos < count && ms == MAPI_E_SUCCESS);
 
 	result = ms == MAPI_E_SUCCESS;
@@ -2129,10 +2262,18 @@ e_mapi_connection_fetch_items   (EMapiConnection *conn, mapi_id_t fid,
 
 /* obj_folder and obj_message are released only when obj_folder is not NULL and when returned TRUE */
 gboolean
-e_mapi_connection_fetch_object_props (EMapiConnection *conn, mapi_object_t *obj_folder, mapi_id_t fid, mapi_id_t mid, mapi_object_t *obj_message,
-				     BuildReadPropsCB build_props, gpointer brp_data,
-				     FetchCallback cb, gpointer data,
-				     guint32 options, GError **perror)
+e_mapi_connection_fetch_object_props (EMapiConnection *conn,
+				      mapi_object_t *obj_folder,
+				      mapi_id_t fid,
+				      mapi_id_t mid,
+				      mapi_object_t *obj_message,
+				      BuildReadPropsCB build_props,
+				      gpointer brp_data,
+				      FetchCallback cb,
+				      gpointer data,
+				      guint32 options,
+				      GCancellable *cancellable,
+				      GError **perror)
 {
 	enum MAPISTATUS ms;
 	TALLOC_CTX *mem_ctx;
@@ -2157,10 +2298,15 @@ e_mapi_connection_fetch_object_props (EMapiConnection *conn, mapi_object_t *obj_
 			PR_HASATTACH,
 			PR_MSG_EDITOR_FORMAT);
 
-		if (!build_props (conn, fid, mem_ctx, propsTagArray, brp_data)) {
+		if (!build_props (conn, fid, mem_ctx, propsTagArray, brp_data, cancellable, perror)) {
 			make_mapi_error (perror, "build_props", MAPI_E_CALL_FAILED);
 			goto cleanup;
 		}
+
+		if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+			ms = MAPI_E_USER_CANCEL;
+			goto cleanup;
+		}
 	}
 
 	if (propsTagArray && propsTagArray->cValues) {
@@ -2173,6 +2319,11 @@ e_mapi_connection_fetch_object_props (EMapiConnection *conn, mapi_object_t *obj_
 		if (ms != MAPI_E_SUCCESS)
 			make_mapi_error (perror, "GetProps", ms);
 
+		if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+			ms = MAPI_E_USER_CANCEL;
+			goto cleanup;
+		}
+
 		/* Conversion from SPropValue to mapi_SPropValue. (no padding here) */
 		properties_array.cValues = prop_count;
 		properties_array.lpProps = talloc_zero_array (mem_ctx, struct mapi_SPropValue, prop_count + 1);
@@ -2189,6 +2340,11 @@ e_mapi_connection_fetch_object_props (EMapiConnection *conn, mapi_object_t *obj_
 		ms = GetPropsAll (obj_message, MAPI_UNICODE, &properties_array);
 		if (ms != MAPI_E_SUCCESS)
 			make_mapi_error (perror, "GetPropsAll", ms);
+
+		if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+			ms = MAPI_E_USER_CANCEL;
+			goto cleanup;
+		}
 	}
 
 	/* Fetch attachments */
@@ -2197,16 +2353,31 @@ e_mapi_connection_fetch_object_props (EMapiConnection *conn, mapi_object_t *obj_
 
 		if (has_attach && *has_attach)
 			e_mapi_util_get_attachments (conn, fid, obj_message, &attach_list, NULL);
+
+		if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+			ms = MAPI_E_USER_CANCEL;
+			goto cleanup;
+		}
 	}
 
 	/* Fetch recipients */
 	if (options & MAPI_OPTIONS_FETCH_RECIPIENTS) {
 		e_mapi_util_get_recipients (conn, obj_message, &recip_list, NULL);
+
+		if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+			ms = MAPI_E_USER_CANCEL;
+			goto cleanup;
+		}
 	}
 
 	/* get the main body stream no matter what */
 	if (options & MAPI_OPTIONS_FETCH_BODY_STREAM) {
 		e_mapi_util_read_body_stream (obj_message, &stream_list, &properties_array, (options & MAPI_OPTIONS_GETBESTBODY) != 0);
+
+		if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+			ms = MAPI_E_USER_CANCEL;
+			goto cleanup;
+		}
 	}
 
 	if (ms == MAPI_E_SUCCESS) {
@@ -2218,6 +2389,11 @@ e_mapi_connection_fetch_object_props (EMapiConnection *conn, mapi_object_t *obj_
 				if ((properties_array.lpProps[z].ulPropTag & 0xFFFF) == PT_BINARY) {
 					e_mapi_util_read_generic_stream (obj_message, e_mapi_util_find_array_propval (&properties_array, PR_INTERNET_CPID), properties_array.lpProps[z].ulPropTag, &stream_list, &properties_array, NULL);
 				}
+
+				if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+					ms = MAPI_E_USER_CANCEL;
+					goto cleanup;
+				}
 			}
 		}
 	}
@@ -2241,7 +2417,7 @@ e_mapi_connection_fetch_object_props (EMapiConnection *conn, mapi_object_t *obj_
 
 		ema_global_unlock ();
 		/* NOTE: stream_list, recipient_list and attach_list should be freed by the callback */
-		cb (item_data, data);
+		cb (item_data, data, cancellable, perror);
 		ema_global_lock ();
 
 		g_free (item_data);
@@ -2263,10 +2439,16 @@ cleanup:
 }
 
 gboolean
-e_mapi_connection_fetch_item (EMapiConnection *conn, mapi_id_t fid, mapi_id_t mid,
-				     BuildReadPropsCB build_props, gpointer brp_data,
-				     FetchCallback cb, gpointer data,
-				     guint32 options, GError **perror)
+e_mapi_connection_fetch_item (EMapiConnection *conn,
+			      mapi_id_t fid,
+			      mapi_id_t mid,
+			      BuildReadPropsCB build_props,
+			      gpointer brp_data,
+			      FetchCallback cb,
+			      gpointer data,
+			      guint32 options,
+			      GCancellable *cancellable,
+			      GError **perror)
 {
 	enum MAPISTATUS ms;
 	TALLOC_CTX *mem_ctx;
@@ -2291,6 +2473,11 @@ e_mapi_connection_fetch_item (EMapiConnection *conn, mapi_id_t fid, mapi_id_t mi
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
+
 	/* Open the item */
 	ms = OpenMessage (&obj_folder, fid, mid, &obj_message, 0x0);
 	if (ms != MAPI_E_SUCCESS) {
@@ -2298,9 +2485,14 @@ e_mapi_connection_fetch_item (EMapiConnection *conn, mapi_id_t fid, mapi_id_t mi
 		goto cleanup;
 	}
 
-	result = e_mapi_connection_fetch_object_props (conn, &obj_folder, fid, mid, &obj_message, build_props, brp_data, cb, data, options, perror);
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
 
-cleanup:
+	result = e_mapi_connection_fetch_object_props (conn, &obj_folder, fid, mid, &obj_message, build_props, brp_data, cb, data, options, cancellable, perror);
+
+ cleanup:
 	if (!result) {
 		mapi_object_release (&obj_message);
 		mapi_object_release (&obj_folder);
@@ -2314,7 +2506,13 @@ cleanup:
 }
 
 mapi_id_t
-e_mapi_connection_create_folder (EMapiConnection *conn, uint32_t olFolder, mapi_id_t pfid, guint32 fid_options, const gchar *name, GError **perror)
+e_mapi_connection_create_folder (EMapiConnection *conn,
+				 uint32_t olFolder,
+				 mapi_id_t pfid,
+				 guint32 fid_options,
+				 const gchar *name,
+				 GCancellable *cancellable,
+				 GError **perror)
 {
 	enum MAPISTATUS ms;
 	mapi_object_t obj_folder;
@@ -2338,6 +2536,11 @@ e_mapi_connection_create_folder (EMapiConnection *conn, uint32_t olFolder, mapi_
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
+
 	/* Attempt to create the folder */
 	ms = CreateFolder (&obj_top, FOLDER_GENERIC, name, "Created using Evolution/LibMAPI", OPEN_IF_EXISTS | MAPI_UNICODE, &obj_folder);
 	if (ms != MAPI_E_SUCCESS) {
@@ -2389,7 +2592,7 @@ e_mapi_connection_create_folder (EMapiConnection *conn, uint32_t olFolder, mapi_
 
 	g_static_rec_mutex_unlock (&priv->folders_lock);
 
-cleanup:
+ cleanup:
 	mapi_object_release(&obj_folder);
 	mapi_object_release(&obj_top);
 
@@ -2402,7 +2605,11 @@ cleanup:
 }
 
 gboolean
-e_mapi_connection_empty_folder (EMapiConnection *conn, mapi_id_t fid, guint32 fid_options, GError **perror)
+e_mapi_connection_empty_folder (EMapiConnection *conn,
+				mapi_id_t fid,
+				guint32 fid_options,
+				GCancellable *cancellable,
+				GError **perror)
 {
 	enum MAPISTATUS ms;
 	mapi_object_t obj_folder;
@@ -2422,6 +2629,11 @@ e_mapi_connection_empty_folder (EMapiConnection *conn, mapi_id_t fid, guint32 fi
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
+
 	/* Empty the contents of the folder */
 	ms = EmptyFolder (&obj_folder);
 	if (ms != MAPI_E_SUCCESS) {
@@ -2433,7 +2645,7 @@ e_mapi_connection_empty_folder (EMapiConnection *conn, mapi_id_t fid, guint32 fi
 
 	result = TRUE;
 
-cleanup:
+ cleanup:
 	mapi_object_release(&obj_folder);
 	UNLOCK ();
 
@@ -2443,7 +2655,11 @@ cleanup:
 }
 
 gboolean
-e_mapi_connection_remove_folder (EMapiConnection *conn, mapi_id_t fid, guint32 fid_options, GError **perror)
+e_mapi_connection_remove_folder (EMapiConnection *conn,
+				 mapi_id_t fid,
+				 guint32 fid_options,
+				 GCancellable *cancellable,
+				 GError **perror)
 {
 	enum MAPISTATUS ms;
 	mapi_object_t obj_top;
@@ -2478,12 +2694,22 @@ e_mapi_connection_remove_folder (EMapiConnection *conn, mapi_id_t fid, guint32 f
 	 * Note that this has to be done recursively, for the sub-folders as well.
 	 */
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
+
 	/* Attempt to open the folder to be removed */
 	ms = open_folder (conn, 0, &fid, fid_options, &obj_folder, perror);
 	if (ms != MAPI_E_SUCCESS) {
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
+
 	/* Empty the contents of the folder */
 	ms = EmptyFolder (&obj_folder);
 	if (ms != MAPI_E_SUCCESS) {
@@ -2499,6 +2725,11 @@ e_mapi_connection_remove_folder (EMapiConnection *conn, mapi_id_t fid, guint32 f
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
+
 	/* Call DeleteFolder on the folder to be removed */
 	ms = DeleteFolder (&obj_top, fid, DEL_FOLDERS, NULL);
 	if (ms != MAPI_E_SUCCESS) {
@@ -2510,7 +2741,7 @@ e_mapi_connection_remove_folder (EMapiConnection *conn, mapi_id_t fid, guint32 f
 
 	result = TRUE;
 
-cleanup:
+ cleanup:
 	mapi_object_release(&obj_folder);
 	mapi_object_release(&obj_top);
 
@@ -2528,7 +2759,12 @@ cleanup:
 }
 
 gboolean
-e_mapi_connection_rename_folder (EMapiConnection *conn, mapi_id_t fid, guint32 fid_options, const gchar *new_name, GError **perror)
+e_mapi_connection_rename_folder (EMapiConnection *conn,
+				 mapi_id_t fid,
+				 guint32 fid_options,
+				 const gchar *new_name,
+				 GCancellable *cancellable,
+				 GError **perror)
 {
 	enum MAPISTATUS ms;
 	mapi_object_t obj_folder;
@@ -2551,6 +2787,11 @@ e_mapi_connection_rename_folder (EMapiConnection *conn, mapi_id_t fid, guint32 f
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
+
 	props = talloc_zero(mem_ctx, struct SPropValue);
 	set_SPropValue_proptag (props, PR_DISPLAY_NAME_UNICODE, new_name);
 
@@ -2562,7 +2803,7 @@ e_mapi_connection_rename_folder (EMapiConnection *conn, mapi_id_t fid, guint32 f
 
 	result = TRUE;
 
-cleanup:
+ cleanup:
 	mapi_object_release(&obj_folder);
 	talloc_free(mem_ctx);
 	UNLOCK ();
@@ -2575,7 +2816,15 @@ 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
-e_mapi_connection_move_folder (EMapiConnection *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, GError **perror)
+e_mapi_connection_move_folder  (EMapiConnection *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,
+				GCancellable *cancellable,
+				GError **perror)
 {
 	enum MAPISTATUS ms;
 	mapi_object_t obj_src, obj_src_parent, obj_des;
@@ -2601,16 +2850,31 @@ e_mapi_connection_move_folder (EMapiConnection *conn, mapi_id_t src_fid, mapi_id
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
+
 	ms = open_folder (conn, 0, &src_parent_fid, src_fid_options, &obj_src_parent, perror);
 	if (ms != MAPI_E_SUCCESS) {
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
+
 	ms = open_folder (conn, 0, &des_fid, des_fid_options, &obj_des, perror);
 	if (ms != MAPI_E_SUCCESS) {
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
+
 	ms = MoveFolder (&obj_src, &obj_src_parent, &obj_des, (gchar *)new_name, TRUE);
 	if (ms != MAPI_E_SUCCESS) {
 		make_mapi_error (perror, "MoveFolder", ms);
@@ -2619,7 +2883,7 @@ e_mapi_connection_move_folder (EMapiConnection *conn, mapi_id_t src_fid, mapi_id
 
 	result = TRUE;
 
-cleanup:
+ cleanup:
 	mapi_object_release (&obj_des);
 	mapi_object_release (&obj_src_parent);
 	mapi_object_release (&obj_src);
@@ -2631,7 +2895,12 @@ cleanup:
 
 /* named_ids_list contains pointers to ResolveNamedIDsData structure */
 gboolean
-e_mapi_connection_resolve_named_props (EMapiConnection *conn, mapi_id_t fid, ResolveNamedIDsData *named_ids_list, guint named_ids_n_elems, GError **perror)
+e_mapi_connection_resolve_named_props  (EMapiConnection *conn,
+					mapi_id_t fid,
+					ResolveNamedIDsData *named_ids_list,
+					guint named_ids_n_elems,
+					GCancellable *cancellable,
+					GError **perror)
 {
 	enum MAPISTATUS ms;
 	TALLOC_CTX *mem_ctx;
@@ -2689,6 +2958,11 @@ e_mapi_connection_resolve_named_props (EMapiConnection *conn, mapi_id_t fid, Res
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
+
 	if (!todo) {
 		todo = g_ptr_array_new ();
 		for (i = 0; i < named_ids_n_elems; i++) {
@@ -2705,12 +2979,22 @@ e_mapi_connection_resolve_named_props (EMapiConnection *conn, mapi_id_t fid, Res
 			data->propid = 0;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
+
 	ms = mapi_nameid_GetIDsFromNames (nameid, &obj_folder, SPropTagArray);
 	if (ms != MAPI_E_SUCCESS) {
 		make_mapi_error (perror, "mapi_nameid_GetIDsFromNames", ms);
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
+
 	for (i = 0, j = 0; i < SPropTagArray->cValues && j < todo->len; i++) {
 		while (j < todo->len) {
 			ResolveNamedIDsData *data = todo->pdata[j];
@@ -2763,7 +3047,11 @@ e_mapi_connection_resolve_named_props (EMapiConnection *conn, mapi_id_t fid, Res
 
 /* returns MAPI_E_RESERVED on any error */
 uint32_t
-e_mapi_connection_resolve_named_prop (EMapiConnection *conn, mapi_id_t fid, uint32_t pidlid_propid, GError **perror)
+e_mapi_connection_resolve_named_prop (EMapiConnection *conn,
+				      mapi_id_t fid,
+				      uint32_t pidlid_propid,
+				      GCancellable *cancellable,
+				      GError **perror)
 {
 	enum MAPISTATUS ms;
 	TALLOC_CTX *mem_ctx;
@@ -2808,6 +3096,11 @@ e_mapi_connection_resolve_named_prop (EMapiConnection *conn, mapi_id_t fid, uint
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
+
 	mapi_nameid_canonical_add (nameid, pidlid_propid);
 
 	ms = mapi_nameid_GetIDsFromNames(nameid, &obj_folder, SPropTagArray);
@@ -2836,7 +3129,7 @@ e_mapi_connection_resolve_named_prop (EMapiConnection *conn, mapi_id_t fid, uint
 		g_hash_table_insert (ids, GUINT_TO_POINTER (pidlid_propid), GUINT_TO_POINTER (res));
 	}
 
-cleanup:
+ cleanup:
 	mapi_object_release(&obj_folder);
 	talloc_free(mem_ctx);
 
@@ -2883,7 +3176,10 @@ e_mapi_connection_unresolve_proptag_to_nameid (EMapiConnection *conn, mapi_id_t
 }
 
 mapi_id_t
-e_mapi_connection_get_default_folder_id (EMapiConnection *conn, uint32_t olFolder, GError **perror)
+e_mapi_connection_get_default_folder_id (EMapiConnection *conn,
+					 uint32_t olFolder,
+					 GCancellable *cancellable,
+					 GError **perror)
 {
 	enum MAPISTATUS ms;
 	mapi_id_t fid = 0;
@@ -2901,7 +3197,7 @@ e_mapi_connection_get_default_folder_id (EMapiConnection *conn, uint32_t olFolde
 		goto cleanup;
 	}
 
-cleanup:
+ cleanup:
 	UNLOCK ();
 
 	e_mapi_debug_print("%s: Leaving %s ", G_STRLOC, G_STRFUNC);
@@ -2910,10 +3206,17 @@ cleanup:
 }
 
 mapi_id_t
-e_mapi_connection_create_item (EMapiConnection *conn, uint32_t olFolder, mapi_id_t fid,
-			   BuildWritePropsCB build_props, gpointer bwp_data,
-			   GSList *recipients, GSList *attachments, GSList *generic_streams,
-			   uint32_t options, GError **perror)
+e_mapi_connection_create_item  (EMapiConnection *conn,
+				uint32_t olFolder,
+				mapi_id_t fid,
+				BuildWritePropsCB build_props,
+				gpointer bwp_data,
+				GSList *recipients,
+				GSList *attachments,
+				GSList *generic_streams,
+				uint32_t options,
+				GCancellable *cancellable,
+				GError **perror)
 {
 	enum MAPISTATUS ms;
 	TALLOC_CTX *mem_ctx;
@@ -2940,6 +3243,11 @@ e_mapi_connection_create_item (EMapiConnection *conn, uint32_t olFolder, mapi_id
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
+
 	/* Create the item */
 	ms = CreateMessage (&obj_folder, &obj_message);
 	if (ms != MAPI_E_SUCCESS) {
@@ -2947,10 +3255,13 @@ e_mapi_connection_create_item (EMapiConnection *conn, uint32_t olFolder, mapi_id
 		goto cleanup;
 	}
 
-//	d(mapi_object_debug (&obj_message));
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
 
 	/* Add regular props using callback */
-	if (build_props && !build_props (conn, fid, mem_ctx, &props, &propslen, bwp_data)) {
+	if (build_props && !build_props (conn, fid, mem_ctx, &props, &propslen, bwp_data, cancellable, perror)) {
 		e_mapi_debug_print ("%s: (%s): build_props failed! propslen = %d ", G_STRLOC, G_STRFUNC, propslen);
 		make_mapi_error (perror, "build_props", MAPI_E_CALL_FAILED);
 		goto cleanup;
@@ -2963,21 +3274,41 @@ e_mapi_connection_create_item (EMapiConnection *conn, uint32_t olFolder, mapi_id
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
+
 	if (generic_streams) {
 		if (!e_mapi_util_write_generic_streams (&obj_message, generic_streams, perror))
 			goto cleanup;
+
+		if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+			ms = MAPI_E_USER_CANCEL;
+			goto cleanup;
+		}
 	}
 
 	/* Set attachments if any */
 	if (attachments) {
 		if (!e_mapi_util_set_attachments (conn, fid, mem_ctx, &obj_message, attachments, FALSE, perror))
 			goto cleanup;
+
+		if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+			ms = MAPI_E_USER_CANCEL;
+			goto cleanup;
+		}
 	}
 
 	/* Set recipients if any */
 	if (recipients) {
 		if (!e_mapi_util_modify_recipients (conn, mem_ctx, &obj_message, recipients, FALSE, perror))
 			goto cleanup;
+
+		if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+			ms = MAPI_E_USER_CANCEL;
+			goto cleanup;
+		}
 	}
 
 	/* Finally, save all changes */
@@ -2988,6 +3319,11 @@ e_mapi_connection_create_item (EMapiConnection *conn, uint32_t olFolder, mapi_id
 	}
 
 	if (recipients && !(options & MAPI_OPTIONS_DONT_SUBMIT)) {
+		if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+			ms = MAPI_E_USER_CANCEL;
+			goto cleanup;
+		}
+
 		/* Mark message as ready to be sent */
 		ms = SubmitMessage (&obj_message);
 		if (ms != MAPI_E_SUCCESS) {
@@ -3022,7 +3358,7 @@ e_mapi_connection_create_item (EMapiConnection *conn, uint32_t olFolder, mapi_id
 
 	mid = mapi_object_get_id (&obj_message);
 
-cleanup:
+ cleanup:
 	mapi_object_release(&obj_message);
 	mapi_object_release(&obj_folder);
 	talloc_free(mem_ctx);
@@ -3035,10 +3371,18 @@ cleanup:
 }
 
 gboolean
-e_mapi_connection_modify_item (EMapiConnection *conn, uint32_t olFolder, mapi_id_t fid, mapi_id_t mid,
-			   BuildWritePropsCB build_props, gpointer bwp_data,
-			   GSList *recipients, GSList *attachments, GSList *generic_streams,
-			   uint32_t options, GError **perror)
+e_mapi_connection_modify_item  (EMapiConnection *conn,
+				uint32_t olFolder,
+				mapi_id_t fid,
+				mapi_id_t mid,
+				BuildWritePropsCB build_props,
+				gpointer bwp_data,
+				GSList *recipients,
+				GSList *attachments,
+				GSList *generic_streams,
+				uint32_t options,
+				GCancellable *cancellable,
+				GError **perror)
 {
 	enum MAPISTATUS ms;
 	TALLOC_CTX *mem_ctx;
@@ -3065,6 +3409,11 @@ e_mapi_connection_modify_item (EMapiConnection *conn, uint32_t olFolder, mapi_id
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
+
 	/* Open the item to be modified */
 	ms = OpenMessage (&obj_folder, fid, mid, &obj_message, MAPI_MODIFY);
 	if (ms != MAPI_E_SUCCESS) {
@@ -3072,15 +3421,18 @@ e_mapi_connection_modify_item (EMapiConnection *conn, uint32_t olFolder, mapi_id
 		goto cleanup;
 	}
 
-//	d(mapi_object_debug (&obj_message));
-
 	/* Add regular props using callback */
-	if (build_props && !build_props (conn, fid, mem_ctx, &props, &propslen, bwp_data)) {
+	if (build_props && !build_props (conn, fid, mem_ctx, &props, &propslen, bwp_data, cancellable, perror)) {
 		e_mapi_debug_print ("%s: (%s): Could not build props ", G_STRLOC, G_STRFUNC);
 		make_mapi_error (perror, "build_props", MAPI_E_CALL_FAILED);
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
+
 	/* set properties for the item */
 	ms = SetProps (&obj_message, MAPI_PROPS_SKIP_NAMEDID_CHECK, props, propslen);
 	if (ms != MAPI_E_SUCCESS) {
@@ -3088,15 +3440,30 @@ e_mapi_connection_modify_item (EMapiConnection *conn, uint32_t olFolder, mapi_id
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
+
 	if (generic_streams) {
 		if (!e_mapi_util_write_generic_streams (&obj_message, generic_streams, perror))
 			goto cleanup;
+
+		if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+			ms = MAPI_E_USER_CANCEL;
+			goto cleanup;
+		}
 	}
 
 	/* Set attachments if any */
 	if (attachments) {
 		if (!e_mapi_util_set_attachments (conn, fid, mem_ctx, &obj_message, attachments, TRUE, perror))
 			goto cleanup;
+
+		if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+			ms = MAPI_E_USER_CANCEL;
+			goto cleanup;
+		}
 	} else {
 		e_mapi_util_delete_attachments (&obj_message, NULL);
 	}
@@ -3105,6 +3472,11 @@ e_mapi_connection_modify_item (EMapiConnection *conn, uint32_t olFolder, mapi_id
 	if (recipients) {
 		if (!e_mapi_util_modify_recipients (conn, mem_ctx, &obj_message, recipients, TRUE, perror))
 			goto cleanup;
+
+		if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+			ms = MAPI_E_USER_CANCEL;
+			goto cleanup;
+		}
 	}
 
 	/* Finally, save all changes */
@@ -3115,6 +3487,11 @@ e_mapi_connection_modify_item (EMapiConnection *conn, uint32_t olFolder, mapi_id
 	}
 
 	if (recipients && !(options & MAPI_OPTIONS_DONT_SUBMIT)) {
+		if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+			ms = MAPI_E_USER_CANCEL;
+			goto cleanup;
+		}
+
 		/* Mark message as ready to be sent */
 		ms = SubmitMessage (&obj_message);
 		if (ms != MAPI_E_SUCCESS) {
@@ -3125,7 +3502,7 @@ e_mapi_connection_modify_item (EMapiConnection *conn, uint32_t olFolder, mapi_id
 
 	result = TRUE;
 
-cleanup:
+ cleanup:
 	mapi_object_release(&obj_message);
 	mapi_object_release(&obj_folder);
 	talloc_free(mem_ctx);
@@ -3138,7 +3515,14 @@ cleanup:
 }
 
 gboolean
-e_mapi_connection_set_flags (EMapiConnection *conn, uint32_t olFolder, mapi_id_t fid, guint32 fid_options, GSList *mids, uint32_t flag, GError **perror)
+e_mapi_connection_set_flags (EMapiConnection *conn,
+			     uint32_t olFolder,
+			     mapi_id_t fid,
+			     guint32 fid_options,
+			     GSList *mids,
+			     uint32_t flag,
+			     GCancellable *cancellable,
+			     GError **perror)
 {
 	enum MAPISTATUS ms;
 	TALLOC_CTX *mem_ctx;
@@ -3167,6 +3551,11 @@ e_mapi_connection_set_flags (EMapiConnection *conn, uint32_t olFolder, mapi_id_t
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
+
 	ms = SetReadFlags (&obj_folder, flag, i, id_messages);
 	if (ms != MAPI_E_SUCCESS) {
 		make_mapi_error (perror, "SetReadFlags", ms);
@@ -3175,7 +3564,7 @@ e_mapi_connection_set_flags (EMapiConnection *conn, uint32_t olFolder, mapi_id_t
 
 	result = TRUE;
 
-cleanup:
+ cleanup:
 	mapi_object_release(&obj_folder);
 	talloc_free(mem_ctx);
 
@@ -3187,7 +3576,15 @@ cleanup:
 }
 
 static gboolean
-mapi_move_items (EMapiConnection *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, GError **perror)
+mapi_move_items (EMapiConnection *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,
+		 GCancellable *cancellable,
+		 GError **perror)
 {
 	enum MAPISTATUS	ms;
 	mapi_object_t obj_folder_src;
@@ -3204,11 +3601,21 @@ mapi_move_items (EMapiConnection *conn, mapi_id_t src_fid, guint32 src_fid_optio
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
+
 	ms = open_folder (conn, 0, &dest_fid, dest_fid_options, &obj_folder_dst, perror);
 	if (ms != MAPI_E_SUCCESS) {
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
+
 	while (mid_list) {
 		mapi_id_array_t msg_id_array;
 		gint count = 0;
@@ -3227,9 +3634,14 @@ mapi_move_items (EMapiConnection *conn, mapi_id_t src_fid, guint32 src_fid_optio
 			make_mapi_error (perror, "MoveCopyMessages", ms);
 			break;
 		}
+
+		if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+			ms = MAPI_E_USER_CANCEL;
+			break;
+		}
 	}
 
-cleanup:
+ cleanup:
 	mapi_object_release(&obj_folder_dst);
 	mapi_object_release(&obj_folder_src);
 
@@ -3237,7 +3649,14 @@ cleanup:
 }
 
 gboolean
-e_mapi_connection_copy_items (EMapiConnection *conn, mapi_id_t src_fid, guint32 src_fid_options, mapi_id_t dest_fid, guint32 dest_fid_options, GSList *mids, GError **perror)
+e_mapi_connection_copy_items (EMapiConnection *conn,
+			      mapi_id_t src_fid,
+			      guint32 src_fid_options,
+			      mapi_id_t dest_fid,
+			      guint32 dest_fid_options,
+			      GSList *mids,
+			      GCancellable *cancellable,
+			      GError **perror)
 {
 	enum MAPISTATUS ms;
 
@@ -3247,7 +3666,7 @@ e_mapi_connection_copy_items (EMapiConnection *conn, mapi_id_t src_fid, guint32
 	e_mapi_debug_print("%s: Entering %s ", G_STRLOC, G_STRFUNC);
 
 	LOCK ();
-	ms = mapi_move_items (conn, src_fid, src_fid_options, dest_fid, dest_fid_options, mids, TRUE, perror);
+	ms = mapi_move_items (conn, src_fid, src_fid_options, dest_fid, dest_fid_options, mids, TRUE, cancellable, perror);
 	UNLOCK ();
 
 	e_mapi_debug_print("%s: Leaving %s ", G_STRLOC, G_STRFUNC);
@@ -3256,7 +3675,14 @@ e_mapi_connection_copy_items (EMapiConnection *conn, mapi_id_t src_fid, guint32
 }
 
 gboolean
-e_mapi_connection_move_items (EMapiConnection *conn, mapi_id_t src_fid, guint32 src_fid_options, mapi_id_t dest_fid, guint32 dest_fid_options, GSList *mids, GError **perror)
+e_mapi_connection_move_items (EMapiConnection *conn,
+			      mapi_id_t src_fid,
+			      guint32 src_fid_options,
+			      mapi_id_t dest_fid,
+			      guint32 dest_fid_options,
+			      GSList *mids,
+			      GCancellable *cancellable,
+			      GError **perror)
 {
 	enum MAPISTATUS ms;
 
@@ -3266,7 +3692,7 @@ e_mapi_connection_move_items (EMapiConnection *conn, mapi_id_t src_fid, guint32
 	e_mapi_debug_print("%s: Entering %s ", G_STRLOC, G_STRFUNC);
 
 	LOCK ();
-	ms = mapi_move_items (conn, src_fid, src_fid_options, dest_fid, dest_fid_options, mids, FALSE, perror);
+	ms = mapi_move_items (conn, src_fid, src_fid_options, dest_fid, dest_fid_options, mids, FALSE, cancellable, perror);
 	UNLOCK ();
 
 	e_mapi_debug_print("%s: Leaving %s ", G_STRLOC, G_STRFUNC);
@@ -3275,7 +3701,13 @@ e_mapi_connection_move_items (EMapiConnection *conn, mapi_id_t src_fid, guint32
 }
 
 gboolean
-e_mapi_connection_remove_items (EMapiConnection *conn, uint32_t olFolder, mapi_id_t fid, guint32 fid_options, GSList *mids, GError **perror)
+e_mapi_connection_remove_items (EMapiConnection *conn,
+				uint32_t olFolder,
+				mapi_id_t fid,
+				guint32 fid_options,
+				GSList *mids,
+				GCancellable *cancellable,
+				GError **perror)
 {
 	enum MAPISTATUS ms;
 	TALLOC_CTX *mem_ctx;
@@ -3307,6 +3739,11 @@ e_mapi_connection_remove_items (EMapiConnection *conn, uint32_t olFolder, mapi_i
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
+
 	/* Delete the messages from the folder */
 	ms = DeleteMessage (&obj_folder, id_messages, i);
 	if (ms != MAPI_E_SUCCESS) {
@@ -3316,7 +3753,7 @@ e_mapi_connection_remove_items (EMapiConnection *conn, uint32_t olFolder, mapi_i
 
 	result = TRUE;
 
-cleanup:
+ cleanup:
 	mapi_object_release(&obj_folder);
 	talloc_free(mem_ctx);
 
@@ -3327,30 +3764,96 @@ cleanup:
 	return result;
 }
 
+struct GetFolderHierarchyCBData
+{
+	EMapiFolderCategory folder_hier;
+	mapi_id_t folder_id;
+	GSList **mapi_folders;
+	ProgressNotifyCB cb;
+	gpointer cb_user_data;
+};
+
+static gboolean
+get_folder_hierarchy_cb (EMapiConnection *conn,
+			 mapi_id_t fid,
+			 TALLOC_CTX *mem_ctx,
+			 struct SRow *srow,
+			 guint32 row_index,
+			 guint32 rows_total,
+			 gpointer user_data,
+			 GCancellable *cancellable,
+			 GError **perror)
+{
+	struct GetFolderHierarchyCBData *gfh = user_data;
+
+	g_return_val_if_fail (gfh != NULL, FALSE);
+
+	if (srow) {
+		EMapiFolder *folder = NULL;
+		const mapi_id_t *fid = e_mapi_util_find_row_propval (srow, PR_FID);
+		const mapi_id_t *pid = e_mapi_util_find_row_propval (srow, PR_PARENT_FID);
+		const gchar *klass = e_mapi_util_find_row_propval (srow, PR_CONTAINER_CLASS);
+		const gchar *name = e_mapi_util_find_row_propval (srow, PR_DISPLAY_NAME_UNICODE);
+		const uint32_t *unread = e_mapi_util_find_row_propval (srow, PR_CONTENT_UNREAD);
+		const uint32_t *total = e_mapi_util_find_row_propval (srow, PR_CONTENT_COUNT);
+		const uint32_t *child = e_mapi_util_find_row_propval (srow, PR_FOLDER_CHILD_COUNT);
+		const uint32_t *folder_size = e_mapi_util_find_row_propval (srow, PR_MESSAGE_SIZE);
+
+		if (!klass)
+			klass = IPF_NOTE;
+
+		e_mapi_debug_print("|---+ %-15s : (Container class: %s %016" G_GINT64_MODIFIER "X) UnRead : %d Total : %d size : %d",
+			name, klass, *fid, unread ? *unread : 0, total ? *total : 0, folder_size ? *folder_size : 0);
+
+		folder = e_mapi_folder_new (name, klass, gfh->folder_hier, *fid, pid ? *pid : gfh->folder_id,
+						   child ? *child : 0, unread ? *unread : 0, total ? *total : 0);
+
+		folder->size = folder_size ? *folder_size : 0;
+
+		*gfh->mapi_folders = g_slist_prepend (*gfh->mapi_folders, folder);
+	}
+
+	if (gfh->cb)
+		return gfh->cb (conn, row_index, rows_total, gfh->cb_user_data, cancellable, perror);
+
+	return TRUE;
+}
+
 static gboolean
-get_child_folders (TALLOC_CTX *mem_ctx, EMapiFolderCategory folder_hier, mapi_object_t *parent,
-		   mapi_id_t folder_id, GSList **mapi_folders, GError **perror)
+get_child_folders (EMapiConnection *conn,
+		   TALLOC_CTX *mem_ctx,
+		   EMapiFolderCategory folder_hier,
+		   mapi_object_t *parent,
+		   mapi_id_t folder_id,
+		   GSList **mapi_folders,
+		   ProgressNotifyCB cb,
+		   gpointer cb_user_data,
+		   GCancellable *cancellable,
+		   GError **perror)
 {
 	enum MAPISTATUS		ms;
 	mapi_object_t		obj_folder;
 	mapi_object_t		obj_table;
-	struct SPropTagArray	*SPropTagArray = NULL;
-	struct SRowSet		rowset;
-	uint32_t		i, row_count = 0, cursor_pos, count;
-	gboolean		result = TRUE;
+	struct SPropTagArray	*spropTagArray = NULL;
+	uint32_t row_count = 0;
+	struct GetFolderHierarchyCBData gfh;
 
 	/* sanity check */
 	e_return_val_mapi_error_if_fail (mem_ctx != NULL, MAPI_E_INVALID_PARAMETER, FALSE);
 	e_return_val_mapi_error_if_fail (parent != NULL, MAPI_E_INVALID_PARAMETER, FALSE);
 
-	mapi_object_init(&obj_folder);
-	mapi_object_init(&obj_table);
+	mapi_object_init (&obj_folder);
+	mapi_object_init (&obj_table);
 
 	/* Attempt to open the folder */
 	ms = OpenFolder (parent, folder_id, &obj_folder);
 	if (ms != MAPI_E_SUCCESS) {
 		make_mapi_error (perror, "OpenFolder", ms);
-		result = FALSE;
+		goto cleanup;
+	}
+
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
 		goto cleanup;
 	}
 
@@ -3358,83 +3861,49 @@ get_child_folders (TALLOC_CTX *mem_ctx, EMapiFolderCategory folder_hier, mapi_ob
 	ms = GetHierarchyTable (&obj_folder, &obj_table, TableFlags_Depth | TableFlags_NoNotifications, &row_count);
 	if (ms != MAPI_E_SUCCESS) {
 		make_mapi_error (perror, "GetHierarchyTable", ms);
-		result = FALSE;
 		goto cleanup;
 	}
 
-	SPropTagArray = set_SPropTagArray(mem_ctx, 8,
-					  PR_FID,
-					  PR_PARENT_FID,
-					  PR_CONTAINER_CLASS,
-					  PR_DISPLAY_NAME_UNICODE,
-					  PR_CONTENT_UNREAD,
-					  PR_CONTENT_COUNT,
-					  PR_MESSAGE_SIZE,
-					  PR_FOLDER_CHILD_COUNT);
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror) || !row_count) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
 
-	ms = SetColumns (&obj_table, SPropTagArray);
+	spropTagArray = set_SPropTagArray (mem_ctx, 8,
+					   PR_FID,
+					   PR_PARENT_FID,
+					   PR_CONTAINER_CLASS,
+					   PR_DISPLAY_NAME_UNICODE,
+					   PR_CONTENT_UNREAD,
+					   PR_CONTENT_COUNT,
+					   PR_MESSAGE_SIZE,
+					   PR_FOLDER_CHILD_COUNT);
+
+	ms = SetColumns (&obj_table, spropTagArray);
 	if (ms != MAPI_E_SUCCESS) {
 		make_mapi_error (perror, "SetColumns", ms);
-		result = FALSE;
 		goto cleanup;
 	}
 
-	cursor_pos = 0;
-
-	do {
-		ms = QueryPosition (&obj_table, &cursor_pos, &count);
-		if (ms != MAPI_E_SUCCESS) {
-			make_mapi_error (perror, "QueryPosition", ms);
-			result = FALSE;
-			goto cleanup;
-		}
-
-		if (!count)
-			break;
-
-		/* Fill the table columns with data from the rows */
-		ms = QueryRows (&obj_table, 100, TBL_ADVANCE, &rowset);
-		if (ms != MAPI_E_SUCCESS) {
-			make_mapi_error (perror, "QueryRows", ms);
-			result = FALSE;
-			goto cleanup;
-		}
-
-		for (i = 0; i < rowset.cRows; i++) {
-			EMapiFolder *folder = NULL;
-
-			const mapi_id_t *fid = e_mapi_util_find_row_propval (&rowset.aRow[i], PR_FID);
-			const mapi_id_t *pid = e_mapi_util_find_row_propval (&rowset.aRow[i], PR_PARENT_FID);
-			const gchar *klass = e_mapi_util_find_row_propval (&rowset.aRow[i], PR_CONTAINER_CLASS);
-			const gchar *name = e_mapi_util_find_row_propval (&rowset.aRow[i], PR_DISPLAY_NAME_UNICODE);
-			const uint32_t *unread = e_mapi_util_find_row_propval (&rowset.aRow[i], PR_CONTENT_UNREAD);
-			const uint32_t *total = e_mapi_util_find_row_propval (&rowset.aRow[i], PR_CONTENT_COUNT);
-			const uint32_t *child = e_mapi_util_find_row_propval (&rowset.aRow[i], PR_FOLDER_CHILD_COUNT);
-			const uint32_t *folder_size = e_mapi_util_find_row_propval (&rowset.aRow[i], PR_MESSAGE_SIZE);
-
-			if (!klass)
-				klass = IPF_NOTE;
-
-			e_mapi_debug_print("|---+ %-15s : (Container class: %s %016" G_GINT64_MODIFIER "X) UnRead : %d Total : %d size : %d",
-				name, klass, *fid, unread ? *unread : 0, total ? *total : 0, folder_size ? *folder_size : 0);
-
-			folder = e_mapi_folder_new (name, klass, folder_hier, *fid, pid ? *pid : folder_id,
-							   child ? *child : 0, unread ? *unread : 0, total ? *total : 0);
-
-			folder->size = folder_size ? *folder_size : 0;
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
 
-			*mapi_folders = g_slist_prepend (*mapi_folders, folder);
-		}
+	gfh.folder_hier = folder_hier;
+	gfh.folder_id = folder_id;
+	gfh.mapi_folders = mapi_folders;
+	gfh.cb = cb;
+	gfh.cb_user_data = cb_user_data;
 
-		cursor_pos += rowset.cRows;
-	} while (cursor_pos < row_count && rowset.cRows);
+	ms = foreach_tablerow (conn, folder_id, mem_ctx, &obj_table, get_folder_hierarchy_cb, &gfh, cancellable, perror);
 
-cleanup:
-	MAPIFreeBuffer (SPropTagArray);
+ cleanup:
+	MAPIFreeBuffer (spropTagArray);
 	mapi_object_release (&obj_folder);
 	mapi_object_release (&obj_table);
 
-	return result;
+	return ms == MAPI_E_SUCCESS;
 }
 
 /* TODO : Find a right place for this.
@@ -3452,7 +3921,11 @@ cleanup:
 /*NOTE : IsMailboxFolder doesn't support this yet. */
 /* Ticket : http://trac.openchange.org/ticket/134  */
 static gboolean
-mapi_get_ren_additional_fids (mapi_object_t *obj_store, GHashTable **folder_list, GError **perror)
+mapi_get_ren_additional_fids (TALLOC_CTX *mem_ctx,
+			      mapi_object_t *obj_store,
+			      GHashTable **folder_list,
+			      GCancellable *cancellable,
+			      GError **perror)
 {
 	mapi_id_t inbox_id, fid;
 	mapi_object_t obj_folder_inbox;
@@ -3466,8 +3939,6 @@ mapi_get_ren_additional_fids (mapi_object_t *obj_store, GHashTable **folder_list
 	guint32 count, *folder_type;
 	guint i = 0;
 
-	TALLOC_CTX *mem_ctx;
-
 	/*Note : Do not change the order.*/
 	const guint32 olfolder_defaults[] = {
 		olFolderConflicts,
@@ -3477,8 +3948,7 @@ mapi_get_ren_additional_fids (mapi_object_t *obj_store, GHashTable **folder_list
 		olFolderJunk
 	};
 
-	mem_ctx = talloc_init("ExchangeMAPI_GetAdditionalFIDs");
-	mapi_object_init(&obj_folder_inbox);
+	mapi_object_init (&obj_folder_inbox);
 
 	/* Get Inbox FID using GetDefaultFolder. */
 	ms = GetDefaultFolder (obj_store, &inbox_id, olFolderInbox);
@@ -3487,6 +3957,11 @@ mapi_get_ren_additional_fids (mapi_object_t *obj_store, GHashTable **folder_list
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
+
 	/* Open InboxFolder. */
 	ms = OpenFolder (obj_store, inbox_id, &obj_folder_inbox);
 	if (ms != MAPI_E_SUCCESS) {
@@ -3494,6 +3969,11 @@ mapi_get_ren_additional_fids (mapi_object_t *obj_store, GHashTable **folder_list
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
+
 	/* GetProps on Inbox for PR_ADDITIONAL_REN_ENTRYIDS */
 	SPropTagArray = set_SPropTagArray(mem_ctx, 0x1, PR_ADDITIONAL_REN_ENTRYIDS);
 
@@ -3504,6 +3984,11 @@ mapi_get_ren_additional_fids (mapi_object_t *obj_store, GHashTable **folder_list
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
+
 	/* Build a SRow structure */
 	aRow.ulAdrEntryPad = 0;
 	aRow.cValues = count;
@@ -3529,22 +4014,25 @@ mapi_get_ren_additional_fids (mapi_object_t *obj_store, GHashTable **folder_list
 		}
 	}
 
-cleanup:
-	mapi_object_release(&obj_folder_inbox);
-	talloc_free (mem_ctx);
+ cleanup:
+	mapi_object_release (&obj_folder_inbox);
 
 	return ms == MAPI_E_SUCCESS;
 }
 
 static gboolean
-set_default_folders (mapi_object_t *obj_store, GSList **mapi_folders, GError **perror)
+set_default_folders (TALLOC_CTX *mem_ctx,
+		     mapi_object_t *obj_store,
+		     GSList **mapi_folders,
+		     GCancellable *cancellable,
+		     GError **perror)
 {
 	GSList *folder_list = *mapi_folders;
 
 	GHashTable *default_folders = g_hash_table_new_full (g_str_hash, g_str_equal,
 							     g_free, g_free);
 
-	if (!mapi_get_ren_additional_fids (obj_store, &default_folders, perror)) {
+	if (!mapi_get_ren_additional_fids (mem_ctx, obj_store, &default_folders, cancellable, perror)) {
 		g_hash_table_destroy (default_folders);
 		return FALSE;
 	}
@@ -3590,7 +4078,12 @@ set_user_name (gpointer data, gpointer user_data)
 }
 
 gboolean
-e_mapi_connection_get_folders_list (EMapiConnection *conn, GSList **mapi_folders, GError **perror)
+e_mapi_connection_get_folders_list (EMapiConnection *conn,
+				    GSList **mapi_folders,
+				    ProgressNotifyCB cb,
+				    gpointer cb_user_data,
+				    GCancellable *cancellable,
+				    GError **perror)
 {
 	enum MAPISTATUS	ms;
 	TALLOC_CTX		*mem_ctx;
@@ -3622,6 +4115,11 @@ e_mapi_connection_get_folders_list (EMapiConnection *conn, GSList **mapi_folders
 					  PR_MESSAGE_SIZE,
 					  PidTagMailboxOwnerName);
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
+
 	lpProps = talloc_zero(mem_ctx, struct SPropValue);
 	ms = GetProps (&priv->msg_store, MAPI_PROPS_SKIP_NAMEDID_CHECK | MAPI_UNICODE, SPropTagArray, &lpProps, &count);
 	MAPIFreeBuffer(SPropTagArray);
@@ -3631,6 +4129,11 @@ e_mapi_connection_get_folders_list (EMapiConnection *conn, GSList **mapi_folders
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
+
 	/* Build a SRow structure */
 	aRow.ulAdrEntryPad = 0;
 	aRow.cValues = count;
@@ -3649,6 +4152,11 @@ e_mapi_connection_get_folders_list (EMapiConnection *conn, GSList **mapi_folders
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
+
 	/* FIXME: May have to get the child folders count? Do we need/use it? */
 	folder = e_mapi_folder_new (mailbox_name, IPF_NOTE,
 					   MAPI_PERSONAL_FOLDER, mailbox_id, 0, 0, 0 ,0);
@@ -3659,18 +4167,18 @@ e_mapi_connection_get_folders_list (EMapiConnection *conn, GSList **mapi_folders
 	*mapi_folders = g_slist_prepend (*mapi_folders, folder);
 
 	/* FIXME: check status of get_child_folders */
-	result = get_child_folders (mem_ctx, MAPI_PERSONAL_FOLDER, &priv->msg_store, mailbox_id, mapi_folders, perror);
+	result = get_child_folders (conn, mem_ctx, MAPI_PERSONAL_FOLDER, &priv->msg_store, mailbox_id, mapi_folders, cb, cb_user_data, cancellable, perror);
 
 	*mapi_folders = g_slist_reverse (*mapi_folders);
 
-	if (!set_default_folders (&priv->msg_store, mapi_folders, perror)) {
+	if (result && !set_default_folders (mem_ctx, &priv->msg_store, mapi_folders, cancellable, perror)) {
 		goto cleanup;
 	}
 
 	g_slist_foreach (*mapi_folders, (GFunc) set_owner_name, (gpointer) mailbox_owner_name);
 	g_slist_foreach (*mapi_folders, (GFunc) set_user_name, (gpointer) mailbox_user_name);
 
-cleanup:
+ cleanup:
 	talloc_free (mem_ctx);
 
 	UNLOCK ();
@@ -3681,7 +4189,12 @@ cleanup:
 }
 
 gboolean
-e_mapi_connection_get_pf_folders_list (EMapiConnection *conn, GSList **mapi_folders, GError **perror)
+e_mapi_connection_get_pf_folders_list (EMapiConnection *conn,
+				       GSList **mapi_folders,
+				       ProgressNotifyCB cb,
+				       gpointer cb_user_data,
+				       GCancellable *cancellable,
+				       GError **perror)
 {
 	enum MAPISTATUS		ms;
 	TALLOC_CTX		*mem_ctx;
@@ -3700,20 +4213,30 @@ e_mapi_connection_get_pf_folders_list (EMapiConnection *conn, GSList **mapi_fold
 	if (!ensure_public_store (priv, perror))
 		goto cleanup;
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
+
 	ms = GetDefaultPublicFolder (&priv->public_store, &mailbox_id, olFolderPublicIPMSubtree);
 	if (ms != MAPI_E_SUCCESS) {
 		make_mapi_error (perror, "GetDefaultPublicFolder", ms);
 		goto cleanup;
 	}
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+		goto cleanup;
+	}
+
 	folder = e_mapi_folder_new (_("All Public Folders"), IPF_NOTE, 0, mailbox_id, 0, 0, 0, 0);
 	folder->is_default = true;
 	folder->default_type = olPublicFoldersAllPublicFolders;
 	*mapi_folders = g_slist_prepend (*mapi_folders, folder);
-	result = get_child_folders (mem_ctx, MAPI_FAVOURITE_FOLDER, &priv->public_store, mailbox_id, mapi_folders, perror);
+	result = get_child_folders (conn, mem_ctx, MAPI_FAVOURITE_FOLDER, &priv->public_store, mailbox_id, mapi_folders, cb, cb_user_data, cancellable, perror);
 	*mapi_folders = g_slist_reverse (*mapi_folders);
 
-cleanup:
+ cleanup:
 	talloc_free (mem_ctx);
 
 	UNLOCK ();
@@ -3736,7 +4259,7 @@ e_mapi_connection_peek_folders_list (EMapiConnection *conn)
 
 	if (!priv->folders) {
 		LOCK ();
-		e_mapi_connection_get_folders_list (conn, &priv->folders, perror);
+		e_mapi_connection_get_folders_list (conn, &priv->folders, NULL, NULL, NULL, perror);
 		UNLOCK ();
 	}
 
@@ -3747,7 +4270,11 @@ e_mapi_connection_peek_folders_list (EMapiConnection *conn)
 
 /* free returned pointer with g_free() */
 gchar *
-e_mapi_connection_ex_to_smtp (EMapiConnection *conn, const gchar *ex_address, gchar **display_name, GError **perror)
+e_mapi_connection_ex_to_smtp (EMapiConnection *conn,
+			      const gchar *ex_address,
+			      gchar **display_name,
+			      GCancellable *cancellable,
+			      GError **perror)
 {
 	enum MAPISTATUS	ms;
 	TALLOC_CTX		*mem_ctx;
@@ -3777,6 +4304,10 @@ e_mapi_connection_ex_to_smtp (EMapiConnection *conn, const gchar *ex_address, gc
 	if (ms != MAPI_E_SUCCESS)
 		ms = ResolveNames (priv->session, (const gchar **)str_array, SPropTagArray, &SRowSet, &flaglist, 0);
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+		ms = MAPI_E_USER_CANCEL;
+	}
+
 	if (ms == MAPI_E_SUCCESS && SRowSet && SRowSet->cRows == 1) {
 		smtp_addr = g_strdup (e_mapi_util_find_row_propval (SRowSet->aRow, PR_SMTP_ADDRESS_UNICODE));
 		if (display_name)
@@ -3794,7 +4325,9 @@ e_mapi_connection_ex_to_smtp (EMapiConnection *conn, const gchar *ex_address, gc
 }
 
 gboolean
-e_mapi_connection_events_init (EMapiConnection *conn, GError **perror)
+e_mapi_connection_events_init (EMapiConnection *conn,
+			       GCancellable *cancellable,
+			       GError **perror)
 {
 	enum MAPISTATUS ms;
 
@@ -3812,9 +4345,14 @@ e_mapi_connection_events_init (EMapiConnection *conn, GError **perror)
 }
 
 gboolean
-e_mapi_connection_events_subscribe (EMapiConnection *conn, guint32 options,
-				guint16 event_mask, guint32 *events_conn_id,
-				mapi_notify_callback_t callback, gpointer data, GError **perror)
+e_mapi_connection_events_subscribe (EMapiConnection *conn,
+				    guint32 options,
+				    guint16 event_mask,
+				    guint32 *events_conn_id,
+				    mapi_notify_callback_t callback,
+				    gpointer data,
+				    GCancellable *cancellable,
+				    GError **perror)
 {
 	enum MAPISTATUS	ms = MAPI_E_CALL_FAILED;
 	gboolean use_store = ((options & MAPI_EVENTS_USE_STORE) ||
@@ -3847,7 +4385,7 @@ e_mapi_connection_events_subscribe (EMapiConnection *conn, guint32 options,
 }
 
 gboolean
-e_mapi_connection_events_unsubscribe (EMapiConnection *conn, guint32 events_conn_id, GError **perror)
+e_mapi_connection_events_unsubscribe (EMapiConnection *conn, guint32 events_conn_id, GCancellable *cancellable, GError **perror)
 {
 	enum MAPISTATUS	ms;
 
@@ -3926,7 +4464,7 @@ try_create_profile_main_thread_cb (struct tcp_data *data)
 
 				if (profname && g_str_equal (profname, data->profname)) {
 					/* do not use locking here, because when this is called then other thread is holding the lock */
-					data->has_profile = mapi_profile_create (&empd, NULL, NULL, NULL, FALSE);
+					data->has_profile = mapi_profile_create (&empd, NULL, NULL, NULL, NULL, FALSE);
 
 					g_free (profname);
 					g_object_unref (settings);
@@ -4044,7 +4582,7 @@ ema_global_unlock (void)
 }
 
 static struct mapi_session *
-mapi_profile_load (const gchar *profname, const gchar *password, GError **perror)
+mapi_profile_load (const gchar *profname, const gchar *password, GCancellable *cancellable, GError **perror)
 {
 	enum MAPISTATUS	ms = MAPI_E_SUCCESS;
 	struct mapi_session *session = NULL;
@@ -4107,6 +4645,7 @@ create_profile_fallback_callback (struct SRowSet *rowset, gconstpointer data)
 static gboolean
 mapi_profile_create (const EMapiProfileData *empd,
 		     mapi_profile_callback_t callback, gconstpointer data,
+		     GCancellable *cancellable,
 		     GError **perror,
 		     gboolean use_locking)
 {
@@ -4188,6 +4727,9 @@ mapi_profile_create (const EMapiProfileData *empd,
 	}
 	e_mapi_debug_print("MapiLogonProvider : succeeded \n");
 
+	if (g_cancellable_set_error_if_cancelled (cancellable, perror))
+		goto cleanup;
+
 	ms = ProcessNetworkProfile (session, empd->username, callback, data);
 	if (ms != MAPI_E_SUCCESS) {
 		make_mapi_error (perror, "ProcessNetworkProfile", ms);
@@ -4227,10 +4769,12 @@ mapi_profile_create (const EMapiProfileData *empd,
 
 gboolean
 e_mapi_create_profile (EMapiProfileData *empd,
-			      mapi_profile_callback_t callback, gconstpointer data,
-			      GError **perror)
+		       mapi_profile_callback_t callback,
+		       gconstpointer data,
+		       GCancellable *cancellable,
+		       GError **perror)
 {
-	return mapi_profile_create (empd, callback, data, perror, TRUE);
+	return mapi_profile_create (empd, callback, data, cancellable, perror, TRUE);
 }
 
 gboolean
diff --git a/src/libexchangemapi/e-mapi-connection.h b/src/libexchangemapi/e-mapi-connection.h
index 9d7e92b..319f525 100644
--- a/src/libexchangemapi/e-mapi-connection.h
+++ b/src/libexchangemapi/e-mapi-connection.h
@@ -27,6 +27,7 @@
 
 #include <glib.h>
 #include <glib-object.h>
+#include <gio/gio.h>
 
 #include <libmapi/libmapi.h>
 
@@ -147,19 +148,32 @@ typedef struct {
 	time_t last_modified; /* PR_LAST_MODIFICATION_TIME as UTC */
 } ListItemsData;
 
-typedef gboolean (*FetchCallback)		(FetchItemsCallbackData *item_data, gpointer data);
-typedef gboolean (*FetchGALCallback)		(EMapiConnection *conn, uint32_t row_index, uint32_t n_rows, struct SRow *aRow, gpointer data);
+typedef gboolean (*FetchCallback)		(FetchItemsCallbackData *item_data,
+						 gpointer data,
+						 GCancellable *cancellable,
+						 GError **perror);
+typedef gboolean (*FetchGALCallback)		(EMapiConnection *conn,
+						 uint32_t row_index,
+						 uint32_t n_rows,
+						 struct SRow *aRow,
+						 gpointer data,
+						 GCancellable *cancellable,
+						 GError **perror);
 typedef gboolean (*BuildWritePropsCB)		(EMapiConnection *conn,
 						 mapi_id_t fid,
 						 TALLOC_CTX *mem_ctx,
 						 struct SPropValue **values,
 						 uint32_t *n_values,
-						 gpointer data);
+						 gpointer data,
+						 GCancellable *cancellable,
+						 GError **perror);
 typedef gboolean (*BuildReadPropsCB)		(EMapiConnection *conn,
 						 mapi_id_t fid,
 						 TALLOC_CTX *mem_ctx,
 						 struct SPropTagArray *props,
-						 gpointer data);
+						 gpointer data,
+						 GCancellable *cancellable,
+						 GError **perror);
 typedef gboolean (*ListItemsCB)			(EMapiConnection *conn,
 						 mapi_id_t fid,
 						 TALLOC_CTX *mem_ctx,
@@ -167,12 +181,21 @@ typedef gboolean (*ListItemsCB)			(EMapiConnection *conn,
 						 guint32 item_index,
 						 guint32 items_total,
 						 gpointer user_data,
+						 GCancellable *cancellable,
 						 GError **perror);
 typedef gboolean (*GetFolderPropertiesCB)	(EMapiConnection *conn,
 						 mapi_id_t fid,
 						 TALLOC_CTX *mem_ctx,
 						 /* const */ struct mapi_SPropValue_array *properties,
 						 gpointer user_data,
+						 GCancellable *cancellable,
+						 GError **perror);
+
+typedef gboolean (*ProgressNotifyCB)		(EMapiConnection *conn,
+						 guint32 item_index,
+						 guint32 items_total,
+						 gpointer user_data,
+						 GCancellable *cancellable,
 						 GError **perror);
 
 struct _EMapiConnection {
@@ -187,93 +210,244 @@ struct _EMapiConnectionClass {
 	/* signals */
 };
 
-GType			e_mapi_connection_get_type (void);
-EMapiConnection *e_mapi_connection_new (const gchar *profile, const gchar *password, GError **perror);
-EMapiConnection *e_mapi_connection_find (const gchar *profile);
-gboolean		e_mapi_connection_reconnect (EMapiConnection *conn, const gchar *password, GError **perror);
-gboolean		e_mapi_connection_close (EMapiConnection *conn);
-gboolean		e_mapi_connection_connected (EMapiConnection *conn);
-
-gboolean		e_mapi_connection_get_folder_properties (EMapiConnection *conn, mapi_id_t fid, guint32 options,
-					BuildReadPropsCB brp_cb, gpointer brp_cb_user_data,
-					GetFolderPropertiesCB cb, gpointer cb_user_data,
-					GError **perror);
-
-gboolean		e_mapi_connection_list_items (EMapiConnection *conn, mapi_id_t fid, guint32 options,
-					struct mapi_SRestriction *restrictions,
-					ListItemsCB cb, gpointer user_data,
-					GError **perror);
-
-gboolean		e_mapi_connection_fetch_object_props (
-					EMapiConnection *conn, mapi_object_t *obj_folder, mapi_id_t fid, mapi_id_t mid, mapi_object_t *obj_message,
-					BuildReadPropsCB build_props, gpointer brp_data,
-					FetchCallback cb, gpointer data,
-					guint32 options, GError **perror);
-
-gboolean		e_mapi_connection_fetch_item (EMapiConnection *conn, mapi_id_t fid, mapi_id_t mid,
-					BuildReadPropsCB build_props, gpointer brp_data,
-					FetchCallback cb, gpointer data,
-					guint32 options, GError **perror);
-
-gboolean		e_mapi_connection_fetch_items (EMapiConnection *conn, mapi_id_t fid,
-					struct mapi_SRestriction *res, struct SSortOrderSet *sort_order,
-					BuildReadPropsCB build_props, gpointer brp_data,
-					FetchCallback cb, gpointer data,
-					guint32 options, GError **perror);
-
-gboolean		e_mapi_connection_fetch_gal (EMapiConnection *conn, struct mapi_SRestriction *restrictions,
-					BuildReadPropsCB build_props, gpointer brp_data,
-					FetchGALCallback cb, gpointer data, GError **perror);
-
-gboolean		e_mapi_connection_get_public_folder (EMapiConnection *conn, mapi_object_t *obj_object, GError **perror);
-
-mapi_id_t		e_mapi_connection_create_folder (EMapiConnection *conn, uint32_t olFolder, mapi_id_t pfid, guint32 fid_options, const gchar *name, GError **perror);
-gboolean		e_mapi_connection_remove_folder (EMapiConnection *conn, mapi_id_t fid, guint32 fid_options, GError **perror);
-gboolean		e_mapi_connection_empty_folder (EMapiConnection *conn, mapi_id_t fid, guint32 fid_options, GError **perror);
-gboolean		e_mapi_connection_rename_folder (EMapiConnection *conn, mapi_id_t fid, guint32 fid_options, const gchar *new_name, GError **perror);
-gboolean		e_mapi_connection_move_folder (EMapiConnection *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, GError **perror);
-GSList *		e_mapi_connection_check_restriction (EMapiConnection *conn, mapi_id_t fid, guint32 fid_options, struct mapi_SRestriction *res, GError **perror);
-mapi_id_t		e_mapi_connection_get_default_folder_id (EMapiConnection *conn, uint32_t olFolder, GError **perror);
-mapi_id_t		e_mapi_connection_create_item (EMapiConnection *conn, uint32_t olFolder, mapi_id_t fid,
-					BuildWritePropsCB build_props, gpointer bwp_data,
-					GSList *recipients, GSList *attachments, GSList *generic_streams,
-					uint32_t options, GError **perror);
-
-gboolean		e_mapi_connection_modify_item (EMapiConnection *conn, uint32_t olFolder, mapi_id_t fid, mapi_id_t mid,
-					BuildWritePropsCB build_props, gpointer bwp_data,
-					GSList *recipients, GSList *attachments, GSList *generic_streams,
-					uint32_t options, GError **perror);
-
-gboolean		e_mapi_connection_set_flags (EMapiConnection *conn, uint32_t olFolder, mapi_id_t fid, guint32 fid_options, GSList *mid_list, uint32_t flag, GError **perror);
-gboolean		e_mapi_connection_remove_items (EMapiConnection *conn, uint32_t olFolder, mapi_id_t fid, guint32 fid_options, GSList *mids, GError **perror);
-gboolean		e_mapi_connection_copy_items (EMapiConnection *conn, mapi_id_t src_fid, guint32 src_fid_options, mapi_id_t dest_fid, guint32 dest_fid_options, GSList *mids, GError **perror);
-gboolean		e_mapi_connection_move_items (EMapiConnection *conn, mapi_id_t src_fid, guint32 src_fid_options, mapi_id_t dest_fid, guint32 dest_fid_options, GSList *mids, GError **perror);
-gboolean		e_mapi_connection_get_folders_list (EMapiConnection *conn, GSList **mapi_folders, GError **perror);
-gboolean		e_mapi_connection_get_pf_folders_list (EMapiConnection *conn, GSList **mapi_folders, GError **perror);
-GSList *		e_mapi_connection_peek_folders_list (EMapiConnection *conn);
-
-gboolean		e_mapi_connection_resolve_named_props (EMapiConnection *conn, mapi_id_t fid, ResolveNamedIDsData *named_ids_list, guint named_ids_n_elems, GError **perror);
-uint32_t		e_mapi_connection_resolve_named_prop (EMapiConnection *conn, mapi_id_t fid, uint32_t pidlid_propid, GError **perror);
-uint32_t		e_mapi_connection_unresolve_proptag_to_nameid (EMapiConnection *conn, mapi_id_t fid, uint32_t proptag);
-
-gchar *			e_mapi_connection_ex_to_smtp (EMapiConnection *conn, const gchar *ex_address, gchar **display_name, GError **perror);
+GType			e_mapi_connection_get_type		(void);
+EMapiConnection *	e_mapi_connection_new			(const gchar *profile,
+								 const gchar *password,
+								 GCancellable *cancellable,
+								 GError **perror);
+EMapiConnection *	e_mapi_connection_find			(const gchar *profile);
+gboolean		e_mapi_connection_reconnect		(EMapiConnection *conn,
+								 const gchar *password,
+								 GCancellable *cancellable,
+								 GError **perror);
+gboolean		e_mapi_connection_close			(EMapiConnection *conn);
+gboolean		e_mapi_connection_connected		(EMapiConnection *conn);
+
+gboolean		e_mapi_connection_get_folder_properties	(EMapiConnection *conn,
+								 mapi_id_t fid,
+								 guint32 options,
+								 BuildReadPropsCB brp_cb,
+								 gpointer brp_cb_user_data,
+								 GetFolderPropertiesCB cb,
+								 gpointer cb_user_data,
+								 GCancellable *cancellable,
+								 GError **perror);
+
+gboolean		e_mapi_connection_list_items		(EMapiConnection *conn,
+								 mapi_id_t fid,
+								 guint32 options,
+								 struct mapi_SRestriction *restrictions,
+								 ListItemsCB cb,
+								 gpointer user_data,
+								 GCancellable *cancellable,
+								 GError **perror);
+
+gboolean		e_mapi_connection_fetch_object_props	(EMapiConnection *conn,
+								 mapi_object_t *obj_folder,
+								 mapi_id_t fid,
+								 mapi_id_t mid,
+								 mapi_object_t *obj_message,
+								 BuildReadPropsCB build_props,
+								 gpointer brp_data,
+								 FetchCallback cb,
+								 gpointer data,
+								 guint32 options,
+								 GCancellable *cancellable,
+								 GError **perror);
+
+gboolean		e_mapi_connection_fetch_item		(EMapiConnection *conn,
+								 mapi_id_t fid,
+								 mapi_id_t mid,
+								 BuildReadPropsCB build_props,
+								 gpointer brp_data,
+								 FetchCallback cb,
+								 gpointer data,
+								 guint32 options,
+								 GCancellable *cancellable,
+								 GError **perror);
+
+gboolean		e_mapi_connection_fetch_items		(EMapiConnection *conn,
+								 mapi_id_t fid,
+								 struct mapi_SRestriction *res,
+								 struct SSortOrderSet *sort_order,
+								 BuildReadPropsCB build_props,
+								 gpointer brp_data,
+								 FetchCallback cb,
+								 gpointer data,
+								 guint32 options,
+								 GCancellable *cancellable,
+								 GError **perror);
+
+gboolean		e_mapi_connection_fetch_gal		(EMapiConnection *conn,
+								 struct mapi_SRestriction *restrictions,
+								 BuildReadPropsCB build_props,
+								 gpointer brp_data,
+								 FetchGALCallback cb,
+								 gpointer data,
+								 GCancellable *cancellable,
+								 GError **perror);
+
+gboolean		e_mapi_connection_get_public_folder	(EMapiConnection *conn,
+								 mapi_object_t *obj_object,
+								 GCancellable *cancellable,
+								 GError **perror);
+
+mapi_id_t		e_mapi_connection_create_folder		(EMapiConnection *conn,
+								 uint32_t olFolder,
+								 mapi_id_t pfid,
+								 guint32 fid_options,
+								 const gchar *name,
+								 GCancellable *cancellable,
+								 GError **perror);
+gboolean		e_mapi_connection_remove_folder		(EMapiConnection *conn,
+								 mapi_id_t fid,
+								 guint32 fid_options,
+								 GCancellable *cancellable,
+								 GError **perror);
+gboolean		e_mapi_connection_empty_folder		(EMapiConnection *conn,
+								 mapi_id_t fid,
+								 guint32 fid_options,
+								 GCancellable *cancellable,
+								 GError **perror);
+gboolean		e_mapi_connection_rename_folder		(EMapiConnection *conn,
+								 mapi_id_t fid,
+								 guint32 fid_options,
+								 const gchar *new_name,
+								 GCancellable *cancellable,
+								 GError **perror);
+gboolean		e_mapi_connection_move_folder		(EMapiConnection *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,
+								 GCancellable *cancellable,
+								 GError **perror);
+GSList *		e_mapi_connection_check_restriction	(EMapiConnection *conn,
+								 mapi_id_t fid,
+								 guint32 fid_options,
+								 struct mapi_SRestriction *res,
+								 GCancellable *cancellable,
+								 GError **perror);
+mapi_id_t		e_mapi_connection_get_default_folder_id	(EMapiConnection *conn,
+								 uint32_t olFolder,
+								 GCancellable *cancellable,
+								 GError **perror);
+mapi_id_t		e_mapi_connection_create_item		(EMapiConnection *conn,
+								 uint32_t olFolder,
+								 mapi_id_t fid,
+								 BuildWritePropsCB build_props,
+								 gpointer bwp_data,
+								 GSList *recipients,
+								 GSList *attachments,
+								 GSList *generic_streams,
+								 uint32_t options,
+								 GCancellable *cancellable,
+								 GError **perror);
+
+gboolean		e_mapi_connection_modify_item		(EMapiConnection *conn,
+								 uint32_t olFolder,
+								 mapi_id_t fid,
+								 mapi_id_t mid,
+								 BuildWritePropsCB build_props,
+								 gpointer bwp_data,
+								 GSList *recipients,
+								 GSList *attachments,
+								 GSList *generic_streams,
+								 uint32_t options,
+								 GCancellable *cancellable,
+								 GError **perror);
+
+gboolean		e_mapi_connection_set_flags		(EMapiConnection *conn,
+								 uint32_t olFolder,
+								 mapi_id_t fid,
+								 guint32 fid_options,
+								 GSList *mid_list,
+								 uint32_t flag,
+								 GCancellable *cancellable,
+								 GError **perror);
+gboolean		e_mapi_connection_remove_items		(EMapiConnection *conn,
+								 uint32_t olFolder,
+								 mapi_id_t fid,
+								 guint32 fid_options,
+								 GSList *mids,
+								 GCancellable *cancellable,
+								 GError **perror);
+gboolean		e_mapi_connection_copy_items		(EMapiConnection *conn,
+								 mapi_id_t src_fid,
+								 guint32 src_fid_options,
+								 mapi_id_t dest_fid,
+								 guint32 dest_fid_options,
+								 GSList *mids,
+								 GCancellable *cancellable,
+								 GError **perror);
+gboolean		e_mapi_connection_move_items		(EMapiConnection *conn,
+								 mapi_id_t src_fid,
+								 guint32 src_fid_options,
+								 mapi_id_t dest_fid,
+								 guint32 dest_fid_options,
+								 GSList *mids,
+								 GCancellable *cancellable,
+								 GError **perror);
+gboolean		e_mapi_connection_get_folders_list	(EMapiConnection *conn,
+								 GSList **mapi_folders,
+								 ProgressNotifyCB cb,
+								 gpointer cb_user_data,
+								 GCancellable *cancellable,
+								 GError **perror);
+gboolean		e_mapi_connection_get_pf_folders_list	(EMapiConnection *conn,
+								 GSList **mapi_folders,
+								 ProgressNotifyCB cb,
+								 gpointer cb_user_data,
+								 GCancellable *cancellable,
+								 GError **perror);
+GSList *		e_mapi_connection_peek_folders_list	(EMapiConnection *conn);
+
+gboolean		e_mapi_connection_resolve_named_props	(EMapiConnection *conn,
+								 mapi_id_t fid,
+								 ResolveNamedIDsData *named_ids_list,
+								 guint named_ids_n_elems,
+								 GCancellable *cancellable,
+								 GError **perror);
+uint32_t		e_mapi_connection_resolve_named_prop	(EMapiConnection *conn,
+								 mapi_id_t fid,
+								 uint32_t pidlid_propid,
+								 GCancellable *cancellable,
+								 GError **perror);
+uint32_t		e_mapi_connection_unresolve_proptag_to_nameid
+								(EMapiConnection *conn,
+								 mapi_id_t fid,
+								 uint32_t proptag);
+
+gchar *			e_mapi_connection_ex_to_smtp		(EMapiConnection *conn,
+								 const gchar *ex_address,
+								 gchar **display_name,
+								 GCancellable *cancellable,
+								 GError **perror);
 
 /* Push notifications APIs */
 typedef gboolean (*exchange_check_continue) (void);
 
-gboolean		e_mapi_connection_events_init (EMapiConnection *conn, GError **perror);
-gboolean		e_mapi_connection_events_monitor (EMapiConnection *conn, struct mapi_notify_continue_callback_data *cb_data);
-
-gboolean		e_mapi_connection_events_subscribe (EMapiConnection *conn, guint32 options,
-					guint16 event_mask, guint32 *events_conn_id,
-					mapi_notify_callback_t callback, gpointer data, GError **perror);
-
-gboolean		e_mapi_connection_events_subscribe_and_monitor (EMapiConnection *conn, mapi_id_t *obj_id, guint32 options,
-					guint16 event_mask, guint32 *events_conn_id,
-					gboolean use_store, mapi_notify_callback_t callback,
-					gpointer data);
-
-gboolean		e_mapi_connection_events_unsubscribe (EMapiConnection *conn, guint32 events_conn_id, GError **perror);
+gboolean		e_mapi_connection_events_init		(EMapiConnection *conn,
+								 GCancellable *cancellable,
+								 GError **perror);
+gboolean		e_mapi_connection_events_monitor	(EMapiConnection *conn,
+								 struct mapi_notify_continue_callback_data *cb_data);
+
+gboolean		e_mapi_connection_events_subscribe	(EMapiConnection *conn,
+								 guint32 options,
+								 guint16 event_mask,
+								 guint32 *events_conn_id,
+								 mapi_notify_callback_t callback,
+								 gpointer data,
+								 GCancellable *cancellable,
+								 GError **perror);
+
+gboolean		e_mapi_connection_events_unsubscribe	(EMapiConnection *conn,
+								 guint32 events_conn_id,
+								 GCancellable *cancellable,
+								 GError **perror);
 
 /* profile functions */
 
@@ -292,15 +466,22 @@ typedef struct {
 	 && (((x)->domain && *(x)->domain && (x)->password && *(x)->password) \
 	     || ((x)->krb_sso && (x)->krb_realm && *(x)->krb_realm)))
 
-gboolean		e_mapi_create_profile (EMapiProfileData *profile,
-				       mapi_profile_callback_t cb, gconstpointer data, GError **perror);
+gboolean		e_mapi_create_profile			(EMapiProfileData *profile,
+								 mapi_profile_callback_t cb,
+								 gconstpointer data,
+								 GCancellable *cancellable,
+								 GError **perror);
 
-gboolean		e_mapi_delete_profile (const gchar *profile, GError **perror);
-void			e_mapi_rename_profile (const gchar *old_name, const gchar *new_name);
+gboolean		e_mapi_delete_profile			(const gchar *profile,
+								 GError **perror);
+void			e_mapi_rename_profile			(const gchar *old_name,
+								 const gchar *new_name);
 
 /* utility functions */
 
-void make_mapi_error (GError **perror, const gchar *context, enum MAPISTATUS mapi_status);
+void			make_mapi_error				(GError **perror,
+								 const gchar *context,
+								 enum MAPISTATUS mapi_status);
 
 G_END_DECLS
 
diff --git a/src/libexchangemapi/e-mapi-mail-utils.c b/src/libexchangemapi/e-mapi-mail-utils.c
index 3336c2a..77e893d 100644
--- a/src/libexchangemapi/e-mapi-mail-utils.c
+++ b/src/libexchangemapi/e-mapi-mail-utils.c
@@ -57,7 +57,10 @@ mail_item_free (MailItem *item)
 }
 
 gboolean
-fetch_props_to_mail_item_cb (FetchItemsCallbackData *item_data, gpointer data)
+fetch_props_to_mail_item_cb (FetchItemsCallbackData *item_data,
+			     gpointer data,
+			     GCancellable *cancellable,
+			     GError **perror)
 {
 	long *flags = NULL;
 	struct FILETIME *delivery_date = NULL;
@@ -77,7 +80,7 @@ fetch_props_to_mail_item_cb (FetchItemsCallbackData *item_data, gpointer data)
 		camel_debug_end();
 	}
 
-	content_class_pid = e_mapi_connection_resolve_named_prop (item_data->conn, item_data->fid, PidNameContentClass, NULL);
+	content_class_pid = e_mapi_connection_resolve_named_prop (item_data->conn, item_data->fid, PidNameContentClass, cancellable, perror);
 	if (content_class_pid == MAPI_E_RESERVED)
 		content_class_pid = 0;
 
@@ -251,7 +254,13 @@ fetch_read_item_common_data (MailItem *item, uint32_t propTag, gconstpointer pro
 }
 
 gboolean
-mapi_mail_get_item_prop_list (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, struct SPropTagArray *props, gpointer data)
+mapi_mail_get_item_prop_list (EMapiConnection *conn,
+			      mapi_id_t fid,
+			      TALLOC_CTX *mem_ctx,
+			      struct SPropTagArray *props,
+			      gpointer data,
+			      GCancellable *cancellable,
+			      GError **perror)
 {
 	static const uint32_t item_props[] = {
 		PR_FID,
@@ -314,7 +323,7 @@ mapi_mail_get_item_prop_list (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *
 	if (!e_mapi_utils_add_props_to_props_array (mem_ctx, props, item_props, G_N_ELEMENTS (item_props)))
 		return FALSE;
 
-	return e_mapi_utils_add_named_ids_to_props_array (conn, fid, mem_ctx, props, nids, G_N_ELEMENTS (nids));
+	return e_mapi_utils_add_named_ids_to_props_array (conn, fid, mem_ctx, props, nids, G_N_ELEMENTS (nids), cancellable, perror);
 }
 
 static gboolean
@@ -367,7 +376,7 @@ mapi_mime_set_recipient_list (EMapiConnection *conn, CamelMimeMessage *msg, Mail
 			if (name && !strchr (name, '@')) {
 				gchar *to_free;
 
-				to_free = e_mapi_connection_ex_to_smtp (conn, recip->email_id, &display_name, NULL);
+				to_free = e_mapi_connection_ex_to_smtp (conn, recip->email_id, &display_name, NULL, NULL);
 				g_free (to_free);
 			}
 		}
@@ -480,7 +489,7 @@ mapi_mime_set_msg_headers (EMapiConnection *conn, CamelMimeMessage *msg, MailIte
 		if ((item->header.from_type != NULL) && !g_utf8_collate (item->header.from_type, "EX")) {
 			gchar *from_email;
 
-			from_email = e_mapi_connection_ex_to_smtp (conn, item->header.from_email, NULL, NULL);
+			from_email = e_mapi_connection_ex_to_smtp (conn, item->header.from_email, NULL, NULL, NULL);
 			g_free (item->header.from_email);
 			item->header.from_email = from_email;
 		}
@@ -784,7 +793,7 @@ mapi_mime_classify_attachments (EMapiConnection *conn, mapi_id_t fid, const gcha
 			camel_mime_part_set_encoding (part, CAMEL_TRANSFER_ENCODING_BASE64);
 
 			strm = NULL;
-			proptag = e_mapi_connection_resolve_named_prop (conn, fid, PidNameAttachmentMacInfo, NULL);
+			proptag = e_mapi_connection_resolve_named_prop (conn, fid, PidNameAttachmentMacInfo, NULL, NULL);
 			if (proptag != MAPI_E_RESERVED)
 				strm = e_mapi_util_find_stream (attach->streams, proptag);
 			if (!strm)
@@ -1603,7 +1612,14 @@ mapi_mime_message_to_mail_item (CamelMimeMessage *message, gint32 message_camel_
 }
 
 gboolean
-mapi_mail_utils_create_item_build_props (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, struct SPropValue **values, uint32_t *n_values, gpointer data)
+mapi_mail_utils_create_item_build_props (EMapiConnection *conn,
+					 mapi_id_t fid,
+					 TALLOC_CTX *mem_ctx,
+					 struct SPropValue **values,
+					 uint32_t *n_values,
+					 gpointer data,
+					 GCancellable *cancellable,
+					 GError **perror)
 {
 
 	MailItem *item = (MailItem *) data;
@@ -1621,7 +1637,7 @@ mapi_mail_utils_create_item_build_props (EMapiConnection *conn, mapi_id_t fid, T
 	}
 	
 	if (item->pid_name_content_type) {
-		if (!e_mapi_utils_add_spropvalue_namedid (conn, fid, mem_ctx, values, n_values, PidNameContentType, item->pid_name_content_type))
+		if (!e_mapi_utils_add_spropvalue_namedid (conn, fid, mem_ctx, values, n_values, PidNameContentType, item->pid_name_content_type, cancellable, perror))
 			return FALSE;
 	}
 
diff --git a/src/libexchangemapi/e-mapi-mail-utils.h b/src/libexchangemapi/e-mapi-mail-utils.h
index 8234afe..01c9cf7 100644
--- a/src/libexchangemapi/e-mapi-mail-utils.h
+++ b/src/libexchangemapi/e-mapi-mail-utils.h
@@ -82,19 +82,35 @@ typedef struct _MailItem {
 void mail_item_free (MailItem *item);
 
 /* fetch callback, the 'data' is pointer to a MailItem pointer, where new MailItem will be placed */
-gboolean fetch_props_to_mail_item_cb (FetchItemsCallbackData *item_data, gpointer data);
+gboolean fetch_props_to_mail_item_cb (FetchItemsCallbackData *item_data,
+				      gpointer data,
+				      GCancellable *cancellable,
+				      GError **perror);
 
 /* returns TRUE when filled an entry in the MailItem based on the propTag and its value */
 gboolean fetch_read_item_common_data (MailItem *item, uint32_t propTag, gconstpointer prop_data);
 
-gboolean mapi_mail_get_item_prop_list (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, struct SPropTagArray *props, gpointer data);
+gboolean mapi_mail_get_item_prop_list (EMapiConnection *conn,
+				       mapi_id_t fid,
+				       TALLOC_CTX *mem_ctx,
+				       struct SPropTagArray *props, gpointer data,
+				       GCancellable *cancellable,
+				       GError **perror);
 
 struct _CamelMimeMessage;
 struct _CamelMimeMessage *mapi_mail_item_to_mime_message (EMapiConnection *conn, MailItem *item);
 
 struct _CamelAddress;
 MailItem *mapi_mime_message_to_mail_item (struct _CamelMimeMessage *message, gint32 message_camel_flags, struct _CamelAddress *from, GCancellable *cancellable, GError **error);
+
 /* uses MailItem * as 'data' pointer */
-gboolean  mapi_mail_utils_create_item_build_props (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, struct SPropValue **values, uint32_t *n_values, gpointer data);
+gboolean  mapi_mail_utils_create_item_build_props (EMapiConnection *conn,
+						   mapi_id_t fid,
+						   TALLOC_CTX *mem_ctx,
+						   struct SPropValue **values,
+						   uint32_t *n_values,
+						   gpointer data,
+						   GCancellable *cancellable,
+						   GError **perror);
 
 #endif /* E_MAPI_MAIL_UTILS */
diff --git a/src/libexchangemapi/e-mapi-utils.c b/src/libexchangemapi/e-mapi-utils.c
index 69a1424..f974343 100644
--- a/src/libexchangemapi/e-mapi-utils.c
+++ b/src/libexchangemapi/e-mapi-utils.c
@@ -131,7 +131,7 @@ e_mapi_util_find_SPropVal_array_namedid (struct SPropValue *values, EMapiConnect
 	g_return_val_if_fail (values != NULL, NULL);
 	g_return_val_if_fail (conn != NULL, NULL);
 
-	proptag = e_mapi_connection_resolve_named_prop (conn, fid, namedid, NULL);
+	proptag = e_mapi_connection_resolve_named_prop (conn, fid, namedid, NULL, NULL);
 	if (proptag != MAPI_E_RESERVED)
 		res = e_mapi_util_find_SPropVal_array_propval (values, proptag);
 
@@ -190,7 +190,7 @@ e_mapi_util_find_row_namedid (struct SRow *aRow, EMapiConnection *conn, mapi_id_
 	g_return_val_if_fail (aRow != NULL, NULL);
 	g_return_val_if_fail (conn != NULL, NULL);
 
-	proptag = e_mapi_connection_resolve_named_prop (conn, fid, namedid, NULL);
+	proptag = e_mapi_connection_resolve_named_prop (conn, fid, namedid, NULL, NULL);
 	if (proptag != MAPI_E_RESERVED)
 		res = e_mapi_util_find_row_propval (aRow, proptag);
 
@@ -249,7 +249,7 @@ e_mapi_util_find_array_namedid (struct mapi_SPropValue_array *properties, EMapiC
 	g_return_val_if_fail (properties != NULL, NULL);
 	g_return_val_if_fail (conn != NULL, NULL);
 
-	proptag = e_mapi_connection_resolve_named_prop (conn, fid, namedid, NULL);
+	proptag = e_mapi_connection_resolve_named_prop (conn, fid, namedid, NULL, NULL);
 	if (proptag != MAPI_E_RESERVED)
 		res = e_mapi_util_find_array_propval (properties, proptag);
 
@@ -278,7 +278,7 @@ e_mapi_util_find_array_datetime_namedid (struct timeval *tv, struct mapi_SPropVa
 	g_return_val_if_fail (properties != NULL, MAPI_E_INVALID_PARAMETER);
 	g_return_val_if_fail (conn != NULL, MAPI_E_INVALID_PARAMETER);
 
-	proptag = e_mapi_connection_resolve_named_prop (conn, fid, namedid, NULL);
+	proptag = e_mapi_connection_resolve_named_prop (conn, fid, namedid, NULL, NULL);
 	if (proptag != MAPI_E_RESERVED)
 		res = e_mapi_util_find_array_datetime_propval (tv, properties, proptag);
 
@@ -313,7 +313,7 @@ e_mapi_util_find_stream_namedid (GSList *stream_list, EMapiConnection *conn, map
 	if (!stream_list)
 		return NULL;
 
-	proptag = e_mapi_connection_resolve_named_prop (conn, fid, namedid, NULL);
+	proptag = e_mapi_connection_resolve_named_prop (conn, fid, namedid, NULL, NULL);
 	if (proptag != MAPI_E_RESERVED)
 		res = e_mapi_util_find_stream (stream_list, proptag);
 
@@ -751,7 +751,7 @@ e_mapi_util_recip_entryid_decode (EMapiConnection *conn, const struct Binary_r *
 	}
 
 	if (recip_entryid_decode_ex (entryid, &exchange_dn)) {
-		*email = e_mapi_connection_ex_to_smtp (conn, exchange_dn, display_name, NULL);
+		*email = e_mapi_connection_ex_to_smtp (conn, exchange_dn, display_name, NULL, NULL);
 		g_free (exchange_dn);
 
 		return *email != NULL;
@@ -951,7 +951,10 @@ e_mapi_util_profile_name (const EMapiProfileData *empd, gboolean migrate)
  * Adds prop_ids to props array. props should be created within the given mem_ctx.
  **/
 gboolean
-e_mapi_utils_add_props_to_props_array (TALLOC_CTX *mem_ctx, struct SPropTagArray *props, const uint32_t *prop_ids, guint prop_ids_n_elems)
+e_mapi_utils_add_props_to_props_array (TALLOC_CTX *mem_ctx,
+				       struct SPropTagArray *props,
+				       const uint32_t *prop_ids,
+				       guint prop_ids_n_elems)
 {
 	guint i;
 
@@ -969,7 +972,14 @@ e_mapi_utils_add_props_to_props_array (TALLOC_CTX *mem_ctx, struct SPropTagArray
 
 /* Beware, the named_ids_list array is modified */
 gboolean
-e_mapi_utils_add_named_ids_to_props_array (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, struct SPropTagArray *props, ResolveNamedIDsData *named_ids_list, guint named_ids_n_elems)
+e_mapi_utils_add_named_ids_to_props_array (EMapiConnection *conn,
+					   mapi_id_t fid,
+					   TALLOC_CTX *mem_ctx,
+					   struct SPropTagArray *props,
+					   ResolveNamedIDsData *named_ids_list,
+					   guint named_ids_n_elems,
+					   GCancellable *cancellable,
+					   GError **perror)
 {
 	guint i;
 
@@ -980,7 +990,7 @@ e_mapi_utils_add_named_ids_to_props_array (EMapiConnection *conn, mapi_id_t fid,
 	g_return_val_if_fail (named_ids_list != NULL, FALSE);
 	g_return_val_if_fail (named_ids_n_elems > 0, FALSE);
 
-	if (!e_mapi_connection_resolve_named_props (conn, fid, named_ids_list, named_ids_n_elems, NULL))
+	if (!e_mapi_connection_resolve_named_props (conn, fid, named_ids_list, named_ids_n_elems, cancellable, perror))
 		return FALSE;
 
 	for (i = 0; i < named_ids_n_elems; i++) {
@@ -996,7 +1006,11 @@ e_mapi_utils_add_named_ids_to_props_array (EMapiConnection *conn, mapi_id_t fid,
  * *n_values holds number of items stored in the array, and will be increased by one.
  **/
 gboolean
-e_mapi_utils_add_spropvalue (TALLOC_CTX *mem_ctx, struct SPropValue **values_array, uint32_t *n_values, uint32_t prop_tag, gconstpointer prop_value)
+e_mapi_utils_add_spropvalue (TALLOC_CTX *mem_ctx,
+			     struct SPropValue **values_array,
+			     uint32_t *n_values,
+			     uint32_t prop_tag,
+			     gconstpointer prop_value)
 {
 	g_return_val_if_fail (mem_ctx != NULL, FALSE);
 	g_return_val_if_fail (values_array != NULL, FALSE);
@@ -1009,7 +1023,15 @@ e_mapi_utils_add_spropvalue (TALLOC_CTX *mem_ctx, struct SPropValue **values_arr
 
 /* similar as e_mapi_utils_add_spropvalue, just here is not used prop_tag, but named id */
 gboolean
-e_mapi_utils_add_spropvalue_namedid (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, struct SPropValue **values_array, uint32_t *n_values, uint32_t named_id, gconstpointer prop_value)
+e_mapi_utils_add_spropvalue_namedid (EMapiConnection *conn,
+				     mapi_id_t fid,
+				     TALLOC_CTX *mem_ctx,
+				     struct SPropValue **values_array,
+				     uint32_t *n_values,
+				     uint32_t named_id,
+				     gconstpointer prop_value,
+				     GCancellable *cancellable,
+				     GError **perror)
 {
 	uint32_t prop_tag;
 
@@ -1019,7 +1041,7 @@ e_mapi_utils_add_spropvalue_namedid (EMapiConnection *conn, mapi_id_t fid, TALLO
 	g_return_val_if_fail (values_array != NULL, FALSE);
 	g_return_val_if_fail (n_values != NULL, FALSE);
 
-	prop_tag = e_mapi_connection_resolve_named_prop (conn, fid, named_id, NULL);
+	prop_tag = e_mapi_connection_resolve_named_prop (conn, fid, named_id, cancellable, perror);
 	if (prop_tag == MAPI_E_RESERVED)
 		return FALSE;
 
diff --git a/src/libexchangemapi/e-mapi-utils.h b/src/libexchangemapi/e-mapi-utils.h
index 8a914b2..01c39ef 100644
--- a/src/libexchangemapi/e-mapi-utils.h
+++ b/src/libexchangemapi/e-mapi-utils.h
@@ -62,11 +62,33 @@ void e_mapi_util_profiledata_from_settings (EMapiProfileData *empd, CamelMapiSet
 gchar *e_mapi_util_profile_name (const EMapiProfileData *empd, gboolean migrate);
 gboolean e_mapi_util_trigger_krb_auth (const EMapiProfileData *empd, GError **error);
 
-gboolean e_mapi_utils_add_props_to_props_array (TALLOC_CTX *mem_ctx, struct SPropTagArray *props, const uint32_t *prop_ids, guint prop_ids_n_elems);
-gboolean e_mapi_utils_add_named_ids_to_props_array (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, struct SPropTagArray *props, ResolveNamedIDsData *named_ids_list, guint named_ids_n_elems);
-
-gboolean e_mapi_utils_add_spropvalue (TALLOC_CTX *mem_ctx, struct SPropValue **values_array, uint32_t *n_values, uint32_t prop_tag, gconstpointer prop_value);
-gboolean e_mapi_utils_add_spropvalue_namedid (EMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, struct SPropValue **values_array, uint32_t *n_values, uint32_t named_id, gconstpointer prop_value);
+gboolean	e_mapi_utils_add_props_to_props_array		(TALLOC_CTX *mem_ctx,
+								 struct SPropTagArray *props,
+								 const uint32_t *prop_ids,
+								 guint prop_ids_n_elems);
+gboolean	e_mapi_utils_add_named_ids_to_props_array	(EMapiConnection *conn,
+								 mapi_id_t fid,
+								 TALLOC_CTX *mem_ctx,
+								 struct SPropTagArray *props,
+								 ResolveNamedIDsData *named_ids_list,
+								 guint named_ids_n_elems,
+								 GCancellable *cancellable,
+								 GError **perror);
+
+gboolean	e_mapi_utils_add_spropvalue			(TALLOC_CTX *mem_ctx,
+								 struct SPropValue **values_array,
+								 uint32_t *n_values,
+								 uint32_t prop_tag,
+								 gconstpointer prop_value);
+gboolean	e_mapi_utils_add_spropvalue_namedid		(EMapiConnection *conn,
+								 mapi_id_t fid,
+								 TALLOC_CTX *mem_ctx,
+								 struct SPropValue **values_array,
+								 uint32_t *n_values,
+								 uint32_t named_id,
+								 gconstpointer prop_value,
+								 GCancellable *cancellable,
+								 GError **perror);
 
 uint32_t e_mapi_utils_push_crc32 (uint32_t crc32, uint8_t *bytes, uint32_t n_bytes);
 



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