=== modified file 'configure.ac'
--- old/configure.ac	2010-09-27 10:28:11 +0000
+++ new/configure.ac	2011-01-25 18:44:56 +0000
@@ -253,6 +253,20 @@
 fi
 
 dnl ****************************
+dnl Check for MAPIInitialize function with two params
+dnl ****************************
+AC_MSG_CHECKING([libmapi MAPIInitialize function with two params])
+save_cflags=$CFLAGS; CFLAGS=$LIBMAPI_CFLAGS
+save_libs=$LIBS; LIBS="$LIBMAPI_LIBS"
+AC_LINK_IFELSE([AC_LANG_PROGRAM(
+	[[#include <libmapi/libmapi.h>]],
+	[[MAPIInitialize (NULL, NULL)]])],
+	[AC_DEFINE(HAVE_LIBMAPI_CONTEXT_PARAM, 1, [libmapi uses context parameters]) ac_cv_have_lcp=yes],[ac_cv_have_lcp=no])
+CFLAGS=$save_cflags
+LIBS=$save_libs
+AC_MSG_RESULT([$ac_cv_have_lcp])
+
+dnl ****************************
 dnl Expose version information
 dnl ****************************
 API_VERSION=$EDS_PACKAGE

=== modified file 'src/libexchangemapi/exchange-mapi-connection.c'
--- old/src/libexchangemapi/exchange-mapi-connection.c	2010-10-19 10:33:25 +0000
+++ new/src/libexchangemapi/exchange-mapi-connection.c	2011-01-25 19:24:59 +0000
@@ -143,6 +143,10 @@
 	g_propagate_error (perror, error);
 }
 
+#ifdef HAVE_LIBMAPI_CONTEXT_PARAM
+struct mapi_context *mapi_ctx = NULL;
+#endif
+
 typedef struct _ExchangeMapiConnectionPrivate ExchangeMapiConnectionPrivate;
 
 struct _ExchangeMapiConnectionPrivate {
@@ -2808,7 +2812,11 @@
 
 	mapi_object_init(&obj_folder_src);
 	mapi_object_init(&obj_folder_dst);
-	mapi_id_array_init(&msg_id_array);
+	mapi_id_array_init (
+		#ifdef HAVE_LIBMAPI_CONTEXT_PARAM
+		mapi_ctx,
+		#endif
+		&msg_id_array);
 
 	for (l = mid_list; l != NULL; l = g_slist_next (l))
 		mapi_id_array_add_id (&msg_id_array, *((mapi_id_t *)l->data));
@@ -3602,7 +3610,11 @@
 		}
 	}
 
-	ms = MAPIInitialize (profpath);
+	ms = MAPIInitialize (
+		#ifdef HAVE_LIBMAPI_CONTEXT_PARAM
+		&mapi_ctx,
+		#endif
+		profpath);
 	if (ms == MAPI_E_SESSION_LIMIT) {
 		/* do nothing, the profile store is already initialized */
 		/* but this shouldn't happen */
@@ -3664,15 +3676,31 @@
 	/* Initialize libmapi logger*/
 	if (g_getenv ("MAPI_DEBUG")) {
 		debug_log_level = atoi (g_getenv ("MAPI_DEBUG"));
-		SetMAPIDumpData(TRUE);
-		SetMAPIDebugLevel(debug_log_level);
+		SetMAPIDumpData (
+			#ifdef HAVE_LIBMAPI_CONTEXT_PARAM
+			mapi_ctx,
+			#endif
+			TRUE);
+		SetMAPIDebugLevel (
+			#ifdef HAVE_LIBMAPI_CONTEXT_PARAM
+			mapi_ctx,
+			#endif
+			debug_log_level);
 	}
 
 	g_debug("Loading profile %s ", profname);
 
-	ms = MapiLogonEx (&session, profname, password);
+	ms = MapiLogonEx (
+		#ifdef HAVE_LIBMAPI_CONTEXT_PARAM
+		mapi_ctx,
+		#endif
+		&session, profname, password);
 	if (ms == MAPI_E_NOT_FOUND && try_create_profile (profname, password))
-		ms = MapiLogonEx (&session, profname, password);
+		ms = MapiLogonEx (
+			#ifdef HAVE_LIBMAPI_CONTEXT_PARAM
+			mapi_ctx,
+			#endif
+			&session, profname, password);
 
 	if (ms != MAPI_E_SUCCESS) {
 		make_mapi_error (perror, "MapiLogonEx", ms);
@@ -3717,34 +3745,60 @@
 	profname = exchange_mapi_util_profile_name (username, domain, server, TRUE);
 
 	/* Delete any existing profiles with the same profilename */
-	ms = DeleteProfile (profname);
+	ms = DeleteProfile (
+		#ifdef HAVE_LIBMAPI_CONTEXT_PARAM
+		mapi_ctx,
+		#endif
+		profname);
 	/* don't bother to check error - it would be valid if we got an error */
 
-	ms = CreateProfile (profname, username, password, OC_PROFILE_NOPASSWORD);
+	ms = CreateProfile (
+		#ifdef HAVE_LIBMAPI_CONTEXT_PARAM
+		mapi_ctx,
+		#endif
+		profname, username, password, OC_PROFILE_NOPASSWORD);
 	if (ms != MAPI_E_SUCCESS) {
 		make_mapi_error (perror, "CreateProfile", ms);
 		goto cleanup;
 	}
 
-	mapi_profile_add_string_attr(profname, "binding", server);
-	mapi_profile_add_string_attr(profname, "workstation", workstation);
-	mapi_profile_add_string_attr(profname, "domain", domain);
+	#ifdef HAVE_LIBMAPI_CONTEXT_PARAM
+	#define add_string_attr(_prof,_aname,_val)				\
+		mapi_profile_add_string_attr (mapi_ctx, _prof, _aname, _val)
+	#else
+	#define add_string_attr(_prof,_aname,_val)				\
+		mapi_profile_add_string_attr (_prof, _aname, _val)
+	#endif
+
+	add_string_attr (profname, "binding", server);
+	add_string_attr (profname, "workstation", workstation);
+	add_string_attr (profname, "domain", domain);
 
 	if ((flags & CREATE_PROFILE_FLAG_USE_SSL) != 0)
-		mapi_profile_add_string_attr (profname, "seal", "true");
+		add_string_attr (profname, "seal", "true");
 
 	/* This is only convenient here and should be replaced at some point */
-	mapi_profile_add_string_attr(profname, "codepage", "0x4e4");
-	mapi_profile_add_string_attr(profname, "language", "0x409");
-	mapi_profile_add_string_attr(profname, "method", "0x409");
+	add_string_attr (profname, "codepage", "0x4e4");
+	add_string_attr (profname, "language", "0x409");
+	add_string_attr (profname, "method", "0x409");
+
+	#undef add_string_attr
 
 	/* Login now */
 	g_debug("Logging into the server... ");
-	ms = MapiLogonProvider (&session, profname, password, PROVIDER_ID_NSPI);
+	ms = MapiLogonProvider (
+		#ifdef HAVE_LIBMAPI_CONTEXT_PARAM
+		mapi_ctx,
+		#endif
+		&session, profname, password, PROVIDER_ID_NSPI);
 	if (ms != MAPI_E_SUCCESS) {
 		make_mapi_error (perror, "MapiLogonProvider", ms);
 		g_debug ("Deleting profile %s ", profname);
-		DeleteProfile (profname);
+		DeleteProfile (
+			#ifdef HAVE_LIBMAPI_CONTEXT_PARAM
+			mapi_ctx,
+			#endif
+			profname);
 		goto cleanup;
 	}
 	g_debug("MapiLogonProvider : succeeded \n");
@@ -3753,7 +3807,11 @@
 	if (ms != MAPI_E_SUCCESS) {
 		make_mapi_error (perror, "ProcessNetworkProfile", ms);
 		g_debug ("Deleting profile %s ", profname);
-		DeleteProfile (profname);
+		DeleteProfile (
+			#ifdef HAVE_LIBMAPI_CONTEXT_PARAM
+			mapi_ctx,
+			#endif
+			profname);
 		goto cleanup;
 	}
 	g_debug("ProcessNetworkProfile : succeeded \n");
@@ -3807,7 +3865,11 @@
 
 		g_debug ("Deleting profile %s ", profile);
 
-		ms = DeleteProfile (profile);
+		ms = DeleteProfile (
+			#ifdef HAVE_LIBMAPI_CONTEXT_PARAM
+			mapi_ctx,
+			#endif
+			profile);
 		if (ms == MAPI_E_SUCCESS) {
 			result = TRUE;
 		} else {
@@ -3820,4 +3882,21 @@
 	return result;
 }
 
+void
+exchange_mapi_rename_profile (const gchar *old_name, const gchar *new_name)
+{
+	g_return_if_fail (old_name != NULL);
+	g_return_if_fail (new_name != NULL);
+
+	g_static_rec_mutex_lock (&profile_mutex);
+
+	RenameProfile (
+		#ifdef HAVE_LIBMAPI_CONTEXT_PARAM
+		mapi_ctx,
+		#endif
+		old_name, new_name);
+
+	g_static_rec_mutex_unlock (&profile_mutex);
+}
+
 /* profile related functions - end */

=== modified file 'src/libexchangemapi/exchange-mapi-connection.h'
--- old/src/libexchangemapi/exchange-mapi-connection.h	2010-08-02 22:02:21 +0000
+++ new/src/libexchangemapi/exchange-mapi-connection.h	2011-01-25 18:44:56 +0000
@@ -240,6 +240,7 @@
 				       mapi_profile_callback_t cb, gpointer data, GError **perror);
 
 gboolean		exchange_mapi_delete_profile (const gchar *profile, GError **perror);
+void			exchange_mapi_rename_profile (const gchar *old_name, const gchar *new_name);
 
 /* utility functions */
 

=== modified file 'src/libexchangemapi/exchange-mapi-utils.c'
--- old/src/libexchangemapi/exchange-mapi-utils.c	2010-11-02 17:03:41 +0000
+++ new/src/libexchangemapi/exchange-mapi-utils.c	2011-01-25 18:44:56 +0000
@@ -947,7 +947,7 @@
 		old_name = g_strdup_printf ("%s@%s", username, domain);
 		old_name = g_strcanon (old_name, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@", '_');
 
-		RenameProfile (old_name, res);
+		exchange_mapi_rename_profile (old_name, res);
 
 		g_free (old_name);
 	}

