[evolution-mapi] Bug #622695 - Report more detailed errors from operations



commit e87d1eea4bd1a31dbf08c37c4264c91292152400
Author: Milan Crha <mcrha redhat com>
Date:   Mon Jul 12 15:17:36 2010 +0200

    Bug #622695 - Report more detailed errors from operations

 .../exchange-mapi-account-listener.c               |   21 +-
 .../exchange-mapi-account-setup.c                  |   44 +-
 src/addressbook/e-book-backend-mapi-gal.c          |   39 +-
 src/addressbook/e-book-backend-mapi-utils.c        |   33 +-
 src/addressbook/e-book-backend-mapi-utils.h        |    3 +
 src/addressbook/e-book-backend-mapi.c              |  133 ++-
 src/calendar/e-cal-backend-mapi.c                  |  199 +++-
 src/camel/camel-mapi-folder.c                      |  129 ++-
 src/camel/camel-mapi-folder.h                      |    2 +-
 src/camel/camel-mapi-notifications.c               |    8 +-
 src/camel/camel-mapi-store.c                       |  101 ++-
 src/camel/camel-mapi-transport.c                   |   22 +-
 src/libexchangemapi/exchange-mapi-cal-utils.c      |   52 +-
 src/libexchangemapi/exchange-mapi-cal-utils.h      |    2 +-
 src/libexchangemapi/exchange-mapi-connection.c     | 1368 +++++++++++---------
 src/libexchangemapi/exchange-mapi-connection.h     |   69 +-
 src/libexchangemapi/exchange-mapi-mail-utils.c     |    9 +-
 src/libexchangemapi/exchange-mapi-utils.c          |   10 +-
 18 files changed, 1401 insertions(+), 843 deletions(-)
---
diff --git a/src/account-setup-eplugin/exchange-mapi-account-listener.c b/src/account-setup-eplugin/exchange-mapi-account-listener.c
index 0066f81..9ce653d 100644
--- a/src/account-setup-eplugin/exchange-mapi-account-listener.c
+++ b/src/account-setup-eplugin/exchange-mapi-account-listener.c
@@ -783,7 +783,7 @@ update_sources_idle_cb (gpointer data)
 	folders_list = exchange_mapi_connection_peek_folders_list (conn);
 
 	if (account->enabled && lookup_account_info (account->uid)) {
-		mapi_id_t trash_fid = exchange_mapi_connection_get_default_folder_id (conn, olFolderDeletedItems);
+		mapi_id_t trash_fid = exchange_mapi_connection_get_default_folder_id (conn, olFolderDeletedItems, NULL);
 
 		add_addressbook_sources (account, folders_list, trash_fid);
 		add_calendar_sources (account, folders_list, trash_fid);
@@ -949,10 +949,17 @@ mapi_account_removed (EAccountList *account_listener, EAccount *account)
 	if (url != NULL) {
 		const gchar *profile = camel_url_get_param (url, "profile");
 		gchar *key = camel_url_to_string (url, CAMEL_URL_HIDE_PASSWORD | CAMEL_URL_HIDE_PARAMS);
-		exchange_mapi_delete_profile (profile);
+		GError *error = NULL;
+
+		exchange_mapi_delete_profile (profile, &error);
 		e_passwords_forget_password (EXCHANGE_MAPI_PASSWORD_COMPONENT, key);
+
 		g_free (key);
 		camel_url_free (url);
+		if (error) {
+			g_warning ("%s: Failed to delete profile: %s", G_STRFUNC, error->message);
+			g_error_free (error);
+		}
 	}
 
 	/* Free up the structure */
@@ -986,9 +993,10 @@ create_profile_entry (CamelURL *url, EAccount *account)
 		g_free (key);
 
 		if (password) {
+			GError *error = NULL;
 			guint32 cp_flags = (camel_url_get_param (url, "ssl") && g_str_equal (camel_url_get_param (url, "ssl"), "1")) ? CREATE_PROFILE_FLAG_USE_SSL : CREATE_PROFILE_FLAG_NONE;
 
-			status = exchange_mapi_create_profile (url->user, password, camel_url_get_param (url, "domain"), url->host, cp_flags, NULL, NULL, NULL);
+			status = exchange_mapi_create_profile (url->user, password, camel_url_get_param (url, "domain"), url->host, cp_flags, NULL, NULL, &error);
 			if (status) {
 				/* profile was created, try to connect to the server */
 				ExchangeMapiConnection *conn;
@@ -997,7 +1005,7 @@ create_profile_entry (CamelURL *url, EAccount *account)
 				status = FALSE;
 				profname = exchange_mapi_util_profile_name (url->user, camel_url_get_param (url, "domain"), url->host, FALSE);
 
-				conn = exchange_mapi_connection_new (profname, password);
+				conn = exchange_mapi_connection_new (profname, password, &error);
 				if (conn) {
 					status = exchange_mapi_connection_connected (conn);
 					g_object_unref (conn);
@@ -1005,6 +1013,11 @@ create_profile_entry (CamelURL *url, EAccount *account)
 
 				g_free (profname);
 			}
+
+			if (error) {
+				g_warning ("%s: Failed to create profile: %s", G_STRFUNC, error->message);
+				g_error_free (error);
+			}
 		}
 
 		++attempts;
diff --git a/src/account-setup-eplugin/exchange-mapi-account-setup.c b/src/account-setup-eplugin/exchange-mapi-account-setup.c
index 7df3dd8..1571d43 100644
--- a/src/account-setup-eplugin/exchange-mapi-account-setup.c
+++ b/src/account-setup-eplugin/exchange-mapi-account-setup.c
@@ -236,10 +236,10 @@ validate_credentials (GtkWidget *widget, EConfig *config)
 	/*Can there be a account without password ?*/
 	if (password && *password && domain_name && *domain_name && *url->user && *url->host) {
 		guint32 cp_flags = (camel_url_get_param (url, "ssl") && g_str_equal (camel_url_get_param (url, "ssl"), "1")) ? CREATE_PROFILE_FLAG_USE_SSL : CREATE_PROFILE_FLAG_NONE;
-		gchar *error_msg = NULL;
-		gboolean status = exchange_mapi_create_profile (url->user, password, domain_name,
-								url->host, cp_flags, &error_msg,
-								(mapi_profile_callback_t) create_profile_callback, url->user);
+		GError *error = NULL;
+		gboolean status = exchange_mapi_create_profile (url->user, password, domain_name, url->host, cp_flags,
+								(mapi_profile_callback_t) create_profile_callback, url->user,
+								&error);
 		if (status) {
 			/* profile was created, try to connect to the server */
 			ExchangeMapiConnection *conn;
@@ -248,7 +248,7 @@ validate_credentials (GtkWidget *widget, EConfig *config)
 			status = FALSE;
 			profname = exchange_mapi_util_profile_name (url->user, domain_name, url->host, FALSE);
 
-			conn = exchange_mapi_connection_new (profname, password);
+			conn = exchange_mapi_connection_new (profname, password, &error);
 			if (conn) {
 				status = exchange_mapi_connection_connected (conn);
 				g_object_unref (conn);
@@ -276,14 +276,15 @@ validate_credentials (GtkWidget *widget, EConfig *config)
 
 			e_passwords_forget_password (EXCHANGE_MAPI_PASSWORD_COMPONENT, key);
 
-			e = g_strconcat (_("Authentication failed."), "\n", error_msg, NULL);
+			e = g_strconcat (_("Authentication failed."), "\n", error ? error->message : NULL, NULL);
 
 			e_notice (NULL, GTK_MESSAGE_ERROR, "%s", e);
 
 			g_free (e);
 		}
 
-		g_free (error_msg);
+		if (error)
+			g_error_free (error);
 	} else {
 		e_passwords_forget_password (EXCHANGE_MAPI_PASSWORD_COMPONENT, key);
 		e_notice (NULL, GTK_MESSAGE_ERROR, "%s", _("Authentication failed."));
@@ -754,6 +755,8 @@ exchange_mapi_book_commit (EPlugin *epl, EConfigTarget *target)
 	ESourceGroup *grp;
 	ExchangeMapiConnection *conn;
 	mapi_id_t fid, pfid;
+	GError *mapi_error = NULL;
+
 	uri_text = e_source_get_uri (source);
 	if (uri_text && g_ascii_strncasecmp (uri_text, MAPI_URI_PREFIX, MAPI_PREFIX_LENGTH))
 		return;
@@ -764,9 +767,20 @@ exchange_mapi_book_commit (EPlugin *epl, EConfigTarget *target)
 	conn = exchange_mapi_connection_find (e_source_get_property (source, "profile"));
 	g_return_if_fail (conn != NULL);
 
-	fid = exchange_mapi_connection_create_folder (conn, olFolderContacts, pfid, 0, e_source_peek_name (source));
+	fid = exchange_mapi_connection_create_folder (conn, olFolderContacts, pfid, 0, e_source_peek_name (source), &mapi_error);
 	g_object_unref (conn);
 
+	if (!fid) {
+		if (mapi_error) {
+			e_notice (NULL, GTK_MESSAGE_ERROR, _("Failed to create address book '%s': %s"), e_source_peek_name (source), mapi_error->message);
+			g_error_free (mapi_error);
+		} else {
+			e_notice (NULL, GTK_MESSAGE_ERROR, _("Failed to create address book '%s'"), e_source_peek_name (source));
+		}
+
+		return;
+	}
+
 	sfid = exchange_mapi_util_mapi_id_to_string (fid);
 	r_uri = g_strconcat (";", sfid, NULL);
 	e_source_set_relative_uri (source, r_uri);
@@ -831,6 +845,7 @@ exchange_mapi_cal_commit (EPlugin *epl, EConfigTarget *target)
 	mapi_id_t fid, pfid;
 	uint32_t type;
 	gchar *uri_text = e_source_get_uri (source);
+	GError *mapi_error = NULL;
 
 	if (!uri_text || g_ascii_strncasecmp (uri_text, MAPI_URI_PREFIX, MAPI_PREFIX_LENGTH))
 		return;
@@ -859,9 +874,20 @@ exchange_mapi_cal_commit (EPlugin *epl, EConfigTarget *target)
 	conn = exchange_mapi_connection_find (e_source_get_property (source, "profile"));
 	g_return_if_fail (conn != NULL);
 
-	fid = exchange_mapi_connection_create_folder (conn, type, pfid, 0, e_source_peek_name (source));
+	fid = exchange_mapi_connection_create_folder (conn, type, pfid, 0, e_source_peek_name (source), &mapi_error);
 	g_object_unref (conn);
 
+	if (!fid) {
+		if (mapi_error) {
+			e_notice (NULL, GTK_MESSAGE_ERROR, _("Failed to create calendar '%s': %s"), e_source_peek_name (source), mapi_error->message);
+			g_error_free (mapi_error);
+		} else {
+			e_notice (NULL, GTK_MESSAGE_ERROR, _("Failed to create calendar '%s'"), e_source_peek_name (source));
+		}
+
+		return;
+	}
+
 	sfid = exchange_mapi_util_mapi_id_to_string (fid);
 	tmp = g_strconcat (";", sfid, NULL);
 	e_source_set_relative_uri (source, tmp);
diff --git a/src/addressbook/e-book-backend-mapi-gal.c b/src/addressbook/e-book-backend-mapi-gal.c
index cdd0c3b..b514e4d 100644
--- a/src/addressbook/e-book-backend-mapi-gal.c
+++ b/src/addressbook/e-book-backend-mapi-gal.c
@@ -187,6 +187,7 @@ static gpointer
 build_cache (EBookBackendMAPIGAL *ebmapi)
 {
 	EBookBackendMAPIGALPrivate *priv = ebmapi->priv;
+	GError *mapi_error = NULL;
 	gchar *tmp;
 	struct fetch_gal_data fgd = { 0 };
 
@@ -198,17 +199,27 @@ build_cache (EBookBackendMAPIGAL *ebmapi)
 
 	fgd.ebmapi = ebmapi;
 	fgd.book_view = find_book_view (ebmapi);
-	fgd.fid = exchange_mapi_connection_get_default_folder_id (priv->conn, olFolderContacts);
+	fgd.fid = exchange_mapi_connection_get_default_folder_id (priv->conn, olFolderContacts, NULL);
 	fgd.last_update = current_time_ms ();
 
 	e_file_cache_freeze_changes (E_FILE_CACHE (priv->cache));
 	exchange_mapi_connection_fetch_gal (priv->conn,
 					mapi_book_utils_get_prop_list, GET_ALL_KNOWN_IDS,
-					fetch_gal_cb, &fgd);
+					fetch_gal_cb, &fgd, &mapi_error);
 
 	if (fgd.book_view) {
-		e_data_book_view_notify_complete (fgd.book_view, NULL /* Success */);
+		GError *error = NULL;
+
+		if (mapi_error) {
+			mapi_error_to_edb_error (&error, mapi_error, E_DATA_BOOK_STATUS_OTHER_ERROR, _("Failed to fetch GAL entries"));
+			g_error_free (mapi_error);
+		}
+
+		e_data_book_view_notify_complete (fgd.book_view, error);
 		e_data_book_view_unref (fgd.book_view);
+
+		if (error)
+			g_error_free (error);
 	}
 
 	tmp = g_strdup_printf("%d", priv->kill_cache_build ? 0 : (gint)time (NULL));
@@ -267,6 +278,7 @@ e_book_backend_mapi_gal_authenticate_user (EBookBackend *backend,
 {
 	EBookBackendMAPIGAL *ebmapi = (EBookBackendMAPIGAL *) backend;
 	EBookBackendMAPIGALPrivate *priv = ebmapi->priv;
+	GError *mapi_error = NULL;
 
 	if (enable_debug) {
 		printf ("mapi: authenticate user\n");
@@ -286,13 +298,24 @@ e_book_backend_mapi_gal_authenticate_user (EBookBackend *backend,
 		/* rather reuse already established connection */
 		priv->conn = exchange_mapi_connection_find (priv->profile);
 		if (priv->conn && !exchange_mapi_connection_connected (priv->conn))
-			exchange_mapi_connection_reconnect (priv->conn, passwd);
+			exchange_mapi_connection_reconnect (priv->conn, passwd, &mapi_error);
 		else if (!priv->conn)
-			priv->conn = exchange_mapi_connection_new (priv->profile, passwd);
+			priv->conn = exchange_mapi_connection_new (priv->profile, passwd, &mapi_error);
 
-		if (!priv->conn) {
-			e_data_book_respond_authenticate_user (book, opid, EDB_ERROR_EX (OTHER_ERROR, "Cannot connect"));
+		if (!priv->conn || mapi_error) {
+			GError *err = NULL;
+
+			if (priv->conn) {
+				g_object_unref (priv->conn);
+				priv->conn = NULL;
+			}
+				
+			mapi_error_to_edb_error (&err, mapi_error, E_DATA_BOOK_STATUS_OTHER_ERROR, _("Cannot connect"));
+			e_data_book_respond_authenticate_user (book, opid, err);
 			g_static_mutex_unlock (&priv->running_mutex);
+
+			if (mapi_error)
+				g_error_free (mapi_error);
 			return;
 		}
 
diff --git a/src/addressbook/e-book-backend-mapi-utils.c b/src/addressbook/e-book-backend-mapi-utils.c
index 311aa08..6585ccc 100644
--- a/src/addressbook/e-book-backend-mapi-utils.c
+++ b/src/addressbook/e-book-backend-mapi-utils.c
@@ -30,6 +30,7 @@
 #include <string.h>
 #include <glib.h>
 #include <glib/gstdio.h>
+#include <glib/gi18n-lib.h>
 
 #include <libebook/e-contact.h>
 #include <camel/camel.h>
@@ -218,7 +219,7 @@ mapi_book_utils_get_prop_list (ExchangeMapiConnection *conn, mapi_id_t fid, TALL
 
 	/* called with fid = 0 from GAL */
 	if (!fid)
-		fid = exchange_mapi_connection_get_default_folder_id (conn, olFolderContacts);
+		fid = exchange_mapi_connection_get_default_folder_id (conn, olFolderContacts, NULL);
 
 	return exchange_mapi_utils_add_named_ids_to_props_array (conn, fid, mem_ctx, props, nids, G_N_ELEMENTS (nids));
 }
@@ -432,3 +433,33 @@ mapi_book_utils_contact_from_props (ExchangeMapiConnection *conn, mapi_id_t fid,
 
 	return contact;
 }
+
+void
+mapi_error_to_edb_error (GError **perror, const GError *mapi_error, EDataBookStatus code, const gchar *context)
+{
+	gchar *err_msg = NULL;
+
+	if (!perror)
+		return;
+
+	if (code == E_DATA_BOOK_STATUS_OTHER_ERROR && mapi_error) {
+		/* Change error to more accurate only with OTHER_ERROR */
+		switch (mapi_error->code) {
+		case MAPI_E_PASSWORD_CHANGE_REQUIRED:
+		case MAPI_E_PASSWORD_EXPIRED:
+			code = E_DATA_BOOK_STATUS_AUTHENTICATION_REQUIRED;
+			break;
+		default:
+			break;
+		}
+	}
+
+	if (context)
+		err_msg = g_strconcat (context, mapi_error ? ": " : NULL, mapi_error ? mapi_error->message : NULL, NULL);
+	else if (!mapi_error)
+		err_msg = g_strdup (_("Uknown error"));
+
+	g_propagate_error (perror, e_data_book_create_error (code, err_msg ? err_msg : mapi_error->message));
+
+	g_free (err_msg);
+}
diff --git a/src/addressbook/e-book-backend-mapi-utils.h b/src/addressbook/e-book-backend-mapi-utils.h
index eb02462..2d32454 100644
--- a/src/addressbook/e-book-backend-mapi-utils.h
+++ b/src/addressbook/e-book-backend-mapi-utils.h
@@ -21,11 +21,14 @@
 #ifndef __E_BOOK_BACKEND_MAPI_UTILS_H__
 #define __E_BOOK_BACKEND_MAPI_UTILS_H__
 
+#include <libedata-book/e-data-book.h>
 #include "exchange-mapi-connection.h"
 
 #define EDB_ERROR(_code) e_data_book_create_error (E_DATA_BOOK_STATUS_ ## _code, NULL)
 #define EDB_ERROR_EX(_code, _msg) e_data_book_create_error (E_DATA_BOOK_STATUS_ ## _code, _msg)
 
+void mapi_error_to_edb_error (GError **perror, const GError *mapi_error, EDataBookStatus code, const gchar *context);
+
 /* vCard parameter name in contact list */
 #define EMA_X_MEMBERID "X-EMA-MEMBER-ID"
 #define EMA_X_MEMBERVALUE "X-EMA-MEMBER-VALUE"
diff --git a/src/addressbook/e-book-backend-mapi.c b/src/addressbook/e-book-backend-mapi.c
index 385d7ef..582a269 100644
--- a/src/addressbook/e-book-backend-mapi.c
+++ b/src/addressbook/e-book-backend-mapi.c
@@ -30,6 +30,7 @@
 #include <string.h>
 #include <glib.h>
 #include <glib/gstdio.h>
+#include <glib/gi18n-lib.h>
 
 #include <sys/time.h>
 /*
@@ -199,17 +200,17 @@ build_multiple_restriction_emails_contains (ExchangeMapiConnection *conn, mapi_i
 
 	or_res[3].rt = RES_CONTENT;
 	or_res[3].res.resContent.fuzzy = FL_FULLSTRING | FL_IGNORECASE;
-	or_res[3].res.resContent.ulPropTag = exchange_mapi_connection_resolve_named_prop (conn, fid, PidLidEmail1OriginalDisplayName);
+	or_res[3].res.resContent.ulPropTag = exchange_mapi_connection_resolve_named_prop (conn, fid, PidLidEmail1OriginalDisplayName, 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 = exchange_mapi_connection_resolve_named_prop (conn, fid, PidLidEmail2OriginalDisplayName);
+	or_res[4].res.resContent.ulPropTag = exchange_mapi_connection_resolve_named_prop (conn, fid, PidLidEmail2OriginalDisplayName, 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 = exchange_mapi_connection_resolve_named_prop (conn, fid, PidLidEmail3OriginalDisplayName);
+	or_res[5].res.resContent.ulPropTag = exchange_mapi_connection_resolve_named_prop (conn, fid, PidLidEmail3OriginalDisplayName, NULL);
 	or_res[5].res.resContent.lpProp.value.lpszA = email;
 
 	res = g_new0 (struct mapi_SRestriction, 1);
@@ -452,7 +453,7 @@ mapi_book_write_props (ExchangeMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *
 	g_return_val_if_fail (values != NULL, FALSE);
 	g_return_val_if_fail (n_values != NULL, FALSE);
 
-	if (!exchange_mapi_connection_resolve_named_props (conn, fid, nids, G_N_ELEMENTS (nids)))
+	if (!exchange_mapi_connection_resolve_named_props (conn, fid, nids, G_N_ELEMENTS (nids), NULL))
 		return FALSE;
 
 	if (GPOINTER_TO_INT (e_contact_get (mcd->contact, E_CONTACT_IS_LIST))) {
@@ -701,6 +702,7 @@ e_book_backend_mapi_create_contact (EBookBackend *backend,
 	mapi_id_t status;
 	MapiCreateitemData mcd;
 	EBookBackendMAPIPrivate *priv = ((EBookBackendMAPI *) backend)->priv;
+	GError *mapi_error = NULL;
 
 	if (enable_debug)
 		printf("mapi create_contact \n");
@@ -717,9 +719,16 @@ e_book_backend_mapi_create_contact (EBookBackend *backend,
 		mcd.cache = priv->cache;
 		status = exchange_mapi_connection_create_item (priv->conn, olFolderContacts, priv->fid,
 				mapi_book_write_props, &mcd,
-				NULL, NULL, NULL, 0);
+				NULL, NULL, NULL, 0, &mapi_error);
 		if (!status) {
-			e_data_book_respond_create(book, opid, EDB_ERROR (OTHER_ERROR), NULL);
+			GError *error = NULL;
+
+			mapi_error_to_edb_error (&error, mapi_error, E_DATA_BOOK_STATUS_OTHER_ERROR, _("Failed to create item on a server"));
+
+			e_data_book_respond_create (book, opid, error, NULL);
+
+			if (mapi_error)
+				g_error_free (mapi_error);
 			return;
 		}
 		id = exchange_mapi_util_mapi_ids_to_uid (priv->fid, status);
@@ -751,6 +760,7 @@ e_book_backend_mapi_remove_contacts (EBookBackend *backend,
 	GList *tmp = id_list;
 	EBookBackendMAPIPrivate *priv = ((EBookBackendMAPI *) backend)->priv;
 	mapi_id_t fid, mid;
+	GError *err = NULL;
 
 	if (enable_debug)
 		printf("mapi: remove_contacts\n");
@@ -770,7 +780,7 @@ e_book_backend_mapi_remove_contacts (EBookBackend *backend,
 			tmp = tmp->next;
 		}
 
-		exchange_mapi_connection_remove_items (priv->conn, olFolderContacts, priv->fid, 0, list);
+		exchange_mapi_connection_remove_items (priv->conn, olFolderContacts, priv->fid, 0, list, &err);
 		if (priv->marked_for_offline && priv->is_cache_ready) {
 			tmp = id_list;
 			while (tmp) {
@@ -788,7 +798,17 @@ e_book_backend_mapi_remove_contacts (EBookBackend *backend,
 		}
 
 		g_slist_free (list);
-		e_data_book_respond_remove_contacts (book, opid, NULL /* Success */, id_list);
+
+		if (err) {
+			GError *mapi_err = err;
+
+			err = NULL;
+			mapi_error_to_edb_error (&err, mapi_err, E_DATA_BOOK_STATUS_OTHER_ERROR, NULL);
+
+			g_error_free (mapi_err);
+		}
+
+		e_data_book_respond_remove_contacts (book, opid, err, id_list);
 		break;
 	default:
 		break;
@@ -807,6 +827,7 @@ e_book_backend_mapi_modify_contact (EBookBackend *backend,
 	mapi_id_t fid, mid;
 	gboolean status;
 	gchar *tmp;
+	GError *mapi_error = NULL;
 
 	if (enable_debug)
 		printf("mapi: modify_contacts\n");
@@ -826,10 +847,15 @@ e_book_backend_mapi_modify_contact (EBookBackend *backend,
 		mcd.cache = priv->cache;
 		status = exchange_mapi_connection_modify_item (priv->conn, olFolderContacts, priv->fid, mid,
 				mapi_book_write_props, &mcd,
-				NULL, NULL, NULL, 0);
+				NULL, NULL, NULL, 0, &mapi_error);
 		printf("getting %d\n", status);
 		if (!status) {
-			e_data_book_respond_modify (book, opid, EDB_ERROR (OTHER_ERROR), NULL);
+			GError *perror = NULL;
+
+			mapi_error_to_edb_error (&perror, mapi_error, E_DATA_BOOK_STATUS_OTHER_ERROR, _("Failed to modify item on a server"));
+			e_data_book_respond_modify (book, opid, perror, NULL);
+			if (mapi_error)
+				g_error_free (mapi_error);
 			break;
 		}
 
@@ -891,7 +917,7 @@ e_book_backend_mapi_get_contact (EBookBackend *backend,
 		options |= MAPI_OPTIONS_USE_PFSTORE;
 		is_public = TRUE;
 	}
- 
+
 	if (enable_debug)
 		printf("mapi: get_contact %s\n", id);
 
@@ -939,12 +965,13 @@ e_book_backend_mapi_get_contact (EBookBackend *backend,
 
 		} else {
 			mapi_id_t fid, mid;
+			GError *mapi_error = NULL;
 
 			exchange_mapi_util_mapi_ids_from_uid (id, &fid, &mid);
 			exchange_mapi_connection_fetch_item (priv->conn, priv->fid, mid,
 							is_public ? NULL : mapi_book_utils_get_prop_list, GET_ALL_KNOWN_IDS,
 							create_contact_item, contact,
-							options);
+							options, &mapi_error);
 
 			if (contact) {
 				e_contact_set (contact, E_CONTACT_BOOK_URI, priv->uri);
@@ -959,7 +986,19 @@ e_book_backend_mapi_get_contact (EBookBackend *backend,
 				return;
 
 			} else {
-				e_data_book_respond_get_contact (book, opid, EDB_ERROR (CONTACT_NOT_FOUND), "");
+				GError *err = NULL;
+
+				if (!mapi_error || mapi_error->code == MAPI_E_NOT_FOUND) {
+					err = EDB_ERROR (CONTACT_NOT_FOUND);
+				} else {
+					mapi_error_to_edb_error (&err, mapi_error, E_DATA_BOOK_STATUS_CONTACT_NOT_FOUND, NULL);
+				}
+
+				e_data_book_respond_get_contact (book, opid, err, "");
+
+				if (mapi_error)
+					g_error_free (mapi_error);
+
 				return;
 			}
 		}
@@ -1064,6 +1103,7 @@ e_book_backend_mapi_get_contact_list (EBookBackend *backend,
 			return;
 		}
 		else {
+			GError *mapi_error = NULL;
 			struct mapi_SRestriction res;
 			GList *vcard_str = NULL;
 			gboolean no_summary_search = g_ascii_strcasecmp (query, "(contains \"x-evolution-any-field\" \"\")") == 0;
@@ -1079,8 +1119,15 @@ e_book_backend_mapi_get_contact_list (EBookBackend *backend,
 			if (!exchange_mapi_connection_fetch_items (priv->conn, priv->fid, no_summary_search ? NULL : &res, NULL,
 								is_public ? NULL : mapi_book_utils_get_prop_list, GET_ALL_KNOWN_IDS,
 								create_contact_list_cb, &vcard_str,
-								options)) {
-				e_data_book_respond_get_contact_list (book, opid, EDB_ERROR (OTHER_ERROR), NULL);
+								options, &mapi_error)) {
+				GError *err = NULL;
+
+				mapi_error_to_edb_error (&err, mapi_error, E_DATA_BOOK_STATUS_OTHER_ERROR, _("Failed to fetch items from a server"));
+				e_data_book_respond_get_contact_list (book, opid, err, NULL);
+
+				if (mapi_error)
+					g_error_free (mapi_error);
+
 				return;
 			}
 			printf("get_contact_list in %s returning %d contacts\n", priv->uri, g_list_length (vcard_str));
@@ -1220,6 +1267,7 @@ book_view_thread (gpointer data)
 	guint32 options = MAPI_OPTIONS_FETCH_ALL; 
 	gboolean is_public = FALSE;
 	GError *err = NULL;
+	GError *mapi_error = NULL;
 
 	source = e_book_backend_get_source(E_BOOK_BACKEND(backend));
 	if (strcmp (e_source_get_property(source, "public"), "yes") == 0 ) {
@@ -1362,11 +1410,14 @@ book_view_thread (gpointer data)
 			if (!exchange_mapi_connection_fetch_items (priv->conn, priv->fid, &res, NULL,
 							   is_public ? NULL : mapi_book_utils_get_prop_list, GET_SHORT_SUMMARY,
 							   create_contact_cb, closure,
-							   options)) {
-				err = EDB_ERROR (OTHER_ERROR);
+							   options, &mapi_error)) {
+				mapi_error_to_edb_error (&err, mapi_error, E_DATA_BOOK_STATUS_OTHER_ERROR, _("Failed to fetch items from a server"));
 				e_data_book_view_notify_complete (book_view, err);
 				g_error_free (err);
 
+				if (mapi_error)
+					g_error_free (mapi_error);
+
 				if (or_res)
 					g_free(or_res);
 				g_free (to_free);
@@ -1381,10 +1432,14 @@ book_view_thread (gpointer data)
 			if (!exchange_mapi_connection_fetch_items (priv->conn, priv->fid, NULL, NULL,
 							is_public ? NULL : mapi_book_utils_get_prop_list, GET_ALL_KNOWN_IDS,
 							create_contact_cb, closure,
-							options)) {
-				err = EDB_ERROR (OTHER_ERROR);
+							options, &mapi_error)) {
+				mapi_error_to_edb_error (&err, mapi_error, E_DATA_BOOK_STATUS_OTHER_ERROR, _("Failed to fetch items from a server"));
 				e_data_book_view_notify_complete (book_view, err);
 				g_error_free (err);
+
+				if (mapi_error)
+					g_error_free (mapi_error);
+
 				untrack_book_view (backend, book_view);
 				destroy_closure (closure);
 				return;
@@ -1488,7 +1543,7 @@ build_cache (EBookBackendMAPI *ebmapi)
 	if (!exchange_mapi_connection_fetch_items (priv->conn, priv->fid, NULL, NULL,
 						is_public ? NULL : mapi_book_utils_get_prop_list, GET_ALL_KNOWN_IDS,
 						cache_contact_cb, ebmapi,
-						options)) {
+						options, NULL)) {
 		printf("Error during caching addressbook\n");
 		e_file_cache_thaw_changes (E_FILE_CACHE (priv->cache));
 		return NULL;
@@ -1532,7 +1587,7 @@ update_cache (EBookBackendMAPI *ebmapi)
 	if (!exchange_mapi_connection_fetch_items (priv->conn, priv->fid, &res, NULL,
 						mapi_book_utils_get_prop_list, GET_ALL_KNOWN_IDS,
 						cache_contact_cb, ebmapi,
-						MAPI_OPTIONS_FETCH_ALL)) {
+						MAPI_OPTIONS_FETCH_ALL, NULL)) {
 		printf("Error during caching addressbook\n");
 		e_file_cache_thaw_changes (E_FILE_CACHE (priv->cache));
 		return NULL;
@@ -1556,6 +1611,7 @@ e_book_backend_mapi_authenticate_user (EBookBackend *backend,
 					    const gchar *auth_method)
 {
 	EBookBackendMAPIPrivate *priv = ((EBookBackendMAPI *) backend)->priv;
+	GError *mapi_error = NULL;
 
 	if (enable_debug) {
 		printf ("mapi: authenticate user\n");
@@ -1574,13 +1630,24 @@ e_book_backend_mapi_authenticate_user (EBookBackend *backend,
 		/* rather reuse already established connection */
 		priv->conn = exchange_mapi_connection_find (priv->profile);
 		if (priv->conn && !exchange_mapi_connection_connected (priv->conn))
-			exchange_mapi_connection_reconnect (priv->conn, passwd);
+			exchange_mapi_connection_reconnect (priv->conn, passwd, &mapi_error);
 		else if (!priv->conn)
-			priv->conn = exchange_mapi_connection_new (priv->profile, passwd);
+			priv->conn = exchange_mapi_connection_new (priv->profile, passwd, &mapi_error);
+
+		if (!priv->conn || mapi_error) {
+			GError *err = NULL;
 
-		if (!priv->conn) {
-			e_data_book_respond_authenticate_user (book, opid, EDB_ERROR_EX (OTHER_ERROR, "Cannot connect"));
+			if (priv->conn) {
+				g_object_unref (priv->conn);
+				priv->conn = NULL;
+			}
+				
+			mapi_error_to_edb_error (&err, mapi_error, E_DATA_BOOK_STATUS_OTHER_ERROR, _("Cannot connect"));
+			e_data_book_respond_authenticate_user (book, opid, err);
 			g_static_mutex_unlock (&priv->running_mutex);
+
+			if (mapi_error)
+				g_error_free (mapi_error);
 			return;
 		}
 
@@ -1674,7 +1741,10 @@ e_book_backend_mapi_remove (EBookBackend *backend,
 	gchar *cache_uri = NULL;
 	gboolean status = TRUE;
 	ESource *source;
+	GError *mapi_error = NULL;
+
 	source = e_book_backend_get_source (backend);
+
 	if (enable_debug)
 		printf("mapi: remove\n");
 
@@ -1687,10 +1757,19 @@ e_book_backend_mapi_remove (EBookBackend *backend,
 	case E_DATA_BOOK_MODE_REMOTE:
 		
 		if (strcmp (e_source_get_property(source, "public"), "yes") != 0)
-			status = exchange_mapi_connection_remove_folder (priv->conn, priv->fid, 0);
+			status = exchange_mapi_connection_remove_folder (priv->conn, priv->fid, 0, &mapi_error);
 		
 		if (!status) {
-			e_data_book_respond_remove (book, opid, EDB_ERROR (OTHER_ERROR));
+			GError *err = NULL;
+
+			if (mapi_error) {
+				mapi_error_to_edb_error (&err, mapi_error, E_DATA_BOOK_STATUS_OTHER_ERROR, _("Failed to remove public folder"));
+				g_error_free (mapi_error);
+			} else {
+				err = EDB_ERROR (OTHER_ERROR);
+			}
+
+			e_data_book_respond_remove (book, opid, err);
 			return;
 		}
 
diff --git a/src/calendar/e-cal-backend-mapi.c b/src/calendar/e-cal-backend-mapi.c
index 535c9d2..924656c 100644
--- a/src/calendar/e-cal-backend-mapi.c
+++ b/src/calendar/e-cal-backend-mapi.c
@@ -103,11 +103,42 @@ static ECalBackendClass *parent_class = NULL;
 
 static GStaticMutex auth_mutex = G_STATIC_MUTEX_INIT;
 
+static void
+mapi_error_to_edc_error (GError **perror, const GError *mapi_error, EDataCalCallStatus code, const gchar *context)
+{
+	gchar *err_msg = NULL;
+
+	if (!perror)
+		return;
+
+	if (code == OtherError && mapi_error) {
+		/* Change error to more accurate only with OtherError */
+		switch (mapi_error->code) {
+		case MAPI_E_PASSWORD_CHANGE_REQUIRED:
+		case MAPI_E_PASSWORD_EXPIRED:
+			code = AuthenticationRequired;
+			break;
+		default:
+			break;
+		}
+	}
+
+	if (context)
+		err_msg = g_strconcat (context, mapi_error ? ": " : NULL, mapi_error ? mapi_error->message : NULL, NULL);
+	else if (!mapi_error)
+		err_msg = g_strdup (_("Uknown error"));
+
+	g_propagate_error (perror, EDC_ERROR_EX (code, err_msg ? err_msg : mapi_error->message));
+
+	g_free (err_msg);
+}
+
 static gboolean
 e_cal_backend_mapi_authenticate (ECalBackend *backend, GError **perror)
 {
 	ECalBackendMAPI *cbmapi;
 	ECalBackendMAPIPrivate *priv;
+	GError *mapi_error = NULL;
 
 	cbmapi = E_CAL_BACKEND_MAPI (backend);
 	priv = cbmapi->priv;
@@ -118,14 +149,22 @@ e_cal_backend_mapi_authenticate (ECalBackend *backend, GError **perror)
 	/* rather reuse already established connection */
 	priv->conn = exchange_mapi_connection_find (priv->profile);
 	if (priv->conn && !exchange_mapi_connection_connected (priv->conn))
-		exchange_mapi_connection_reconnect (priv->conn, priv->password);
+		exchange_mapi_connection_reconnect (priv->conn, priv->password, &mapi_error);
 	else if (!priv->conn)
-		priv->conn = exchange_mapi_connection_new (priv->profile, priv->password);
+		priv->conn = exchange_mapi_connection_new (priv->profile, priv->password, &mapi_error);
 
 	if (priv->conn && exchange_mapi_connection_connected (priv->conn)) {
 		/* Success */;
 	} else {
-		g_propagate_error (perror, EDC_ERROR (AuthenticationFailed));
+		mapi_error_to_edc_error (perror, mapi_error, AuthenticationFailed, NULL);
+		if (mapi_error)
+			g_error_free (mapi_error);
+		return FALSE;
+	}
+
+	if (mapi_error) {
+		mapi_error_to_edc_error (perror, mapi_error, AuthenticationFailed, NULL);
+		g_error_free (mapi_error);
 		return FALSE;
 	}
 
@@ -345,8 +384,12 @@ e_cal_backend_mapi_remove (ECalBackendSync *backend, EDataCal *cal, GError **per
 		return;
 	}
 	if (strcmp (e_source_get_property (source, "public"), "yes") != 0) {
-		if (!exchange_mapi_connection_remove_folder (priv->conn, priv->fid, 0)) {
-			g_propagate_error (perror, EDC_ERROR (OtherError));
+		GError *mapi_error = NULL;
+
+		if (!exchange_mapi_connection_remove_folder (priv->conn, priv->fid, 0, &mapi_error)) {
+			mapi_error_to_edc_error (perror, mapi_error, OtherError, _("Failed to remove public folder"));
+			if (mapi_error)
+				g_error_free (mapi_error);
 			return;
 		}
 	}
@@ -675,6 +718,7 @@ get_deltas (gpointer handle)
 	guint32 options= MAPI_OPTIONS_FETCH_ALL;
 	gboolean is_public = FALSE;
 	TALLOC_CTX *mem_ctx = NULL;
+	GError *mapi_error = NULL;
 
 	if (!handle)
 		return FALSE;
@@ -731,9 +775,16 @@ get_deltas (gpointer handle)
 		if (!exchange_mapi_connection_fetch_items (priv->conn, priv->fid, use_restriction ? &res : NULL, NULL,
 						is_public ? NULL : mapi_cal_get_known_ids, NULL,
 						mapi_cal_get_changes_cb, cbmapi,
-						options)) {
-			/* FIXME: String : We need to restart evolution-data-server */
-			e_cal_backend_notify_error (E_CAL_BACKEND (cbmapi), _("Error fetching changes from the server."));
+						options, &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);
+				g_free (msg);
+				g_error_free (mapi_error);
+			} else {
+				e_cal_backend_notify_error (E_CAL_BACKEND (cbmapi), _("Failed to fetch changes from a server"));
+			}
+
 //			e_file_cache_thaw_changes (E_FILE_CACHE (priv->cache));
 			g_static_mutex_unlock (&updating);
 			if (mem_ctx)
@@ -750,14 +801,21 @@ get_deltas (gpointer handle)
 		if (!exchange_mapi_connection_fetch_items (priv->conn, priv->fid, use_restriction ? &res : NULL, NULL,
 						is_public ? NULL : exchange_mapi_cal_utils_get_props_cb, GINT_TO_POINTER (kind),
 						mapi_cal_get_changes_cb, cbmapi,
-						options)) {
-		/* FIXME: String : We need to restart evolution-data-server */
-		e_cal_backend_notify_error (E_CAL_BACKEND (cbmapi), _("Error fetching changes from the server."));
-//		e_file_cache_thaw_changes (E_FILE_CACHE (priv->cache));
-		g_static_mutex_unlock (&updating);
-		if (mem_ctx)
-			talloc_free (mem_ctx);
-		return FALSE;
+						options, &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);
+				g_free (msg);
+				g_error_free (mapi_error);
+			} else {
+				e_cal_backend_notify_error (E_CAL_BACKEND (cbmapi), _("Failed to fetch changes from a server"));
+			}
+
+			//e_file_cache_thaw_changes (E_FILE_CACHE (priv->cache));
+			g_static_mutex_unlock (&updating);
+			if (mem_ctx)
+				talloc_free (mem_ctx);
+			return FALSE;
 		}
 	}
 //	e_file_cache_thaw_changes (E_FILE_CACHE (priv->cache));
@@ -789,9 +847,16 @@ get_deltas (gpointer handle)
 	if (!exchange_mapi_connection_fetch_items (priv->conn, priv->fid, NULL, NULL,
 						mapi_cal_get_idlist, NULL,
 						handle_deleted_items_cb, &did,
-						options)) {
-		/* FIXME: String : We need to restart evolution-data-server */
-		e_cal_backend_notify_error (E_CAL_BACKEND (cbmapi), _("Error fetching changes from the server."));
+						options, &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);
+			g_free (msg);
+			g_error_free (mapi_error);
+		} else {
+			e_cal_backend_notify_error (E_CAL_BACKEND (cbmapi), _("Failed to fetch changes from a server"));
+		}
+
 		g_slist_free (did.cache_keys);
 		g_static_mutex_unlock (&updating);
 		return FALSE;
@@ -858,9 +923,17 @@ get_deltas (gpointer handle)
 			if (!exchange_mapi_connection_fetch_items (priv->conn, priv->fid, &res, NULL,
 						is_public ? NULL : mapi_cal_get_known_ids, NULL,
 						mapi_cal_get_changes_cb, cbmapi,
-						options)) {
+						options, &mapi_error)) {
 								
-				e_cal_backend_notify_error (E_CAL_BACKEND (cbmapi), _("Error fetching changes from the server."));
+				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);
+					g_free (msg);
+					g_error_free (mapi_error);
+				} else {
+					e_cal_backend_notify_error (E_CAL_BACKEND (cbmapi), _("Failed to fetch changes from a server"));
+				}
+
 				g_static_mutex_unlock (&updating);
 				g_free (or_res);
 				return FALSE;
@@ -874,11 +947,19 @@ get_deltas (gpointer handle)
 			if (!exchange_mapi_connection_fetch_items (priv->conn, priv->fid, &res, NULL,
 						is_public ? NULL : exchange_mapi_cal_utils_get_props_cb, GINT_TO_POINTER (kind),
 						mapi_cal_get_changes_cb, cbmapi,
-						options)) {
-			e_cal_backend_notify_error (E_CAL_BACKEND (cbmapi), _("Error fetching changes from the server."));
-			g_free (or_res);
-			g_static_mutex_unlock (&updating);
-			return FALSE;
+						options, &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);
+					g_free (msg);
+					g_error_free (mapi_error);
+				} else {
+					e_cal_backend_notify_error (E_CAL_BACKEND (cbmapi), _("Failed to fetch changes from a server"));
+				}
+
+				g_free (or_res);
+				g_static_mutex_unlock (&updating);
+				return FALSE;
 			}
 		}
 		g_free (or_res);
@@ -1179,7 +1260,9 @@ populate_cache (ECalBackendMAPI *cbmapi, GError **perror)
 	gchar *time_string = NULL;
 	gchar t_str [26];
 	guint32 options= MAPI_OPTIONS_FETCH_ALL;
-	gboolean is_public = FALSE;  
+	gboolean is_public = FALSE;
+	GError *mapi_error = NULL;
+
 	priv = cbmapi->priv;
 
 	g_mutex_lock (priv->mutex);
@@ -1211,12 +1294,15 @@ populate_cache (ECalBackendMAPI *cbmapi, GError **perror)
 		if (!exchange_mapi_connection_fetch_items (priv->conn, priv->fid, NULL, NULL,
 						is_public ? NULL : mapi_cal_get_known_ids, NULL,
 						mapi_cal_cache_create_cb, cbmapi,
-						options)) {
+						options, &mapi_error)) {
 			e_file_cache_thaw_changes (E_FILE_CACHE (priv->cache));
 			g_mutex_lock (priv->mutex);
 			priv->populating_cache = FALSE;
 			g_mutex_unlock (priv->mutex);
-			g_propagate_error (perror, EDC_ERROR_EX (OtherError, _("Could not create cache file")));
+			mapi_error_to_edc_error (perror, mapi_error, OtherError, _("Failed to fetch items from a server"));
+			if (mapi_error)
+				g_error_free (mapi_error);
+
 			return FALSE;
 		}
 	} else {
@@ -1228,12 +1314,16 @@ populate_cache (ECalBackendMAPI *cbmapi, GError **perror)
 		if (!exchange_mapi_connection_fetch_items (priv->conn, priv->fid, NULL, NULL,
 						is_public ? NULL : exchange_mapi_cal_utils_get_props_cb, GINT_TO_POINTER (kind),
 						mapi_cal_cache_create_cb, cbmapi,
-						options)) {
+						options, &mapi_error)) {
 			e_file_cache_thaw_changes (E_FILE_CACHE (priv->cache));
 			g_mutex_lock (priv->mutex);
 			priv->populating_cache = FALSE;
 			g_mutex_unlock (priv->mutex);
-			g_propagate_error (perror, EDC_ERROR_EX (OtherError, _("Could not create cache file")));
+
+			mapi_error_to_edc_error (perror, mapi_error, OtherError, _("Failed to fetch items from a server"));
+			if (mapi_error)
+				g_error_free (mapi_error);
+
 			return FALSE;
 		}
 	}
@@ -1540,11 +1630,11 @@ get_server_data (ECalBackendMAPI *cbmapi, icalcomponent *comp, struct cal_cbdata
 	if (exchange_mapi_connection_fetch_item (priv->conn, priv->fid, mid,
 					mapi_cal_get_required_props, NULL,
 					capture_req_props, cbdata,
-					MAPI_OPTIONS_FETCH_GENERIC_STREAMS))
+					MAPI_OPTIONS_FETCH_GENERIC_STREAMS, NULL))
 
 		return;
 
-	proptag = exchange_mapi_connection_resolve_named_prop (priv->conn, priv->fid, PidLidCleanGlobalObjectId);
+	proptag = exchange_mapi_connection_resolve_named_prop (priv->conn, priv->fid, PidLidCleanGlobalObjectId, NULL);
 	if (proptag == MAPI_E_RESERVED) proptag = PidLidCleanGlobalObjectId;
 
 	res.rt = RES_PROPERTY;
@@ -1564,7 +1654,7 @@ get_server_data (ECalBackendMAPI *cbmapi, icalcomponent *comp, struct cal_cbdata
 	exchange_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);
+					MAPI_OPTIONS_FETCH_GENERIC_STREAMS, NULL);
 
 	talloc_free (mem_ctx);
 }
@@ -1588,6 +1678,7 @@ e_cal_backend_mapi_create_object (ECalBackendSync *backend, EDataCal *cal, gchar
 	struct cal_cbdata cbdata = { 0 };
 	struct Binary_r globalid;
 	struct icaltimetype current;
+	GError *mapi_error = NULL;
 
 	cbmapi = E_CAL_BACKEND_MAPI (backend);
 	priv = cbmapi->priv;
@@ -1627,7 +1718,7 @@ e_cal_backend_mapi_create_object (ECalBackendSync *backend, EDataCal *cal, gchar
 		if (ba) {
 			ExchangeMAPIStream *stream = g_new0 (ExchangeMAPIStream, 1);
 			stream->value = ba;
-			stream->proptag = exchange_mapi_connection_resolve_named_prop (priv->conn, priv->fid, PidLidAppointmentRecur);
+			stream->proptag = exchange_mapi_connection_resolve_named_prop (priv->conn, priv->fid, PidLidAppointmentRecur, NULL);
 			if (stream->proptag != MAPI_E_RESERVED)
 				streams = g_slist_append (streams, stream);
 		}
@@ -1669,7 +1760,7 @@ e_cal_backend_mapi_create_object (ECalBackendSync *backend, EDataCal *cal, gchar
 
 			mid = exchange_mapi_connection_create_item (priv->conn, priv->olFolder, priv->fid,
 							exchange_mapi_cal_utils_write_props_cb, &cbdata,
-							recipients, attachments, streams, MAPI_OPTIONS_DONT_SUBMIT);
+							recipients, attachments, streams, MAPI_OPTIONS_DONT_SUBMIT, &mapi_error);
 			g_free (cbdata.props);
 //			g_free (globalid.lpb);
 			if (!mid) {
@@ -1677,7 +1768,9 @@ e_cal_backend_mapi_create_object (ECalBackendSync *backend, EDataCal *cal, gchar
 				exchange_mapi_util_free_recipient_list (&recipients);
 				exchange_mapi_util_free_stream_list (&streams);
 				exchange_mapi_util_free_attachment_list (&attachments);
-				g_propagate_error (error, EDC_ERROR (OtherError));
+				mapi_error_to_edc_error (error, mapi_error, OtherError, _("Failed to create item on a server"));
+				if (mapi_error)
+					g_error_free (mapi_error);
 				return;
 			}
 
@@ -1784,6 +1877,7 @@ e_cal_backend_mapi_modify_object (ECalBackendSync *backend, EDataCal *cal, const
 	gboolean no_increment = FALSE;
 	icalproperty *prop;
 	struct icaltimetype current;
+	GError *mapi_error = NULL;
 
 	*old_object = *new_object = NULL;
 	cbmapi = E_CAL_BACKEND_MAPI (backend);
@@ -1832,7 +1926,7 @@ e_cal_backend_mapi_modify_object (ECalBackendSync *backend, EDataCal *cal, const
 		if (ba) {
 			ExchangeMAPIStream *stream = g_new0 (ExchangeMAPIStream, 1);
 			stream->value = ba;
-			stream->proptag = exchange_mapi_connection_resolve_named_prop (priv->conn, priv->fid, PidLidAppointmentRecur);
+			stream->proptag = exchange_mapi_connection_resolve_named_prop (priv->conn, priv->fid, PidLidAppointmentRecur, NULL);
 			if (stream->proptag != MAPI_E_RESERVED)
 				streams = g_slist_append (streams, stream);
 		}
@@ -1895,7 +1989,7 @@ e_cal_backend_mapi_modify_object (ECalBackendSync *backend, EDataCal *cal, const
 
 		status = exchange_mapi_connection_modify_item (priv->conn, priv->olFolder, priv->fid, mid,
 						exchange_mapi_cal_utils_write_props_cb, &cbdata,
-						recipients, attachments, streams, MAPI_OPTIONS_DONT_SUBMIT);
+						recipients, attachments, streams, MAPI_OPTIONS_DONT_SUBMIT, &mapi_error);
 		g_free (cbdata.props);
 		if (!status) {
 			g_object_unref (comp);
@@ -1903,7 +1997,10 @@ e_cal_backend_mapi_modify_object (ECalBackendSync *backend, EDataCal *cal, const
 			exchange_mapi_util_free_recipient_list (&recipients);
 			exchange_mapi_util_free_stream_list (&streams);
 			exchange_mapi_util_free_attachment_list (&attachments);
-			g_propagate_error (error, EDC_ERROR (OtherError));
+
+			mapi_error_to_edc_error (error, mapi_error, OtherError, _("Failed to modify item on a server"));
+			if (mapi_error)
+				g_error_free (mapi_error);
 			return;
 		}
 		break;
@@ -1990,6 +2087,7 @@ e_cal_backend_mapi_remove_object (ECalBackendSync *backend, EDataCal *cal,
 			g_free (new_calobj);
 		} else {
 			GSList *list=NULL, *l, *comp_list = e_cal_backend_cache_get_components_by_uid (priv->cache, uid);
+			GError *ri_error = NULL;
 
 //			if (e_cal_component_has_attendees (E_CAL_COMPONENT (comp_list->data))) {
 //			} else {
@@ -1998,7 +2096,7 @@ e_cal_backend_mapi_remove_object (ECalBackendSync *backend, EDataCal *cal,
 				list = g_slist_prepend (list, (gpointer) data);
 //			}
 
-			if (exchange_mapi_connection_remove_items (priv->conn, priv->olFolder, priv->fid, 0, list)) {
+			if (exchange_mapi_connection_remove_items (priv->conn, priv->olFolder, priv->fid, 0, list, &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);
@@ -2014,7 +2112,7 @@ e_cal_backend_mapi_remove_object (ECalBackendSync *backend, EDataCal *cal,
 				*object = NULL;
 				err = NULL; /* Success */
 			} else
-				err = EDC_ERROR_EX (OtherError, "Cannot remove items from a server");
+				mapi_error_to_edc_error (&err, ri_error, OtherError, "Cannot remove items from a server");
 
 			g_slist_free (list);
 			g_slist_free (comp_list);
@@ -2044,6 +2142,7 @@ e_cal_backend_mapi_send_objects (ECalBackendSync *backend, EDataCal *cal, const
 	ECalBackendMAPIPrivate *priv;
 	icalcomponent_kind kind;
 	icalcomponent *icalcomp;
+	GError *mapi_error = NULL;
 
 	cbmapi = E_CAL_BACKEND_MAPI (backend);
 	priv = cbmapi->priv;
@@ -2088,7 +2187,7 @@ e_cal_backend_mapi_send_objects (ECalBackendSync *backend, EDataCal *cal, const
 				if (ba) {
 					ExchangeMAPIStream *stream = g_new0 (ExchangeMAPIStream, 1);
 					stream->value = ba;
-					stream->proptag = exchange_mapi_connection_resolve_named_prop (priv->conn, priv->fid, PidLidAppointmentRecur);
+					stream->proptag = exchange_mapi_connection_resolve_named_prop (priv->conn, priv->fid, PidLidAppointmentRecur, NULL);
 					if (stream->proptag != MAPI_E_RESERVED)
 						streams = g_slist_append (streams, stream);
 				}
@@ -2146,13 +2245,15 @@ e_cal_backend_mapi_send_objects (ECalBackendSync *backend, EDataCal *cal, const
 
 			mid = exchange_mapi_connection_create_item (priv->conn, olFolderSentMail, 0,
 							exchange_mapi_cal_utils_write_props_cb, &cbdata,
-							recipients, attachments, streams, MAPI_OPTIONS_DELETE_ON_SUBMIT_FAILURE);
+							recipients, attachments, streams, MAPI_OPTIONS_DELETE_ON_SUBMIT_FAILURE, &mapi_error);
 			g_free (cbdata.props);
 			if (!mid) {
 				g_object_unref (comp);
 				exchange_mapi_util_free_recipient_list (&recipients);
 				exchange_mapi_util_free_attachment_list (&attachments);
-				g_propagate_error (error, EDC_ERROR_EX (OtherError, "Cannot create item on a server"));
+				mapi_error_to_edc_error (error, mapi_error, OtherError, _("Failed to create item on a server"));
+				if (mapi_error)
+					g_error_free (mapi_error);
 				return;
 			}
 
@@ -2356,11 +2457,17 @@ e_cal_backend_mapi_get_free_busy (ECalBackendSync *backend, EDataCal *cal,
 {
 	ECalBackendMAPI *cbmapi;
 	ECalBackendMAPIPrivate *priv;
+	GError *mapi_error = NULL;
 
 	cbmapi = E_CAL_BACKEND_MAPI (backend);
 	priv = cbmapi->priv;
 
-	exchange_mapi_cal_utils_get_free_busy_data (priv->conn, users, start, end, freebusy);
+	if (!exchange_mapi_cal_utils_get_free_busy_data (priv->conn, users, start, end, freebusy, &mapi_error)) {
+		mapi_error_to_edc_error (perror, mapi_error, OtherError, _("Failed to get Free/Busy data"));
+
+		if (mapi_error)
+			g_error_free (mapi_error);
+	}
 }
 
 typedef struct {
diff --git a/src/camel/camel-mapi-folder.c b/src/camel/camel-mapi-folder.c
index a231235..653bb6f 100644
--- a/src/camel/camel-mapi-folder.c
+++ b/src/camel/camel-mapi-folder.c
@@ -334,7 +334,7 @@ mapi_update_cache (CamelFolder *folder, GSList *list, CamelFolderChangeInfo **ch
 	CamelFolderChangeInfo *changes = NULL;
 	gboolean exists = FALSE;
 	GString *str = g_string_new (NULL);
-	const gchar *from_email, *folder_id = NULL;
+	const gchar *folder_id = NULL;
 	const gchar *full_name;
 	GSList *item_list = list;
 	gint total_items = g_slist_length (item_list), i=0;
@@ -467,12 +467,14 @@ mapi_update_cache (CamelFolder *folder, GSList *list, CamelFolderChangeInfo **ch
 			}
 
 			if ((item->header.from_type != NULL) && !g_utf8_collate (item->header.from_type, "EX")) {
+				gchar *from_email;
+
 				camel_service_lock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
-				from_email = exchange_mapi_connection_ex_to_smtp (camel_mapi_store_get_exchange_connection (mapi_store), item->header.from_email);
+				from_email = exchange_mapi_connection_ex_to_smtp (camel_mapi_store_get_exchange_connection (mapi_store), item->header.from_email, NULL);
 				camel_service_unlock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 
 				g_free (item->header.from_email);
-				item->header.from_email = g_strdup (from_email);
+				item->header.from_email = from_email;
 			}
 
 			item->header.from_email = item->header.from_email ?
@@ -599,10 +601,10 @@ mapi_sync_deleted (CamelSession *session, CamelSessionThreadMsg *msg)
 	server_messages = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
 
 	/*Get the UID list from server.*/
-	exchange_mapi_connection_fetch_items  (camel_mapi_store_get_exchange_connection (mapi_store), m->folder_id, NULL, NULL,
+	exchange_mapi_connection_fetch_items (camel_mapi_store_get_exchange_connection (mapi_store), m->folder_id, NULL, NULL,
 					       NULL, NULL,
 					       deleted_items_sync_cb, server_messages,
-					       options | MAPI_OPTIONS_DONT_OPEN_MESSAGE);
+					       options | MAPI_OPTIONS_DONT_OPEN_MESSAGE, NULL);
 
 	camel_operation_end (NULL);
 
@@ -830,13 +832,13 @@ mapi_sync (CamelFolder *folder, gboolean expunge, GError **error)
 
 	if (read_items) {
 		camel_service_lock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
-		exchange_mapi_connection_set_flags (camel_mapi_store_get_exchange_connection (mapi_store), 0, fid, options, read_items, 0);
+		exchange_mapi_connection_set_flags (camel_mapi_store_get_exchange_connection (mapi_store), 0, fid, options, read_items, 0, NULL);
 		camel_service_unlock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 	}
 
 	if (unread_items) {
 		camel_service_lock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
-		exchange_mapi_connection_set_flags (camel_mapi_store_get_exchange_connection (mapi_store), 0, fid, options, unread_items, CLEAR_READ_FLAG);
+		exchange_mapi_connection_set_flags (camel_mapi_store_get_exchange_connection (mapi_store), 0, fid, options, unread_items, CLEAR_READ_FLAG, NULL);
 		camel_service_unlock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 	}
 
@@ -844,10 +846,17 @@ mapi_sync (CamelFolder *folder, gboolean expunge, GError **error)
 	if (deleted_items) {
 		camel_service_lock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 		if ((mapi_folder->type & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_TRASH) {
-			exchange_mapi_connection_remove_items (camel_mapi_store_get_exchange_connection (mapi_store), 0, fid, options, deleted_items);
+			exchange_mapi_connection_remove_items (camel_mapi_store_get_exchange_connection (mapi_store), 0, fid, options, deleted_items, NULL);
 		} else {
+			GError *err = NULL;
+
 			exchange_mapi_util_mapi_id_from_string (camel_mapi_store_system_folder_fid (mapi_store, olFolderDeletedItems), &deleted_items_fid);
-			exchange_mapi_connection_move_items (camel_mapi_store_get_exchange_connection (mapi_store), fid, options, deleted_items_fid, 0, deleted_items);
+			exchange_mapi_connection_move_items (camel_mapi_store_get_exchange_connection (mapi_store), fid, options, deleted_items_fid, 0, deleted_items, &err);
+
+			if (err) {
+				g_warning ("%s: Failed to move deleted items: %s", G_STRFUNC, err->message);
+				g_error_free (err);
+			}
 		}
 
 		camel_service_unlock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
@@ -856,14 +865,20 @@ mapi_sync (CamelFolder *folder, gboolean expunge, GError **error)
 	
 	if (junk_items) {
 		mapi_id_t junk_fid = 0;
+		GError *err = NULL;
 
 		camel_service_lock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 		exchange_mapi_util_mapi_id_from_string (camel_mapi_store_system_folder_fid (mapi_store, olFolderJunk), &junk_fid);
-		exchange_mapi_connection_move_items (camel_mapi_store_get_exchange_connection (mapi_store), fid, options, junk_fid, 0, junk_items);
+		exchange_mapi_connection_move_items (camel_mapi_store_get_exchange_connection (mapi_store), fid, options, junk_fid, 0, junk_items, &err);
 		camel_service_unlock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 
 		/* in junk_items are only emails which are not deleted */
 		deleted_items = g_slist_concat (deleted_items, g_slist_copy (junk_items));
+
+		if (err) {
+			g_warning ("%s: Failed to move junk items: %s", G_STRFUNC, err->message);
+			g_error_free (err);
+		}
 	}
 
 	/*Remove messages from local cache*/
@@ -924,7 +939,7 @@ mapi_camel_get_summary_list (ExchangeMapiConnection *conn, mapi_id_t fid, TALLOC
 
 gboolean
 camel_mapi_folder_fetch_summary (CamelStore *store, CamelFolder *folder, const mapi_id_t fid, struct mapi_SRestriction *res,
-				 struct SSortOrderSet *sort, fetch_items_data *fetch_data, guint32 options)
+				 struct SSortOrderSet *sort, fetch_items_data *fetch_data, guint32 options, GError **mapi_error)
 {
 	gboolean status;
 	CamelMapiStore *mapi_store = (CamelMapiStore *) store;
@@ -938,7 +953,7 @@ camel_mapi_folder_fetch_summary (CamelStore *store, CamelFolder *folder, const m
 	status = exchange_mapi_connection_fetch_items  (camel_mapi_store_get_exchange_connection (mapi_store), fid, res, sort,
 							mapi_camel_get_summary_list, NULL,
 							fetch_items_summary_cb, fetch_data,
-							options);
+							options, mapi_error);
 
 	camel_service_unlock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 
@@ -1008,6 +1023,7 @@ mapi_refresh_folder(CamelFolder *folder, GError **error)
 	if (!is_proxy) {
 		mapi_id_t temp_folder_id;
 		guint32 options = 0;
+		GError *mapi_error = NULL;
 
 		if (mapi_summary->sync_time_stamp && *mapi_summary->sync_time_stamp &&
 		    g_time_val_from_iso8601 (mapi_summary->sync_time_stamp,
@@ -1064,13 +1080,19 @@ mapi_refresh_folder(CamelFolder *folder, GError **error)
 			options |= MAPI_OPTIONS_USE_PFSTORE;
 
 		status = camel_mapi_folder_fetch_summary ((CamelStore *)mapi_store, folder, temp_folder_id, res, sort,
-							  fetch_data, options);
+							  fetch_data, options, &mapi_error);
 
 		if (!status) {
-			g_set_error (
-				error, CAMEL_SERVICE_ERROR,
-				CAMEL_SERVICE_ERROR_INVALID,
-				_("Fetching items failed"));
+			if (mapi_error) {
+				g_set_error (
+					error, CAMEL_SERVICE_ERROR, CAMEL_SERVICE_ERROR_INVALID,
+					_("Fetching items failed: %s"), mapi_error->message);
+				g_error_free (mapi_error);
+			} else {
+				g_set_error_literal (
+					error, CAMEL_SERVICE_ERROR, CAMEL_SERVICE_ERROR_INVALID,
+					_("Fetching items failed"));
+			}
 			success = FALSE;
 			goto end1;
 		}
@@ -1126,6 +1148,7 @@ mapi_folder_get_message( CamelFolder *folder, const gchar *uid, GError **error )
 	mapi_id_t id_message;
 	MailItem *item = NULL;
 	guint32 options = 0;
+	GError *mapi_error = NULL;
 
 	parent_store = camel_folder_get_parent_store (folder);
 
@@ -1209,14 +1232,22 @@ mapi_folder_get_message( CamelFolder *folder, const gchar *uid, GError **error )
 	exchange_mapi_connection_fetch_item (camel_mapi_store_get_exchange_connection (mapi_store), id_folder, id_message,
 					mapi_mail_get_item_prop_list, NULL,
 					fetch_props_to_mail_item_cb, &item,
-					options);
+					options, &mapi_error);
 	camel_service_unlock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 
 	if (item == NULL) {
-		g_set_error (
-			error, CAMEL_SERVICE_ERROR,
-			CAMEL_SERVICE_ERROR_INVALID,
-			_("Could not get message"));
+		if (mapi_error) {
+			g_set_error (
+				error, CAMEL_SERVICE_ERROR,
+				CAMEL_SERVICE_ERROR_INVALID,
+				_("Could not get message: %s"), mapi_error->message);
+			g_error_free (mapi_error);
+		} else {
+			g_set_error (
+				error, CAMEL_SERVICE_ERROR,
+				CAMEL_SERVICE_ERROR_INVALID,
+				_("Could not get message"));
+		}
 		camel_message_info_free (&mi->info);
 		return NULL;
 	}
@@ -1352,18 +1383,28 @@ mapi_expunge (CamelFolder *folder, GError **error)
 	exchange_mapi_util_mapi_id_from_string (folder_id, &fid);
 
 	if ((mapi_folder->type & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_TRASH) {
+		GError *mapi_error = NULL;
+
 		camel_service_lock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
-		status = exchange_mapi_connection_empty_folder (camel_mapi_store_get_exchange_connection (mapi_store), fid, 0);
+		status = exchange_mapi_connection_empty_folder (camel_mapi_store_get_exchange_connection (mapi_store), fid, 0, &mapi_error);
 		camel_service_unlock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 
 		if (status) {
 			camel_folder_freeze (folder);
 			mapi_summary_clear (folder->summary, TRUE);
 			camel_folder_thaw (folder);
-		} else
-			g_warning ("Could not Empty Trash\n");
+		} else if (mapi_error) {
+			g_set_error (
+				error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
+				_("Failed to empty Trash: %s"), mapi_error->message);
+			g_error_free (mapi_error);
+		} else {
+			g_set_error_literal (
+				error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
+				_("Failed to empty Trash"));
+		}
 
-		return TRUE;
+		return status;
 	}
 
 	changes = camel_folder_change_info_new ();
@@ -1397,7 +1438,7 @@ mapi_expunge (CamelFolder *folder, GError **error)
 	if (deleted_items) {
 		camel_service_lock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 
-		status = exchange_mapi_connection_remove_items (camel_mapi_store_get_exchange_connection (mapi_store), 0, fid, 0, deleted_items);
+		status = exchange_mapi_connection_remove_items (camel_mapi_store_get_exchange_connection (mapi_store), 0, fid, 0, deleted_items, NULL);
 
 		camel_service_unlock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 
@@ -1491,13 +1532,14 @@ mapi_transfer_messages_to (CamelFolder *source, GPtrArray *uids,
 	}
 
 	if (delete_originals) {
-		enum MAPISTATUS retval = exchange_mapi_connection_move_items (camel_mapi_store_get_exchange_connection (mapi_store), src_fid, src_fid_options, dest_fid, dest_fid_options, src_msg_ids);
-		if (retval != MAPI_E_SUCCESS) {
-			const gchar *err_str = mapi_get_errstr (retval);
-
+		GError *err = NULL;
+		
+		if (!exchange_mapi_connection_move_items (camel_mapi_store_get_exchange_connection (mapi_store), src_fid, src_fid_options, dest_fid, dest_fid_options, src_msg_ids, &err)) {
 			g_set_error (
 				error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
-				"%s", err_str ? err_str : _("Unknown error"));
+				"%s", err ? err->message : _("Unknown error"));
+			if (err)
+				g_error_free (err);
 			success = FALSE;
 		} else {
 			changes = camel_folder_change_info_new ();
@@ -1511,13 +1553,14 @@ mapi_transfer_messages_to (CamelFolder *source, GPtrArray *uids,
 
 		}
 	} else {
-		enum MAPISTATUS retval = exchange_mapi_connection_copy_items (camel_mapi_store_get_exchange_connection (mapi_store), src_fid, src_fid_options, dest_fid, dest_fid_options, src_msg_ids);
-		if (retval != MAPI_E_SUCCESS) {
-			const gchar *err_str = mapi_get_errstr (retval);
+		GError *err = NULL;
 
+		if (!exchange_mapi_connection_copy_items (camel_mapi_store_get_exchange_connection (mapi_store), src_fid, src_fid_options, dest_fid, dest_fid_options, src_msg_ids, &err)) {
 			g_set_error (
 				error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
-				"%s", err_str ? err_str : _("Unknown error"));
+				"%s", err ? err->message : _("Unknown error"));
+			if (err)
+				g_error_free (err);
 			success = FALSE;
 		}
 	}
@@ -1558,6 +1601,7 @@ mapi_append_message (CamelFolder *folder, CamelMimeMessage *message,
 	const gchar *folder_id;
 	const gchar *full_name;
 	guint32 folder_flags = 0;
+	GError *mapi_error = NULL;
 
 	full_name = camel_folder_get_full_name (folder);
 	parent_store = camel_folder_get_parent_store (folder);
@@ -1602,7 +1646,18 @@ mapi_append_message (CamelFolder *folder, CamelMimeMessage *message,
 	mid = exchange_mapi_connection_create_item (camel_mapi_store_get_exchange_connection (mapi_store), -1, fid,
 					 camel_mapi_utils_create_item_build_props, item,
 					 item->recipients, item->attachments,
-					 item->generic_streams, 0);
+					 item->generic_streams, 0, &mapi_error);
+
+	if (!mid) {
+		if (mapi_error) {
+			g_set_error_literal (error, CAMEL_ERROR, CAMEL_ERROR_GENERIC, mapi_error->message);
+			g_error_free (mapi_error);
+		} else {
+			g_set_error (error, CAMEL_ERROR, CAMEL_ERROR_GENERIC, _("Offline."));
+		}
+
+		return FALSE;
+	}
 
 	if (appended_uid)
 		*appended_uid = exchange_mapi_util_mapi_ids_to_uid(fid, mid);
diff --git a/src/camel/camel-mapi-folder.h b/src/camel/camel-mapi-folder.h
index 7f66dca..69a9881 100644
--- a/src/camel/camel-mapi-folder.h
+++ b/src/camel/camel-mapi-folder.h
@@ -95,7 +95,7 @@ camel_mapi_folder_new(CamelStore *store, const gchar *folder_name, const gchar *
 void mapi_update_summary ( CamelFolder *folder, GList *item_list,GError **error);
 gboolean mapi_refresh_folder(CamelFolder *folder, GError **error);
 gboolean camel_mapi_folder_fetch_summary (CamelStore *store, CamelFolder *folder, const mapi_id_t fid, struct mapi_SRestriction *res,
-					  struct SSortOrderSet *sort, fetch_items_data *fetch_data, guint32 options);
+					  struct SSortOrderSet *sort, fetch_items_data *fetch_data, guint32 options, GError **mapi_error);
 
 G_END_DECLS
 
diff --git a/src/camel/camel-mapi-notifications.c b/src/camel/camel-mapi-notifications.c
index c6a7b28..21fc3dc 100644
--- a/src/camel/camel-mapi-notifications.c
+++ b/src/camel/camel-mapi-notifications.c
@@ -117,7 +117,7 @@ process_mapi_new_mail_notif (CamelMapiStore *store, struct NewMailNotification *
 	fetch_data->folder = folder;
 
 	camel_service_lock (CAMEL_SERVICE (store), CAMEL_SERVICE_REC_CONNECT_LOCK);
-	camel_mapi_folder_fetch_summary ((CamelStore *)store, folder, new_mail_notif->FID, res, NULL, fetch_data, options);
+	camel_mapi_folder_fetch_summary ((CamelStore *)store, folder, new_mail_notif->FID, res, NULL, fetch_data, options, NULL);
 	camel_service_unlock (CAMEL_SERVICE (store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 
 	camel_folder_summary_touch (folder->summary);
@@ -231,14 +231,14 @@ mapi_push_notification_listener_thread (gpointer data)
 
 	g_object_ref (conn);
 
-	if (exchange_mapi_connection_events_init (conn)) {
+	if (exchange_mapi_connection_events_init (conn, NULL)) {
 		exchange_mapi_connection_events_subscribe (conn, thread_data->event_options, thread_data->event_mask,
 						&thread_data->connection, mapi_notifications_filter,
-						thread_data->event_data);
+						thread_data->event_data, NULL);
 
 		camel_service_unlock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 		exchange_mapi_connection_events_monitor (conn, cb_data); /*Blocking call. Don't hold locks here*/
-		exchange_mapi_connection_events_unsubscribe (conn, thread_data->connection);
+		exchange_mapi_connection_events_unsubscribe (conn, thread_data->connection, 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 3d33c37..e88009b 100644
--- a/src/camel/camel-mapi-store.c
+++ b/src/camel/camel-mapi-store.c
@@ -342,6 +342,8 @@ mapi_auth_loop (CamelService *service, GError **error)
 	service->url->passwd = NULL;
 
 	while (!authenticated) {
+		GError *mapi_error = NULL;
+
 		if (errbuf) {
 			/* We need to un-cache the password before prompting again */
 			prompt_flags |= CAMEL_SESSION_PASSWORD_REPROMPT;
@@ -376,10 +378,14 @@ mapi_auth_loop (CamelService *service, GError **error)
 			}
 		}
 
-		store->priv->conn = exchange_mapi_connection_new (store->priv->profile, service->url->passwd);
+		store->priv->conn = exchange_mapi_connection_new (store->priv->profile, service->url->passwd, &mapi_error);
 		if (!store->priv->conn || !exchange_mapi_connection_connected (store->priv->conn)) {
-			errbuf = g_strdup_printf (_("Unable to authenticate to Exchange MAPI server."));
-
+			if (mapi_error) {
+				errbuf = g_strdup_printf (_("Unable to authenticate to Exchange MAPI server: %s"), mapi_error->message);
+				g_error_free (mapi_error);
+			} else {
+				errbuf = g_strdup (_("Unable to authenticate to Exchange MAPI server"));
+			}
 		} else
 			authenticated = TRUE;
 
@@ -549,6 +555,7 @@ mapi_create_folder(CamelStore *store, const gchar *parent_name, const gchar *fol
 	CamelFolderInfo *root = NULL;
 	gchar *parent_id;
 	mapi_id_t parent_fid, new_folder_id;
+	GError *mapi_error = NULL;
 
 	if (((CamelOfflineStore *) store)->state == CAMEL_OFFLINE_STORE_NETWORK_UNAVAIL) {
 		g_set_error (
@@ -581,7 +588,7 @@ mapi_create_folder(CamelStore *store, const gchar *parent_name, const gchar *fol
 	camel_service_lock (CAMEL_SERVICE (store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 
 	exchange_mapi_util_mapi_id_from_string (parent_id, &parent_fid);
-	new_folder_id = exchange_mapi_connection_create_folder (priv->conn, olFolderInbox, parent_fid, 0, folder_name);
+	new_folder_id = exchange_mapi_connection_create_folder (priv->conn, olFolderInbox, parent_fid, 0, folder_name, &mapi_error);
 	if (new_folder_id != 0) {
 		CamelMapiStoreInfo *si;
 		gchar *fid = g_strdup_printf ("%016" G_GINT64_MODIFIER "X", new_folder_id);
@@ -594,6 +601,17 @@ mapi_create_folder(CamelStore *store, const gchar *parent_name, const gchar *fol
 		mapi_update_folder_hash_tables (mapi_store, root->full_name, fid, parent_id);
 
 		camel_store_folder_created (store, root);
+	} else {
+		if (mapi_error) {
+			g_set_error (
+				error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
+				_("Cannot create folder '%s': %s"), folder_name, mapi_error->message);
+			g_error_free (mapi_error);
+		} else {
+			g_set_error (
+				error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
+				_("Cannot create folder '%s'"), folder_name);
+		}
 	}
 
 	camel_service_unlock (CAMEL_SERVICE (store), CAMEL_SERVICE_REC_CONNECT_LOCK);
@@ -667,7 +685,7 @@ mapi_delete_folder(CamelStore *store, const gchar *folder_name, GError **error)
 
 	folder_id = g_hash_table_lookup (priv->name_hash, folder_name);
 	exchange_mapi_util_mapi_id_from_string (folder_id, &folder_fid);
-	status = exchange_mapi_connection_remove_folder (priv->conn, folder_fid, 0);
+	status = exchange_mapi_connection_remove_folder (priv->conn, folder_fid, 0, &local_error);
 
 	if (status) {
 		/* Fixme ??  */
@@ -679,6 +697,22 @@ mapi_delete_folder(CamelStore *store, const gchar *folder_name, GError **error)
 		/*g_hash_table_remove (priv->parent_hash, folder_id);*/
 		g_hash_table_remove (priv->id_hash, folder_id);
 		g_hash_table_remove (priv->name_hash, folder_name);
+	} else {
+		success = FALSE;
+
+		if (local_error) {
+			g_set_error (
+				error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
+				_("Cannot remove folder '%s': %s"),
+				folder_name, local_error->message);
+			
+			g_error_free (local_error);
+		} else {
+			g_set_error (
+				error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
+				_("Cannot remove folder '%s'"),
+				folder_name);
+		}
 	}
 
 	camel_service_unlock (CAMEL_SERVICE (store), CAMEL_SERVICE_REC_CONNECT_LOCK);
@@ -817,13 +851,22 @@ mapi_rename_folder(CamelStore *store, const gchar *old_name, const gchar *new_na
 		gchar *folder_id;
 
 		/* renaming in the same folder, thus no MoveFolder necessary */
-		if (!exchange_mapi_connection_rename_folder (priv->conn, old_fid, 0, tmp ? tmp : new_name)) {
-			/*To translators : '%s to %s' is current name of the folder  and
-			new name of the folder.*/
-			g_set_error (
-				error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
-				_("Cannot rename MAPI folder '%s' to '%s'"),
-				old_name, new_name);
+		if (!exchange_mapi_connection_rename_folder (priv->conn, old_fid, 0, tmp ? tmp : new_name, &local_error)) {
+			if (local_error) {
+				g_set_error (
+					error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
+					/* Translators: '%s to %s' is current name of the folder and new name of the folder.
+					   The last '%s' is a detailed error message. */
+					_("Cannot rename MAPI folder '%s' to '%s': %s"),
+					old_name, new_name, local_error->message);
+				g_error_free (local_error);
+			} else {
+				g_set_error (
+					error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
+					/* Translators: '%s to %s' is current name of the folder and new name of the folder. */
+					_("Cannot rename MAPI folder '%s' to '%s'"),
+					old_name, new_name);
+			}
 
 			camel_service_unlock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 			g_free (old_parent);
@@ -872,12 +915,20 @@ mapi_rename_folder(CamelStore *store, const gchar *old_name, const gchar *new_na
 		} else if (!old_parent_fid_str || !new_parent_fid_str ||
 			   !exchange_mapi_util_mapi_id_from_string (old_parent_fid_str, &old_parent_fid) ||
 			   !exchange_mapi_util_mapi_id_from_string (new_parent_fid_str, &new_parent_fid) ||
-			   !exchange_mapi_connection_move_folder (priv->conn, old_fid, old_parent_fid, 0, new_parent_fid, 0, tmp)) {
+			   !exchange_mapi_connection_move_folder (priv->conn, old_fid, old_parent_fid, 0, new_parent_fid, 0, tmp, &local_error)) {
 			camel_service_unlock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
-			g_set_error (
-				error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
-				_("Cannot rename MAPI folder '%s' to '%s'"),
-				old_name, new_name);
+			if (local_error) {
+				g_set_error (
+					error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
+					_("Cannot rename MAPI folder '%s' to '%s': %s"),
+					old_name, new_name, local_error->message);
+				g_error_free (local_error);
+			} else {
+				g_set_error (
+					error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
+					_("Cannot rename MAPI folder '%s' to '%s'"),
+					old_name, new_name);
+			}
 			g_free (old_parent);
 			g_free (new_parent);
 			return FALSE;
@@ -1432,6 +1483,7 @@ mapi_folders_sync (CamelMapiStore *store, guint32 flags, GError **error)
 	guint32 count, i;
 	CamelStoreInfo *si = NULL;
 	GHashTable *old_cache_folders;
+	GError *err = NULL;
 
 	if (!camel_mapi_store_connected (store, NULL)) {
 		g_set_error (
@@ -1441,10 +1493,12 @@ mapi_folders_sync (CamelMapiStore *store, guint32 flags, GError **error)
 		return FALSE;
 	}
 
-	status = exchange_mapi_connection_get_folders_list (priv->conn, &folder_list);
+	status = exchange_mapi_connection_get_folders_list (priv->conn, &folder_list, &err);
 
 	if (!status) {
-		g_warning ("Could not get folder list..\n");
+		g_warning ("Could not get folder list (%s)\n", err ? err->message : "Unknown error");
+		if (err)
+			g_error_free (err);
 		return TRUE;
 	}
 
@@ -1467,10 +1521,15 @@ mapi_folders_sync (CamelMapiStore *store, guint32 flags, GError **error)
 
 	subscription_list = (flags & CAMEL_STORE_FOLDER_INFO_SUBSCRIPTION_LIST);
 	if (subscription_list) {
+		GError *err = NULL;
+
 		/*Consult the name <-> fid hash table for a FID.*/
-		status = exchange_mapi_connection_get_pf_folders_list (priv->conn, &folder_list);
+		status = exchange_mapi_connection_get_pf_folders_list (priv->conn, &folder_list, &err);
 		if (!status)
-			g_warning ("Could not get Public folder list..\n");
+			g_warning ("Could not get Public folder list (%s)\n", err ? err->message : "Unknown error");
+
+		if (err)
+			g_error_free (err);
 	}
 
 	temp_list = folder_list;
diff --git a/src/camel/camel-mapi-transport.c b/src/camel/camel-mapi-transport.c
index 521e83b..1467a1e 100644
--- a/src/camel/camel-mapi-transport.c
+++ b/src/camel/camel-mapi-transport.c
@@ -58,14 +58,14 @@ 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 (ExchangeMapiConnection *conn, MailItem *item)
+mapi_message_item_send (ExchangeMapiConnection *conn, MailItem *item, GError **perror)
 {
 	guint64 fid = 0;
 	mapi_id_t mid = 0;
 
 	mid = exchange_mapi_connection_create_item (conn, olFolderSentMail, fid,
 					 camel_mapi_utils_create_item_build_props, item,
-					 item->recipients, item->attachments, item->generic_streams, MAPI_OPTIONS_DELETE_ON_SUBMIT_FAILURE);
+					 item->recipients, item->attachments, item->generic_streams, MAPI_OPTIONS_DELETE_ON_SUBMIT_FAILURE, perror);
 
 	return mid;
 }
@@ -80,6 +80,7 @@ mapi_send_to (CamelTransport *transport, CamelMimeMessage *message,
 	const gchar *addressp;
 	mapi_id_t st = 0;
 	CamelURL *url;
+	GError *mapi_error = NULL;
 
 	if (!camel_internet_address_get((CamelInternetAddress *)from, 0, &namep, &addressp)) {
 		return (FALSE);
@@ -103,16 +104,21 @@ mapi_send_to (CamelTransport *transport, CamelMimeMessage *message,
 	item = camel_mapi_utils_mime_to_item (message, from, NULL);
 
 	/* send */
-	st = mapi_message_item_send (conn, item);
+	st = mapi_message_item_send (conn, item, error);
 
 	g_object_unref (conn);
 
 	if (st == 0) {
-		/*Fixme : Set a better error message. Would be helful in troubleshooting. */
-		g_set_error (
-			error, CAMEL_SERVICE_ERROR,
-			CAMEL_SERVICE_ERROR_UNAVAILABLE,
-			_("Could not send message."));
+		if (mapi_error) {
+			g_set_error (
+				error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
+				_("Could not send message: %s"), mapi_error->message);
+			g_error_free (mapi_error);
+		} else {
+			g_set_error (
+				error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
+				_("Could not send message."));
+		}
 		return FALSE;
 	}
 
diff --git a/src/libexchangemapi/exchange-mapi-cal-utils.c b/src/libexchangemapi/exchange-mapi-cal-utils.c
index acf16c7..0684a73 100644
--- a/src/libexchangemapi/exchange-mapi-cal-utils.c
+++ b/src/libexchangemapi/exchange-mapi-cal-utils.c
@@ -816,7 +816,7 @@ exchange_mapi_cal_util_mapi_props_to_comp (ExchangeMapiConnection *conn, icalcom
 			b = (const bool *)find_mapi_SPropValue_data(properties, PR_RESPONSE_REQUESTED);
 			ical_attendees_from_props (ical_comp, recipients, (b && *b));
 			if (icalcomponent_get_first_property (ical_comp, ICAL_ORGANIZER_PROPERTY) == NULL) {
-				gchar *val;
+				gchar *val, *sender_free = NULL, *sent_free = NULL;
 //				const gchar *sender_name = (const gchar *) exchange_mapi_util_find_array_propval (properties, PR_SENDER_NAME_UNICODE);
 				const gchar *sender_email_type = (const gchar *) exchange_mapi_util_find_array_propval (properties, PR_SENDER_ADDRTYPE_UNICODE);
 				const gchar *sender_email = (const gchar *) exchange_mapi_util_find_array_propval (properties, PR_SENDER_EMAIL_ADDRESS_UNICODE);
@@ -824,10 +824,14 @@ exchange_mapi_cal_util_mapi_props_to_comp (ExchangeMapiConnection *conn, icalcom
 				const gchar *sent_email_type = (const gchar *) exchange_mapi_util_find_array_propval (properties, PR_SENT_REPRESENTING_ADDRTYPE_UNICODE);
 				const gchar *sent_email = (const gchar *) exchange_mapi_util_find_array_propval (properties, PR_SENT_REPRESENTING_EMAIL_ADDRESS_UNICODE);
 
-				if (!g_utf8_collate (sender_email_type, "EX"))
-					sender_email = exchange_mapi_connection_ex_to_smtp (conn, sender_email);
-				if (!g_utf8_collate (sent_email_type, "EX"))
-					sent_email = exchange_mapi_connection_ex_to_smtp (conn, sent_email);
+				if (!g_utf8_collate (sender_email_type, "EX")) {
+					sender_free = exchange_mapi_connection_ex_to_smtp (conn, sender_email, NULL);
+					sender_email = sender_free;
+				}
+				if (!g_utf8_collate (sent_email_type, "EX")) {
+					sent_free = exchange_mapi_connection_ex_to_smtp (conn, sent_email, NULL);
+					sent_email = sent_free;
+				}
 
 				val = g_strdup_printf ("MAILTO:%s", sent_email);
 				prop = icalproperty_new_organizer (val);
@@ -844,6 +848,9 @@ exchange_mapi_cal_util_mapi_props_to_comp (ExchangeMapiConnection *conn, icalcom
 				}
 
 				icalcomponent_add_property (ical_comp, prop);
+
+				g_free (sender_free);
+				g_free (sent_free);
 			}
 		}
 
@@ -1046,12 +1053,12 @@ exchange_mapi_cal_util_camel_helper (ExchangeMapiConnection *conn, mapi_id_t ori
 		exchange_mapi_connection_fetch_object_props (conn, NULL, orig_fid, orig_mid, obj_message,
 					exchange_mapi_cal_utils_get_props_cb, GINT_TO_POINTER (fccd.kind),
 					fetch_camel_cal_comp_cb, &fccd,
-					MAPI_OPTIONS_FETCH_ALL);
+					MAPI_OPTIONS_FETCH_ALL, NULL);
 	else
 		exchange_mapi_connection_fetch_item (conn, orig_fid, orig_mid,
 					exchange_mapi_cal_utils_get_props_cb, GINT_TO_POINTER (fccd.kind),
 					fetch_camel_cal_comp_cb, &fccd,
-					MAPI_OPTIONS_FETCH_ALL);
+					MAPI_OPTIONS_FETCH_ALL, NULL);
 
 	return fccd.result_data;
 }
@@ -1075,7 +1082,7 @@ exchange_mapi_cal_utils_add_named_ids (ExchangeMapiConnection *conn, mapi_id_t f
 	icalcomponent_kind kind = pkind;
 
 	if (!props) {
-		if (!exchange_mapi_connection_resolve_named_props (conn, fid, common_nids, G_N_ELEMENTS (common_nids)))
+		if (!exchange_mapi_connection_resolve_named_props (conn, fid, common_nids, G_N_ELEMENTS (common_nids), NULL))
 			return FALSE;
 	} else if (!exchange_mapi_utils_add_named_ids_to_props_array (conn, fid, mem_ctx, props, common_nids, G_N_ELEMENTS (common_nids)))
 		return FALSE;
@@ -1129,7 +1136,7 @@ appt_build_name_id (ExchangeMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem
 	};
 
 	if (!props)
-		return exchange_mapi_connection_resolve_named_props (conn, fid, nids, G_N_ELEMENTS (nids));
+		return exchange_mapi_connection_resolve_named_props (conn, fid, nids, G_N_ELEMENTS (nids), NULL);
 
 	return exchange_mapi_utils_add_named_ids_to_props_array (conn, fid, mem_ctx, props, nids, G_N_ELEMENTS (nids));
 }
@@ -1158,7 +1165,7 @@ task_build_name_id (ExchangeMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem
 	};
 
 	if (!props)
-		return exchange_mapi_connection_resolve_named_props (conn, fid, nids, G_N_ELEMENTS (nids));
+		return exchange_mapi_connection_resolve_named_props (conn, fid, nids, G_N_ELEMENTS (nids), NULL);
 
 	return exchange_mapi_utils_add_named_ids_to_props_array (conn, fid, mem_ctx, props, nids, G_N_ELEMENTS (nids));
 }
@@ -1174,7 +1181,7 @@ note_build_name_id (ExchangeMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem
 	};
 
 	if (!props)
-		return exchange_mapi_connection_resolve_named_props (conn, fid, nids, G_N_ELEMENTS (nids));
+		return exchange_mapi_connection_resolve_named_props (conn, fid, nids, G_N_ELEMENTS (nids), NULL);
 
 	return exchange_mapi_utils_add_named_ids_to_props_array (conn, fid, mem_ctx, props, nids, G_N_ELEMENTS (nids));
 }
@@ -1788,7 +1795,7 @@ exchange_mapi_cal_util_get_new_appt_id (ExchangeMapiConnection *conn, mapi_id_t
 				mem_ctx,
 				#endif
 				&(res.res.resProperty.lpProp), &sprop);
-			ids = exchange_mapi_connection_check_restriction (conn, fid, 0, &res);
+			ids = exchange_mapi_connection_check_restriction (conn, fid, 0, &res, NULL);
 			if (ids) {
 				GSList *l;
 				for (l = ids; l; l = l->next)
@@ -1930,10 +1937,10 @@ populate_freebusy_data (struct Binary_r *bin, uint32_t month, uint32_t year, GLi
 }
 
 gboolean
-exchange_mapi_cal_utils_get_free_busy_data (ExchangeMapiConnection *conn, GList *users, time_t start, time_t end, GList **freebusy)
+exchange_mapi_cal_utils_get_free_busy_data (ExchangeMapiConnection *conn, GList *users, time_t start, time_t end, GList **freebusy, GError **mapi_error)
 {
 	struct SRow		aRow;
-	enum MAPISTATUS		retval;
+	enum MAPISTATUS		ms;
 	uint32_t		i;
 	mapi_object_t           obj_store;
 	GList *l;
@@ -1956,12 +1963,22 @@ exchange_mapi_cal_utils_get_free_busy_data (ExchangeMapiConnection *conn, GList
 	icaltimetype start_time, end_time;
 	icaltimezone *default_zone = NULL;
 
-	exchange_mapi_connection_get_public_folder (conn, &obj_store);
+	if (!exchange_mapi_connection_get_public_folder (conn, &obj_store, mapi_error)) {
+		return FALSE;
+	}
 	
 	for ( l = users; l != NULL; l = g_list_next (l)) {
-		retval = GetUserFreeBusyData (&obj_store, (const gchar *)l->data, &aRow);
+		ms = GetUserFreeBusyData (&obj_store, (const gchar *)l->data, &aRow);
+
+		if (ms != MAPI_E_SUCCESS) {
+			gchar *context = g_strconcat ("GetUserFreeBusyData for ", l->data, NULL);
 
-		if (retval != MAPI_E_SUCCESS) return false;
+			make_mapi_error (mapi_error, context, ms);
+
+			g_free (context);
+
+			return FALSE;
+		}
 
 		/* Step 2. Dump properties */
 		publish_start = (const uint32_t *) find_SPropValue_data(&aRow, PR_FREEBUSY_START_RANGE);
@@ -2030,6 +2047,7 @@ exchange_mapi_cal_utils_get_free_busy_data (ExchangeMapiConnection *conn, GList
 //		g_object_unref (comp);
 		MAPIFreeBuffer(aRow.lpProps);
 	}
+
 	return TRUE;
 }
 
diff --git a/src/libexchangemapi/exchange-mapi-cal-utils.h b/src/libexchangemapi/exchange-mapi-cal-utils.h
index bc8416d..b5b0500 100644
--- a/src/libexchangemapi/exchange-mapi-cal-utils.h
+++ b/src/libexchangemapi/exchange-mapi-cal-utils.h
@@ -101,7 +101,7 @@ gboolean exchange_mapi_cal_utils_add_named_ids (ExchangeMapiConnection *conn, ma
 gboolean exchange_mapi_cal_utils_get_props_cb (ExchangeMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, struct SPropTagArray *props, gpointer data);
 gboolean exchange_mapi_cal_utils_write_props_cb (ExchangeMapiConnection *conn, mapi_id_t fid, TALLOC_CTX *mem_ctx, struct SPropValue **values, uint32_t *n_values, gpointer data);
 
-gboolean exchange_mapi_cal_utils_get_free_busy_data (ExchangeMapiConnection *conn, GList *users, time_t start, time_t end, GList **freebusy);
+gboolean exchange_mapi_cal_utils_get_free_busy_data (ExchangeMapiConnection *conn, GList *users, time_t start, time_t end, GList **freebusy, GError **mapi_error);
 
 G_END_DECLS
 
diff --git a/src/libexchangemapi/exchange-mapi-connection.c b/src/libexchangemapi/exchange-mapi-connection.c
index 53ba1e4..c3c6e44 100644
--- a/src/libexchangemapi/exchange-mapi-connection.c
+++ b/src/libexchangemapi/exchange-mapi-connection.c
@@ -39,7 +39,7 @@
 
 static void register_connection (ExchangeMapiConnection *conn);
 static void unregister_connection (ExchangeMapiConnection *conn);
-static struct mapi_session *mapi_profile_load (const gchar *profname, const gchar *password);
+static struct mapi_session *mapi_profile_load (const gchar *profname, const gchar *password, GError **perror);
 
 /* GObject foo - begin */
 
@@ -51,6 +51,88 @@ G_DEFINE_TYPE (ExchangeMapiConnection, exchange_mapi_connection, G_TYPE_OBJECT)
 #define LOCK()		g_debug ("%s: %s: lock(session_lock)", G_STRLOC, G_STRFUNC); g_static_rec_mutex_lock (&priv->session_lock);
 #define UNLOCK()	g_debug ("%s: %s: unlock(session_lock)", G_STRLOC, G_STRFUNC); g_static_rec_mutex_unlock (&priv->session_lock);
 
+#define e_return_val_mapi_error_if_fail(expr, _code, _val)				\
+	G_STMT_START {									\
+		if (G_LIKELY(expr)) {							\
+		} else {								\
+			g_log (G_LOG_DOMAIN,						\
+				G_LOG_LEVEL_CRITICAL,					\
+				"file %s: line %d (%s): assertion `%s' failed",		\
+				__FILE__, __LINE__, G_STRFUNC, #expr);			\
+			if (perror)							\
+				g_set_error (perror, E_MAPI_ERROR, (_code),		\
+					"file %s: line %d (%s): assertion `%s' failed",	\
+					__FILE__, __LINE__, G_STRFUNC, #expr);		\
+			return (_val);							\
+		}									\
+	} G_STMT_END
+
+/* Create the EDataCal error quark */
+GQuark
+e_mapi_error_quark (void)
+{
+	static GQuark quark = 0;
+	if (!quark)
+		quark = g_quark_from_static_string ("e_mapi_error");
+	return quark;
+}
+
+void
+make_mapi_error (GError **perror, const gchar *context, enum MAPISTATUS mapi_status)
+{
+	const gchar *error_msg = NULL;
+	gchar *to_free = NULL;
+	GError *error;
+
+	if (!perror)
+		return;
+
+	g_return_if_fail (*perror == NULL);
+
+	switch (mapi_status) {
+	case MAPI_E_SUCCESS:
+		return;
+	#define err(_code, _str)		\
+		case _code:			\
+			error_msg = _str;	\
+			break
+
+	err (MAPI_E_LOGON_FAILED,			_("Failed to login into the server"));
+	err (MAPI_E_SESSION_LIMIT,			_("Cannot create more sessions, session limit was reached"));
+	err (MAPI_E_USER_CANCEL,			_("User cancelled operation"));
+	err (MAPI_E_UNABLE_TO_ABORT,			_("Unable to abort"));
+	err (MAPI_E_NETWORK_ERROR,			_("Network error"));
+	err (MAPI_E_DISK_ERROR,				_("Disk error"));
+	err (MAPI_E_PASSWORD_CHANGE_REQUIRED,		_("Password change required"));
+	err (MAPI_E_PASSWORD_EXPIRED,			_("Password expired"));
+	err (MAPI_E_INVALID_WORKSTATION_ACCOUNT,	_("Invalid workstation account"));
+	err (MAPI_E_INVALID_ACCESS_TIME,		_("Invalid access time"));
+	err (MAPI_E_ACCOUNT_DISABLED,			_("Account is disabled"));
+	err (MAPI_E_END_OF_SESSION,			_("End of session"));
+
+	#undef err
+
+	default:
+		to_free = g_strdup_printf (_("MAPI error %s (0x%x) occurred"), mapi_get_errstr (mapi_status), mapi_status);
+		error_msg = to_free;
+	}
+
+	g_return_if_fail (error_msg != NULL);
+
+	if (context && *context) {
+		/* Translators: The first '%s' is replaced with an error context,
+		   aka where the error occurred, the second '%s' is replaced with
+		   the error message. */
+		error = g_error_new (E_MAPI_ERROR, mapi_status, C_("EXCHANGEMAPI_ERROR", "%s: %s"), context, error_msg);
+	} else {
+		error = g_error_new_literal (E_MAPI_ERROR, mapi_status, error_msg);
+	}
+
+	g_free (to_free);
+
+	g_propagate_error (perror, error);
+}
+
 typedef struct _ExchangeMapiConnectionPrivate ExchangeMapiConnectionPrivate;
 
 struct _ExchangeMapiConnectionPrivate {
@@ -96,20 +178,23 @@ disconnect (ExchangeMapiConnectionPrivate *priv)
 
 /* should have session_lock locked already, when calling this function */
 static gboolean
-ensure_public_store (ExchangeMapiConnectionPrivate *priv)
+ensure_public_store (ExchangeMapiConnectionPrivate *priv, GError **perror)
 {
-	g_return_val_if_fail (priv != NULL, FALSE);
+	e_return_val_mapi_error_if_fail (priv != NULL, MAPI_E_INVALID_PARAMETER, FALSE);
 
 	if (!priv->session)
 		return FALSE;
 
 	if (!priv->has_public_store) {
+		enum MAPISTATUS ms;
+
 		mapi_object_init (&priv->public_store);
 
-		if (OpenPublicFolder (priv->session, &priv->public_store) == MAPI_E_SUCCESS) {
+		ms = OpenPublicFolder (priv->session, &priv->public_store);
+		if (ms == MAPI_E_SUCCESS) {
 			priv->has_public_store = TRUE;
 		} else {
-			mapi_errstr ("OpenPublicFolder", GetLastError());
+			make_mapi_error (perror, "OpenPublicFolder", ms);
 		}
 	}
 
@@ -247,26 +332,27 @@ exchange_mapi_connection_find (const gchar *profile)
 #define STREAM_ACCESS_WRITE     0x0001
 #define STREAM_ACCESS_READWRITE 0x0002
 
-#define CHECK_CORRECT_CONN_AND_GET_PRIV(_conn, _val)				\
-	ExchangeMapiConnectionPrivate *priv;					\
-										\
-	g_return_val_if_fail (_conn != NULL, _val);				\
-	g_return_val_if_fail (EXCHANGE_IS_MAPI_CONNECTION (_conn), _val);	\
-										\
-	priv = EXCHANGE_MAPI_CONNECTION_GET_PRIVATE (_conn);			\
-	g_return_val_if_fail (priv != NULL, _val);
+#define CHECK_CORRECT_CONN_AND_GET_PRIV(_conn, _val)								\
+	ExchangeMapiConnectionPrivate *priv;									\
+														\
+	e_return_val_mapi_error_if_fail (_conn != NULL, MAPI_E_INVALID_PARAMETER, _val); 			\
+	e_return_val_mapi_error_if_fail (EXCHANGE_IS_MAPI_CONNECTION (_conn), MAPI_E_INVALID_PARAMETER, _val);	\
+														\
+	priv = EXCHANGE_MAPI_CONNECTION_GET_PRIVATE (_conn);							\
+	e_return_val_mapi_error_if_fail (priv != NULL, MAPI_E_INVALID_PARAMETER, _val);
 
 /* Creates a new connection object and connects to a server as defined in 'profile' */
 ExchangeMapiConnection *
-exchange_mapi_connection_new (const gchar *profile, const gchar *password)
+exchange_mapi_connection_new (const gchar *profile, const gchar *password, GError **perror)
 {
 	ExchangeMapiConnection *conn;
 	ExchangeMapiConnectionPrivate *priv;
 	struct mapi_session *session;
+	enum MAPISTATUS ms;
 
-	g_return_val_if_fail (profile != NULL, NULL);
+	e_return_val_mapi_error_if_fail (profile != NULL, MAPI_E_INVALID_PARAMETER, NULL);
 
-	session = mapi_profile_load (profile, password);
+	session = mapi_profile_load (profile, password, perror);
 	if (!session) {
 		g_debug ("%s: %s: Login failed ", G_STRLOC, G_STRFUNC);
 		return NULL;
@@ -274,15 +360,16 @@ exchange_mapi_connection_new (const gchar *profile, const gchar *password)
 
 	conn = g_object_new (EXCHANGE_TYPE_MAPI_CONNECTION, NULL);
 	priv = EXCHANGE_MAPI_CONNECTION_GET_PRIVATE (conn);
-	g_return_val_if_fail (priv != NULL, conn);
+	e_return_val_mapi_error_if_fail (priv != NULL, MAPI_E_INVALID_PARAMETER, conn);
 
 	LOCK ();
 	mapi_object_init (&priv->msg_store);
 	priv->session = session;
 
 	/* Open the message store and keep it opened for all the life-time for this connection */
-	if (OpenMsgStore (priv->session, &priv->msg_store) != MAPI_E_SUCCESS) {
-		mapi_errstr ("OpenMsgStore", GetLastError());
+	ms = OpenMsgStore (priv->session, &priv->msg_store);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "OpenMsgStore", ms);
 
 		/* how to close and free session without store? */
 		priv->session = NULL;
@@ -305,6 +392,8 @@ gboolean
 exchange_mapi_connection_close (ExchangeMapiConnection *conn)
 {
 	gboolean res = FALSE;
+	/* to have this used in the below macros */
+	GError **perror = NULL;
 
 	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, FALSE);
 
@@ -319,17 +408,19 @@ exchange_mapi_connection_close (ExchangeMapiConnection *conn)
 }
 
 gboolean
-exchange_mapi_connection_reconnect (ExchangeMapiConnection *conn, const gchar *password)
+exchange_mapi_connection_reconnect (ExchangeMapiConnection *conn, const gchar *password, GError **perror)
 {
+	enum MAPISTATUS ms;
+
 	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, FALSE);
 
-	g_return_val_if_fail (priv->profile != NULL, FALSE);
+	e_return_val_mapi_error_if_fail (priv->profile != NULL, MAPI_E_INVALID_PARAMETER, FALSE);
 
 	LOCK ();
 	if (priv->session)
 		exchange_mapi_connection_close (conn);
 
-	priv->session = mapi_profile_load (priv->profile, password);
+	priv->session = mapi_profile_load (priv->profile, password, perror);
 	if (!priv->session) {
 		g_debug ("%s: %s: Login failed ", G_STRLOC, G_STRFUNC);
 		UNLOCK ();
@@ -339,8 +430,9 @@ exchange_mapi_connection_reconnect (ExchangeMapiConnection *conn, const gchar *p
 	mapi_object_init (&priv->msg_store);
 
 	/* Open the message store and keep it opened for all the life-time for this connection */
-	if (OpenMsgStore (priv->session, &priv->msg_store) != MAPI_E_SUCCESS) {
-		mapi_errstr ("OpenMsgStore", GetLastError());
+	ms = OpenMsgStore (priv->session, &priv->msg_store);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "OpenMsgStore", ms);
 
 		/* how to close and free session without store? */
 		priv->session = NULL;
@@ -361,15 +453,18 @@ exchange_mapi_connection_reconnect (ExchangeMapiConnection *conn, const gchar *p
 gboolean
 exchange_mapi_connection_connected (ExchangeMapiConnection *conn)
 {
+	/* to have this used in the below macros */
+	GError **perror = NULL;
+
 	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, FALSE);
 
 	return priv->session != NULL;
 }
 
 static gboolean
-exchange_mapi_util_read_generic_stream (mapi_object_t *obj_message, const uint32_t *cpid, uint32_t proptag, GSList **stream_list)
+exchange_mapi_util_read_generic_stream (mapi_object_t *obj_message, const uint32_t *cpid, uint32_t proptag, GSList **stream_list, GError **perror)
 {
-	enum MAPISTATUS	retval;
+	enum MAPISTATUS	ms;
 	TALLOC_CTX	*mem_ctx;
 	mapi_object_t	obj_stream;
 	uint16_t	cn_read = 0;
@@ -379,8 +474,8 @@ exchange_mapi_util_read_generic_stream (mapi_object_t *obj_message, const uint32
 	gboolean	done = FALSE;
 
 	/* sanity */
-	g_return_val_if_fail (obj_message, FALSE);
-	g_return_val_if_fail (((proptag & 0xFFFF) == PT_BINARY), FALSE);
+	e_return_val_mapi_error_if_fail (obj_message, MAPI_E_INVALID_PARAMETER, FALSE);
+	e_return_val_mapi_error_if_fail (((proptag & 0xFFFF) == PT_BINARY), MAPI_E_INVALID_PARAMETER, FALSE);
 
 	/* if compressed RTF stream, then return */
 	if (proptag == PR_RTF_COMPRESSED)
@@ -393,17 +488,17 @@ exchange_mapi_util_read_generic_stream (mapi_object_t *obj_message, const uint32
 	mapi_object_init(&obj_stream);
 
 	/* get a stream on specified proptag */
-	retval = OpenStream(obj_message, proptag, STREAM_ACCESS_READ, &obj_stream);
-	if (retval != MAPI_E_SUCCESS) {
+	ms = OpenStream(obj_message, proptag, STREAM_ACCESS_READ, &obj_stream);
+	if (ms != MAPI_E_SUCCESS) {
 	/* If OpenStream failed, should we attempt any other call(s) to fetch the blob? */
-		mapi_errstr("OpenStream", GetLastError());
+		make_mapi_error (perror, "OpenStream", ms);
 		goto cleanup;
 	}
 
 	/* NOTE: This may prove unreliable for streams larger than 4GB length */
-	retval = GetStreamSize(&obj_stream, &buf_size);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("GetStreamSize", GetLastError());
+	ms = GetStreamSize(&obj_stream, &buf_size);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "GetStreamSize", ms);
 		goto cleanup;
 	}
 
@@ -413,12 +508,9 @@ exchange_mapi_util_read_generic_stream (mapi_object_t *obj_message, const uint32
 
 	/* Read from the stream */
 	while (!done) {
-		retval = ReadStream(&obj_stream,
-				    (buf_data) + off_data,
-				    STREAM_MAX_READ_SIZE,
-				    &cn_read);
-		if (retval != MAPI_E_SUCCESS) {
-			mapi_errstr("ReadStream", GetLastError());
+		ms = ReadStream (&obj_stream, (buf_data) + off_data, STREAM_MAX_READ_SIZE, &cn_read);
+		if (ms != MAPI_E_SUCCESS) {
+			make_mapi_error (perror, "ReadStream", ms);
 			done = TRUE;
 		} else if (cn_read == 0) {
 			done = TRUE;
@@ -429,7 +521,7 @@ exchange_mapi_util_read_generic_stream (mapi_object_t *obj_message, const uint32
 		}
 	};
 
-	if (retval == MAPI_E_SUCCESS) {
+	if (ms == MAPI_E_SUCCESS) {
 		ExchangeMAPIStream		*stream = g_new0 (ExchangeMAPIStream, 1);
 		struct mapi_SPropValue_array	properties_array;
 
@@ -475,13 +567,13 @@ cleanup:
 
 	g_debug("%s: Leaving %s ", G_STRLOC, G_STRFUNC);
 
-	return (retval == MAPI_E_SUCCESS);
+	return (ms == MAPI_E_SUCCESS);
 }
 
 static gboolean
-exchange_mapi_util_read_body_stream (mapi_object_t *obj_message, GSList **stream_list, gboolean getbestbody)
+exchange_mapi_util_read_body_stream (mapi_object_t *obj_message, GSList **stream_list, gboolean getbestbody, GError **perror)
 {
-	enum MAPISTATUS			retval;
+	enum MAPISTATUS			ms;
 	TALLOC_CTX			*mem_ctx;
 	struct SPropTagArray		*SPropTagArray;
 	struct SPropValue		*lpProps;
@@ -493,7 +585,7 @@ exchange_mapi_util_read_body_stream (mapi_object_t *obj_message, GSList **stream
 	uint32_t			proptag = 0;
 
 	/* sanity check */
-	g_return_val_if_fail (obj_message, FALSE);
+	e_return_val_mapi_error_if_fail (obj_message, MAPI_E_INVALID_PARAMETER, FALSE);
 
 	g_debug("%s: Entering %s ", G_STRLOC, G_STRFUNC);
 
@@ -510,19 +602,19 @@ exchange_mapi_util_read_body_stream (mapi_object_t *obj_message, GSList **stream
 					  PR_RTF_IN_SYNC);
 
 	lpProps = talloc_zero(mem_ctx, struct SPropValue);
-	retval = GetProps(obj_message, SPropTagArray, &lpProps, &count);
+	ms = GetProps (obj_message, SPropTagArray, &lpProps, &count);
 	MAPIFreeBuffer(SPropTagArray);
 
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("GetProps", GetLastError());
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "GetProps", ms);
 		return FALSE;
 	}
 
 	if (getbestbody) {
 		/* Use BestBody Algo */
-		retval = GetBestBody(obj_message, &editor);
-		if (retval != MAPI_E_SUCCESS) {
-			mapi_errstr("GetBestBody", GetLastError());
+		ms = GetBestBody (obj_message, &editor);
+		if (ms != MAPI_E_SUCCESS) {
+			make_mapi_error (perror, "GetBestBody", ms);
 			/* On failure, fallback to Plain Text */
 			editor = olEditorText;
 		}
@@ -540,7 +632,7 @@ exchange_mapi_util_read_body_stream (mapi_object_t *obj_message, GSList **stream
 	body.data = NULL;
 	body.length = 0;
 
-	retval = -1;
+	ms = -1;
 	switch (editor) {
 		case olEditorText:
 			if ((data = (const gchar *) exchange_mapi_util_find_SPropVal_array_propval (lpProps, PR_BODY_UNICODE)) != NULL)
@@ -551,7 +643,7 @@ exchange_mapi_util_read_body_stream (mapi_object_t *obj_message, GSList **stream
 				gsize size = strlen(data)+1;
 				body.data = talloc_memdup(mem_ctx, data, size);
 				body.length = size;
-				retval = MAPI_E_SUCCESS;
+				ms = MAPI_E_SUCCESS;
 			}
 			break;
 		case olEditorHTML:
@@ -565,9 +657,9 @@ exchange_mapi_util_read_body_stream (mapi_object_t *obj_message, GSList **stream
 				gsize size = strlen(data)+1;
 				body.data = talloc_memdup(mem_ctx, data, size);
 				body.length = size;
-				retval = MAPI_E_SUCCESS;
-			} else if (exchange_mapi_util_read_generic_stream (obj_message, exchange_mapi_util_find_SPropVal_array_propval (lpProps, PR_INTERNET_CPID), PR_HTML, stream_list)) {
-				retval = MAPI_E_SUCCESS;
+				ms = MAPI_E_SUCCESS;
+			} else if (exchange_mapi_util_read_generic_stream (obj_message, exchange_mapi_util_find_SPropVal_array_propval (lpProps, PR_INTERNET_CPID), PR_HTML, stream_list, NULL)) {
+				ms = MAPI_E_SUCCESS;
 			}
 			break;
 		case olEditorRTF:
@@ -578,16 +670,16 @@ exchange_mapi_util_read_body_stream (mapi_object_t *obj_message, GSList **stream
 
 				mapi_object_init(&obj_stream);
 
-				retval = OpenStream(obj_message, PR_RTF_COMPRESSED, STREAM_ACCESS_READ, &obj_stream);
-				if (retval != MAPI_E_SUCCESS) {
-					mapi_errstr("OpenStream", GetLastError());
+				ms = OpenStream(obj_message, PR_RTF_COMPRESSED, STREAM_ACCESS_READ, &obj_stream);
+				if (ms != MAPI_E_SUCCESS) {
+					make_mapi_error (perror, "OpenStream", ms);
 					mapi_object_release(&obj_stream);
 					break;
 				}
 
-				retval = WrapCompressedRTFStream(&obj_stream, &body);
-				if (retval != MAPI_E_SUCCESS) {
-					mapi_errstr("WrapCompressedRTFStream", GetLastError());
+				ms = WrapCompressedRTFStream(&obj_stream, &body);
+				if (ms != MAPI_E_SUCCESS) {
+					make_mapi_error (perror, "WrapCompressedRTFStream", ms);
 					mapi_object_release(&obj_stream);
 					break;
 				}
@@ -601,7 +693,7 @@ exchange_mapi_util_read_body_stream (mapi_object_t *obj_message, GSList **stream
 			break;
 	}
 
-	if (retval == MAPI_E_SUCCESS && proptag) {
+	if (ms == MAPI_E_SUCCESS && proptag) {
 		ExchangeMAPIStream	*stream = g_new0 (ExchangeMAPIStream, 1);
 
 		stream->value = g_byte_array_sized_new (body.length);
@@ -616,15 +708,15 @@ exchange_mapi_util_read_body_stream (mapi_object_t *obj_message, GSList **stream
 
 	g_debug("%s: Leaving %s ", G_STRLOC, G_STRFUNC);
 
-	return (retval == MAPI_E_SUCCESS);
+	return (ms == MAPI_E_SUCCESS) && (!perror || !*perror);
 }
 
 /* Returns TRUE if all streams were written succcesfully, else returns FALSE */
 static gboolean
-exchange_mapi_util_write_generic_streams (mapi_object_t *obj_message, GSList *stream_list)
+exchange_mapi_util_write_generic_streams (mapi_object_t *obj_message, GSList *stream_list, GError **perror)
 {
 	GSList		*l;
-	enum MAPISTATUS	retval;
+	enum MAPISTATUS	ms;
 	gboolean	status = TRUE;
 
 	g_debug("%s: Entering %s ", G_STRLOC, G_STRFUNC);
@@ -638,16 +730,16 @@ exchange_mapi_util_write_generic_streams (mapi_object_t *obj_message, GSList *st
 		mapi_object_init(&obj_stream);
 
 		/* OpenStream on required proptag */
-		retval = OpenStream(obj_message, stream->proptag, STREAM_ACCESS_READWRITE, &obj_stream);
-		if (retval != MAPI_E_SUCCESS) {
-			mapi_errstr("OpenStream", GetLastError());
+		ms = OpenStream (obj_message, stream->proptag, STREAM_ACCESS_READWRITE, &obj_stream);
+		if (ms != MAPI_E_SUCCESS) {
+			make_mapi_error (perror, "OpenStream", ms);
 			goto cleanup;
 		}
 
 		/* Set the stream size */
-		retval = SetStreamSize(&obj_stream, stream->value->len);
-		if (retval != MAPI_E_SUCCESS) {
-			mapi_errstr("SetStreamSize", GetLastError());
+		ms = SetStreamSize (&obj_stream, stream->value->len);
+		if (ms != MAPI_E_SUCCESS) {
+			make_mapi_error (perror, "SetStreamSize", ms);
 			goto cleanup;
 		}
 
@@ -661,12 +753,10 @@ exchange_mapi_util_write_generic_streams (mapi_object_t *obj_message, GSList *st
 					(stream->value->len - total_written) : STREAM_MAX_WRITE_SIZE;
 			blob.data = (stream->value->data) + total_written;
 
-			retval = WriteStream(&obj_stream,
-					     &blob,
-					     &cn_written);
+			ms = WriteStream (&obj_stream, &blob, &cn_written);
 
-			if (retval != MAPI_E_SUCCESS) {
-				mapi_errstr("WriteStream", GetLastError());
+			if (ms != MAPI_E_SUCCESS) {
+				make_mapi_error (perror, "WriteStream", ms);
 				done = TRUE;
 			} else if (cn_written == 0) {
 				done = TRUE;
@@ -678,14 +768,14 @@ exchange_mapi_util_write_generic_streams (mapi_object_t *obj_message, GSList *st
 		}
 
 		/* Commit the stream */
-		retval = CommitStream(&obj_stream);
-		if (retval != MAPI_E_SUCCESS) {
-			mapi_errstr("CommitStream", GetLastError());
+		ms = CommitStream (&obj_stream);
+		if (ms != MAPI_E_SUCCESS) {
+			make_mapi_error (perror, "CommitStream", ms);
 			goto cleanup;
 		}
 
 	cleanup:
-		if (retval != MAPI_E_SUCCESS)
+		if (ms != MAPI_E_SUCCESS)
 			status = FALSE;
 		mapi_object_release(&obj_stream);
 	}
@@ -696,9 +786,9 @@ exchange_mapi_util_write_generic_streams (mapi_object_t *obj_message, GSList *st
 }
 
 static gboolean
-exchange_mapi_util_delete_attachments (mapi_object_t *obj_message)
+exchange_mapi_util_delete_attachments (mapi_object_t *obj_message, GError **perror)
 {
-	enum MAPISTATUS		retval;
+	enum MAPISTATUS		ms;
 	TALLOC_CTX		*mem_ctx;
 	mapi_object_t		obj_tb_attach;
 	struct SPropTagArray	*proptags;
@@ -720,27 +810,27 @@ exchange_mapi_util_delete_attachments (mapi_object_t *obj_message)
 	mapi_object_init(&obj_tb_attach);
 
 	/* open attachment table */
-	retval = GetAttachmentTable(obj_message, &obj_tb_attach);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("GetAttachmentTable", GetLastError());
+	ms = GetAttachmentTable (obj_message, &obj_tb_attach);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "GetAttachmentTable", ms);
 		goto cleanup;
 	}
 
-	retval = SetColumns(&obj_tb_attach, proptags);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("SetColumns", GetLastError());
+	ms = SetColumns (&obj_tb_attach, proptags);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "SetColumns", ms);
 		goto cleanup;
 	}
 
-	retval = QueryPosition(&obj_tb_attach, NULL, &attach_count);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("QueryPosition", GetLastError());
+	ms = QueryPosition (&obj_tb_attach, NULL, &attach_count);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "QueryPosition", ms);
 		goto cleanup;
 	}
 
-	retval = QueryRows(&obj_tb_attach, attach_count, TBL_ADVANCE, &rows_attach);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("QueryRows", GetLastError());
+	ms = QueryRows (&obj_tb_attach, attach_count, TBL_ADVANCE, &rows_attach);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "QueryRows", ms);
 		goto cleanup;
 	}
 
@@ -750,15 +840,15 @@ exchange_mapi_util_delete_attachments (mapi_object_t *obj_message)
 
 		num_attach = (const uint32_t *) get_SPropValue_SRow_data(&rows_attach.aRow[i_row_attach], PR_ATTACH_NUM);
 
-		retval = DeleteAttach(obj_message, *num_attach);
-		if (retval != MAPI_E_SUCCESS) {
-			mapi_errstr("DeleteAttach", GetLastError());
+		ms = DeleteAttach (obj_message, *num_attach);
+		if (ms != MAPI_E_SUCCESS) {
+			make_mapi_error (perror, "DeleteAttach", ms);
 			status = FALSE;
 		}
 	}
 
 cleanup:
-	if (retval != MAPI_E_SUCCESS)
+	if (ms != MAPI_E_SUCCESS)
 		status = FALSE;
 	mapi_object_release(&obj_tb_attach);
 	talloc_free (mem_ctx);
@@ -770,17 +860,17 @@ cleanup:
 
 /* Returns TRUE if all attachments were written succcesfully, else returns FALSE */
 static gboolean
-exchange_mapi_util_set_attachments (mapi_object_t *obj_message, GSList *attach_list, gboolean remove_existing)
+exchange_mapi_util_set_attachments (mapi_object_t *obj_message, GSList *attach_list, gboolean remove_existing, GError **perror)
 {
 //	TALLOC_CTX	*mem_ctx;
 	GSList		*l;
-	enum MAPISTATUS	retval;
-	gboolean	status = TRUE;
+	enum MAPISTATUS	ms;
+	gboolean	status = FALSE;
 
 	g_debug("%s: Entering %s ", G_STRLOC, G_STRFUNC);
 
 	if (remove_existing)
-		exchange_mapi_util_delete_attachments (obj_message);
+		exchange_mapi_util_delete_attachments (obj_message, NULL);
 
 //	mem_ctx = talloc_init ("ExchangeMAPI_SetAttachments");
 
@@ -791,32 +881,33 @@ exchange_mapi_util_set_attachments (mapi_object_t *obj_message, GSList *attach_l
 		mapi_object_init(&obj_attach);
 
 		/* CreateAttach */
-		retval = CreateAttach(obj_message, &obj_attach);
-		if (retval != MAPI_E_SUCCESS) {
-			mapi_errstr("CreateAttach", GetLastError());
+		ms = CreateAttach (obj_message, &obj_attach);
+		if (ms != MAPI_E_SUCCESS) {
+			make_mapi_error (perror, "CreateAttach", ms);
 			goto cleanup;
 		}
 
 		/* SetProps */
-		retval = SetProps(&obj_attach, attachment->lpProps, attachment->cValues);
-		if (retval != MAPI_E_SUCCESS) {
-			mapi_errstr("SetProps", GetLastError());
+		ms = SetProps (&obj_attach, attachment->lpProps, attachment->cValues);
+		if (ms != MAPI_E_SUCCESS) {
+			make_mapi_error (perror, "SetProps", ms);
 			goto cleanup;
 		}
 
 		/* If there are any streams to be set, write them. */
-		exchange_mapi_util_write_generic_streams (&obj_attach, attachment->streams);
+		if (!exchange_mapi_util_write_generic_streams (&obj_attach, attachment->streams, perror))
+			goto cleanup;
 
 		/* message->SaveChangesAttachment() */
-		retval = SaveChangesAttachment(obj_message, &obj_attach, KeepOpenReadWrite);
-		if (retval != MAPI_E_SUCCESS) {
-			mapi_errstr("SaveChangesAttachment", GetLastError());
+		ms = SaveChangesAttachment (obj_message, &obj_attach, KeepOpenReadWrite);
+		if (ms != MAPI_E_SUCCESS) {
+			make_mapi_error (perror, "SaveChangesAttachment", ms);
 			goto cleanup;
 		}
 
+		status = TRUE;
+
 	cleanup:
-		if (retval != MAPI_E_SUCCESS)
-			status = FALSE;
 		mapi_object_release(&obj_attach);
 	}
 
@@ -839,7 +930,7 @@ obj_message_to_camel_mime (ExchangeMapiConnection *conn, mapi_id_t fid, mapi_obj
 
 	if (!exchange_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)
+					MAPI_OPTIONS_FETCH_ALL | MAPI_OPTIONS_GETBESTBODY, NULL)
 	    || item == NULL) {
 		if (item)
 			mail_item_free (item);
@@ -868,9 +959,9 @@ obj_message_to_camel_mime (ExchangeMapiConnection *conn, mapi_id_t fid, mapi_obj
 
 /* Returns TRUE if all attachments were read succcesfully, else returns FALSE */
 static gboolean
-exchange_mapi_util_get_attachments (ExchangeMapiConnection *conn, mapi_id_t fid, mapi_object_t *obj_message, GSList **attach_list)
+exchange_mapi_util_get_attachments (ExchangeMapiConnection *conn, mapi_id_t fid, mapi_object_t *obj_message, GSList **attach_list, GError **perror)
 {
-	enum MAPISTATUS		retval;
+	enum MAPISTATUS		ms;
 	TALLOC_CTX		*mem_ctx;
 	mapi_object_t		obj_tb_attach;
 	struct SPropTagArray	*proptags;
@@ -893,27 +984,27 @@ exchange_mapi_util_get_attachments (ExchangeMapiConnection *conn, mapi_id_t fid,
 	mapi_object_init(&obj_tb_attach);
 
 	/* open attachment table */
-	retval = GetAttachmentTable(obj_message, &obj_tb_attach);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("GetAttachmentTable", GetLastError());
+	ms = GetAttachmentTable (obj_message, &obj_tb_attach);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "GetAttachmentTable", ms);
 		goto cleanup;
 	}
 
-	retval = SetColumns(&obj_tb_attach, proptags);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("SetColumns", GetLastError());
+	ms = SetColumns (&obj_tb_attach, proptags);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "SetColumns", ms);
 		goto cleanup;
 	}
 
-	retval = QueryPosition(&obj_tb_attach, NULL, &attach_count);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("QueryPosition", GetLastError());
+	ms = QueryPosition (&obj_tb_attach, NULL, &attach_count);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "QueryPosition", ms);
 		goto cleanup;
 	}
 
-	retval = QueryRows(&obj_tb_attach, attach_count, TBL_ADVANCE, &rows_attach);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("QueryRows", GetLastError());
+	ms = QueryRows (&obj_tb_attach, attach_count, TBL_ADVANCE, &rows_attach);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "QueryRows", ms);
 		goto cleanup;
 	}
 
@@ -929,15 +1020,15 @@ exchange_mapi_util_get_attachments (ExchangeMapiConnection *conn, mapi_id_t fid,
 
 		ui32 = (const uint32_t *) get_SPropValue_SRow_data(&rows_attach.aRow[i_row_attach], PR_ATTACH_NUM);
 
-		retval = OpenAttach(obj_message, *ui32, &obj_attach);
-		if (retval != MAPI_E_SUCCESS) {
-			mapi_errstr("OpenAttach", GetLastError());
+		ms = OpenAttach (obj_message, *ui32, &obj_attach);
+		if (ms != MAPI_E_SUCCESS) {
+			make_mapi_error (perror, "OpenAttach", ms);
 			goto loop_cleanup;
 		}
 
-		retval = GetPropsAll (&obj_attach, &properties);
-		if (retval != MAPI_E_SUCCESS) {
-			mapi_errstr("GetPropsAll", GetLastError());
+		ms = GetPropsAll (&obj_attach, &properties);
+		if (ms != MAPI_E_SUCCESS) {
+			make_mapi_error (perror, "GetPropsAll", ms);
 			goto loop_cleanup;
 		}
 
@@ -968,13 +1059,14 @@ exchange_mapi_util_get_attachments (ExchangeMapiConnection *conn, mapi_id_t fid,
 
 		/* just to get all the other streams */
 		for (z=0; z < properties.cValues; z++) {
-			if ((properties.lpProps[z].ulPropTag & 0xFFFF) == PT_BINARY)
-				exchange_mapi_util_read_generic_stream (&obj_attach, exchange_mapi_util_find_array_propval (&properties, PR_INTERNET_CPID), properties.lpProps[z].ulPropTag, &(attachment->streams));
+			if ((properties.lpProps[z].ulPropTag & 0xFFFF) == PT_BINARY) {
+				exchange_mapi_util_read_generic_stream (&obj_attach, exchange_mapi_util_find_array_propval (&properties, PR_INTERNET_CPID), properties.lpProps[z].ulPropTag, &(attachment->streams), NULL);
+			}
 		}
 
 		ui32 = (const uint32_t *) get_SPropValue_SRow_data(&rows_attach.aRow[i_row_attach], PR_ATTACH_METHOD);
 		if (ui32 && *ui32 == ATTACH_BY_VALUE) {
-			exchange_mapi_util_read_generic_stream (&obj_attach, exchange_mapi_util_find_array_propval (&properties, PR_INTERNET_CPID), PR_ATTACH_DATA_BIN, &(attachment->streams));
+			exchange_mapi_util_read_generic_stream (&obj_attach, exchange_mapi_util_find_array_propval (&properties, PR_INTERNET_CPID), PR_ATTACH_DATA_BIN, &(attachment->streams), NULL);
 		} else if (ui32 && *ui32 == ATTACH_EMBEDDED_MSG) {
 			mapi_object_t obj_emb_msg;
 
@@ -1010,13 +1102,13 @@ exchange_mapi_util_get_attachments (ExchangeMapiConnection *conn, mapi_id_t fid,
 		*attach_list = g_slist_append (*attach_list, attachment);
 
 	loop_cleanup:
-		if (retval != MAPI_E_SUCCESS)
+		if (ms != MAPI_E_SUCCESS)
 			status = FALSE;
 		mapi_object_release(&obj_attach);
 	}
 
 cleanup:
-	if (retval != MAPI_E_SUCCESS)
+	if (ms != MAPI_E_SUCCESS)
 		status = FALSE;
 	mapi_object_release(&obj_tb_attach);
 	talloc_free (mem_ctx);
@@ -1027,53 +1119,53 @@ cleanup:
 }
 
 gboolean
-exchange_mapi_connection_fetch_gal (ExchangeMapiConnection *conn, BuildReadPropsCB build_props, gpointer brp_data, FetchGALCallback cb, gpointer data)
+exchange_mapi_connection_fetch_gal (ExchangeMapiConnection *conn, BuildReadPropsCB build_props, gpointer brp_data, FetchGALCallback cb, gpointer data, GError **perror)
 {
 	struct SPropTagArray	*propsTagArray;
 	struct SRowSet		*aRowSet;
-	enum MAPISTATUS		retval;
+	enum MAPISTATUS		ms;
 	uint32_t		i, count, n_rows = 0;
 	uint8_t			ulFlags;
 	TALLOC_CTX *mem_ctx;
 
 	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, FALSE);
-	g_return_val_if_fail (build_props != NULL, FALSE);
-	g_return_val_if_fail (cb != NULL, FALSE);
+	e_return_val_mapi_error_if_fail (build_props != NULL, MAPI_E_INVALID_PARAMETER, FALSE);
+	e_return_val_mapi_error_if_fail (cb != NULL, MAPI_E_INVALID_PARAMETER, FALSE);
 
 	mem_ctx = talloc_init ("ExchangeMAPI_FetchGAL");
 
 	LOCK ();
 
 	#ifdef HAVE_GETGALTABLECOUNT
-	retval = GetGALTableCount (priv->session, &n_rows);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr ("GetGALTableCount", GetLastError ());
+	ms = GetGALTableCount (priv->session, &n_rows);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "GetGALTableCount", ms);
 		n_rows = 0;
 	}
 	#endif
 
 	propsTagArray = set_SPropTagArray (mem_ctx, 0x1, PR_MESSAGE_CLASS);
 	if (!build_props (conn, 0, mem_ctx, propsTagArray, brp_data)) {
-		mapi_errstr ("build_props", GetLastError ());
+		make_mapi_error (perror, "build_props", MAPI_E_CALL_FAILED);
 		UNLOCK();
 		talloc_free (mem_ctx);
 		return FALSE;
 	}
 
-	retval = MAPI_E_SUCCESS;
+	ms = MAPI_E_SUCCESS;
 	count = 0;
 	ulFlags = TABLE_START;
-	while (retval == MAPI_E_SUCCESS) {
+	while (ms == MAPI_E_SUCCESS) {
 		aRowSet = NULL;
 		/* fetch per 10 items */
-		retval = GetGALTable (priv->session, propsTagArray, &aRowSet, 10, ulFlags);
-		if ((!aRowSet) || (!(aRowSet->aRow)) || retval != MAPI_E_SUCCESS) {
+		ms = GetGALTable (priv->session, propsTagArray, &aRowSet, 10, ulFlags);
+		if ((!aRowSet) || (!(aRowSet->aRow)) || ms != MAPI_E_SUCCESS) {
 			break;
 		}
 		if (aRowSet->cRows) {
 			for (i = 0; i < aRowSet->cRows; i++, count++) {
 				if (!cb (conn, count, n_rows, &aRowSet->aRow[i], data)) {
-					retval = MAPI_E_RESERVED;
+					ms = MAPI_E_RESERVED;
 					break;
 				}
 			}
@@ -1090,38 +1182,41 @@ exchange_mapi_connection_fetch_gal (ExchangeMapiConnection *conn, BuildReadProps
 
 	UNLOCK ();
 
-	return retval == MAPI_E_SUCCESS;
+	if (ms != MAPI_E_SUCCESS && ms != MAPI_E_RESERVED)
+		make_mapi_error (perror, "GetGALTable", ms);
+
+	return ms == MAPI_E_SUCCESS;
 }
 
 gboolean
-exchange_mapi_connection_get_public_folder (ExchangeMapiConnection *conn, mapi_object_t *obj_store)
+exchange_mapi_connection_get_public_folder (ExchangeMapiConnection *conn, mapi_object_t *obj_store, GError **perror)
 {
-	enum MAPISTATUS retval;
+	enum MAPISTATUS ms;
 
 	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, FALSE);
-	g_return_val_if_fail (priv->session != NULL, FALSE);
+	e_return_val_mapi_error_if_fail (priv->session != NULL, MAPI_E_INVALID_PARAMETER, FALSE);
 
 	LOCK ();
 
 	mapi_object_init (&priv->public_store);
 
-	retval = OpenPublicFolder (priv->session, &priv->public_store);
+	ms = OpenPublicFolder (priv->session, &priv->public_store);
 
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr ("OpenPublicFolder", GetLastError());
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "OpenPublicFolder", ms);
 	}
 
 	*obj_store = priv->public_store;
 	UNLOCK ();
 
-	return retval == MAPI_E_SUCCESS;
+	return ms == MAPI_E_SUCCESS;
 }
 
 /* Returns TRUE if all recipients were read succcesfully, else returns FALSE */
 static gboolean
-exchange_mapi_util_get_recipients (mapi_object_t *obj_message, GSList **recip_list)
+exchange_mapi_util_get_recipients (mapi_object_t *obj_message, GSList **recip_list, GError **perror)
 {
-	enum MAPISTATUS		retval;
+	enum MAPISTATUS		ms;
 	struct SPropTagArray	proptags;
 	struct SRowSet		rows_recip;
 	uint32_t		i_row_recip;
@@ -1130,9 +1225,9 @@ exchange_mapi_util_get_recipients (mapi_object_t *obj_message, GSList **recip_li
 	g_debug("%s: Entering %s ", G_STRLOC, G_STRFUNC);
 
 	/* fetch recipient table */
-	retval = GetRecipientTable(obj_message, &rows_recip, &proptags);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("GetRecipientTable", GetLastError());
+	ms = GetRecipientTable (obj_message, &rows_recip, &proptags);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "GetRecipientTable", ms);
 		goto cleanup;
 	}
 
@@ -1157,7 +1252,7 @@ exchange_mapi_util_get_recipients (mapi_object_t *obj_message, GSList **recip_li
 	}
 
 cleanup:
-	if (retval != MAPI_E_SUCCESS)
+	if (ms != MAPI_E_SUCCESS)
 		status = FALSE;
 
 	g_debug("%s: Leaving %s ", G_STRLOC, G_STRFUNC);
@@ -1199,9 +1294,9 @@ set_recipient_properties (TALLOC_CTX *mem_ctx, struct SRow *aRow, ExchangeMAPIRe
 }
 
 static gboolean
-exchange_mapi_util_modify_recipients (ExchangeMapiConnection *conn, TALLOC_CTX *mem_ctx, mapi_object_t *obj_message , GSList *recipients, gboolean remove_existing)
+exchange_mapi_util_modify_recipients (ExchangeMapiConnection *conn, TALLOC_CTX *mem_ctx, mapi_object_t *obj_message , GSList *recipients, gboolean remove_existing, GError **perror)
 {
-	enum MAPISTATUS	retval;
+	enum MAPISTATUS	ms;
 	struct SPropTagArray	*SPropTagArray = NULL;
 	struct SRowSet		*SRowSet = NULL;
 	struct SPropTagArray	*FlagList = NULL;
@@ -1210,7 +1305,7 @@ exchange_mapi_util_modify_recipients (ExchangeMapiConnection *conn, TALLOC_CTX *
 	uint32_t		i, j, count = 0;
 
 	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, FALSE);
-	g_return_val_if_fail (priv->session != NULL, FALSE);
+	e_return_val_mapi_error_if_fail (priv->session != NULL, MAPI_E_INVALID_PARAMETER, FALSE);
 
 	g_debug("%s: Entering %s ", G_STRLOC, G_STRFUNC);
 
@@ -1236,10 +1331,10 @@ exchange_mapi_util_modify_recipients (ExchangeMapiConnection *conn, TALLOC_CTX *
 
 	/* Attempt to resolve names from the server */
 	LOCK ();
-	retval = ResolveNames (priv->session, users, SPropTagArray, &SRowSet, &FlagList, MAPI_UNICODE);
+	ms = ResolveNames (priv->session, users, SPropTagArray, &SRowSet, &FlagList, MAPI_UNICODE);
 	UNLOCK ();
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("ResolveNames", GetLastError());
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "ResolveNames", ms);
 		goto cleanup;
 	}
 
@@ -1271,17 +1366,17 @@ exchange_mapi_util_modify_recipients (ExchangeMapiConnection *conn, TALLOC_CTX *
 	}
 
 	if (remove_existing) {
-		RemoveAllRecipients (obj_message);
-		if (retval != MAPI_E_SUCCESS) {
-			mapi_errstr("RemoveAllRecipients", GetLastError());
+		ms = RemoveAllRecipients (obj_message);
+		if (ms != MAPI_E_SUCCESS) {
+			make_mapi_error (perror, "RemoveAllRecipients", ms);
 			goto cleanup;
 		}
 	}
 
 	/* Modify the recipient table */
-	retval = ModifyRecipients (obj_message, SRowSet);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("ModifyRecpients", GetLastError());
+	ms = ModifyRecipients (obj_message, SRowSet);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "ModifyRecpients", ms);
 		goto cleanup;
 	}
 
@@ -1294,34 +1389,41 @@ cleanup:
 }
 
 static enum MAPISTATUS
-open_folder (ExchangeMapiConnection *conn, uint32_t olFolder, mapi_id_t *fid, guint32 fid_options, mapi_object_t *obj_folder)
+open_folder (ExchangeMapiConnection *conn, uint32_t olFolder, mapi_id_t *fid, guint32 fid_options, mapi_object_t *obj_folder, GError **perror)
 {
+	enum MAPISTATUS ms;
+
 	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, MAPI_E_INVALID_PARAMETER);
-	g_return_val_if_fail (obj_folder != NULL, MAPI_E_INVALID_PARAMETER);
-	g_return_val_if_fail (fid != NULL, MAPI_E_INVALID_PARAMETER);
+	e_return_val_mapi_error_if_fail (obj_folder != NULL, MAPI_E_INVALID_PARAMETER, MAPI_E_INVALID_PARAMETER);
+	e_return_val_mapi_error_if_fail (fid != NULL, MAPI_E_INVALID_PARAMETER, MAPI_E_INVALID_PARAMETER);
 
 	if (*fid == 0) {
-		enum MAPISTATUS retval;
-
-		retval = GetDefaultFolder (&priv->msg_store, fid, olFolder);
-		if (retval != MAPI_E_SUCCESS)
-			return retval;
+		ms = GetDefaultFolder (&priv->msg_store, fid, olFolder);
+		if (ms != MAPI_E_SUCCESS) {
+			make_mapi_error (perror, "GetDefaultFolder", ms);
+			return ms;
+		}
 
 		fid_options = 0;
 	}
 
 	if ((fid_options & MAPI_OPTIONS_USE_PFSTORE) != 0) {
-		if (!ensure_public_store (priv))
+		if (!ensure_public_store (priv, perror)) {
 			return MAPI_E_CALL_FAILED;
+		}
 	}
 
-	return OpenFolder (((fid_options & MAPI_OPTIONS_USE_PFSTORE) != 0 ? &priv->public_store : &priv->msg_store), *fid, obj_folder);
+	ms = OpenFolder (((fid_options & MAPI_OPTIONS_USE_PFSTORE) != 0 ? &priv->public_store : &priv->msg_store), *fid, obj_folder);
+	if (ms != MAPI_E_SUCCESS)
+		make_mapi_error (perror, "OpenFolder", ms);
+
+	return ms;
 }
 
 GSList *
-exchange_mapi_connection_check_restriction (ExchangeMapiConnection *conn, mapi_id_t fid, guint32 fid_options, struct mapi_SRestriction *res)
+exchange_mapi_connection_check_restriction (ExchangeMapiConnection *conn, mapi_id_t fid, guint32 fid_options, struct mapi_SRestriction *res, GError **perror)
 {
-	enum MAPISTATUS retval;
+	enum MAPISTATUS ms;
 	TALLOC_CTX *mem_ctx;
 	mapi_object_t obj_folder;
 	mapi_object_t obj_table;
@@ -1331,7 +1433,7 @@ exchange_mapi_connection_check_restriction (ExchangeMapiConnection *conn, mapi_i
 	GSList *mids = NULL;
 
 	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, NULL);
-	g_return_val_if_fail (priv->session != NULL, NULL);
+	e_return_val_mapi_error_if_fail (priv->session != NULL, MAPI_E_INVALID_PARAMETER, NULL);
 
 	g_debug("%s: Entering %s: folder-id %016" G_GINT64_MODIFIER "X ", G_STRLOC, G_STRFUNC, fid);
 
@@ -1341,16 +1443,15 @@ exchange_mapi_connection_check_restriction (ExchangeMapiConnection *conn, mapi_i
 	mapi_object_init(&obj_table);
 
 	/* Attempt to open the folder */
-	retval = open_folder (conn, 0, &fid, fid_options, &obj_folder);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("open_folder", GetLastError());
+	ms = open_folder (conn, 0, &fid, fid_options, &obj_folder, perror);
+	if (ms != MAPI_E_SUCCESS) {
 		goto cleanup;
 	}
 
 	/* Get a handle on the container */
-	retval = GetContentsTable(&obj_folder, &obj_table, 0, NULL);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("GetContentsTable", GetLastError());
+	ms = GetContentsTable (&obj_folder, &obj_table, 0, NULL);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "GetContentsTable", ms);
 		goto cleanup;
 	}
 
@@ -1372,32 +1473,32 @@ exchange_mapi_connection_check_restriction (ExchangeMapiConnection *conn, mapi_i
 					  PR_RULE_MSG_NAME);
 
 	/* Set primary columns to be fetched */
-	retval = SetColumns(&obj_table, SPropTagArray);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("SetColumns", GetLastError());
+	ms = SetColumns (&obj_table, SPropTagArray);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "SetColumns", ms);
 		goto cleanup;
 	}
 
 	if (res) {
 		/* Applying any restriction that are set. */
-		retval = Restrict(&obj_table, res, NULL);
-		if (retval != MAPI_E_SUCCESS) {
-			mapi_errstr("Restrict", GetLastError());
+		ms = Restrict (&obj_table, res, NULL);
+		if (ms != MAPI_E_SUCCESS) {
+			make_mapi_error (perror, "Restrict", ms);
 			goto cleanup;
 		}
 	}
 
 	/* Number of items in the container */
-	retval = QueryPosition(&obj_table, NULL, &count);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("GetRowCount", GetLastError());
+	ms = QueryPosition (&obj_table, NULL, &count);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "GetRowCount", ms);
 		goto cleanup;
 	}
 
 	/* Fill the table columns with data from the rows */
-	retval = QueryRows(&obj_table, count, TBL_ADVANCE, &SRowSet);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("QueryRows", GetLastError());
+	ms = QueryRows (&obj_table, count, TBL_ADVANCE, &SRowSet);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "QueryRows", ms);
 		goto cleanup;
 	}
 
@@ -1424,9 +1525,9 @@ exchange_mapi_connection_fetch_items   (ExchangeMapiConnection *conn, mapi_id_t
 					struct mapi_SRestriction *res, struct SSortOrderSet *sort_order,
 					BuildReadPropsCB build_props, gpointer brp_data,
 					FetchCallback cb, gpointer data,
-					guint32 options)
+					guint32 options, GError **perror)
 {
-	enum MAPISTATUS retval;
+	enum MAPISTATUS ms;
 	TALLOC_CTX *mem_ctx;
 	mapi_object_t obj_folder;
 	mapi_object_t obj_table;
@@ -1436,7 +1537,7 @@ exchange_mapi_connection_fetch_items   (ExchangeMapiConnection *conn, mapi_id_t
 	gboolean result = FALSE;
 
 	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, FALSE);
-	g_return_val_if_fail (priv->session != NULL, FALSE);
+	e_return_val_mapi_error_if_fail (priv->session != NULL, MAPI_E_INVALID_PARAMETER, FALSE);
 
 	g_debug("%s: Entering %s: folder-id %016" G_GINT64_MODIFIER "X ", G_STRLOC, G_STRFUNC, fid);
 
@@ -1446,16 +1547,15 @@ exchange_mapi_connection_fetch_items   (ExchangeMapiConnection *conn, mapi_id_t
 	mapi_object_init(&obj_table);
 
 	/* Attempt to open the folder */
-	retval = open_folder (conn, 0, &fid, options, &obj_folder);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("open_folder", GetLastError());
+	ms = open_folder (conn, 0, &fid, options, &obj_folder, perror);
+	if (ms != MAPI_E_SUCCESS) {
 		goto cleanup;
 	}
 
 	/* Get a handle on the container */
-	retval = GetContentsTable(&obj_folder, &obj_table, TableFlags_UseUnicode, NULL);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("GetContentsTable", GetLastError());
+	ms = GetContentsTable (&obj_folder, &obj_table, TableFlags_UseUnicode, NULL);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "GetContentsTable", ms);
 		goto cleanup;
 	}
 
@@ -1467,25 +1567,25 @@ exchange_mapi_connection_fetch_items   (ExchangeMapiConnection *conn, mapi_id_t
 					  PR_MESSAGE_FLAGS);
 
 	/* Set primary columns to be fetched */
-	retval = SetColumns(&obj_table, SPropTagArray);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("SetColumns", GetLastError());
+	ms = SetColumns (&obj_table, SPropTagArray);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "SetColumns", ms);
 		goto cleanup;
 	}
 
 	if (res) {
 		/* Applying any restriction that are set. */
-		retval = Restrict(&obj_table, res, NULL);
-		if (retval != MAPI_E_SUCCESS) {
-			mapi_errstr("Restrict", GetLastError());
+		ms = Restrict (&obj_table, res, NULL);
+		if (ms != MAPI_E_SUCCESS) {
+			make_mapi_error (perror, "Restrict", ms);
 			goto cleanup;
 		}
 	}
 
 	if (sort_order) {
-		retval = SortTable(&obj_table, sort_order);
-		if (retval != MAPI_E_SUCCESS) {
-			mapi_errstr("SortTable", GetLastError());
+		ms = SortTable (&obj_table, sort_order);
+		if (ms != MAPI_E_SUCCESS) {
+			make_mapi_error (perror, "SortTable", ms);
 			goto cleanup;
 		}
 	}
@@ -1493,7 +1593,7 @@ exchange_mapi_connection_fetch_items   (ExchangeMapiConnection *conn, mapi_id_t
 	if (build_props) {
 		propsTagArray = set_SPropTagArray (mem_ctx, 0x1, PR_MESSAGE_CLASS);
 		if (!build_props (conn, fid, mem_ctx, propsTagArray, brp_data)) {
-			mapi_errstr ("build_props", GetLastError ());
+			make_mapi_error (perror, "build_props", MAPI_E_CALL_FAILED);
 			goto cleanup;
 		}
 	}
@@ -1502,16 +1602,16 @@ exchange_mapi_connection_fetch_items   (ExchangeMapiConnection *conn, mapi_id_t
 	/* is more of a request and not gauranteed  */
 	do {
 		/* Number of items in the container */
-		retval = QueryPosition(&obj_table, &cursor_pos, &count);
-		if (retval != MAPI_E_SUCCESS) {
-			mapi_errstr("QueryPosition", GetLastError());
+		ms = QueryPosition (&obj_table, &cursor_pos, &count);
+		if (ms != MAPI_E_SUCCESS) {
+			make_mapi_error (perror, "QueryPosition", ms);
 			goto cleanup;
 		}
 
 		/* Fill the table columns with data from the rows */
-		retval = QueryRows(&obj_table, count, TBL_ADVANCE, &SRowSet);
-		if (retval != MAPI_E_SUCCESS) {
-			mapi_errstr("QueryRows", GetLastError());
+		ms = QueryRows (&obj_table, count, TBL_ADVANCE, &SRowSet);
+		if (ms != MAPI_E_SUCCESS) {
+			make_mapi_error (perror, "QueryRows", ms);
 			goto cleanup;
 		}
 
@@ -1538,23 +1638,28 @@ exchange_mapi_connection_fetch_items   (ExchangeMapiConnection *conn, mapi_id_t
 			if (options & MAPI_OPTIONS_DONT_OPEN_MESSAGE)
 				goto relax;
 
-			retval = OpenMessage(&obj_folder, *pfid, *pmid, &obj_message, 0);
-			if (retval != MAPI_E_SUCCESS) {
-				mapi_errstr("OpenMessage", GetLastError());
+			ms = OpenMessage (&obj_folder, *pfid, *pmid, &obj_message, 0);
+			if (ms != MAPI_E_SUCCESS) {
+				make_mapi_error (perror, "OpenMessage", ms);
 				goto loop_cleanup;
 			}
 
 			if (has_attach && *has_attach && (MAPI_OPTIONS_FETCH_ATTACHMENTS & options)) {
-				exchange_mapi_util_get_attachments (conn, fid, &obj_message, &attach_list);
+				if (!exchange_mapi_util_get_attachments (conn, fid, &obj_message, &attach_list, perror))
+					goto loop_cleanup;
 			}
 
-			if (options & MAPI_OPTIONS_FETCH_RECIPIENTS)
-				exchange_mapi_util_get_recipients (&obj_message, &recip_list);
+			if (options & MAPI_OPTIONS_FETCH_RECIPIENTS) {
+				if (!exchange_mapi_util_get_recipients (&obj_message, &recip_list, perror))
+					goto loop_cleanup;
+			}
 
 			/* get the main body stream no matter what */
-			if (options & MAPI_OPTIONS_FETCH_BODY_STREAM)
-				exchange_mapi_util_read_body_stream (&obj_message, &stream_list,
-								     options & MAPI_OPTIONS_GETBESTBODY);
+			if (options & MAPI_OPTIONS_FETCH_BODY_STREAM) {
+				if (!exchange_mapi_util_read_body_stream (&obj_message, &stream_list,
+								     options & MAPI_OPTIONS_GETBESTBODY, perror))
+					goto loop_cleanup;
+			}
 
 			if (propsTagArray && propsTagArray->cValues) {
 				struct SPropValue *lpProps;
@@ -1566,7 +1671,10 @@ exchange_mapi_connection_fetch_items   (ExchangeMapiConnection *conn, mapi_id_t
 				tags = set_SPropTagArray (mem_ctx, 0x1, propsTagArray->aulPropTag[0]);
 				for (k = 1; k < propsTagArray->cValues; k++)
 					SPropTagArray_add (mem_ctx, tags, propsTagArray->aulPropTag[k]);
-				retval = GetProps (&obj_message, tags, &lpProps, &prop_count);
+
+				ms = GetProps (&obj_message, tags, &lpProps, &prop_count);
+				if (ms != MAPI_E_SUCCESS)
+					make_mapi_error (perror, "GetProps", ms);
 
 				MAPIFreeBuffer (tags);
 				properties_array.lpProps = talloc_zero_array (mem_ctx, struct mapi_SPropValue,
@@ -1591,10 +1699,13 @@ exchange_mapi_connection_fetch_items   (ExchangeMapiConnection *conn, mapi_id_t
 							&properties_array.lpProps[k], &lpProps[k]);
 					}
 				}
-			} else
-				retval = GetPropsAll (&obj_message, &properties_array);
+			} else {
+				ms = GetPropsAll (&obj_message, &properties_array);
+				if (ms != MAPI_E_SUCCESS)
+					make_mapi_error (perror, "GetPropsAll", ms);
+			}
  relax:
-			if (retval == MAPI_E_SUCCESS) {
+			if (ms == MAPI_E_SUCCESS) {
 				FetchItemsCallbackData *item_data;
 				uint32_t z;
 
@@ -1603,7 +1714,7 @@ exchange_mapi_connection_fetch_items   (ExchangeMapiConnection *conn, mapi_id_t
 					for (z=0; z < properties_array.cValues; z++) {
 						if ((properties_array.lpProps[z].ulPropTag & 0xFFFF) == PT_BINARY &&
 						    (options & MAPI_OPTIONS_FETCH_GENERIC_STREAMS))
-						exchange_mapi_util_read_generic_stream (&obj_message, exchange_mapi_util_find_array_propval (&properties_array, PR_INTERNET_CPID), properties_array.lpProps[z].ulPropTag, &stream_list);
+						exchange_mapi_util_read_generic_stream (&obj_message, exchange_mapi_util_find_array_propval (&properties_array, PR_INTERNET_CPID), properties_array.lpProps[z].ulPropTag, &stream_list, NULL);
 					}
 
 					mapi_SPropValue_array_named(&obj_message, &properties_array);
@@ -1642,9 +1753,9 @@ exchange_mapi_connection_fetch_items   (ExchangeMapiConnection *conn, mapi_id_t
 			if (!cb_retval) break;
 		}
 
-	} while (cursor_pos < count);
+	} while (cursor_pos < count && ms == MAPI_E_SUCCESS);
 
-	result = TRUE;
+	result = ms == MAPI_E_SUCCESS;
 
  cleanup:
 	if (propsTagArray)
@@ -1664,9 +1775,9 @@ gboolean
 exchange_mapi_connection_fetch_object_props (ExchangeMapiConnection *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)
+				     guint32 options, GError **perror)
 {
-	enum MAPISTATUS retval;
+	enum MAPISTATUS ms;
 	TALLOC_CTX *mem_ctx;
 	struct mapi_SPropValue_array properties_array;
 	struct SPropTagArray *propsTagArray = NULL;
@@ -1676,7 +1787,7 @@ exchange_mapi_connection_fetch_object_props (ExchangeMapiConnection *conn, mapi_
 	gboolean result = FALSE;
 
 	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, FALSE);
-	g_return_val_if_fail (priv->session != NULL, FALSE);
+	e_return_val_mapi_error_if_fail (priv->session != NULL, MAPI_E_INVALID_PARAMETER, FALSE);
 
 	g_debug("%s: Entering %s: folder %p message %p", G_STRLOC, G_STRFUNC, obj_folder, obj_message);
 
@@ -1686,30 +1797,39 @@ exchange_mapi_connection_fetch_object_props (ExchangeMapiConnection *conn, mapi_
 	if (build_props) {
 		propsTagArray = set_SPropTagArray (mem_ctx, 0x1, PR_MESSAGE_CLASS);
 		if (!build_props (conn, fid, mem_ctx, propsTagArray, brp_data)) {
-			mapi_errstr ("build_props", GetLastError ());
+			make_mapi_error (perror, "build_props", MAPI_E_CALL_FAILED);
 			goto cleanup;
 		}
 	}
 
 	/* Fetch attachments */
-	if (options & MAPI_OPTIONS_FETCH_ATTACHMENTS)
-		exchange_mapi_util_get_attachments (conn, fid, obj_message, &attach_list);
+	if (options & MAPI_OPTIONS_FETCH_ATTACHMENTS) {
+		if (!exchange_mapi_util_get_attachments (conn, fid, obj_message, &attach_list, perror))
+			goto cleanup;
+	}
 
 	/* Fetch recipients */
-	if (options & MAPI_OPTIONS_FETCH_RECIPIENTS)
-		exchange_mapi_util_get_recipients (obj_message, &recip_list);
+	if (options & MAPI_OPTIONS_FETCH_RECIPIENTS) {
+		if (!exchange_mapi_util_get_recipients (obj_message, &recip_list, perror))
+			goto cleanup;
+	}
 
 	/* get the main body stream no matter what */
-	if (options & MAPI_OPTIONS_FETCH_BODY_STREAM)
-		exchange_mapi_util_read_body_stream (obj_message, &stream_list,
-			options & MAPI_OPTIONS_GETBESTBODY);
+	if (options & MAPI_OPTIONS_FETCH_BODY_STREAM) {
+		if (!exchange_mapi_util_read_body_stream (obj_message, &stream_list,
+			options & MAPI_OPTIONS_GETBESTBODY, perror))
+			goto cleanup;
+	}
 
 	if (propsTagArray && propsTagArray->cValues) {
 		struct SPropValue *lpProps;
 		uint32_t prop_count = 0, k;
 
 		lpProps = talloc_zero(mem_ctx, struct SPropValue);
-		retval = GetProps (obj_message, propsTagArray, &lpProps, &prop_count);
+
+		ms = GetProps (obj_message, propsTagArray, &lpProps, &prop_count);
+		if (ms != MAPI_E_SUCCESS)
+			make_mapi_error (perror, "GetProps", ms);
 
 		/* Conversion from SPropValue to mapi_SPropValue. (no padding here) */
 		properties_array.cValues = prop_count;
@@ -1721,16 +1841,19 @@ exchange_mapi_connection_fetch_object_props (ExchangeMapiConnection *conn, mapi_
 				#endif
 				&properties_array.lpProps[k], &lpProps[k]);
 
-	} else
-		retval = GetPropsAll (obj_message, &properties_array);
+	} else {
+		ms = GetPropsAll (obj_message, &properties_array);
+		if (ms != MAPI_E_SUCCESS)
+			make_mapi_error (perror, "GetPropsAll", ms);
+	}
 
-	if (retval == MAPI_E_SUCCESS) {
+	if (ms == MAPI_E_SUCCESS) {
 		uint32_t z;
 
 		/* just to get all the other streams */
 		for (z=0; z < properties_array.cValues; z++)
 			if ((properties_array.lpProps[z].ulPropTag & 0xFFFF) == PT_BINARY && (options & MAPI_OPTIONS_FETCH_GENERIC_STREAMS))
-				exchange_mapi_util_read_generic_stream (obj_message, exchange_mapi_util_find_array_propval (&properties_array, PR_INTERNET_CPID), properties_array.lpProps[z].ulPropTag, &stream_list);
+				exchange_mapi_util_read_generic_stream (obj_message, exchange_mapi_util_find_array_propval (&properties_array, PR_INTERNET_CPID), properties_array.lpProps[z].ulPropTag, &stream_list, NULL);
 
 		mapi_SPropValue_array_named (obj_message, &properties_array);
 	}
@@ -1742,7 +1865,7 @@ exchange_mapi_connection_fetch_object_props (ExchangeMapiConnection *conn, mapi_
 		mapi_object_release (obj_folder);
 	}
 
-	if (retval == MAPI_E_SUCCESS) {
+	if (ms == MAPI_E_SUCCESS) {
 		FetchItemsCallbackData *item_data = g_new0 (FetchItemsCallbackData, 1);
 		item_data->conn = conn;
 		item_data->fid = fid;
@@ -1762,7 +1885,7 @@ exchange_mapi_connection_fetch_object_props (ExchangeMapiConnection *conn, mapi_
 		exchange_mapi_util_free_attachment_list (&attach_list);
 	}
 
-	result = TRUE;
+	result = ms == MAPI_E_SUCCESS;
 
 cleanup:
 	talloc_free (mem_ctx);
@@ -1777,16 +1900,16 @@ gboolean
 exchange_mapi_connection_fetch_item (ExchangeMapiConnection *conn, mapi_id_t fid, mapi_id_t mid,
 				     BuildReadPropsCB build_props, gpointer brp_data,
 				     FetchCallback cb, gpointer data,
-				     guint32 options)
+				     guint32 options, GError **perror)
 {
-	enum MAPISTATUS retval;
+	enum MAPISTATUS ms;
 	TALLOC_CTX *mem_ctx;
 	mapi_object_t obj_folder;
 	mapi_object_t obj_message;
 	gboolean result = FALSE;
 
 	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, FALSE);
-	g_return_val_if_fail (priv->session != NULL, FALSE);
+	e_return_val_mapi_error_if_fail (priv->session != NULL, MAPI_E_INVALID_PARAMETER, FALSE);
 
 	g_debug("%s: Entering %s: folder-id %016" G_GINT64_MODIFIER "X message-id %016" G_GINT64_MODIFIER "X",
 				G_STRLOC, G_STRFUNC, fid, mid);
@@ -1797,20 +1920,19 @@ exchange_mapi_connection_fetch_item (ExchangeMapiConnection *conn, mapi_id_t fid
 	mapi_object_init(&obj_message);
 
 	/* Attempt to open the folder */
-	retval = open_folder (conn, 0, &fid, options, &obj_folder);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("open_folder", GetLastError());
+	ms = open_folder (conn, 0, &fid, options, &obj_folder, perror);
+	if (ms != MAPI_E_SUCCESS) {
 		goto cleanup;
 	}
 
 	/* Open the item */
-	retval = OpenMessage(&obj_folder, fid, mid, &obj_message, 0x0);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("OpenMessage", GetLastError());
+	ms = OpenMessage (&obj_folder, fid, mid, &obj_message, 0x0);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "OpenMessage", ms);
 		goto cleanup;
 	}
 
-	result = exchange_mapi_connection_fetch_object_props (conn, &obj_folder, fid, mid, &obj_message, build_props, brp_data, cb, data, options);
+	result = exchange_mapi_connection_fetch_object_props (conn, &obj_folder, fid, mid, &obj_message, build_props, brp_data, cb, data, options, perror);
 
 cleanup:
 	if (!result) {
@@ -1826,9 +1948,9 @@ cleanup:
 }
 
 mapi_id_t
-exchange_mapi_connection_create_folder (ExchangeMapiConnection *conn, uint32_t olFolder, mapi_id_t pfid, guint32 fid_options, const gchar *name)
+exchange_mapi_connection_create_folder (ExchangeMapiConnection *conn, uint32_t olFolder, mapi_id_t pfid, guint32 fid_options, const gchar *name, GError **perror)
 {
-	enum MAPISTATUS retval;
+	enum MAPISTATUS ms;
 	mapi_object_t obj_folder;
 	mapi_object_t obj_top;
 	struct SPropValue vals[1];
@@ -1836,7 +1958,7 @@ exchange_mapi_connection_create_folder (ExchangeMapiConnection *conn, uint32_t o
 	mapi_id_t fid = 0;
 
 	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, 0);
-	g_return_val_if_fail (priv->session != NULL, 0);
+	e_return_val_mapi_error_if_fail (priv->session != NULL, MAPI_E_INVALID_PARAMETER, 0);
 
 	g_debug("%s: Entering %s ", G_STRLOC, G_STRFUNC);
 
@@ -1845,16 +1967,15 @@ exchange_mapi_connection_create_folder (ExchangeMapiConnection *conn, uint32_t o
 	mapi_object_init(&obj_folder);
 
 	/* We now open the top/parent folder */
-	retval = open_folder (conn, olFolder, &pfid, fid_options, &obj_top);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("open_folder", GetLastError());
+	ms = open_folder (conn, olFolder, &pfid, fid_options, &obj_top, perror);
+	if (ms != MAPI_E_SUCCESS) {
 		goto cleanup;
 	}
 
 	/* Attempt to create the folder */
-	retval = CreateFolder(&obj_top, FOLDER_GENERIC, name, "Created using Evolution/LibMAPI", OPEN_IF_EXISTS, &obj_folder);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("CreateFolder", GetLastError());
+	ms = CreateFolder (&obj_top, FOLDER_GENERIC, name, "Created using Evolution/LibMAPI", OPEN_IF_EXISTS, &obj_folder);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "CreateFolder", ms);
 		goto cleanup;
 	}
 
@@ -1881,9 +2002,9 @@ exchange_mapi_connection_create_folder (ExchangeMapiConnection *conn, uint32_t o
 	vals[0].value.lpszA = type;
 	vals[0].ulPropTag = PR_CONTAINER_CLASS;
 
-	retval = SetProps(&obj_folder, vals, 1);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("SetProps", GetLastError());
+	ms = SetProps (&obj_folder, vals, 1);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "SetProps", ms);
 		goto cleanup;
 	}
 
@@ -1903,14 +2024,14 @@ cleanup:
 }
 
 gboolean
-exchange_mapi_connection_empty_folder (ExchangeMapiConnection *conn, mapi_id_t fid, guint32 fid_options)
+exchange_mapi_connection_empty_folder (ExchangeMapiConnection *conn, mapi_id_t fid, guint32 fid_options, GError **perror)
 {
-	enum MAPISTATUS retval;
+	enum MAPISTATUS ms;
 	mapi_object_t obj_folder;
 	gboolean result = FALSE;
 
 	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, FALSE);
-	g_return_val_if_fail (priv->session != NULL, FALSE);
+	e_return_val_mapi_error_if_fail (priv->session != NULL, MAPI_E_INVALID_PARAMETER, FALSE);
 
 	g_debug("%s: Entering %s ", G_STRLOC, G_STRFUNC);
 
@@ -1918,16 +2039,15 @@ exchange_mapi_connection_empty_folder (ExchangeMapiConnection *conn, mapi_id_t f
 	mapi_object_init (&obj_folder);
 
 	/* Attempt to open the folder to be emptied */
-	retval = open_folder (conn, 0, &fid, fid_options, &obj_folder);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("open_folder", GetLastError());
+	ms = open_folder (conn, 0, &fid, fid_options, &obj_folder, perror);
+	if (ms != MAPI_E_SUCCESS) {
 		goto cleanup;
 	}
 
 	/* Empty the contents of the folder */
-	retval = EmptyFolder(&obj_folder);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("EmptyFolder", GetLastError());
+	ms = EmptyFolder (&obj_folder);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "EmptyFolder", ms);
 		goto cleanup;
 	}
 
@@ -1945,9 +2065,9 @@ cleanup:
 }
 
 gboolean
-exchange_mapi_connection_remove_folder (ExchangeMapiConnection *conn, mapi_id_t fid, guint32 fid_options)
+exchange_mapi_connection_remove_folder (ExchangeMapiConnection *conn, mapi_id_t fid, guint32 fid_options, GError **perror)
 {
-	enum MAPISTATUS retval;
+	enum MAPISTATUS ms;
 	mapi_object_t obj_top;
 	mapi_object_t obj_folder;
 	ExchangeMAPIFolder *folder;
@@ -1955,7 +2075,7 @@ exchange_mapi_connection_remove_folder (ExchangeMapiConnection *conn, mapi_id_t
 	GSList *l;
 
 	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, FALSE);
-	g_return_val_if_fail (priv->session != NULL, FALSE);
+	e_return_val_mapi_error_if_fail (priv->session != NULL, MAPI_E_INVALID_PARAMETER, FALSE);
 
 	g_debug("%s: Entering %s ", G_STRLOC, G_STRFUNC);
 
@@ -1967,7 +2087,7 @@ exchange_mapi_connection_remove_folder (ExchangeMapiConnection *conn, mapi_id_t
 			folder = NULL;
 	}
 
-	g_return_val_if_fail (folder != NULL, FALSE);
+	e_return_val_mapi_error_if_fail (folder != NULL, MAPI_E_INVALID_PARAMETER, FALSE);
 
 	LOCK ();
 	mapi_object_init(&obj_top);
@@ -1978,32 +2098,30 @@ exchange_mapi_connection_remove_folder (ExchangeMapiConnection *conn, mapi_id_t
 	 */
 
 	/* Attempt to open the folder to be removed */
-	retval = open_folder (conn, 0, &fid, fid_options, &obj_folder);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("open_folder", GetLastError());
+	ms = open_folder (conn, 0, &fid, fid_options, &obj_folder, perror);
+	if (ms != MAPI_E_SUCCESS) {
 		goto cleanup;
 	}
 
 	/* Empty the contents of the folder */
-	retval = EmptyFolder(&obj_folder);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("EmptyFolder", GetLastError());
+	ms = EmptyFolder (&obj_folder);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "EmptyFolder", ms);
 		goto cleanup;
 	}
 
 	g_debug("Folder with id %016" G_GINT64_MODIFIER "X was emptied ", fid);
 
 	/* Attempt to open the top/parent folder */
-	retval = open_folder (conn, 0, &folder->parent_folder_id, fid_options, &obj_top);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("open_folder", GetLastError());
+	ms = open_folder (conn, 0, &folder->parent_folder_id, fid_options, &obj_top, perror);
+	if (ms != MAPI_E_SUCCESS) {
 		goto cleanup;
 	}
 
 	/* Call DeleteFolder on the folder to be removed */
-	retval = DeleteFolder(&obj_top, fid, DEL_FOLDERS, NULL);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("DeleteFolder", GetLastError());
+	ms = DeleteFolder (&obj_top, fid, DEL_FOLDERS, NULL);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "DeleteFolder", ms);
 		goto cleanup;
 	}
 
@@ -2026,16 +2144,16 @@ cleanup:
 }
 
 gboolean
-exchange_mapi_connection_rename_folder (ExchangeMapiConnection *conn, mapi_id_t fid, guint32 fid_options, const gchar *new_name)
+exchange_mapi_connection_rename_folder (ExchangeMapiConnection *conn, mapi_id_t fid, guint32 fid_options, const gchar *new_name, GError **perror)
 {
-	enum MAPISTATUS retval;
+	enum MAPISTATUS ms;
 	mapi_object_t obj_folder;
 	struct SPropValue *props = NULL;
 	TALLOC_CTX *mem_ctx;
 	gboolean result = FALSE;
 
 	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, FALSE);
-	g_return_val_if_fail (priv->session != NULL, FALSE);
+	e_return_val_mapi_error_if_fail (priv->session != NULL, MAPI_E_INVALID_PARAMETER, FALSE);
 
 	g_debug("%s: Entering %s ", G_STRLOC, G_STRFUNC);
 
@@ -2044,18 +2162,17 @@ exchange_mapi_connection_rename_folder (ExchangeMapiConnection *conn, mapi_id_t
 	mapi_object_init(&obj_folder);
 
 	/* Open the folder to be renamed */
-	retval = open_folder (conn, 0, &fid, fid_options, &obj_folder);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("open_folder", GetLastError());
+	ms = open_folder (conn, 0, &fid, fid_options, &obj_folder, perror);
+	if (ms != MAPI_E_SUCCESS) {
 		goto cleanup;
 	}
 
 	props = talloc_zero(mem_ctx, struct SPropValue);
 	set_SPropValue_proptag (props, PR_DISPLAY_NAME_UNICODE, new_name);
 
-	retval = SetProps(&obj_folder, props, 1);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("SetProps", GetLastError());
+	ms = SetProps (&obj_folder, props, 1);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "SetProps", ms);
 		goto cleanup;
 	}
 
@@ -2074,20 +2191,20 @@ cleanup:
 /* moves folder 'src_fid' to folder 'des_fid' under name 'new_name' (no path in a new_name),
    'src_parent_fid' is folder ID of a parent of the src_fid */
 gboolean
-exchange_mapi_connection_move_folder (ExchangeMapiConnection *conn, mapi_id_t src_fid, mapi_id_t src_parent_fid, guint32 src_fid_options, mapi_id_t des_fid, guint32 des_fid_options, const gchar *new_name)
+exchange_mapi_connection_move_folder (ExchangeMapiConnection *conn, mapi_id_t src_fid, mapi_id_t src_parent_fid, guint32 src_fid_options, mapi_id_t des_fid, guint32 des_fid_options, const gchar *new_name, GError **perror)
 {
-	enum MAPISTATUS retval;
+	enum MAPISTATUS ms;
 	mapi_object_t obj_src, obj_src_parent, obj_des;
 	gboolean result = FALSE;
 
 	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, FALSE);
-	g_return_val_if_fail (priv->session != NULL, FALSE);
+	e_return_val_mapi_error_if_fail (priv->session != NULL, MAPI_E_INVALID_PARAMETER, FALSE);
 
-	g_return_val_if_fail (src_fid != 0, FALSE);
-	g_return_val_if_fail (src_parent_fid != 0, FALSE);
-	g_return_val_if_fail (des_fid != 0, FALSE);
-	g_return_val_if_fail (new_name != NULL, FALSE);
-	g_return_val_if_fail (strchr (new_name, '/') == NULL, FALSE);
+	e_return_val_mapi_error_if_fail (src_fid != 0, MAPI_E_INVALID_PARAMETER, FALSE);
+	e_return_val_mapi_error_if_fail (src_parent_fid != 0, MAPI_E_INVALID_PARAMETER, FALSE);
+	e_return_val_mapi_error_if_fail (des_fid != 0, MAPI_E_INVALID_PARAMETER, FALSE);
+	e_return_val_mapi_error_if_fail (new_name != NULL, MAPI_E_INVALID_PARAMETER, FALSE);
+	e_return_val_mapi_error_if_fail (strchr (new_name, '/') == NULL, MAPI_E_INVALID_PARAMETER, FALSE);
 
 	LOCK ();
 
@@ -2095,27 +2212,24 @@ exchange_mapi_connection_move_folder (ExchangeMapiConnection *conn, mapi_id_t sr
 	mapi_object_init (&obj_src_parent);
 	mapi_object_init (&obj_des);
 
-	retval = open_folder (conn, 0, &src_fid, src_fid_options, &obj_src);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr ("open_folder src_fid", GetLastError());
+	ms = open_folder (conn, 0, &src_fid, src_fid_options, &obj_src, perror);
+	if (ms != MAPI_E_SUCCESS) {
 		goto cleanup;
 	}
 
-	retval = open_folder (conn, 0, &src_parent_fid, src_fid_options, &obj_src_parent);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr ("open_folder src_parent_fid", GetLastError());
+	ms = open_folder (conn, 0, &src_parent_fid, src_fid_options, &obj_src_parent, perror);
+	if (ms != MAPI_E_SUCCESS) {
 		goto cleanup;
 	}
 
-	retval = open_folder (conn, 0, &des_fid, des_fid_options, &obj_des);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr ("open_folder des_fid", GetLastError());
+	ms = open_folder (conn, 0, &des_fid, des_fid_options, &obj_des, perror);
+	if (ms != MAPI_E_SUCCESS) {
 		goto cleanup;
 	}
 
-	retval = MoveFolder (&obj_src, &obj_src_parent, &obj_des, (gchar *)new_name, TRUE);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr ("MoveFolder", GetLastError());
+	ms = MoveFolder (&obj_src, &obj_src_parent, &obj_des, (gchar *)new_name, TRUE);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "MoveFolder", ms);
 		goto cleanup;
 	}
 
@@ -2133,9 +2247,9 @@ cleanup:
 
 /* named_ids_list contains pointers to ResolveNamedIDsData structure */
 gboolean
-exchange_mapi_connection_resolve_named_props (ExchangeMapiConnection *conn, mapi_id_t fid, ResolveNamedIDsData *named_ids_list, guint named_ids_n_elems)
+exchange_mapi_connection_resolve_named_props (ExchangeMapiConnection *conn, mapi_id_t fid, ResolveNamedIDsData *named_ids_list, guint named_ids_n_elems, GError **perror)
 {
-	enum MAPISTATUS retval;
+	enum MAPISTATUS ms;
 	TALLOC_CTX *mem_ctx;
 	mapi_object_t obj_folder;
 	struct mapi_nameid *nameid;
@@ -2145,9 +2259,9 @@ exchange_mapi_connection_resolve_named_props (ExchangeMapiConnection *conn, mapi
 	gboolean res = FALSE;
 
 	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, FALSE);
-	g_return_val_if_fail (named_ids_list != NULL, FALSE);
-	g_return_val_if_fail (named_ids_n_elems > 0, FALSE);
-	g_return_val_if_fail (priv->session != NULL, FALSE);
+	e_return_val_mapi_error_if_fail (named_ids_list != NULL, MAPI_E_INVALID_PARAMETER, FALSE);
+	e_return_val_mapi_error_if_fail (named_ids_n_elems > 0, MAPI_E_INVALID_PARAMETER, FALSE);
+	e_return_val_mapi_error_if_fail (priv->session != NULL, MAPI_E_INVALID_PARAMETER, FALSE);
 
 	g_debug ("%s: Entering %s ", G_STRLOC, G_STRFUNC);
 
@@ -2186,9 +2300,8 @@ exchange_mapi_connection_resolve_named_props (ExchangeMapiConnection *conn, mapi
 	SPropTagArray = talloc_zero (mem_ctx, struct SPropTagArray);
 
 	/* Attempt to open the folder */
-	retval = open_folder (conn, 0, &fid, 0, &obj_folder);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("open_folder", GetLastError());
+	ms = open_folder (conn, 0, &fid, 0, &obj_folder, perror);
+	if (ms != MAPI_E_SUCCESS) {
 		goto cleanup;
 	}
 
@@ -2208,9 +2321,9 @@ exchange_mapi_connection_resolve_named_props (ExchangeMapiConnection *conn, mapi
 			data->propid = 0;
 	}
 
-	retval = mapi_nameid_GetIDsFromNames (nameid, &obj_folder, SPropTagArray);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr ("mapi_nameid_GetIDsFromNames", GetLastError());
+	ms = mapi_nameid_GetIDsFromNames (nameid, &obj_folder, SPropTagArray);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "mapi_nameid_GetIDsFromNames", ms);
 		goto cleanup;
 	}
 
@@ -2266,9 +2379,9 @@ exchange_mapi_connection_resolve_named_props (ExchangeMapiConnection *conn, mapi
 
 /* returns MAPI_E_RESERVED on any error */
 uint32_t
-exchange_mapi_connection_resolve_named_prop (ExchangeMapiConnection *conn, mapi_id_t fid, uint32_t pidlid_propid)
+exchange_mapi_connection_resolve_named_prop (ExchangeMapiConnection *conn, mapi_id_t fid, uint32_t pidlid_propid, GError **perror)
 {
-	enum MAPISTATUS retval;
+	enum MAPISTATUS ms;
 	TALLOC_CTX *mem_ctx;
 	mapi_object_t obj_folder;
 	struct mapi_nameid *nameid;
@@ -2276,7 +2389,7 @@ exchange_mapi_connection_resolve_named_prop (ExchangeMapiConnection *conn, mapi_
 	uint32_t res = MAPI_E_RESERVED;
 
 	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, res);
-	g_return_val_if_fail (priv->session != NULL, res);
+	e_return_val_mapi_error_if_fail (priv->session != NULL, MAPI_E_INVALID_PARAMETER, res);
 
 	g_debug("%s: Entering %s ", G_STRLOC, G_STRFUNC);
 
@@ -2306,17 +2419,16 @@ exchange_mapi_connection_resolve_named_prop (ExchangeMapiConnection *conn, mapi_
 	SPropTagArray = talloc_zero(mem_ctx, struct SPropTagArray);
 
 	/* Attempt to open the folder */
-	retval = open_folder (conn, 0, &fid, 0, &obj_folder);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("open_folder", GetLastError());
+	ms = open_folder (conn, 0, &fid, 0, &obj_folder, perror);
+	if (ms != MAPI_E_SUCCESS) {
 		goto cleanup;
 	}
 
 	mapi_nameid_canonical_add (nameid, pidlid_propid);
 
-	retval = mapi_nameid_GetIDsFromNames(nameid, &obj_folder, SPropTagArray);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("mapi_nameid_GetIDsFromNames", GetLastError());
+	ms = mapi_nameid_GetIDsFromNames(nameid, &obj_folder, SPropTagArray);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "mapi_nameid_GetIDsFromNames", ms);
 		goto cleanup;
 	}
 
@@ -2352,21 +2464,21 @@ cleanup:
 }
 
 mapi_id_t
-exchange_mapi_connection_get_default_folder_id (ExchangeMapiConnection *conn, uint32_t olFolder)
+exchange_mapi_connection_get_default_folder_id (ExchangeMapiConnection *conn, uint32_t olFolder, GError **perror)
 {
-	enum MAPISTATUS retval;
+	enum MAPISTATUS ms;
 	mapi_id_t fid = 0;
 
 	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, 0);
-	g_return_val_if_fail (priv->session != NULL, 0);
+	e_return_val_mapi_error_if_fail (priv->session != NULL, MAPI_E_INVALID_PARAMETER, 0);
 
 	g_debug("%s: Entering %s ", G_STRLOC, G_STRFUNC);
 
 	LOCK ();
 
-	retval = GetDefaultFolder (&priv->msg_store, &fid, olFolder);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("GetDefaultFolder", GetLastError());
+	ms = GetDefaultFolder (&priv->msg_store, &fid, olFolder);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "GetDefaultFolder", ms);
 		goto cleanup;
 	}
 
@@ -2375,16 +2487,16 @@ cleanup:
 
 	g_debug("%s: Leaving %s ", G_STRLOC, G_STRFUNC);
 
-	return (retval == MAPI_E_SUCCESS ? fid : 0);
+	return (ms == MAPI_E_SUCCESS ? fid : 0);
 }
 
 mapi_id_t
 exchange_mapi_connection_create_item (ExchangeMapiConnection *conn, uint32_t olFolder, mapi_id_t fid,
 			   BuildWritePropsCB build_props, gpointer bwp_data,
 			   GSList *recipients, GSList *attachments, GSList *generic_streams,
-			   uint32_t options)
+			   uint32_t options, GError **perror)
 {
-	enum MAPISTATUS retval;
+	enum MAPISTATUS ms;
 	TALLOC_CTX *mem_ctx;
 	mapi_object_t obj_folder;
 	mapi_object_t obj_message;
@@ -2393,7 +2505,7 @@ exchange_mapi_connection_create_item (ExchangeMapiConnection *conn, uint32_t olF
 	mapi_id_t mid = 0;
 
 	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, 0);
-	g_return_val_if_fail (priv->session != NULL, 0);
+	e_return_val_mapi_error_if_fail (priv->session != NULL, MAPI_E_INVALID_PARAMETER, 0);
 
 	g_debug("%s: Entering %s ", G_STRLOC, G_STRFUNC);
 
@@ -2404,16 +2516,15 @@ exchange_mapi_connection_create_item (ExchangeMapiConnection *conn, uint32_t olF
 	mapi_object_init(&obj_message);
 
 	/* Attempt to open the folder */
-	retval = open_folder (conn, olFolder, &fid, options, &obj_folder);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("open_folder", GetLastError());
+	ms = open_folder (conn, olFolder, &fid, options, &obj_folder, perror);
+	if (ms != MAPI_E_SUCCESS) {
 		goto cleanup;
 	}
 
 	/* Create the item */
-	retval = CreateMessage(&obj_folder, &obj_message);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("CreateMessage", GetLastError());
+	ms = CreateMessage (&obj_folder, &obj_message);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "CreateMessage", ms);
 		goto cleanup;
 	}
 
@@ -2422,42 +2533,46 @@ exchange_mapi_connection_create_item (ExchangeMapiConnection *conn, uint32_t olF
 	/* Add regular props using callback */
 	if (build_props && !build_props (conn, fid, mem_ctx, &props, &propslen, bwp_data)) {
 		g_debug ("%s: (%s): build_props failed! propslen = %d ", G_STRLOC, G_STRFUNC, propslen);
+		make_mapi_error (perror, "build_props", MAPI_E_CALL_FAILED);
 		goto cleanup;
 	}
 
 	/* set properties for the item */
-	retval = SetProps(&obj_message, props, propslen);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("SetProps", GetLastError());
+	ms = SetProps (&obj_message, props, propslen);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "SetProps", ms);
 		goto cleanup;
 	}
 
 	if (generic_streams) {
-		exchange_mapi_util_write_generic_streams (&obj_message, generic_streams);
+		if (!exchange_mapi_util_write_generic_streams (&obj_message, generic_streams, perror))
+			goto cleanup;
 	}
 
 	/* Set attachments if any */
 	if (attachments) {
-		exchange_mapi_util_set_attachments (&obj_message, attachments, FALSE);
+		if (!exchange_mapi_util_set_attachments (&obj_message, attachments, FALSE, perror))
+			goto cleanup;
 	}
 
 	/* Set recipients if any */
 	if (recipients) {
-		exchange_mapi_util_modify_recipients (conn, mem_ctx, &obj_message, recipients, FALSE);
+		if (!exchange_mapi_util_modify_recipients (conn, mem_ctx, &obj_message, recipients, FALSE, perror))
+			goto cleanup;
 	}
 
 	/* Finally, save all changes */
-	retval = SaveChangesMessage(&obj_folder, &obj_message, KeepOpenReadWrite);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("SaveChangesMessage", GetLastError());
+	ms = SaveChangesMessage (&obj_folder, &obj_message, KeepOpenReadWrite);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "SaveChangesMessage", ms);
 		goto cleanup;
 	}
 
 	if (recipients && !(options & MAPI_OPTIONS_DONT_SUBMIT)) {
 		/* Mark message as ready to be sent */
-		retval = SubmitMessage(&obj_message);
-		if (retval != MAPI_E_SUCCESS) {
-			mapi_errstr("SubmitMessage", GetLastError());
+		ms = SubmitMessage (&obj_message);
+		if (ms != MAPI_E_SUCCESS) {
+			make_mapi_error (perror, "SubmitMessage", ms);
 
 			/*
 			The code is storing message right to Sent items instead of Outbox,
@@ -2473,9 +2588,9 @@ exchange_mapi_connection_create_item (ExchangeMapiConnection *conn, uint32_t olF
 				/* to not release a message object twice */
 				mapi_object_init (&obj_message);
 
-				retval = DeleteMessage (&obj_folder, &mid, 1);
-				if (retval != MAPI_E_SUCCESS) {
-					mapi_errstr ("DeleteMessage", GetLastError ());
+				ms = DeleteMessage (&obj_folder, &mid, 1);
+				if (ms != MAPI_E_SUCCESS) {
+					make_mapi_error (perror, "DeleteMessage", ms);
 				}
 
 				/* do not forget to set it back to 0, as the function failed */
@@ -2504,9 +2619,9 @@ gboolean
 exchange_mapi_connection_modify_item (ExchangeMapiConnection *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)
+			   uint32_t options, GError **perror)
 {
-	enum MAPISTATUS retval;
+	enum MAPISTATUS ms;
 	TALLOC_CTX *mem_ctx;
 	mapi_object_t obj_folder;
 	mapi_object_t obj_message;
@@ -2515,7 +2630,7 @@ exchange_mapi_connection_modify_item (ExchangeMapiConnection *conn, uint32_t olF
 	gboolean result = FALSE;
 
 	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, FALSE);
-	g_return_val_if_fail (priv->session != NULL, FALSE);
+	e_return_val_mapi_error_if_fail (priv->session != NULL, MAPI_E_INVALID_PARAMETER, FALSE);
 
 	g_debug("%s: Entering %s ", G_STRLOC, G_STRFUNC);
 
@@ -2526,16 +2641,15 @@ exchange_mapi_connection_modify_item (ExchangeMapiConnection *conn, uint32_t olF
 	mapi_object_init(&obj_message);
 
 	/* Attempt to open the folder */
-	retval = open_folder (conn, olFolder, &fid, options, &obj_folder);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("open_folder", GetLastError());
+	ms = open_folder (conn, olFolder, &fid, options, &obj_folder, perror);
+	if (ms != MAPI_E_SUCCESS) {
 		goto cleanup;
 	}
 
 	/* Open the item to be modified */
-	retval = OpenMessage(&obj_folder, fid, mid, &obj_message, MAPI_MODIFY);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("OpenMessage", GetLastError());
+	ms = OpenMessage (&obj_folder, fid, mid, &obj_message, MAPI_MODIFY);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "OpenMessage", ms);
 		goto cleanup;
 	}
 
@@ -2544,44 +2658,48 @@ exchange_mapi_connection_modify_item (ExchangeMapiConnection *conn, uint32_t olF
 	/* Add regular props using callback */
 	if (build_props && !build_props (conn, fid, mem_ctx, &props, &propslen, bwp_data)) {
 		g_debug ("%s: (%s): Could not build props ", G_STRLOC, G_STRFUNC);
+		make_mapi_error (perror, "build_props", MAPI_E_CALL_FAILED);
 		goto cleanup;
 	}
 
 	/* set properties for the item */
-	retval = SetProps(&obj_message, props, propslen);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("SetProps", GetLastError());
+	ms = SetProps (&obj_message, props, propslen);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "SetProps", ms);
 		goto cleanup;
 	}
 
 	if (generic_streams) {
-		exchange_mapi_util_write_generic_streams (&obj_message, generic_streams);
+		if (!exchange_mapi_util_write_generic_streams (&obj_message, generic_streams, perror))
+			goto cleanup;
 	}
 
 	/* Set attachments if any */
 	if (attachments) {
-		exchange_mapi_util_set_attachments (&obj_message, attachments, TRUE);
+		if (!exchange_mapi_util_set_attachments (&obj_message, attachments, TRUE, perror))
+			goto cleanup;
 	} else {
-		exchange_mapi_util_delete_attachments (&obj_message);
+		exchange_mapi_util_delete_attachments (&obj_message, NULL);
 	}
 
 	/* Set recipients if any */
 	if (recipients) {
-		exchange_mapi_util_modify_recipients (conn, mem_ctx, &obj_message, recipients, TRUE);
+		if (!exchange_mapi_util_modify_recipients (conn, mem_ctx, &obj_message, recipients, TRUE, perror))
+			goto cleanup;
 	}
 
 	/* Finally, save all changes */
-	retval = SaveChangesMessage(&obj_folder, &obj_message, KeepOpenReadWrite);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("SaveChangesMessage", GetLastError());
+	ms = SaveChangesMessage (&obj_folder, &obj_message, KeepOpenReadWrite);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "SaveChangesMessage", ms);
 		goto cleanup;
 	}
 
 	if (recipients && !(options & MAPI_OPTIONS_DONT_SUBMIT)) {
 		/* Mark message as ready to be sent */
-		retval = SubmitMessage(&obj_message);
-		if (retval != MAPI_E_SUCCESS) {
-			mapi_errstr("SubmitMessage", GetLastError());
+		ms = SubmitMessage (&obj_message);
+		if (ms != MAPI_E_SUCCESS) {
+			make_mapi_error (perror, "SubmitMessage", ms);
 			goto cleanup;
 		}
 	}
@@ -2601,9 +2719,9 @@ cleanup:
 }
 
 gboolean
-exchange_mapi_connection_set_flags (ExchangeMapiConnection *conn, uint32_t olFolder, mapi_id_t fid, guint32 fid_options, GSList *mids, uint32_t flag)
+exchange_mapi_connection_set_flags (ExchangeMapiConnection *conn, uint32_t olFolder, mapi_id_t fid, guint32 fid_options, GSList *mids, uint32_t flag, GError **perror)
 {
-	enum MAPISTATUS retval;
+	enum MAPISTATUS ms;
 	TALLOC_CTX *mem_ctx;
 	mapi_object_t obj_folder;
 	uint32_t i;
@@ -2612,7 +2730,7 @@ exchange_mapi_connection_set_flags (ExchangeMapiConnection *conn, uint32_t olFol
 	gboolean result = FALSE;
 
 	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, FALSE);
-	g_return_val_if_fail (priv->session != NULL, FALSE);
+	e_return_val_mapi_error_if_fail (priv->session != NULL, MAPI_E_INVALID_PARAMETER, FALSE);
 
 	g_debug("%s: Entering %s ", G_STRLOC, G_STRFUNC);
 
@@ -2625,15 +2743,14 @@ exchange_mapi_connection_set_flags (ExchangeMapiConnection *conn, uint32_t olFol
 		id_messages[i] = *((mapi_id_t *)tmp->data);
 
 	/* Attempt to open the folder */
-	retval = open_folder (conn, olFolder, &fid, fid_options, &obj_folder);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("open_folder", GetLastError());
+	ms = open_folder (conn, olFolder, &fid, fid_options, &obj_folder, perror);
+	if (ms != MAPI_E_SUCCESS) {
 		goto cleanup;
 	}
 
-	retval = SetReadFlags(&obj_folder, flag, i, id_messages);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("SetReadFlags", GetLastError());
+	ms = SetReadFlags (&obj_folder, flag, i, id_messages);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "SetReadFlags", ms);
 		goto cleanup;
 	}
 
@@ -2651,15 +2768,15 @@ cleanup:
 }
 
 static gboolean
-mapi_move_items (ExchangeMapiConnection *conn, mapi_id_t src_fid, guint32 src_fid_options, mapi_id_t dest_fid, guint32 dest_fid_options, GSList *mid_list, gboolean do_copy)
+mapi_move_items (ExchangeMapiConnection *conn, mapi_id_t src_fid, guint32 src_fid_options, mapi_id_t dest_fid, guint32 dest_fid_options, GSList *mid_list, gboolean do_copy, GError **perror)
 {
-	enum MAPISTATUS	retval;
+	enum MAPISTATUS	ms;
 	mapi_object_t obj_folder_src;
 	mapi_object_t obj_folder_dst;
 	mapi_id_array_t msg_id_array;
 	GSList *l;
 
-	g_return_val_if_fail (conn != NULL, MAPI_E_INVALID_PARAMETER);
+	e_return_val_mapi_error_if_fail (conn != NULL, MAPI_E_INVALID_PARAMETER, FALSE);
 
 	mapi_object_init(&obj_folder_src);
 	mapi_object_init(&obj_folder_dst);
@@ -2668,21 +2785,19 @@ mapi_move_items (ExchangeMapiConnection *conn, mapi_id_t src_fid, guint32 src_fi
 	for (l = mid_list; l != NULL; l = g_slist_next (l))
 		mapi_id_array_add_id (&msg_id_array, *((mapi_id_t *)l->data));
 
-	retval = open_folder (conn, 0, &src_fid, src_fid_options, &obj_folder_src);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("open_folder - source folder", GetLastError());
+	ms = open_folder (conn, 0, &src_fid, src_fid_options, &obj_folder_src, perror);
+	if (ms != MAPI_E_SUCCESS) {
 		goto cleanup;
 	}
 
-	retval = open_folder (conn, 0, &dest_fid, dest_fid_options, &obj_folder_dst);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("open_folder - destination folder", GetLastError());
+	ms = open_folder (conn, 0, &dest_fid, dest_fid_options, &obj_folder_dst, perror);
+	if (ms != MAPI_E_SUCCESS) {
 		goto cleanup;
 	}
 
-	retval = MoveCopyMessages(&obj_folder_src, &obj_folder_dst, &msg_id_array, do_copy);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("MoveCopyMessages", GetLastError());
+	ms = MoveCopyMessages (&obj_folder_src, &obj_folder_dst, &msg_id_array, do_copy);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "MoveCopyMessages", ms);
 		goto cleanup;
 	}
 
@@ -2691,51 +2806,51 @@ cleanup:
 	mapi_object_release(&obj_folder_dst);
 	mapi_object_release(&obj_folder_src);
 
-	return retval;
+	return ms;
 }
 
-enum MAPISTATUS
-exchange_mapi_connection_copy_items (ExchangeMapiConnection *conn, mapi_id_t src_fid, guint32 src_fid_options, mapi_id_t dest_fid, guint32 dest_fid_options, GSList *mids)
+gboolean
+exchange_mapi_connection_copy_items (ExchangeMapiConnection *conn, mapi_id_t src_fid, guint32 src_fid_options, mapi_id_t dest_fid, guint32 dest_fid_options, GSList *mids, GError **perror)
 {
-	enum MAPISTATUS retval;
+	enum MAPISTATUS ms;
 
 	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, MAPI_E_INVALID_PARAMETER);
-	g_return_val_if_fail (priv->session != NULL, MAPI_E_INVALID_PARAMETER);
+	e_return_val_mapi_error_if_fail (priv->session != NULL, MAPI_E_INVALID_PARAMETER, MAPI_E_INVALID_PARAMETER);
 
 	g_debug("%s: Entering %s ", G_STRLOC, G_STRFUNC);
 
 	LOCK ();
-	retval = mapi_move_items (conn, src_fid, src_fid_options, dest_fid, dest_fid_options, mids, TRUE);
+	ms = mapi_move_items (conn, src_fid, src_fid_options, dest_fid, dest_fid_options, mids, TRUE, perror);
 	UNLOCK ();
 
 	g_debug("%s: Leaving %s ", G_STRLOC, G_STRFUNC);
 
-	return retval;
+	return ms == MAPI_E_SUCCESS;
 }
 
-enum MAPISTATUS
-exchange_mapi_connection_move_items (ExchangeMapiConnection *conn, mapi_id_t src_fid, guint32 src_fid_options, mapi_id_t dest_fid, guint32 dest_fid_options, GSList *mids)
+gboolean
+exchange_mapi_connection_move_items (ExchangeMapiConnection *conn, mapi_id_t src_fid, guint32 src_fid_options, mapi_id_t dest_fid, guint32 dest_fid_options, GSList *mids, GError **perror)
 {
-	enum MAPISTATUS retval;
+	enum MAPISTATUS ms;
 
 	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, MAPI_E_INVALID_PARAMETER);
-	g_return_val_if_fail (priv->session != NULL, MAPI_E_INVALID_PARAMETER);
+	e_return_val_mapi_error_if_fail (priv->session != NULL, MAPI_E_INVALID_PARAMETER, MAPI_E_INVALID_PARAMETER);
 
 	g_debug("%s: Entering %s ", G_STRLOC, G_STRFUNC);
 
 	LOCK ();
-	retval = mapi_move_items (conn, src_fid, src_fid_options, dest_fid, dest_fid_options, mids, FALSE);
+	ms = mapi_move_items (conn, src_fid, src_fid_options, dest_fid, dest_fid_options, mids, FALSE, perror);
 	UNLOCK ();
 
 	g_debug("%s: Leaving %s ", G_STRLOC, G_STRFUNC);
 
-	return retval;
+	return ms == MAPI_E_SUCCESS;
 }
 
 gboolean
-exchange_mapi_connection_remove_items (ExchangeMapiConnection *conn, uint32_t olFolder, mapi_id_t fid, guint32 fid_options, GSList *mids)
+exchange_mapi_connection_remove_items (ExchangeMapiConnection *conn, uint32_t olFolder, mapi_id_t fid, guint32 fid_options, GSList *mids, GError **perror)
 {
-	enum MAPISTATUS retval;
+	enum MAPISTATUS ms;
 	TALLOC_CTX *mem_ctx;
 	mapi_object_t obj_folder;
 	uint32_t i;
@@ -2744,7 +2859,7 @@ exchange_mapi_connection_remove_items (ExchangeMapiConnection *conn, uint32_t ol
 	gboolean result = FALSE;
 
 	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, FALSE);
-	g_return_val_if_fail (priv->session != NULL, FALSE);
+	e_return_val_mapi_error_if_fail (priv->session != NULL, MAPI_E_INVALID_PARAMETER, FALSE);
 
 	g_debug("%s: Entering %s ", G_STRLOC, G_STRFUNC);
 
@@ -2760,16 +2875,15 @@ exchange_mapi_connection_remove_items (ExchangeMapiConnection *conn, uint32_t ol
 	}
 
 	/* Attempt to open the folder */
-	retval = open_folder (conn, olFolder, &fid, fid_options, &obj_folder);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("open_folder", GetLastError());
+	ms = open_folder (conn, olFolder, &fid, fid_options, &obj_folder, perror);
+	if (ms != MAPI_E_SUCCESS) {
 		goto cleanup;
 	}
 
 	/* Delete the messages from the folder */
-	retval = DeleteMessage(&obj_folder, id_messages, i);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("DeleteMessage", GetLastError());
+	ms = DeleteMessage (&obj_folder, id_messages, i);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "DeleteMessage", ms);
 		goto cleanup;
 	}
 
@@ -2787,10 +2901,10 @@ cleanup:
 }
 
 static gboolean
-get_child_folders(TALLOC_CTX *mem_ctx, ExchangeMAPIFolderCategory folder_hier, mapi_object_t *parent,
-		  mapi_id_t folder_id, GSList **mapi_folders)
+get_child_folders (TALLOC_CTX *mem_ctx, ExchangeMAPIFolderCategory folder_hier, mapi_object_t *parent,
+		   mapi_id_t folder_id, GSList **mapi_folders, GError **perror)
 {
-	enum MAPISTATUS		retval;
+	enum MAPISTATUS		ms;
 	mapi_object_t		obj_folder;
 	mapi_object_t		obj_table;
 	struct SPropTagArray	*SPropTagArray = NULL;
@@ -2799,24 +2913,25 @@ get_child_folders(TALLOC_CTX *mem_ctx, ExchangeMAPIFolderCategory folder_hier, m
 	gboolean		result = TRUE;
 
 	/* sanity check */
-	g_return_val_if_fail (mem_ctx != NULL, FALSE);
-	g_return_val_if_fail (parent != NULL, FALSE);
+	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);
 
 	/* Attempt to open the folder */
-	retval = OpenFolder(parent, folder_id, &obj_folder);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("OpenFolder", GetLastError());
+	ms = OpenFolder (parent, folder_id, &obj_folder);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "OpenFolder", ms);
+		result = FALSE;
 		goto cleanup;
 	}
 
 	/* Get the hierarchy table */
-	retval = GetHierarchyTable (&obj_folder, &obj_table, TableFlags_Depth | TableFlags_NoNotifications | TableFlags_UseUnicode, &row_count);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("GetHierarchyTable", GetLastError());
+	ms = GetHierarchyTable (&obj_folder, &obj_table, TableFlags_Depth | TableFlags_NoNotifications | TableFlags_UseUnicode, &row_count);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "GetHierarchyTable", ms);
+		result = FALSE;
 		goto cleanup;
 	}
 
@@ -2830,25 +2945,28 @@ get_child_folders(TALLOC_CTX *mem_ctx, ExchangeMAPIFolderCategory folder_hier, m
 					  PR_MESSAGE_SIZE,
 					  PR_FOLDER_CHILD_COUNT);
 
-	retval = SetColumns(&obj_table, SPropTagArray);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("SetColumns", GetLastError());
+	ms = SetColumns (&obj_table, SPropTagArray);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "SetColumns", ms);
+		result = FALSE;
 		goto cleanup;
 	}
 
 	cursor_pos = 0;
 
 	do {
-		retval = QueryPosition (&obj_table, &cursor_pos, &count);
-		if (retval != MAPI_E_SUCCESS) {
-			mapi_errstr("QueryPosition", GetLastError());
+		ms = QueryPosition (&obj_table, &cursor_pos, &count);
+		if (ms != MAPI_E_SUCCESS) {
+			make_mapi_error (perror, "QueryPosition", ms);
+			result = FALSE;
 			goto cleanup;
 		}
 
 		/* Fill the table columns with data from the rows */
-		retval = QueryRows (&obj_table, 100, TBL_ADVANCE, &rowset);
-		if (retval != MAPI_E_SUCCESS) {
-			mapi_errstr("QueryRows", GetLastError());
+		ms = QueryRows (&obj_table, 100, TBL_ADVANCE, &rowset);
+		if (ms != MAPI_E_SUCCESS) {
+			make_mapi_error (perror, "QueryRows", ms);
+			result = FALSE;
 			goto cleanup;
 		}
 
@@ -2900,8 +3018,8 @@ cleanup:
 /*NOTE : This should be called when you hold the connection lock*/
 /*NOTE : IsMailboxFolder doesn't support this yet. */
 /* Ticket : http://trac.openchange.org/ticket/134  */
-static void
-mapi_get_ren_additional_fids (mapi_object_t *obj_store, GHashTable **folder_list)
+static gboolean
+mapi_get_ren_additional_fids (mapi_object_t *obj_store, GHashTable **folder_list, GError **perror)
 {
 	mapi_id_t inbox_id, fid;
 	mapi_object_t obj_folder_inbox;
@@ -2910,7 +3028,7 @@ mapi_get_ren_additional_fids (mapi_object_t *obj_store, GHashTable **folder_list
 	struct SRow aRow;
 	const struct BinaryArray_r *entryids;
 	struct Binary_r entryid;
-	enum MAPISTATUS retval;
+	enum MAPISTATUS ms;
 
 	guint32 count, *folder_type;
 	guint i = 0;
@@ -2930,16 +3048,16 @@ mapi_get_ren_additional_fids (mapi_object_t *obj_store, GHashTable **folder_list
 	mapi_object_init(&obj_folder_inbox);
 
 	/* Get Inbox FID using GetDefaultFolder. */
-	retval = GetDefaultFolder(obj_store, &inbox_id, olFolderInbox);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("GetDefaultFolder", GetLastError());
+	ms = GetDefaultFolder (obj_store, &inbox_id, olFolderInbox);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "GetDefaultFolder", ms);
 		goto cleanup;
 	}
 
 	/* Open InboxFolder. */
-	retval = OpenFolder(obj_store, inbox_id, &obj_folder_inbox);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("OpenFolder", GetLastError());
+	ms = OpenFolder (obj_store, inbox_id, &obj_folder_inbox);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "OpenFolder", ms);
 		goto cleanup;
 	}
 
@@ -2947,7 +3065,11 @@ mapi_get_ren_additional_fids (mapi_object_t *obj_store, GHashTable **folder_list
 	SPropTagArray = set_SPropTagArray(mem_ctx, 0x1, PR_ADDITIONAL_REN_ENTRYIDS);
 
 	lpProps = talloc_zero(mem_ctx, struct SPropValue);
-	retval = GetProps (&obj_folder_inbox, SPropTagArray, &lpProps, &count);
+	ms = GetProps (&obj_folder_inbox, SPropTagArray, &lpProps, &count);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "GetProps", ms);
+		goto cleanup;
+	}
 
 	/* Build a SRow structure */
 	aRow.ulAdrEntryPad = 0;
@@ -2961,9 +3083,9 @@ mapi_get_ren_additional_fids (mapi_object_t *obj_store, GHashTable **folder_list
 		for (i = 0; i < G_N_ELEMENTS (olfolder_defaults); i++) {
 			fid = 0;
 			entryid = entryids->lpbin [i];
-			retval = GetFIDFromEntryID(entryid.cb, entryid.lpb, inbox_id, &fid);
+			ms = GetFIDFromEntryID(entryid.cb, entryid.lpb, inbox_id, &fid);
 
-			if (retval == MAPI_E_SUCCESS && fid) {
+			if (ms == MAPI_E_SUCCESS && fid) {
 				folder_type = g_new0 (guint32, 1);
 				*folder_type = olfolder_defaults[i];
 
@@ -2977,17 +3099,22 @@ mapi_get_ren_additional_fids (mapi_object_t *obj_store, GHashTable **folder_list
 cleanup:
 	mapi_object_release(&obj_folder_inbox);
 	talloc_free (mem_ctx);
+
+	return ms == MAPI_E_SUCCESS;
 }
 
-static void
-set_default_folders (mapi_object_t *obj_store, GSList **mapi_folders)
+static gboolean
+set_default_folders (mapi_object_t *obj_store, GSList **mapi_folders, 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);
 
-	mapi_get_ren_additional_fids (obj_store, &default_folders);
+	if (!mapi_get_ren_additional_fids (obj_store, &default_folders, perror)) {
+		g_hash_table_destroy (default_folders);
+		return FALSE;
+	}
 
 	while (folder_list != NULL) {
 		ExchangeMAPIFolder *folder = NULL;
@@ -3011,6 +3138,8 @@ set_default_folders (mapi_object_t *obj_store, GSList **mapi_folders)
 	}
 
 	g_hash_table_destroy (default_folders);
+
+	return TRUE;
 }
 
 static void
@@ -3028,9 +3157,9 @@ set_user_name (gpointer data, gpointer user_data)
 }
 
 gboolean
-exchange_mapi_connection_get_folders_list (ExchangeMapiConnection *conn, GSList **mapi_folders)
+exchange_mapi_connection_get_folders_list (ExchangeMapiConnection *conn, GSList **mapi_folders, GError **perror)
 {
-	enum MAPISTATUS	retval;
+	enum MAPISTATUS	ms;
 	TALLOC_CTX		*mem_ctx;
 	struct SPropTagArray	*SPropTagArray;
 	struct SPropValue	*lpProps;
@@ -3046,7 +3175,7 @@ exchange_mapi_connection_get_folders_list (ExchangeMapiConnection *conn, GSList
 	const uint32_t          *mailbox_size = NULL;
 
 	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, FALSE);
-	g_return_val_if_fail (priv->session != NULL, FALSE);
+	e_return_val_mapi_error_if_fail (priv->session != NULL, MAPI_E_INVALID_PARAMETER, FALSE);
 
 	g_debug("%s: Entering %s ", G_STRLOC, G_STRFUNC);
 
@@ -3062,11 +3191,11 @@ exchange_mapi_connection_get_folders_list (ExchangeMapiConnection *conn, GSList
 					  PR_USER_NAME_UNICODE);
 
 	lpProps = talloc_zero(mem_ctx, struct SPropValue);
-	retval = GetProps (&priv->msg_store, SPropTagArray, &lpProps, &count);
+	ms = GetProps (&priv->msg_store, SPropTagArray, &lpProps, &count);
 	MAPIFreeBuffer(SPropTagArray);
 
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("GetProps", GetLastError());
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "GetProps", ms);
 		goto cleanup;
 	}
 
@@ -3082,9 +3211,9 @@ exchange_mapi_connection_get_folders_list (ExchangeMapiConnection *conn, GSList
 	mailbox_size = (const uint32_t *)exchange_mapi_util_find_row_propval  (&aRow, PR_MESSAGE_SIZE);
 
 	/* Prepare the directory listing */
-	retval = GetDefaultFolder(&priv->msg_store, &mailbox_id, olFolderTopInformationStore);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("GetDefaultFolder", GetLastError());
+	ms = GetDefaultFolder (&priv->msg_store, &mailbox_id, olFolderTopInformationStore);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "GetDefaultFolder", ms);
 		goto cleanup;
 	}
 
@@ -3100,18 +3229,19 @@ exchange_mapi_connection_get_folders_list (ExchangeMapiConnection *conn, GSList
 	*mapi_folders = g_slist_prepend (*mapi_folders, folder);
 
 	/* FIXME: check status of get_child_folders */
-	get_child_folders (mem_ctx, MAPI_PERSONAL_FOLDER, &priv->msg_store, mailbox_id, mapi_folders);
+	result = get_child_folders (mem_ctx, MAPI_PERSONAL_FOLDER, &priv->msg_store, mailbox_id, mapi_folders, perror);
 
 	g_free(utf8_mailbox_name);
 
 	*mapi_folders = g_slist_reverse (*mapi_folders);
 
-	set_default_folders (&priv->msg_store, mapi_folders);
+	if (!set_default_folders (&priv->msg_store, mapi_folders, 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);
 
-	result = TRUE;
-
 cleanup:
 	talloc_free (mem_ctx);
 
@@ -3123,39 +3253,37 @@ cleanup:
 }
 
 gboolean
-exchange_mapi_connection_get_pf_folders_list (ExchangeMapiConnection *conn, GSList **mapi_folders)
+exchange_mapi_connection_get_pf_folders_list (ExchangeMapiConnection *conn, GSList **mapi_folders, GError **perror)
 {
-	enum MAPISTATUS		retval;
+	enum MAPISTATUS		ms;
 	TALLOC_CTX		*mem_ctx;
 	gboolean		result = FALSE;
 	mapi_id_t		mailbox_id;
 	ExchangeMAPIFolder	*folder;
 
 	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, FALSE);
-	g_return_val_if_fail (priv->session != NULL, FALSE);
+	e_return_val_mapi_error_if_fail (priv->session != NULL, MAPI_E_INVALID_PARAMETER, FALSE);
 
 	g_debug("%s: Entering %s ", G_STRLOC, G_STRFUNC);
 
 	LOCK ();
 	mem_ctx = talloc_init("ExchangeMAPI_PF_GetFoldersList");
 
-	if (!ensure_public_store (priv))
+	if (!ensure_public_store (priv, perror))
 		goto cleanup;
 
-	retval = GetDefaultPublicFolder (&priv->public_store, &mailbox_id, olFolderPublicIPMSubtree);
-		if (retval != MAPI_E_SUCCESS) {
-			mapi_errstr("GetDefaultPublicFolder", GetLastError());
-			goto cleanup;
-		}
+	ms = GetDefaultPublicFolder (&priv->public_store, &mailbox_id, olFolderPublicIPMSubtree);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "GetDefaultPublicFolder", ms);
+		goto cleanup;
+	}
 
 	folder = exchange_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);
-	get_child_folders (mem_ctx, MAPI_FAVOURITE_FOLDER, &priv->public_store,
-			   mailbox_id, mapi_folders);
+	result = get_child_folders (mem_ctx, MAPI_FAVOURITE_FOLDER, &priv->public_store, mailbox_id, mapi_folders, perror);
 	*mapi_folders = g_slist_reverse (*mapi_folders);
-	result = TRUE;
 
 cleanup:
 	talloc_free (mem_ctx);
@@ -3170,32 +3298,36 @@ cleanup:
 GSList *
 exchange_mapi_connection_peek_folders_list (ExchangeMapiConnection *conn)
 {
+	/* to have this used in the below macros */
+	GError **perror = NULL;
+
 	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, FALSE);
-	g_return_val_if_fail (priv->session != NULL, FALSE);
+	e_return_val_mapi_error_if_fail (priv->session != NULL, MAPI_E_INVALID_PARAMETER, FALSE);
 
 	LOCK ();
 	if (!priv->folders)
-		exchange_mapi_connection_get_folders_list (conn, &priv->folders);
+		exchange_mapi_connection_get_folders_list (conn, &priv->folders, perror);
 	UNLOCK ();
 
 	return priv->folders;
 }
 
-const gchar *
-exchange_mapi_connection_ex_to_smtp (ExchangeMapiConnection *conn, const gchar *ex_address)
+/* free returned pointer with g_free() */
+gchar *
+exchange_mapi_connection_ex_to_smtp (ExchangeMapiConnection *conn, const gchar *ex_address, GError **perror)
 {
-	enum MAPISTATUS	retval;
+	enum MAPISTATUS	ms;
 	TALLOC_CTX		*mem_ctx;
 	struct SPropTagArray	*SPropTagArray;
 	struct SRowSet		*SRowSet = NULL;
 	struct SPropTagArray	*flaglist = NULL;
 	const gchar		*str_array[2];
-	const gchar		*smtp_addr = NULL;
+	gchar			*smtp_addr = NULL;
 
 	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, FALSE);
-	g_return_val_if_fail (priv->session != NULL, FALSE);
+	e_return_val_mapi_error_if_fail (priv->session != NULL, MAPI_E_INVALID_PARAMETER, FALSE);
 
-	g_return_val_if_fail (ex_address != NULL, NULL);
+	e_return_val_mapi_error_if_fail (ex_address != NULL, MAPI_E_INVALID_PARAMETER, NULL);
 
 	str_array[0] = ex_address;
 	str_array[1] = NULL;
@@ -3207,117 +3339,113 @@ exchange_mapi_connection_ex_to_smtp (ExchangeMapiConnection *conn, const gchar *
 	SPropTagArray = set_SPropTagArray(mem_ctx, 0x1,
 					  PR_SMTP_ADDRESS_UNICODE);
 
-	retval = ResolveNames (priv->session, (const gchar **)str_array, SPropTagArray, &SRowSet, &flaglist, MAPI_UNICODE);
-	if (retval != MAPI_E_SUCCESS)
-		retval = ResolveNames (priv->session, (const gchar **)str_array, SPropTagArray, &SRowSet, &flaglist, 0);
+	ms = ResolveNames (priv->session, (const gchar **)str_array, SPropTagArray, &SRowSet, &flaglist, MAPI_UNICODE);
+	if (ms != MAPI_E_SUCCESS)
+		ms = ResolveNames (priv->session, (const gchar **)str_array, SPropTagArray, &SRowSet, &flaglist, 0);
 
-	if (retval == MAPI_E_SUCCESS && SRowSet && SRowSet->cRows == 1) {
-		smtp_addr = (const gchar *) exchange_mapi_util_find_row_propval (SRowSet->aRow, PR_SMTP_ADDRESS_UNICODE);
+	if (ms == MAPI_E_SUCCESS && SRowSet && SRowSet->cRows == 1) {
+		smtp_addr = g_strdup (exchange_mapi_util_find_row_propval (SRowSet->aRow, PR_SMTP_ADDRESS_UNICODE));
 	}
 
 	talloc_free (mem_ctx);
 
 	UNLOCK ();
 
+	if (ms != MAPI_E_SUCCESS)
+		make_mapi_error (perror, "ResolveNames", ms);
+
 	return smtp_addr;
 }
 
 gboolean
-exchange_mapi_connection_events_init (ExchangeMapiConnection *conn)
+exchange_mapi_connection_events_init (ExchangeMapiConnection *conn, GError **perror)
 {
-	gboolean retval;
+	enum MAPISTATUS ms;
 
 	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, FALSE);
-	g_return_val_if_fail (priv->session != NULL, FALSE);
+	e_return_val_mapi_error_if_fail (priv->session != NULL, MAPI_E_INVALID_PARAMETER, FALSE);
 
 	LOCK ();
 	#ifdef HAVE_CORRECT_REGISTERNOTIFICATION
-	retval = RegisterNotification (priv->session, 0) == MAPI_E_SUCCESS;
+	ms = RegisterNotification (priv->session, 0);
 	#else
-	retval = FALSE;
+	res = MAPI_E_NOT_IMPLEMENTED;
 	#endif
 	UNLOCK ();
 
-	return retval;
+	if (ms != MAPI_E_SUCCESS)
+		make_mapi_error (perror, "RegisterNotification", ms);
+
+	return ms == MAPI_E_SUCCESS;
 }
 
 gboolean
 exchange_mapi_connection_events_subscribe (ExchangeMapiConnection *conn, guint32 options,
 				guint16 event_mask, guint32 *events_conn_id,
-				mapi_notify_callback_t callback, gpointer data)
+				mapi_notify_callback_t callback, gpointer data, GError **perror)
 {
-	enum MAPISTATUS	retval = MAPI_E_CALL_FAILED;
+	enum MAPISTATUS	ms = MAPI_E_CALL_FAILED;
 	gboolean use_store = ((options & MAPI_EVENTS_USE_STORE) ||
 			      (options & MAPI_EVENTS_USE_PF_STORE));
 
 	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, FALSE);
-	g_return_val_if_fail (priv->session != NULL, FALSE);
+	e_return_val_mapi_error_if_fail (priv->session != NULL, MAPI_E_INVALID_PARAMETER, FALSE);
 
 	LOCK ();
 
 	if (options & MAPI_EVENTS_USE_STORE) {
-		retval = Subscribe (&priv->msg_store, events_conn_id, event_mask, use_store, (mapi_notify_callback_t) callback, data);
+		ms = Subscribe (&priv->msg_store, events_conn_id, event_mask, use_store, (mapi_notify_callback_t) callback, data);
 	} else if (options & MAPI_EVENTS_USE_PF_STORE) {
-		if (!ensure_public_store (priv)) {
+		if (!ensure_public_store (priv, perror)) {
 			UNLOCK ();
 			return FALSE;
 		}
 
-		retval = Subscribe (&priv->public_store, events_conn_id, event_mask, use_store, (mapi_notify_callback_t) callback, data);
+		ms = Subscribe (&priv->public_store, events_conn_id, event_mask, use_store, (mapi_notify_callback_t) callback, data);
 	} else if (options & MAPI_EVENTS_FOLDER) {
 		/* TODO */
 	}
 
 	UNLOCK ();
 
-	return (retval == MAPI_E_SUCCESS);
+	if (ms != MAPI_E_SUCCESS)
+		make_mapi_error (perror, "Subscribe", ms);
+
+	return (ms == MAPI_E_SUCCESS);
 }
 
 gboolean
-exchange_mapi_connection_events_unsubscribe (ExchangeMapiConnection *conn, guint32 events_conn_id)
+exchange_mapi_connection_events_unsubscribe (ExchangeMapiConnection *conn, guint32 events_conn_id, GError **perror)
 {
-	enum MAPISTATUS	retval;
+	enum MAPISTATUS	ms;
 
 	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, FALSE);
-	g_return_val_if_fail (priv->session != NULL, FALSE);
+	e_return_val_mapi_error_if_fail (priv->session != NULL, MAPI_E_INVALID_PARAMETER, FALSE);
 
 	LOCK ();
-	retval = Unsubscribe (priv->session, events_conn_id);
+	ms = Unsubscribe (priv->session, events_conn_id);
 	UNLOCK ();
 
-	return (retval == MAPI_E_SUCCESS);
+	if (ms != MAPI_E_SUCCESS)
+		make_mapi_error (perror, "Unsubscribe", ms);
+
+	return (ms == MAPI_E_SUCCESS);
 }
 
 /* Note : Blocking infinite loop. */
 gboolean
 exchange_mapi_connection_events_monitor (ExchangeMapiConnection *conn, struct mapi_notify_continue_callback_data *cb_data)
 {
-	enum MAPISTATUS	retval;
+	enum MAPISTATUS	ms;
+	/* to have this used in the below macros */
+	GError **perror = NULL;
 
 	CHECK_CORRECT_CONN_AND_GET_PRIV (conn, FALSE);
-	g_return_val_if_fail (priv->session != NULL, FALSE);
-
-	retval = MonitorNotification (priv->session, NULL, cb_data);
-
-	return retval;
-}
-
-/* Shows error message on the console, and, if error_msg is not NULL, then
-   sets it to the similar error message as well. */
-static void
-manage_mapi_error (const gchar *context, uint32_t error_id, gchar **error_msg)
-{
-	if (!context)
-		context = "???";
-
-	mapi_errstr (context, error_id);
+	e_return_val_mapi_error_if_fail (priv->session != NULL, MAPI_E_INVALID_PARAMETER, FALSE);
 
-	if (error_msg) {
-		gchar *e = g_strconcat (context, ":", mapi_get_errstr (error_id), NULL);
+	ms = MonitorNotification (priv->session, NULL, cb_data);
 
-		g_free (*error_msg);
-		*error_msg = e;
-	}
+	return ms == MAPI_E_SUCCESS;
 }
 
 /* profile related functions - begin */
@@ -3335,12 +3463,12 @@ mapi_debug_logger_muted (const gchar * domain, GLogLevelFlags level, const gchar
 }
 
 static gboolean
-ensure_mapi_init_called (void)
+ensure_mapi_init_called (GError **perror)
 {
 	static gboolean called = FALSE;
 	static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
 	gchar *profpath;
-	enum MAPISTATUS status;
+	enum MAPISTATUS ms;
 
 	g_static_mutex_lock (&mutex);
 	if (called) {
@@ -3352,9 +3480,9 @@ ensure_mapi_init_called (void)
 
 	if (!g_file_test (profpath, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
 		/* Create a ProfileStore */
-		status = CreateProfileStore (profpath, LIBMAPI_LDIF_DIR);
-		if (status != MAPI_E_SUCCESS && (status != MAPI_E_NO_ACCESS || !g_file_test (profpath, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR))) {
-			mapi_errstr ("CreateProfileStore", GetLastError());
+		ms = CreateProfileStore (profpath, LIBMAPI_LDIF_DIR);
+		if (ms != MAPI_E_SUCCESS && (ms != MAPI_E_NO_ACCESS || !g_file_test (profpath, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR))) {
+			make_mapi_error (perror, "CreateProfileStore", ms);
 			g_free (profpath);
 
 			g_static_mutex_unlock (&mutex);
@@ -3362,13 +3490,12 @@ ensure_mapi_init_called (void)
 		}
 	}
 
-	status = MAPIInitialize (profpath);
-	if (status == MAPI_E_SESSION_LIMIT) {
+	ms = MAPIInitialize (profpath);
+	if (ms == MAPI_E_SESSION_LIMIT) {
 		/* do nothing, the profile store is already initialized */
 		/* but this shouldn't happen */
-		mapi_errstr ("MAPIInitialize", GetLastError());
-	} else if (status != MAPI_E_SUCCESS) {
-		mapi_errstr ("MAPIInitialize", GetLastError());
+	} else if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "MAPIInitialize", ms);
 		g_free (profpath);
 
 		g_static_mutex_unlock (&mutex);
@@ -3387,13 +3514,13 @@ ensure_mapi_init_called (void)
 static GStaticMutex profile_mutex = G_STATIC_MUTEX_INIT;
 
 static struct mapi_session *
-mapi_profile_load (const gchar *profname, const gchar *password)
+mapi_profile_load (const gchar *profname, const gchar *password, GError **perror)
 {
-	enum MAPISTATUS	retval = MAPI_E_SUCCESS;
+	enum MAPISTATUS	ms = MAPI_E_SUCCESS;
 	struct mapi_session *session = NULL;
 	guint32 debug_log_level = 0;
 
-	g_return_val_if_fail (profname != NULL, NULL);
+	e_return_val_mapi_error_if_fail (profname != NULL, MAPI_E_INVALID_PARAMETER, NULL);
 
 	g_static_mutex_lock (&profile_mutex);
 
@@ -3405,7 +3532,7 @@ mapi_profile_load (const gchar *profname, const gchar *password)
 
 	g_debug("%s: Entering %s ", G_STRLOC, G_STRFUNC);
 
-	if (!ensure_mapi_init_called ())
+	if (!ensure_mapi_init_called (perror))
 		goto cleanup;
 
 	/* Initialize libmapi logger*/
@@ -3417,9 +3544,9 @@ mapi_profile_load (const gchar *profname, const gchar *password)
 
 	g_debug("Loading profile %s ", profname);
 
-	retval = MapiLogonEx (&session, profname, password);
-	if (retval != MAPI_E_SUCCESS) {
-		mapi_errstr("MapiLogonEx", GetLastError());
+	ms = MapiLogonEx (&session, profname, password);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "MapiLogonEx", ms);
 		goto cleanup;
 	}
 
@@ -3432,24 +3559,25 @@ mapi_profile_load (const gchar *profname, const gchar *password)
 
 gboolean
 exchange_mapi_create_profile (const gchar *username, const gchar *password, const gchar *domain,
-			      const gchar *server, guint32 flags, gchar **error_msg,
-			      mapi_profile_callback_t callback, gpointer data)
+			      const gchar *server, guint32 flags,
+			      mapi_profile_callback_t callback, gpointer data,
+			      GError **perror)
 {
-	enum MAPISTATUS	retval;
+	enum MAPISTATUS	ms;
 	gboolean result = FALSE;
 	const gchar *workstation = "localhost";
 	gchar *profname = NULL;
 	struct mapi_session *session = NULL;
 
 	/*We need all the params before proceeding.*/
-	g_return_val_if_fail (username && *username && password && *password &&
-			      domain && *domain && server && *server, FALSE);
+	e_return_val_mapi_error_if_fail (username && *username && password && *password &&
+			      domain && *domain && server && *server, MAPI_E_INVALID_PARAMETER, FALSE);
 
 	g_static_mutex_lock (&profile_mutex);
 
 	g_debug ("Create profile with %s %s %s\n", username, domain, server);
 
-	if (!ensure_mapi_init_called ()) {
+	if (!ensure_mapi_init_called (perror)) {
 		g_static_mutex_unlock (&profile_mutex);
 		return FALSE;
 	}
@@ -3457,12 +3585,12 @@ exchange_mapi_create_profile (const gchar *username, const gchar *password, cons
 	profname = exchange_mapi_util_profile_name (username, domain, server, TRUE);
 
 	/* Delete any existing profiles with the same profilename */
-	retval = DeleteProfile (profname);
+	ms = DeleteProfile (profname);
 	/* don't bother to check error - it would be valid if we got an error */
 
-	retval = CreateProfile(profname, username, password, OC_PROFILE_NOPASSWORD);
-	if (retval != MAPI_E_SUCCESS) {
-		manage_mapi_error ("CreateProfile", GetLastError(), error_msg);
+	ms = CreateProfile (profname, username, password, OC_PROFILE_NOPASSWORD);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "CreateProfile", ms);
 		goto cleanup;
 	}
 
@@ -3480,22 +3608,20 @@ exchange_mapi_create_profile (const gchar *username, const gchar *password, cons
 
 	/* Login now */
 	g_debug("Logging into the server... ");
-	retval = MapiLogonProvider(&session, profname, password, PROVIDER_ID_NSPI);
-	if (retval != MAPI_E_SUCCESS) {
-		manage_mapi_error ("MapiLogonProvider", GetLastError(), error_msg);
+	ms = MapiLogonProvider (&session, profname, password, PROVIDER_ID_NSPI);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "MapiLogonProvider", ms);
 		g_debug ("Deleting profile %s ", profname);
-		retval = DeleteProfile(profname);
-		if (retval != MAPI_E_SUCCESS)
-			manage_mapi_error ("DeleteProfile", GetLastError(), error_msg);
+		DeleteProfile (profname);
 		goto cleanup;
 	}
 	g_debug("MapiLogonProvider : succeeded \n");
 
-	retval = ProcessNetworkProfile(session, username, callback, data);
-	if (retval != MAPI_E_SUCCESS) {
-		manage_mapi_error ("ProcessNetworkProfile", GetLastError(), error_msg);
+	ms = ProcessNetworkProfile (session, username, callback, data);
+	if (ms != MAPI_E_SUCCESS) {
+		make_mapi_error (perror, "ProcessNetworkProfile", ms);
 		g_debug ("Deleting profile %s ", profname);
-		DeleteProfile(profname);
+		DeleteProfile (profname);
 		goto cleanup;
 	}
 	g_debug("ProcessNetworkProfile : succeeded \n");
@@ -3511,11 +3637,12 @@ exchange_mapi_create_profile (const gchar *username, const gchar *password, cons
 
 		mapi_object_init (&msg_store);
 
-		if (OpenMsgStore (session, &msg_store) == MAPI_E_SUCCESS) {
+		ms = OpenMsgStore (session, &msg_store);
+		if (ms == MAPI_E_SUCCESS) {
 			Logoff (&msg_store);
 		} else {
 			/ * how to close and free session without store? * /
-			mapi_errstr ("OpenMsgStore", GetLastError());
+			make_mapi_error (perror, "OpenMsgStore", ms);
 		}
 
 		mapi_object_release (&msg_store);
@@ -3527,19 +3654,22 @@ exchange_mapi_create_profile (const gchar *username, const gchar *password, cons
 }
 
 gboolean
-exchange_mapi_delete_profile (const gchar *profile)
+exchange_mapi_delete_profile (const gchar *profile, GError **perror)
 {
 	gboolean result = FALSE;
 
 	g_static_mutex_lock (&profile_mutex);
 
-	if (ensure_mapi_init_called ()) {
+	if (ensure_mapi_init_called (perror)) {
+		enum MAPISTATUS ms;
+
 		g_debug ("Deleting profile %s ", profile);
 
-		if (DeleteProfile (profile) == MAPI_E_SUCCESS) {
+		ms = DeleteProfile (profile);
+		if (ms == MAPI_E_SUCCESS) {
 			result = TRUE;
 		} else {
-			mapi_errstr ("DeleteProfile", GetLastError());
+			make_mapi_error (perror, "DeleteProfile", ms);
 		}
 	}
 
diff --git a/src/libexchangemapi/exchange-mapi-connection.h b/src/libexchangemapi/exchange-mapi-connection.h
index 8d733d7..c7fe895 100644
--- a/src/libexchangemapi/exchange-mapi-connection.h
+++ b/src/libexchangemapi/exchange-mapi-connection.h
@@ -40,6 +40,9 @@
 
 G_BEGIN_DECLS
 
+GQuark e_mapi_error_quark (void);
+#define E_MAPI_ERROR e_mapi_error_quark ()
+
 typedef struct _ExchangeMapiConnection ExchangeMapiConnection;
 typedef struct _ExchangeMapiConnectionClass ExchangeMapiConnectionClass;
 
@@ -149,9 +152,9 @@ struct _ExchangeMapiConnectionClass {
 };
 
 GType			exchange_mapi_connection_get_type (void);
-ExchangeMapiConnection *exchange_mapi_connection_new (const gchar *profile, const gchar *password);
+ExchangeMapiConnection *exchange_mapi_connection_new (const gchar *profile, const gchar *password, GError **perror);
 ExchangeMapiConnection *exchange_mapi_connection_find (const gchar *profile);
-gboolean		exchange_mapi_connection_reconnect (ExchangeMapiConnection *conn, const gchar *password);
+gboolean		exchange_mapi_connection_reconnect (ExchangeMapiConnection *conn, const gchar *password, GError **perror);
 gboolean		exchange_mapi_connection_close (ExchangeMapiConnection *conn);
 gboolean		exchange_mapi_connection_connected (ExchangeMapiConnection *conn);
 
@@ -159,71 +162,71 @@ gboolean		exchange_mapi_connection_fetch_object_props (
 					ExchangeMapiConnection *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);
+					guint32 options, GError **perror);
 
 gboolean		exchange_mapi_connection_fetch_item (ExchangeMapiConnection *conn, mapi_id_t fid, mapi_id_t mid,
 					BuildReadPropsCB build_props, gpointer brp_data,
 					FetchCallback cb, gpointer data,
-					guint32 options);
+					guint32 options, GError **perror);
 
 gboolean		exchange_mapi_connection_fetch_items (ExchangeMapiConnection *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);
+					guint32 options, GError **perror);
 
 gboolean		exchange_mapi_connection_fetch_gal (ExchangeMapiConnection *conn,
 					BuildReadPropsCB build_props, gpointer brp_data,
-					FetchGALCallback cb, gpointer data);
+					FetchGALCallback cb, gpointer data, GError **perror);
 
-gboolean		exchange_mapi_connection_get_public_folder (ExchangeMapiConnection *conn, mapi_object_t *obj_object);
+gboolean		exchange_mapi_connection_get_public_folder (ExchangeMapiConnection *conn, mapi_object_t *obj_object, GError **perror);
 
-mapi_id_t		exchange_mapi_connection_create_folder (ExchangeMapiConnection *conn, uint32_t olFolder, mapi_id_t pfid, guint32 fid_options, const gchar *name);
-gboolean		exchange_mapi_connection_remove_folder (ExchangeMapiConnection *conn, mapi_id_t fid, guint32 fid_options);
-gboolean		exchange_mapi_connection_empty_folder (ExchangeMapiConnection *conn, mapi_id_t fid, guint32 fid_options);
-gboolean		exchange_mapi_connection_rename_folder (ExchangeMapiConnection *conn, mapi_id_t fid, guint32 fid_options, const gchar *new_name);
-gboolean		exchange_mapi_connection_move_folder (ExchangeMapiConnection *conn, mapi_id_t src_fid, mapi_id_t src_parent_fid, guint32 src_fid_options, mapi_id_t des_fid, guint32 des_fid_options, const gchar *new_name);
-GSList *		exchange_mapi_connection_check_restriction (ExchangeMapiConnection *conn, mapi_id_t fid, guint32 fid_options, struct mapi_SRestriction *res);
-mapi_id_t		exchange_mapi_connection_get_default_folder_id (ExchangeMapiConnection *conn, uint32_t olFolder);
+mapi_id_t		exchange_mapi_connection_create_folder (ExchangeMapiConnection *conn, uint32_t olFolder, mapi_id_t pfid, guint32 fid_options, const gchar *name, GError **perror);
+gboolean		exchange_mapi_connection_remove_folder (ExchangeMapiConnection *conn, mapi_id_t fid, guint32 fid_options, GError **perror);
+gboolean		exchange_mapi_connection_empty_folder (ExchangeMapiConnection *conn, mapi_id_t fid, guint32 fid_options, GError **perror);
+gboolean		exchange_mapi_connection_rename_folder (ExchangeMapiConnection *conn, mapi_id_t fid, guint32 fid_options, const gchar *new_name, GError **perror);
+gboolean		exchange_mapi_connection_move_folder (ExchangeMapiConnection *conn, mapi_id_t src_fid, mapi_id_t src_parent_fid, guint32 src_fid_options, mapi_id_t des_fid, guint32 des_fid_options, const gchar *new_name, GError **perror);
+GSList *		exchange_mapi_connection_check_restriction (ExchangeMapiConnection *conn, mapi_id_t fid, guint32 fid_options, struct mapi_SRestriction *res, GError **perror);
+mapi_id_t		exchange_mapi_connection_get_default_folder_id (ExchangeMapiConnection *conn, uint32_t olFolder, GError **perror);
 mapi_id_t		exchange_mapi_connection_create_item (ExchangeMapiConnection *conn, uint32_t olFolder, mapi_id_t fid,
 					BuildWritePropsCB build_props, gpointer bwp_data,
 					GSList *recipients, GSList *attachments, GSList *generic_streams,
-					uint32_t options);
+					uint32_t options, GError **perror);
 
 gboolean		exchange_mapi_connection_modify_item (ExchangeMapiConnection *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);
-
-gboolean		exchange_mapi_connection_set_flags (ExchangeMapiConnection *conn, uint32_t olFolder, mapi_id_t fid, guint32 fid_options, GSList *mid_list, uint32_t flag);
-gboolean		exchange_mapi_connection_remove_items (ExchangeMapiConnection *conn, uint32_t olFolder, mapi_id_t fid, guint32 fid_options, GSList *mids);
-enum MAPISTATUS		exchange_mapi_connection_copy_items (ExchangeMapiConnection *conn, mapi_id_t src_fid, guint32 src_fid_options, mapi_id_t dest_fid, guint32 dest_fid_options, GSList *mids);
-enum MAPISTATUS		exchange_mapi_connection_move_items (ExchangeMapiConnection *conn, mapi_id_t src_fid, guint32 src_fid_options, mapi_id_t dest_fid, guint32 dest_fid_options, GSList *mids);
-gboolean 		exchange_mapi_connection_get_folders_list (ExchangeMapiConnection *conn, GSList **mapi_folders);
-gboolean		exchange_mapi_connection_get_pf_folders_list (ExchangeMapiConnection *conn, GSList **mapi_folders);
+					uint32_t options, GError **perror);
+
+gboolean		exchange_mapi_connection_set_flags (ExchangeMapiConnection *conn, uint32_t olFolder, mapi_id_t fid, guint32 fid_options, GSList *mid_list, uint32_t flag, GError **perror);
+gboolean		exchange_mapi_connection_remove_items (ExchangeMapiConnection *conn, uint32_t olFolder, mapi_id_t fid, guint32 fid_options, GSList *mids, GError **perror);
+gboolean		exchange_mapi_connection_copy_items (ExchangeMapiConnection *conn, mapi_id_t src_fid, guint32 src_fid_options, mapi_id_t dest_fid, guint32 dest_fid_options, GSList *mids, GError **perror);
+gboolean		exchange_mapi_connection_move_items (ExchangeMapiConnection *conn, mapi_id_t src_fid, guint32 src_fid_options, mapi_id_t dest_fid, guint32 dest_fid_options, GSList *mids, GError **perror);
+gboolean 		exchange_mapi_connection_get_folders_list (ExchangeMapiConnection *conn, GSList **mapi_folders, GError **perror);
+gboolean		exchange_mapi_connection_get_pf_folders_list (ExchangeMapiConnection *conn, GSList **mapi_folders, GError **perror);
 GSList *		exchange_mapi_connection_peek_folders_list (ExchangeMapiConnection *conn);
 
-gboolean		exchange_mapi_connection_resolve_named_props (ExchangeMapiConnection *conn, mapi_id_t fid, ResolveNamedIDsData *named_ids_list, guint named_ids_n_elems);
-uint32_t		exchange_mapi_connection_resolve_named_prop (ExchangeMapiConnection *conn, mapi_id_t fid, uint32_t pidlid_propid);
+gboolean		exchange_mapi_connection_resolve_named_props (ExchangeMapiConnection *conn, mapi_id_t fid, ResolveNamedIDsData *named_ids_list, guint named_ids_n_elems, GError **perror);
+uint32_t		exchange_mapi_connection_resolve_named_prop (ExchangeMapiConnection *conn, mapi_id_t fid, uint32_t pidlid_propid, GError **perror);
 
-const gchar *		exchange_mapi_connection_ex_to_smtp (ExchangeMapiConnection *conn, const gchar *ex_address);
+gchar *			exchange_mapi_connection_ex_to_smtp (ExchangeMapiConnection *conn, const gchar *ex_address, GError **perror);
 
 /* Push notifications APIs */
 typedef gboolean (*exchange_check_continue) (void);
 
-gboolean		exchange_mapi_connection_events_init (ExchangeMapiConnection *conn);
+gboolean		exchange_mapi_connection_events_init (ExchangeMapiConnection *conn, GError **perror);
 gboolean		exchange_mapi_connection_events_monitor (ExchangeMapiConnection *conn, struct mapi_notify_continue_callback_data *cb_data);
 
 gboolean		exchange_mapi_connection_events_subscribe (ExchangeMapiConnection *conn, guint32 options,
 					guint16 event_mask, guint32 *events_conn_id,
-					mapi_notify_callback_t callback, gpointer data);
+					mapi_notify_callback_t callback, gpointer data, GError **perror);
 
 gboolean		exchange_mapi_connection_events_subscribe_and_monitor (ExchangeMapiConnection *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		exchange_mapi_connection_events_unsubscribe (ExchangeMapiConnection *conn, guint32 events_conn_id);
+gboolean		exchange_mapi_connection_events_unsubscribe (ExchangeMapiConnection *conn, guint32 events_conn_id, GError **perror);
 
 /* profile functions */
 
@@ -234,9 +237,13 @@ enum {
 
 gboolean		exchange_mapi_create_profile (const gchar *username, const gchar *password,
 				       const gchar *domain, const gchar *server, guint32 flags,
-				       gchar **error_msg, mapi_profile_callback_t cb, gpointer data);
+				       mapi_profile_callback_t cb, gpointer data, GError **perror);
+
+gboolean		exchange_mapi_delete_profile (const gchar *profile, GError **perror);
+
+/* utility functions */
 
-gboolean		exchange_mapi_delete_profile (const gchar *profile);
+void make_mapi_error (GError **perror, const gchar *context, enum MAPISTATUS mapi_status);
 
 G_END_DECLS
 
diff --git a/src/libexchangemapi/exchange-mapi-mail-utils.c b/src/libexchangemapi/exchange-mapi-mail-utils.c
index 8ff5b13..18ef8ce 100644
--- a/src/libexchangemapi/exchange-mapi-mail-utils.c
+++ b/src/libexchangemapi/exchange-mapi-mail-utils.c
@@ -367,7 +367,6 @@ static void
 mapi_mime_set_msg_headers (ExchangeMapiConnection *conn, CamelMimeMessage *msg, MailItem *item)
 {
 	gchar *temp_str = NULL;
-	const gchar *from_email;
 	time_t recieved_time;
 	CamelInternetAddress *addr = NULL;
 	gint offset = 0;
@@ -419,9 +418,11 @@ mapi_mime_set_msg_headers (ExchangeMapiConnection *conn, CamelMimeMessage *msg,
 
 	if (item->header.from) {
 		if ((item->header.from_type != NULL) && !g_utf8_collate (item->header.from_type, "EX")) {
-			from_email = exchange_mapi_connection_ex_to_smtp (conn, item->header.from_email);
+			gchar *from_email;
+
+			from_email = exchange_mapi_connection_ex_to_smtp (conn, item->header.from_email, NULL);
 			g_free (item->header.from_email);
-			item->header.from_email = g_strdup (from_email);
+			item->header.from_email = from_email;
 		}
 
 		item->header.from_email = item->header.from_email ?
@@ -716,7 +717,7 @@ mapi_mime_classify_attachments (ExchangeMapiConnection *conn, mapi_id_t fid, GSL
 			camel_mime_part_set_encoding (part, CAMEL_TRANSFER_ENCODING_BASE64);
 
 			strm = NULL;
-			proptag = exchange_mapi_connection_resolve_named_prop (conn, fid, PidNameAttachmentMacInfo);
+			proptag = exchange_mapi_connection_resolve_named_prop (conn, fid, PidNameAttachmentMacInfo, NULL);
 			if (proptag != MAPI_E_RESERVED)
 				strm = exchange_mapi_util_find_stream (attach->streams, proptag);
 			if (!strm)
diff --git a/src/libexchangemapi/exchange-mapi-utils.c b/src/libexchangemapi/exchange-mapi-utils.c
index 53eda69..8cb99d7 100644
--- a/src/libexchangemapi/exchange-mapi-utils.c
+++ b/src/libexchangemapi/exchange-mapi-utils.c
@@ -172,7 +172,7 @@ exchange_mapi_util_find_SPropVal_array_namedid (struct SPropValue *values, Excha
 	g_return_val_if_fail (values != NULL, NULL);
 	g_return_val_if_fail (conn != NULL, NULL);
 
-	proptag = exchange_mapi_connection_resolve_named_prop (conn, fid, namedid);
+	proptag = exchange_mapi_connection_resolve_named_prop (conn, fid, namedid, NULL);
 	if (proptag != MAPI_E_RESERVED)
 		res = exchange_mapi_util_find_SPropVal_array_propval (values, proptag);
 
@@ -231,7 +231,7 @@ exchange_mapi_util_find_row_namedid (struct SRow *aRow, ExchangeMapiConnection *
 	g_return_val_if_fail (aRow != NULL, NULL);
 	g_return_val_if_fail (conn != NULL, NULL);
 
-	proptag = exchange_mapi_connection_resolve_named_prop (conn, fid, namedid);
+	proptag = exchange_mapi_connection_resolve_named_prop (conn, fid, namedid, NULL);
 	if (proptag != MAPI_E_RESERVED)
 		res = exchange_mapi_util_find_row_propval (aRow, proptag);
 
@@ -290,7 +290,7 @@ exchange_mapi_util_find_array_namedid (struct mapi_SPropValue_array *properties,
 	g_return_val_if_fail (properties != NULL, NULL);
 	g_return_val_if_fail (conn != NULL, NULL);
 
-	proptag = exchange_mapi_connection_resolve_named_prop (conn, fid, namedid);
+	proptag = exchange_mapi_connection_resolve_named_prop (conn, fid, namedid, NULL);
 	if (proptag != MAPI_E_RESERVED)
 		res = exchange_mapi_util_find_array_propval (properties, proptag);
 
@@ -988,7 +988,7 @@ exchange_mapi_utils_add_named_ids_to_props_array (ExchangeMapiConnection *conn,
 	g_return_val_if_fail (named_ids_list != NULL, FALSE);
 	g_return_val_if_fail (named_ids_n_elems > 0, FALSE);
 
-	if (!exchange_mapi_connection_resolve_named_props (conn, fid, named_ids_list, named_ids_n_elems))
+	if (!exchange_mapi_connection_resolve_named_props (conn, fid, named_ids_list, named_ids_n_elems, NULL))
 		return FALSE;
 
 	for (i = 0; i < named_ids_n_elems; i++) {
@@ -1038,7 +1038,7 @@ exchange_mapi_utils_add_spropvalue_named_id (ExchangeMapiConnection *conn, mapi_
 	g_return_val_if_fail (values_array != NULL, FALSE);
 	g_return_val_if_fail (n_values != NULL, FALSE);
 
-	prop_tag = exchange_mapi_connection_resolve_named_prop (conn, fid, named_id);
+	prop_tag = exchange_mapi_connection_resolve_named_prop (conn, fid, named_id, NULL);
 	if (prop_tag == MAPI_E_RESERVED)
 		return FALSE;
 



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