[evolution-ews/wip/mcrha/soup3] Rework request processing in EEwsConnection (not finished)



commit b8bb0eecf7a872417e7cf787ab5714c5012edb5d
Author: Milan Crha <mcrha redhat com>
Date:   Wed Dec 15 20:46:11 2021 +0100

    Rework request processing in EEwsConnection (not finished)

 src/EWS/addressbook/e-book-backend-ews.c           |    2 +-
 src/EWS/calendar/e-cal-backend-ews.c               |    4 +-
 src/EWS/common/CMakeLists.txt                      |    2 +-
 src/EWS/common/e-ews-connection-utils.c            |    4 +-
 src/EWS/common/e-ews-connection.c                  | 8049 +++++++-------------
 src/EWS/common/e-ews-connection.h                  |  675 +-
 src/EWS/common/e-soap-request.c                    |   74 +-
 src/EWS/common/e-soap-request.h                    |   13 +-
 src/EWS/evolution/e-ews-search-user.c              |    4 +-
 src/EWS/evolution/e-ews-subscribe-foreign-folder.c |    2 +-
 10 files changed, 2988 insertions(+), 5841 deletions(-)
---
diff --git a/src/EWS/addressbook/e-book-backend-ews.c b/src/EWS/addressbook/e-book-backend-ews.c
index 29d7bf10..1459c391 100644
--- a/src/EWS/addressbook/e-book-backend-ews.c
+++ b/src/EWS/addressbook/e-book-backend-ews.c
@@ -3460,7 +3460,7 @@ ebb_ews_update_cache_for_expression (EBookBackendEws *bbews,
                success = ebb_ews_build_restriction (expr, &restriction_expr) &&
                        e_book_meta_backend_ensure_connected_sync (meta_backend, cancellable, error) &&
                        e_ews_connection_resolve_names_sync (bbews->priv->cnc, EWS_PRIORITY_MEDIUM, 
restriction_expr,
-                               EWS_SEARCH_AD, NULL, TRUE, &mailboxes, &contacts, &includes_last_item, 
cancellable, error);
+                               EWS_SEARCH_AD, NULL, TRUE, &includes_last_item, &mailboxes, &contacts, 
cancellable, error);
 
                if (success) {
                        EBookCache *book_cache;
diff --git a/src/EWS/calendar/e-cal-backend-ews.c b/src/EWS/calendar/e-cal-backend-ews.c
index 5bc3ac65..de719c79 100644
--- a/src/EWS/calendar/e-cal-backend-ews.c
+++ b/src/EWS/calendar/e-cal-backend-ews.c
@@ -528,8 +528,8 @@ ecb_ews_item_to_component_sync (ECalBackendEws *cbews,
                        /* get delegator mail box*/
                        e_ews_connection_resolve_names_sync (
                                cbews->priv->cnc, EWS_PRIORITY_MEDIUM, task_owner,
-                               EWS_SEARCH_AD, NULL, FALSE, &mailboxes, NULL,
-                               &includes_last_item, cancellable, error);
+                               EWS_SEARCH_AD, NULL, FALSE, &includes_last_item, &mailboxes, NULL,
+                               cancellable, error);
 
                        for (l = mailboxes; l != NULL; l = g_slist_next (l)) {
                                EwsMailbox *mb = l->data;
diff --git a/src/EWS/common/CMakeLists.txt b/src/EWS/common/CMakeLists.txt
index 0cf975b3..40fc3880 100644
--- a/src/EWS/common/CMakeLists.txt
+++ b/src/EWS/common/CMakeLists.txt
@@ -9,7 +9,7 @@ set(SOURCES
        e-ews-calendar-utils.h
        e-ews-camel-common.c
        e-ews-camel-common.h
-       #e-ews-connection.c                     
+       e-ews-connection.c
        e-ews-connection.h
        e-ews-connection-utils.c
        e-ews-connection-utils.h
diff --git a/src/EWS/common/e-ews-connection-utils.c b/src/EWS/common/e-ews-connection-utils.c
index 85bcbb32..76978fd7 100644
--- a/src/EWS/common/e-ews-connection-utils.c
+++ b/src/EWS/common/e-ews-connection-utils.c
@@ -29,12 +29,12 @@ e_ews_connection_utils_set_user_agent_header (SoupMessage *message,
                user_agent = camel_ews_settings_dup_user_agent (settings);
 
                if (user_agent && *user_agent) {
-                       soup_message_headers_append (soup_message_get_request_headers (message), 
"User-Agent", user_agent);
+                       soup_message_headers_replace (soup_message_get_request_headers (message), 
"User-Agent", user_agent);
                }
 
                g_free (user_agent);
        } else {
-               soup_message_headers_append (soup_message_get_request_headers (message), "User-Agent", 
"Evolution/" VERSION);
+               soup_message_headers_replace (soup_message_get_request_headers (message), "User-Agent", 
"Evolution/" VERSION);
        }
 }
 
diff --git a/src/EWS/common/e-ews-connection.c b/src/EWS/common/e-ews-connection.c
index 80e84a47..bc51494d 100644
--- a/src/EWS/common/e-ews-connection.c
+++ b/src/EWS/common/e-ews-connection.c
@@ -51,15 +51,21 @@ static gboolean     ews_connection_authenticate     (SoupMessage *msg,
                                                 gboolean retrying,
                                                 gpointer data);
 
+struct _EEwsSoupThreadData {
+       GMutex mutex;
+       GCond cond;
+       GMainContext *main_context;
+       GMainLoop *main_loop;
+       SoupSession *session;
+       GThread *thread;
+};
+
 /* Connection APIS */
 
 struct _EEwsConnectionPrivate {
        ESource *source;
-       ESoupAuthBearer *bearer_auth;
-       SoupSession *soup_session;
-       GThread *soup_thread;
-       GMainLoop *soup_loop;
-       GMainContext *soup_context;
+       struct _EEwsSoupThreadData soup;
+
        GProxyResolver *proxy_resolver;
        EEwsNotification *notification;
        guint notification_delay_id;
@@ -119,41 +125,8 @@ static guint signals[LAST_SIGNAL];
 
 static guint notification_key = 1;
 
-typedef struct _EwsNode EwsNode;
-typedef struct _EwsAsyncData EwsAsyncData;
-typedef struct _EwsEventsAsyncData EwsEventsAsyncData;
 typedef struct _EwsUrls EwsUrls;
 
-struct _EwsAsyncData {
-       GSList *items_created;
-       GSList *items_updated;
-       GSList *items_deleted;
-       GSList *tzds; /* EEwsCalendarTimeZoneDefinition */
-
-       gint total_items;
-       const gchar *directory;
-       GSList *items;
-       EwsPhotoAttachmentInfo *photo;
-       gchar *sync_state;
-       gboolean includes_last_item;
-       EwsDelegateDeliver deliver_to;
-       EEwsFolderType folder_type;
-       EEwsConnection *cnc;
-       gchar *custom_data; /* Can be re-used by operations, will be freed with g_free() */
-};
-
-struct _EwsNode {
-       ESoapRequest *request;
-       EEwsConnection *cnc;
-       GSimpleAsyncResult *simple;
-
-       gint pri;                /* the command priority */
-       EEwsResponseCallback cb;
-
-       GCancellable *cancellable;
-       gulong cancel_handler_id;
-};
-
 struct _EwsUrls {
        xmlChar *as_url;
        xmlChar *oab_url;
@@ -166,1665 +139,832 @@ struct _EwsUrls {
 
 G_DEFINE_TYPE_WITH_PRIVATE (EEwsConnection, e_ews_connection, G_TYPE_OBJECT)
 
-static guint
-ews_connection_get_concurrent_connections (EEwsConnection *cnc)
+/*
+ * e_ews_debug_handler:
+ *
+ * GLib debug message handler, which is passed all messages from g_debug() calls,
+ * and decides whether to print them.
+ */
+static void
+e_ews_debug_handler (const gchar *log_domain,
+                    GLogLevelFlags log_level,
+                    const gchar *message,
+                    gpointer user_data)
 {
-       g_return_val_if_fail (E_IS_EWS_CONNECTION (cnc), 1);
-
-       return cnc->priv->concurrent_connections;
+       if (e_ews_debug_get_log_level () >= 3)
+               g_log_default_handler (log_domain, log_level, message, NULL);
 }
 
+/*
+ * e_ews_soup_log_print:
+ *
+ * Log printer for the libsoup logging functionality, which just marshal all soup log
+ * output to the standard GLib logging framework (and thus to debug_handler(), above).
+ */
 static void
-ews_connection_set_concurrent_connections (EEwsConnection *cnc,
-                                          guint concurrent_connections)
+e_ews_soup_log_printer (SoupLogger *logger,
+                       SoupLoggerLogLevel level,
+                       char direction,
+                       const gchar *data,
+                       gpointer user_data)
 {
-       g_return_if_fail (E_IS_EWS_CONNECTION (cnc));
+       const gchar *filtered_data = NULL;
 
-       concurrent_connections = CLAMP (
-               concurrent_connections,
-               MIN_CONCURRENT_CONNECTIONS,
-               MAX_CONCURRENT_CONNECTIONS);
+       if (e_ews_debug_get_log_level () >= 3) {
+               if (direction == '>' && g_ascii_strncasecmp (data, "Host:", 5) == 0)
+                       filtered_data = "Host: <redacted>";
+               else if (direction == '>' && g_ascii_strncasecmp (data, "Authorization:", 14) == 0)
+                       filtered_data = "Authorization: <redacted>";
+               else if (direction == '<' && g_ascii_strncasecmp (data, "Set-Cookie:", 11) == 0)
+                       filtered_data = "Set-Cookie: <redacted>";
+               else
+                       filtered_data = data;
+       }
 
-       if (cnc->priv->concurrent_connections == concurrent_connections)
-               return;
+       g_debug ("%c %s", direction, filtered_data ? filtered_data : data);
+}
 
-       cnc->priv->concurrent_connections = concurrent_connections;
+static ESoupSession *
+e_ews_connection_create_soup_session (EEwsConnection *cnc)
+{
+       ESoupSession *session;
+       gint log_level;
 
-       if (cnc->priv->soup_session) {
-               g_object_set (G_OBJECT (cnc->priv->soup_session),
-                       SOUP_SESSION_MAX_CONNS, concurrent_connections,
-                       SOUP_SESSION_MAX_CONNS_PER_HOST, concurrent_connections,
-                       NULL);
+       session = e_soup_session_new (cnc->priv->source);
+
+       g_object_set (G_OBJECT (session),
+               "timeout", 90,
+               "max-conns", cnc->priv->concurrent_connections,
+               "max-conns-per-host", cnc->priv->concurrent_connections,
+               NULL);
+
+       e_binding_bind_property (
+               cnc, "proxy-resolver",
+               session, "proxy-resolver",
+               G_BINDING_SYNC_CREATE);
+
+       log_level = e_ews_debug_get_log_level ();
+
+       if (log_level >= 1) {
+               SoupLogger *logger;
+
+               logger = soup_logger_new (log_level == 1 ? SOUP_LOGGER_LOG_HEADERS : SOUP_LOGGER_LOG_BODY);
+
+               if (log_level >= 3)
+                       soup_logger_set_printer (logger, e_ews_soup_log_printer, NULL, NULL);
+
+               soup_session_add_feature (session, SOUP_SESSION_FEATURE (logger));
+
+               g_object_unref (logger);
        }
 
-       g_object_notify (G_OBJECT (cnc), "concurrent-connections");
+       soup_session_add_feature_by_type (session, SOUP_TYPE_COOKIE_JAR);
+
+       return session;
 }
 
-GQuark
-ews_connection_error_quark (void)
+static gpointer
+e_ews_soup_worker_thread (gpointer user_data)
 {
-       static GQuark quark = 0;
+       EEwsConnection *cnc = user_data;
+       CamelEwsSettings *settings;
 
-       if (G_UNLIKELY (quark == 0)) {
-               const gchar *string = "ews-connection-error-quark";
-               quark = g_quark_from_static_string (string);
-       }
+       g_warn_if_fail (cnc->priv->soup.session == NULL);
 
-       return quark;
+       settings = e_ews_connection_ref_settings (cnc);
+
+       g_main_context_push_thread_default (cnc->priv->soup.main_context);
+       g_mutex_lock (&cnc->priv->soup.mutex);
+       cnc->priv->soup.session = SOUP_SESSION (e_ews_connection_create_soup_session (cnc));
+
+       e_ews_connection_utils_prepare_auth_method (session,
+               camel_ews_settings_get_auth_mechanism (settings));
+
+       g_cond_broadcast (&cnc->priv->soup.cond);
+       g_mutex_unlock (&cnc->priv->soup.mutex);
+
+       g_clear_object (&settings);
+
+       g_main_loop_run (cnc->priv->soup.main_loop);
+
+       soup_session_abort (cnc->priv->soup.session);
+       g_clear_object (&cnc->priv->soup.session);
+
+       g_main_context_pop_thread_default (cnc->priv->soup.main_context);
+
+       return NULL;
 }
 
+typedef struct _ProcessData {
+       GMutex mutex;
+       GCond cond;
+       gboolean done;
+       EEwsConnection *cnc;
+       SoupMessage *message;
+       gpointer prepare_data;
+       GCancellable *cancellable;
+       GInputStream *input_stream;
+       GError *error;
+       gchar **out_certificate_pem;
+       GTlsCertificateFlags *out_certificate_errors;
+} ProcessData;
+
 static void
-async_data_free (EwsAsyncData *async_data)
+e_ews_connection_process_request_ready_cb (GObject *source_object,
+                                          GAsyncResult *result,
+                                          gpointer user_data)
 {
-       g_free (async_data->custom_data);
-       g_slice_free (EwsAsyncData, async_data);
-}
+       ProcessData *pd = user_data;
 
-EEwsNotificationEvent *
-e_ews_notification_event_new (void)
-{
-       return g_new0 (EEwsNotificationEvent, 1);
+       g_mutex_lock (&pd->mutex);
+       pd->input_stream = e_soup_session_send_message_finish (E_SOUP_SESSION (source_object), result, 
pd->out_certificate_pem, pd->out_certificate_errors, &pd->error);
+       pd->done = TRUE;
+       g_cond_signal (&pd->cond);
+       g_mutex_unlock (&pd->mutex);
 }
 
-void
-e_ews_notification_event_free (EEwsNotificationEvent *event)
+static gboolean
+e_ews_connection_process_request_run_cb (gpointer user_data)
 {
-       if (event != NULL) {
-               g_free (event->folder_id);
-               g_free (event->old_folder_id);
-               g_free (event);
+       ProcessData *pd = user_data;
+
+       if (pd->cnc->priv->soup.session) {
+               e_soup_session_send_message (E_SOUP_SESSION (pd->cnc->priv->soup.session), pd->message, 
G_PRIORITY_DEFAULT,
+                       pd->prepare_data, pd->cancellable, e_ews_connection_process_request_ready_cb, pd);
+       } else {
+               g_mutex_lock (&pd->mutex);
+               g_set_error_literal (&pd->error, G_IO_ERROR, G_IO_ERROR_FAILED, "SoupSession missing");
+               pd->done = TRUE;
+               g_cond_signal (&pd->cond);
+               g_mutex_unlock (&pd->mutex);
        }
+
+       return FALSE;
 }
 
-EEwsCalendarTo *
-e_ews_calendar_to_new (void)
+static GInputStream *
+e_ews_connection_process_request_sync (EEwsConnection *cnc,
+                                      ESoapRequest *request,
+                                      SoupMessage **out_message,
+                                      gchar **out_certificate_pem,
+                                      GTlsCertificateFlags *out_certificate_errors,
+                                      GCancellable *cancellable,
+                                      GError **error)
 {
-       return g_new0 (EEwsCalendarTo, 1);
-}
+       ProcessData pd;
+       CamelEwsSettings *settings;
+       GSource *source;
 
-void
-e_ews_calendar_to_free (EEwsCalendarTo *to) {
-       if (to != NULL) {
-               g_free (to->kind);
-               g_free (to->value);
-               g_free (to);
-       }
-}
+       g_return_val_if_fail (E_IS_SOAP_REQUEST (request), NULL);
+       g_return_val_if_fail (out_message != NULL, NULL);
 
-EEwsCalendarAbsoluteDateTransition *
-e_ews_calendar_absolute_date_transition_new (void)
-{
-       return g_new0 (EEwsCalendarAbsoluteDateTransition, 1);
-}
+       *out_message = NULL;
 
-void
-e_ews_calendar_absolute_date_transition_free (EEwsCalendarAbsoluteDateTransition *adt)
-{
-       if (adt != NULL) {
-               e_ews_calendar_to_free (adt->to);
-               g_free (adt->date_time);
-               g_free (adt);
+       settings = e_ews_connection_ref_settings (cnc);
+
+       g_mutex_lock (&cnc->priv->soup.mutex);
+       if (!cnc->priv->soup.thread)
+               cnc->priv->soup.thread = g_thread_new ("e_ews_soup_worker_thread", e_ews_soup_worker_thread, 
cnc);
+       while (!cnc->priv->soup.session) {
+               g_cond_wait (&cnc->priv->soup.cond, &cnc->priv->soup.mutex);
        }
-}
+       g_mutex_unlock (&cnc->priv->soup.mutex);
 
-EEwsCalendarRecurringDayTransition *
-e_ews_calendar_recurring_day_transition_new (void)
-{
-       return g_new0 (EEwsCalendarRecurringDayTransition, 1);
-}
+       pd.message = e_soap_request_persist (request, E_SOUP_SESSION (cnc->priv->soup.session), settings);
 
-void
-e_ews_calendar_recurring_day_transition_free (EEwsCalendarRecurringDayTransition *rdayt)
-{
-       if (rdayt != NULL) {
-               e_ews_calendar_to_free (rdayt->to);
-               g_free (rdayt->time_offset);
-               g_free (rdayt->month);
-               g_free (rdayt->day_of_week);
-               g_free (rdayt->occurrence);
-               g_free (rdayt);
+       g_clear_object (&settings);
+
+       pd.prepare_data = e_soup_session_prepare_message_send_sync (E_SOUP_SESSION (cnc->priv->soup.session), 
pd.message, cancellable, error);
+
+       if (!pd.prepare_data) {
+               g_clear_object (&pd.message);
+               return NULL;
        }
-}
 
-EEwsCalendarRecurringDateTransition *
-e_ews_calendar_recurring_date_transition_new (void)
-{
-       return g_new0 (EEwsCalendarRecurringDateTransition, 1);
-}
+       g_mutex_init (&pd.mutex);
+       g_cond_init (&pd.cond);
+       pd.done = FALSE;
+       pd.cnc = cnc;
+       pd.cancellable = cancellable;
+       pd.input_stream = NULL;
+       pd.error = NULL;
+       pd.out_certificate_pem = out_certificate_pem;
+       pd.out_certificate_errors = out_certificate_errors;
 
-void
-e_ews_calendar_recurring_date_transition_free (EEwsCalendarRecurringDateTransition *rdatet)
-{
-       if (rdatet != NULL) {
-               e_ews_calendar_to_free (rdatet->to);
-               g_free (rdatet->time_offset);
-               g_free (rdatet->month);
-               g_free (rdatet->day);
-               g_free (rdatet);
+       g_mutex_lock (&pd.mutex);
+
+       source = g_idle_source_new ();
+       g_source_set_priority (source, G_PRIORITY_DEFAULT);
+       g_source_set_callback (source, e_ews_connection_process_request_run_cb, &pd, NULL);
+       g_source_attach (source, cnc->priv->soup.main_context);
+       g_source_unref (source);
+
+       while (!pd.done) {
+               g_cond_wait (&pd.cond, &pd.mutex);
        }
-}
 
-EEwsCalendarPeriod *
-e_ews_calendar_period_new (void)
-{
-       return g_new0 (EEwsCalendarPeriod, 1);
+       g_mutex_unlock (&pd.mutex);
+
+       if (pd.input_stream)
+               *out_message = g_steal_pointer (&pd.message);
+
+       g_clear_object (&pd.message);
+       g_mutex_clear (&pd.mutex);
+       g_cond_clear (&pd.cond);
+
+       g_warn_if_fail ((pd.error == NULL && pd.input_stream != NULL) ||
+                       (pd.error != NULL && pd.input_stream == NULL));
+
+       if (pd.error)
+               g_propagate_error (error, pd.error);
+
+       return pd.input_stream;
 }
 
-void
-e_ews_calendar_period_free (EEwsCalendarPeriod *period)
+static gboolean
+ews_connection_credentials_failed (EEwsConnection *connection,
+                                  SoupMessage *message,
+                                  GError **error)
 {
-       if (period != NULL) {
-               g_free (period->bias);
-               g_free (period->name);
-               g_free (period->id);
-               g_free (period);
+       gint expire_in_days = 0;
+       gboolean expired = FALSE;
+       gchar *service_url = NULL;
+
+       g_return_val_if_fail (E_IS_EWS_CONNECTION (connection), FALSE);
+       g_return_val_if_fail (SOUP_IS_MESSAGE (message), FALSE);
+
+       if (!e_ews_connection_utils_check_x_ms_credential_headers (message, &expire_in_days, &expired, 
&service_url))
+               return FALSE;
+
+       if (expired) {
+               e_ews_connection_utils_expired_password_to_error (service_url, error);
+       } else if (expire_in_days > 0) {
+               g_signal_emit (connection, signals[PASSWORD_WILL_EXPIRE], 0, expire_in_days, service_url);
        }
-}
 
-EEwsCalendarTransitionsGroup *
-e_ews_calendar_transitions_group_new (void)
-{
-       return g_new0 (EEwsCalendarTransitionsGroup, 1);
+       g_free (service_url);
+
+       return expired;
 }
 
-void
-e_ews_calendar_transitions_group_free (EEwsCalendarTransitionsGroup *tg)
+static gboolean
+e_ews_connection_handle_backoff_policy (EEwsConnection *cnc,
+                                       ESoapResponse *response,
+                                       GCancelalble *cancellable,
+                                       GError **error)
 {
-       if (tg != NULL) {
-               g_free (tg->id);
-               e_ews_calendar_to_free (tg->transition);
-               g_slist_free_full (
-                       tg->absolute_date_transitions,
-                       (GDestroyNotify) e_ews_calendar_absolute_date_transition_free);
-               g_slist_free_full (
-                       tg->recurring_day_transitions,
-                       (GDestroyNotify) e_ews_calendar_recurring_day_transition_free);
-               g_slist_free_full (
-                       tg->recurring_date_transitions,
-                       (GDestroyNotify) e_ews_calendar_recurring_date_transition_free);
-               g_free (tg);
-       }
-}
+       ESoapParameter *param;
+       gint wait_ms = 0;
+       gboolean repeat = FALSE;
 
-EEwsCalendarTransitions *
-e_ews_calendar_transitions_new (void)
-{
-       return g_new0 (EEwsCalendarTransitions, 1);
-}
+       param = e_soap_response_get_first_parameter_by_name (response, "detail", NULL);
+       if (param)
+               param = e_soap_parameter_get_first_child_by_name (param, "ResponseCode");
+       if (param) {
+               gchar *value;
 
-void
-e_ews_calendar_transitions_free (EEwsCalendarTransitions *transitions)
-{
-       if (transitions != NULL) {
-               e_ews_calendar_to_free (transitions->transition);
-               g_slist_free_full (
-                       transitions->absolute_date_transitions,
-                       (GDestroyNotify) e_ews_calendar_absolute_date_transition_free);
-               g_slist_free_full (
-                       transitions->recurring_day_transitions,
-                       (GDestroyNotify) e_ews_calendar_recurring_day_transition_free);
-               g_slist_free_full (
-                       transitions->recurring_date_transitions,
-                       (GDestroyNotify) e_ews_calendar_recurring_date_transition_free);
-               g_free (transitions);
-       }
-}
+               value = e_soap_parameter_get_string_value (param);
+               if (value && ews_get_error_code (value) == EWS_CONNECTION_ERROR_SERVERBUSY) {
+                       param = e_soap_response_get_first_parameter_by_name (response, "detail", NULL);
+                       if (param)
+                               param = e_soap_parameter_get_first_child_by_name (param, "MessageXml");
+                       if (param) {
+                               param = e_soap_parameter_get_first_child_by_name (param, "Value");
+                               if (param) {
+                                       g_free (value);
 
-EEwsCalendarTimeZoneDefinition *
-e_ews_calendar_time_zone_definition_new (void)
-{
-       return g_new0 (EEwsCalendarTimeZoneDefinition, 1);
-}
+                                       value = e_soap_parameter_get_property (param, "Name");
+                                       if (g_strcmp0 (value, "BackOffMilliseconds") == 0) {
+                                               wait_ms = e_soap_parameter_get_int_value (param);
+                                       }
+                               }
+                       }
+               }
 
-void
-e_ews_calendar_time_zone_definition_free (EEwsCalendarTimeZoneDefinition *tzd)
-{
-       if (tzd != NULL) {
-               g_free (tzd->name);
-               g_free (tzd->id);
-               g_slist_free_full (tzd->periods, (GDestroyNotify) e_ews_calendar_period_free);
-               g_slist_free_full (tzd->transitions_groups, (GDestroyNotify) 
e_ews_calendar_transitions_group_free);
-               e_ews_calendar_transitions_free (tzd->transitions);
-               g_free (tzd);
+               g_free (value);
        }
-}
 
-EEwsExtendedFieldURI *
-e_ews_extended_field_uri_new (void)
-{
-       return g_new0 (EEwsExtendedFieldURI, 1);
-}
+       if (wait_ms > 0 && e_ews_connection_get_backoff_enabled (cnc)) {
+               EFlag *flag;
 
-void
-e_ews_extended_field_uri_free (EEwsExtendedFieldURI *ex_field_uri)
-{
-       if (ex_field_uri != NULL) {
-               g_free (ex_field_uri->distinguished_prop_set_id);
-               g_free (ex_field_uri->prop_set_id);
-               g_free (ex_field_uri->prop_tag);
-               g_free (ex_field_uri->prop_name);
-               g_free (ex_field_uri->prop_id);
-               g_free (ex_field_uri->prop_type);
-               g_free (ex_field_uri);
-       }
-}
+               flag = e_flag_new ();
 
-EEwsIndexedFieldURI *
-e_ews_indexed_field_uri_new (const gchar *uri,
-                            const gchar *index)
-{
-       EEwsIndexedFieldURI *furi;
+               while (wait_ms > 0 && !g_cancellable_is_cancelled (cancellable)) {
+                       gint64 now = g_get_monotonic_time ();
+                       gint left_minutes, left_seconds;
 
-       furi = g_new0 (EEwsIndexedFieldURI, 1);
-       furi->field_uri = g_strdup (uri);
-       furi->field_index = g_strdup (index);
+                       left_minutes = wait_ms / 60000;
+                       left_seconds = (wait_ms / 1000) % 60;
 
-       return furi;
-}
+                       if (left_minutes > 0) {
+                               camel_operation_push_message (cancellable,
+                                       g_dngettext (GETTEXT_PACKAGE,
+                                               "Exchange server is busy, waiting to retry (%d:%02d minute)",
+                                               "Exchange server is busy, waiting to retry (%d:%02d 
minutes)", left_minutes),
+                                       left_minutes, left_seconds);
+                       } else {
+                               camel_operation_push_message (cancellable,
+                                       g_dngettext (GETTEXT_PACKAGE,
+                                               "Exchange server is busy, waiting to retry (%d second)",
+                                               "Exchange server is busy, waiting to retry (%d seconds)", 
left_seconds),
+                                       left_seconds);
+                       }
 
-void
-e_ews_indexed_field_uri_free (EEwsIndexedFieldURI *id_field_uri)
-{
-       if (id_field_uri != NULL) {
-               g_free (id_field_uri->field_uri);
-               g_free (id_field_uri->field_index);
-               g_free (id_field_uri);
-       }
-}
+                       e_flag_wait_until (flag, now + (G_TIME_SPAN_MILLISECOND * (wait_ms > 1000 ? 1000 : 
wait_ms)));
 
-EEwsAdditionalProps *
-e_ews_additional_props_new (void)
-{
-       return g_new0 (EEwsAdditionalProps, 1);
-}
+                       now = g_get_monotonic_time () - now;
+                       now = now / G_TIME_SPAN_MILLISECOND;
 
-void
-e_ews_additional_props_free (EEwsAdditionalProps *add_props)
-{
-       if (add_props != NULL) {
-               g_free (add_props->field_uri);
-               g_slist_free_full (add_props->extended_furis, (GDestroyNotify) e_ews_extended_field_uri_free);
-               g_slist_free_full (add_props->indexed_furis, (GDestroyNotify) e_ews_indexed_field_uri_free);
-               g_free (add_props);
+                       if (now >= wait_ms)
+                               wait_ms = 0;
+                       wait_ms -= now;
+
+                       camel_operation_pop_message (cancellable);
+               }
+
+               e_flag_free (flag);
+
+               repeat = !g_cancellable_set_error_if_cancelled (cancellable);
        }
-}
 
-static EwsNode *
-ews_node_new (void)
-{
-       return g_slice_new0 (EwsNode);
+       return repeat;
 }
 
-static void
-autodiscover_parse_protocol (xmlNode *node,
-                             EwsUrls *urls)
+static ESoapResponse *
+e_ews_connection_send_request_sync (EEwsConnection *cnc,
+                                   ESoapRequest *request,
+                                   GCancellable *cancellable,
+                                   GError **error)
 {
-       for (node = node->children; node; node = node->next) {
-               if (node->type == XML_ELEMENT_NODE &&
-                   !strcmp ((gchar *) node->name, "ASUrl")) {
-                       if (urls->as_url != NULL)
-                               xmlFree (urls->as_url);
-
-                       urls->as_url = xmlNodeGetContent (node);
-               } else if (node->type == XML_ELEMENT_NODE &&
-                   !strcmp ((gchar *) node->name, "OABUrl")) {
-                       if (urls->oab_url != NULL)
-                               xmlFree (urls->oab_url);
+       ESoapResponse *response = NULL;
+       SoupMessage *message = NULL;
+       GInputStream *input_stream;
+       gchar *certificate_pem = NULL;
+       GTlsCertificateFlags certificate_errors = 0;
+       gboolean repeat = TRUE;
+       GError *local_error = NULL;
 
-                       urls->oab_url = xmlNodeGetContent (node);
-               }
+       while (repeat) {
+               const gchar *persistent_auth;
+               GError *local_error2 = NULL;
 
-               /* Once we find both, we can stop looking for the URLs */
-               if (urls->as_url && urls->oab_url)
-                       return;
-       }
-}
+               repeat = FALSE;
 
-static xmlChar *
-autodiscover_get_protocol_type (xmlNode *node)
-{
-       for (node = node->children; node; node = node->next) {
-               if (node->type == XML_ELEMENT_NODE &&
-                   !strcmp ((gchar *) node->name, "Type")) {
-                       return xmlNodeGetContent (node);
-               }
-       }
+               g_clear_error (&local_error);
 
-       return NULL;
-}
+               input_stream = e_ews_connection_process_request_sync (cnc, request, &message, 
&certificate_pem, &certificate_errors, cancellable, &local_error);
 
-static gchar *
-autodiscover_dup_element_value (xmlNode *node,
-                               const gchar *element_name)
-{
-       for (node = node->children; node; node = node->next) {
-               if (node->type == XML_ELEMENT_NODE &&
-                   !g_strcmp0 ((gchar *) node->name, element_name)) {
-                       xmlChar *str = xmlNodeGetContent (node);
-                       gchar *res;
+               persistent_auth = soup_message_headers_get_one (soup_message_get_response_headers (request), 
"Persistent-Auth");
+               if (persistent_auth && g_ascii_strcasecmp (persistent_auth, "false") == 0) {
+                       SoupSessionFeature *feature;
 
-                       res = g_strdup ((const gchar *) str);
-                       xmlFree (str);
-                       return res;
+                       feature = soup_session_get_feature (session, SOUP_TYPE_AUTH_MANAGER);
+                       if (feature) {
+                               soup_auth_manager_clear_cached_credentials (SOUP_AUTH_MANAGER (feature));
+                       }
                }
-       }
 
-       return NULL;
-}
+               g_mutex_lock (&cnc->priv->property_lock);
+               g_clear_pointer (&cnc->priv->ssl_certificate_pem, g_free);
+               cnc->priv->ssl_info_set = certificate_pem != NULL;
+               cnc->priv->ssl_certificate_pem = g_strdup (certificate_pem);
+               cnc->priov->ssl_certificate_errors = certificate_errors;
+               g_mutex_unlock (&connection->priv->property_lock);
 
-static gint
-comp_func (gconstpointer a,
-           gconstpointer b)
-{
-       EwsNode *node1 = (EwsNode *) a;
-       EwsNode *node2 = (EwsNode *) b;
-       if (node1->pri > node2->pri)
-               return -1;
-       else if (node1->pri < node2->pri)
-               return 1;
-       else
-               return 0;
-}
+               e_soap_request_take_tls_error_details (request, certificate_pem, certificate_errors);
 
-typedef enum _EwsScheduleOp {
-       EWS_SCHEDULE_OP_QUEUE_MESSAGE,
-       EWS_SCHEDULE_OP_CANCEL,
-       EWS_SCHEDULE_OP_ABORT
-} EwsScheduleOp;
+               if (!ews_connection_credentials_failed (cnc, message, &local_error2)) {
+                       if (soup_message_get_status (request) == SOUP_STATUS_UNAUTHORIZED) {
+                               if (soup_message_get_response_headers (request)) {
+                                       const gchar *diagnostics;
 
-typedef struct _EwsScheduleData
-{
-       EEwsConnection *cnc;
-       SoupMessage *message;
+                                       diagnostics = soup_message_headers_get_list 
(soup_message_get_response_headers (request), "X-MS-DIAGNOSTICS");
+                                       if (diagnostics && strstr (diagnostics, "invalid_grant")) {
+                                               g_set_error_literal (&local_error2, EWS_CONNECTION_ERROR, 
EWS_CONNECTION_ERROR_ACCESSDENIED, diagnostics);
+                                       } else if (diagnostics && *diagnostics) {
+                                               g_set_error_literal (&local_error2, EWS_CONNECTION_ERROR, 
EWS_CONNECTION_ERROR_AUTHENTICATION_FAILED, diagnostics);
+                                       }
+                               }
 
-       EwsScheduleOp op;
+                               if (!local_error2)
+                                       g_set_error_literal (&local_error2, EWS_CONNECTION_ERROR, 
EWS_CONNECTION_ERROR_AUTHENTICATION_FAILED, _("Authentication failed"));
+                       }
+               }
 
-       SoupSessionCallback queue_callback;
-       gpointer queue_user_data;
-} EwsScheduleData;
+               if (local_error2) {
+                       g_clear_error (&local_error);
+                       local_error = local_error2;
+               }
 
-/* this is run in priv->soup_thread */
-static gboolean
-ews_connection_scheduled_cb (gpointer user_data)
-{
-       EwsScheduleData *sd = user_data;
+               if (!local_error) {
+                       response = e_soap_response_new ();
 
-       g_return_val_if_fail (sd != NULL, FALSE);
+                       if (!e_soap_response_from_message_sync (response, message, input_stream, cancellable, 
&local_error)) {
+                               g_clear_object (&response);
 
-       switch (sd->op) {
-       case EWS_SCHEDULE_OP_QUEUE_MESSAGE:
-               if (!e_ews_connection_utils_prepare_message (sd->cnc, NULL, sd->message, NULL)) {
-                       if (sd->queue_callback) {
-                               sd->queue_callback (sd->cnc->priv->soup_session, sd->message, 
sd->queue_user_data);
-                       } else {
-                               /* This should not happen */
-                               g_warn_if_reached ();
+                               if (!local_error) {
+                                       g_set_error (&local_error, EWS_CONNECTION_ERROR, 
EWS_CONNECTION_ERROR_NORESPONSE,
+                                               _("No response: %s"), soup_message_get_reason_phrase 
(messsage));
+                               }
                        }
-               } else {
-                       g_signal_connect (
-                               sd->message, "authenticate",
-                               G_CALLBACK (ews_connection_authenticate), cnc);
 
-                       soup_session_queue_message (
-                               sd->cnc->priv->soup_session, sd->message,
-                               sd->queue_callback, sd->queue_user_data);
+                       if (response) {
+                               repeat = e_ews_connection_handle_backoff_policy (cnc, response, cancellable, 
&local_error);
+
+                               if (repeat || local_error)
+                                       g_clear_object (&response);
+                       }
                }
-               break;
-       case EWS_SCHEDULE_OP_CANCEL:
-               soup_session_cancel_message (sd->cnc->priv->soup_session, sd->message, SOUP_STATUS_CANCELLED);
-               break;
-       case EWS_SCHEDULE_OP_ABORT:
-               soup_session_abort (sd->cnc->priv->soup_session);
-               break;
+
+               g_clear_object (&input_stream);
+               g_clear_object (&message);
        }
 
-       if (sd->message)
-               g_object_unref (sd->message);
-       /* in case this is the last reference */
-       e_ews_connection_utils_unref_in_thread (sd->cnc);
-       g_slice_free (EwsScheduleData, sd);
+       if (local_error) {
+               g_propagate_error (error, local_error);
 
-       return FALSE;
-}
+       if (response && cnc->priv->version == E_EWS_EXCHANGE_UNKNOWN) {
+               ESoapParameter *param;
 
-static void
-ews_connection_schedule_queue_message (EEwsConnection *cnc,
-                                       SoupMessage *message,
-                                       SoupSessionCallback callback,
-                                       gpointer user_data)
-{
-       EwsScheduleData *sd;
-       GSource *source;
+               param = e_soap_response_get_first_parameter_by_name (response, "ServerVersionInfo", NULL);
+               if (param) {
+                       gchar *version;
 
-       g_return_if_fail (E_IS_EWS_CONNECTION (cnc));
-       g_return_if_fail (SOUP_IS_MESSAGE (message));
+                       version = e_soap_parameter_get_property (param, "Version");
 
-       sd = g_slice_new0 (EwsScheduleData);
-       sd->cnc = g_object_ref (cnc);
-       sd->message = g_object_ref (message);
-       sd->op = EWS_SCHEDULE_OP_QUEUE_MESSAGE;
-       sd->queue_callback = callback;
-       sd->queue_user_data = user_data;
+                       e_ews_connection_set_server_version_from_string (cnc, version);
 
-       source = g_idle_source_new ();
-       g_source_set_priority (source, G_PRIORITY_DEFAULT);
-       g_source_set_callback (source, ews_connection_scheduled_cb, sd, NULL);
-       g_source_attach (source, cnc->priv->soup_context);
-       g_source_unref (source);
+                       g_free (version);
+               }
+       }
+
+       return response;
 }
 
-static void
-ews_connection_schedule_cancel_message (EEwsConnection *cnc,
-                                        SoupMessage *message)
+static gboolean
+ews_update_concurrect_connections_cb (gpointer user_data)
 {
-       EwsScheduleData *sd;
-       GSource *source;
+       GWeakRef *weak_ref = user_data;
+       EEwsConnection *cnc = g_weak_ref_get (cnc);
 
-       g_return_if_fail (E_IS_EWS_CONNECTION (cnc));
-       g_return_if_fail (SOUP_IS_MESSAGE (message));
+       if (cnc) {
+               g_mutex_lock (&cnc->priv->soup.mutex);
 
-       sd = g_slice_new0 (EwsScheduleData);
-       sd->cnc = g_object_ref (cnc);
-       sd->message = g_object_ref (message);
-       sd->op = EWS_SCHEDULE_OP_CANCEL;
+               if (cnc->priv->soup.session) {
+                       g_object_set (G_OBJECT (cnc->priv->soup.session),
+                               "max-conns", cnc->priv->concurrent_connections,
+                               "max-conns-per-host", cnc->priv->concurrent_connections,
+                               NULL);
+               }
 
-       source = g_idle_source_new ();
-       g_source_set_priority (source, G_PRIORITY_DEFAULT);
-       g_source_set_callback (source, ews_connection_scheduled_cb, sd, NULL);
-       g_source_attach (source, cnc->priv->soup_context);
-       g_source_unref (source);
-}
+               g_mutex_unlock (&cnc->priv->soup.mutex);
 
-static void
-ews_connection_schedule_abort (EEwsConnection *cnc)
-{
-       EwsScheduleData *sd;
-       GSource *source;
+               g_object_unref (cnc);
+       }
 
-       g_return_if_fail (E_IS_EWS_CONNECTION (cnc));
+       return FALSE;
+}
 
-       sd = g_slice_new0 (EwsScheduleData);
-       sd->cnc = g_object_ref (cnc);
-       sd->op = EWS_SCHEDULE_OP_ABORT;
+static guint
+ews_connection_get_concurrent_connections (EEwsConnection *cnc)
+{
+       g_return_val_if_fail (E_IS_EWS_CONNECTION (cnc), 1);
 
-       source = g_idle_source_new ();
-       g_source_set_priority (source, G_PRIORITY_DEFAULT);
-       g_source_set_callback (source, ews_connection_scheduled_cb, sd, NULL);
-       g_source_attach (source, cnc->priv->soup_context);
-       g_source_unref (source);
+       return cnc->priv->concurrent_connections;
 }
 
-static void ews_cancel_request (GCancellable *cancellable, gpointer user_data);
-
 static void
-ews_discover_server_version (EEwsConnection *cnc,
-                            ESoapResponse *response)
+ews_connection_set_concurrent_connections (EEwsConnection *cnc,
+                                          guint concurrent_connections)
 {
-       ESoapParameter *param;
-       gchar *version;
+       g_return_if_fail (E_IS_EWS_CONNECTION (cnc));
 
-       g_return_if_fail (cnc != NULL);
+       concurrent_connections = CLAMP (
+               concurrent_connections,
+               MIN_CONCURRENT_CONNECTIONS,
+               MAX_CONCURRENT_CONNECTIONS);
 
-       if (cnc->priv->version != E_EWS_EXCHANGE_UNKNOWN)
+       if (cnc->priv->concurrent_connections == concurrent_connections)
                return;
 
-       param = e_soap_response_get_first_parameter_by_name (
-               response, "ServerVersionInfo", NULL);
-       if (!param)
-               return;
+       cnc->priv->concurrent_connections = concurrent_connections;
 
-       version = e_soap_parameter_get_property (param, "Version");
+       if (cnc->priv->soup.thread) {
+               GSource *source;
 
-       e_ews_connection_set_server_version_from_string (cnc, version);
+               source = g_idle_source_new ();
+               g_source_set_priority (source, G_PRIORITY_DEFAULT);
+               g_source_set_callback (source, ews_update_concurrect_connections_cb, e_weak_ref_new (cnc), 
(GDestroyNotify) e_weak_ref_free);
+               g_source_attach (source, cnc->priv->soup.main_context);
+               g_source_unref (source);
+       }
 
-       g_free (version);
+       g_object_notify (G_OBJECT (cnc), "concurrent-connections");
 }
 
-/* this is run in priv->soup_thread */
-static gboolean
-ews_next_request (gpointer _cnc)
+GQuark
+ews_connection_error_quark (void)
 {
-       EEwsConnection *cnc = _cnc;
-       GSList *l;
-       EwsNode *node;
-
-       QUEUE_LOCK (cnc);
-
-       l = cnc->priv->jobs;
+       static GQuark quark = 0;
 
-       if (!l || g_slist_length (cnc->priv->active_job_queue) >= ews_connection_get_concurrent_connections 
(cnc)) {
-               QUEUE_UNLOCK (cnc);
-               return FALSE;
+       if (G_UNLIKELY (quark == 0)) {
+               const gchar *string = "ews-connection-error-quark";
+               quark = g_quark_from_static_string (string);
        }
 
-       node = (EwsNode *) l->data;
-
-       /* Remove the node from the priority queue */
-       cnc->priv->jobs = g_slist_remove (cnc->priv->jobs, (gconstpointer *) node);
-
-       /* Add to active job queue */
-       cnc->priv->active_job_queue = g_slist_append (cnc->priv->active_job_queue, node);
-
-       QUEUE_UNLOCK (cnc);
+       return quark;
+}
 
-       if (cnc->priv->soup_session) {
-               SoupMessage *msg = SOUP_MESSAGE (node->msg);
+EEwsNotificationEvent *
+e_ews_notification_event_new (void)
+{
+       return g_new0 (EEwsNotificationEvent, 1);
+}
 
-               if (!e_ews_connection_utils_prepare_message (cnc, NULL, msg, node->cancellable)) {
-                       ews_response_cb (cnc->priv->soup_session, msg, node);
-               } else {
-                       soup_session_queue_message (cnc->priv->soup_session, msg, ews_response_cb, node);
-               }
-       } else {
-               ews_cancel_request (NULL, node);
+void
+e_ews_notification_event_free (EEwsNotificationEvent *event)
+{
+       if (event != NULL) {
+               g_free (event->folder_id);
+               g_free (event->old_folder_id);
+               g_free (event);
        }
-
-       return FALSE;
 }
 
-static void
-ews_trigger_next_request (EEwsConnection *cnc)
+EEwsCalendarTo *
+e_ews_calendar_to_new (void)
 {
-       GSource *source;
-
-       g_return_if_fail (cnc != NULL);
+       return g_new0 (EEwsCalendarTo, 1);
+}
 
-       if (cnc->priv->soup_session) {
-               source = g_idle_source_new ();
-               g_source_set_priority (source, G_PRIORITY_DEFAULT);
-               g_source_set_callback (source, ews_next_request, cnc, NULL);
-               g_source_attach (source, cnc->priv->soup_context);
-               g_source_unref (source);
-       } else {
-               ews_next_request (cnc);
+void
+e_ews_calendar_to_free (EEwsCalendarTo *to) {
+       if (to != NULL) {
+               g_free (to->kind);
+               g_free (to->value);
+               g_free (to);
        }
 }
 
-/**
- * ews_active_job_done
- * @cnc:
- * @msg:
- * Removes the node from active Queue and free's the node
- *
- * Returns:
- **/
-static void
-ews_active_job_done (EEwsConnection *cnc,
-                     EwsNode *ews_node)
+EEwsCalendarAbsoluteDateTransition *
+e_ews_calendar_absolute_date_transition_new (void)
 {
-       g_return_if_fail (cnc != NULL);
-       g_return_if_fail (ews_node != NULL);
-
-       QUEUE_LOCK (cnc);
-
-       cnc->priv->active_job_queue = g_slist_remove (cnc->priv->active_job_queue, ews_node);
-       if (ews_node->cancellable && ews_node->cancel_handler_id)
-               g_signal_handler_disconnect (ews_node->cancellable, ews_node->cancel_handler_id);
-
-       QUEUE_UNLOCK (cnc);
-
-       ews_trigger_next_request (cnc);
-
-       if (ews_node->cancellable)
-               g_object_unref (ews_node->cancellable);
+       return g_new0 (EEwsCalendarAbsoluteDateTransition, 1);
+}
 
-       if (ews_node->simple) {
-               /* the 'simple' holds reference on 'cnc' and this function
-                * is called in a dedicated thread, which 'cnc' joins on dispose,
-                * thus to avoid race condition, unref the object in its own thread */
-               e_ews_connection_utils_unref_in_thread (ews_node->simple);
+void
+e_ews_calendar_absolute_date_transition_free (EEwsCalendarAbsoluteDateTransition *adt)
+{
+       if (adt != NULL) {
+               e_ews_calendar_to_free (adt->to);
+               g_free (adt->date_time);
+               g_free (adt);
        }
-
-       g_slice_free (EwsNode, ews_node);
 }
 
-static void
-ews_cancel_request (GCancellable *cancellable,
-                    gpointer user_data)
+EEwsCalendarRecurringDayTransition *
+e_ews_calendar_recurring_day_transition_new (void)
 {
-       EwsNode *node = user_data;
-       EEwsConnection *cnc = node->cnc;
-       GSimpleAsyncResult *simple = node->simple;
-       ESoapRequest *request = node->msg;
-       GSList *found;
-
-       QUEUE_LOCK (cnc);
-       found = g_slist_find (cnc->priv->active_job_queue, node);
-       cnc->priv->jobs = g_slist_remove (cnc->priv->jobs, node);
-       QUEUE_UNLOCK (cnc);
-
-       g_simple_async_result_set_error (
-               simple,
-               G_IO_ERROR,
-               G_IO_ERROR_CANCELLED,
-               _("Operation Cancelled"));
-       if (found) {
-               ews_connection_schedule_cancel_message (cnc, SOUP_MESSAGE (request));
-       } else {
-               ews_response_cb (cnc->priv->soup_session, SOUP_MESSAGE (request), node);
-       }
+       return g_new0 (EEwsCalendarRecurringDayTransition, 1);
 }
 
 void
-e_ews_connection_queue_request (EEwsConnection *cnc,
-                                ESoapRequest *request,
-                                EEwsResponseCallback cb,
-                                gint pri,
-                                GCancellable *cancellable,
-                                GSimpleAsyncResult *simple)
+e_ews_calendar_recurring_day_transition_free (EEwsCalendarRecurringDayTransition *rdayt)
 {
-       EwsNode *node;
-
-       g_return_if_fail (cnc != NULL);
-       g_return_if_fail (cb != NULL);
-       g_return_if_fail (G_IS_SIMPLE_ASYNC_RESULT (simple));
-
-       node = ews_node_new ();
-       node->msg = msg;
-       node->pri = pri;
-       node->cb = cb;
-       node->cnc = cnc;
-       node->simple = g_object_ref (simple);
-
-       QUEUE_LOCK (cnc);
-       cnc->priv->jobs = g_slist_insert_sorted (cnc->priv->jobs, (gpointer *) node, (GCompareFunc) 
comp_func);
-       QUEUE_UNLOCK (cnc);
-
-       if (cancellable) {
-               node->cancellable = g_object_ref (cancellable);
-               if (g_cancellable_is_cancelled (cancellable))
-                       ews_cancel_request (cancellable, node);
-               else
-                       node->cancel_handler_id = g_cancellable_connect (
-                               cancellable,
-                               G_CALLBACK (ews_cancel_request),
-                               (gpointer) node, NULL);
+       if (rdayt != NULL) {
+               e_ews_calendar_to_free (rdayt->to);
+               g_free (rdayt->time_offset);
+               g_free (rdayt->month);
+               g_free (rdayt->day_of_week);
+               g_free (rdayt->occurrence);
+               g_free (rdayt);
        }
-
-       ews_trigger_next_request (cnc);
 }
 
-static gboolean
-ews_connection_credentials_failed (EEwsConnection *connection,
-                                  SoupMessage *message,
-                                  GSimpleAsyncResult *simple)
+EEwsCalendarRecurringDateTransition *
+e_ews_calendar_recurring_date_transition_new (void)
 {
-       gint expire_in_days = 0;
-       gboolean expired = FALSE;
-       gchar *service_url = NULL;
-
-       g_return_val_if_fail (E_IS_EWS_CONNECTION (connection), FALSE);
-       g_return_val_if_fail (SOUP_IS_MESSAGE (message), FALSE);
-       g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (simple), FALSE);
-
-       if (!e_ews_connection_utils_check_x_ms_credential_headers (message, &expire_in_days, &expired, 
&service_url))
-               return FALSE;
-
-       if (expired) {
-               GError *error = NULL;
+       return g_new0 (EEwsCalendarRecurringDateTransition, 1);
+}
 
-               e_ews_connection_utils_expired_password_to_error (service_url, &error);
-               g_simple_async_result_take_error (simple, error);
-       } else if (expire_in_days > 0) {
-               g_signal_emit (connection, signals[PASSWORD_WILL_EXPIRE], 0, expire_in_days, service_url);
+void
+e_ews_calendar_recurring_date_transition_free (EEwsCalendarRecurringDateTransition *rdatet)
+{
+       if (rdatet != NULL) {
+               e_ews_calendar_to_free (rdatet->to);
+               g_free (rdatet->time_offset);
+               g_free (rdatet->month);
+               g_free (rdatet->day);
+               g_free (rdatet);
        }
-
-       g_free (service_url);
-
-       return expired;
 }
 
-static void
-ews_connection_check_ssl_error (EEwsConnection *connection,
-                               SoupMessage *message)
+EEwsCalendarPeriod *
+e_ews_calendar_period_new (void)
 {
-       g_return_if_fail (E_IS_EWS_CONNECTION (connection));
-       g_return_if_fail (SOUP_IS_MESSAGE (message));
-
-       if (message->status_code == SOUP_STATUS_SSL_FAILED) {
-               GTlsCertificate *certificate = NULL;
-
-               g_mutex_lock (&connection->priv->property_lock);
-
-               g_clear_pointer (&connection->priv->ssl_certificate_pem, g_free);
-               connection->priv->ssl_info_set = FALSE;
-
-               g_object_get (G_OBJECT (message),
-                       "tls-certificate", &certificate,
-                       "tls-errors", &connection->priv->ssl_certificate_errors,
-                       NULL);
-
-               if (certificate) {
-                       g_object_get (certificate, "certificate-pem", &connection->priv->ssl_certificate_pem, 
NULL);
-                       connection->priv->ssl_info_set = TRUE;
-
-                       g_object_unref (certificate);
-               }
+       return g_new0 (EEwsCalendarPeriod, 1);
+}
 
-               g_mutex_unlock (&connection->priv->property_lock);
+void
+e_ews_calendar_period_free (EEwsCalendarPeriod *period)
+{
+       if (period != NULL) {
+               g_free (period->bias);
+               g_free (period->name);
+               g_free (period->id);
+               g_free (period);
        }
 }
 
-/* Response callbacks */
+EEwsCalendarTransitionsGroup *
+e_ews_calendar_transitions_group_new (void)
+{
+       return g_new0 (EEwsCalendarTransitionsGroup, 1);
+}
 
-static void
-ews_response_cb (SoupSession *session,
-                 SoupMessage *msg,
-                 gpointer data)
+void
+e_ews_calendar_transitions_group_free (EEwsCalendarTransitionsGroup *tg)
 {
-       EwsNode *enode = (EwsNode *) data;
-       ESoapResponse *response;
-       ESoapParameter *param;
-       const gchar *persistent_auth;
-       gint wait_ms = 0;
+       if (tg != NULL) {
+               g_free (tg->id);
+               e_ews_calendar_to_free (tg->transition);
+               g_slist_free_full (
+                       tg->absolute_date_transitions,
+                       (GDestroyNotify) e_ews_calendar_absolute_date_transition_free);
+               g_slist_free_full (
+                       tg->recurring_day_transitions,
+                       (GDestroyNotify) e_ews_calendar_recurring_day_transition_free);
+               g_slist_free_full (
+                       tg->recurring_date_transitions,
+                       (GDestroyNotify) e_ews_calendar_recurring_date_transition_free);
+               g_free (tg);
+       }
+}
 
-       persistent_auth = soup_message_headers_get_one (soup_message_get_response_headers (request), 
"Persistent-Auth");
-       if (persistent_auth && g_ascii_strcasecmp (persistent_auth, "false") == 0) {
-               SoupSessionFeature *feature;
+EEwsCalendarTransitions *
+e_ews_calendar_transitions_new (void)
+{
+       return g_new0 (EEwsCalendarTransitions, 1);
+}
 
-               feature = soup_session_get_feature (session, SOUP_TYPE_AUTH_MANAGER);
-               if (feature) {
-                       soup_auth_manager_clear_cached_credentials (SOUP_AUTH_MANAGER (feature));
-               }
+void
+e_ews_calendar_transitions_free (EEwsCalendarTransitions *transitions)
+{
+       if (transitions != NULL) {
+               e_ews_calendar_to_free (transitions->transition);
+               g_slist_free_full (
+                       transitions->absolute_date_transitions,
+                       (GDestroyNotify) e_ews_calendar_absolute_date_transition_free);
+               g_slist_free_full (
+                       transitions->recurring_day_transitions,
+                       (GDestroyNotify) e_ews_calendar_recurring_day_transition_free);
+               g_slist_free_full (
+                       transitions->recurring_date_transitions,
+                       (GDestroyNotify) e_ews_calendar_recurring_date_transition_free);
+               g_free (transitions);
        }
+}
 
-       if (g_cancellable_is_cancelled (enode->cancellable))
-               goto exit;
+EEwsCalendarTimeZoneDefinition *
+e_ews_calendar_time_zone_definition_new (void)
+{
+       return g_new0 (EEwsCalendarTimeZoneDefinition, 1);
+}
 
-       ews_connection_check_ssl_error (enode->cnc, msg);
+void
+e_ews_calendar_time_zone_definition_free (EEwsCalendarTimeZoneDefinition *tzd)
+{
+       if (tzd != NULL) {
+               g_free (tzd->name);
+               g_free (tzd->id);
+               g_slist_free_full (tzd->periods, (GDestroyNotify) e_ews_calendar_period_free);
+               g_slist_free_full (tzd->transitions_groups, (GDestroyNotify) 
e_ews_calendar_transitions_group_free);
+               e_ews_calendar_transitions_free (tzd->transitions);
+               g_free (tzd);
+       }
+}
 
-       if (ews_connection_credentials_failed (enode->cnc, msg, enode->simple)) {
-               goto exit;
-       } else if (msg->status_code == SOUP_STATUS_SSL_FAILED) {
-               g_simple_async_result_set_error (
-                       enode->simple, SOUP_HTTP_ERROR, SOUP_STATUS_SSL_FAILED,
-                       "%s", msg->reason_phrase);
-               goto exit;
-       } else if (soup_message_get_status (request) == SOUP_STATUS_UNAUTHORIZED) {
-               if (soup_message_get_response_headers (request)) {
-                       const gchar *diagnostics;
-
-                       diagnostics = soup_message_headers_get_list (soup_message_get_response_headers 
(request), "X-MS-DIAGNOSTICS");
-                       if (diagnostics && strstr (diagnostics, "invalid_grant")) {
-                               g_simple_async_result_set_error (
-                                       enode->simple,
-                                       EWS_CONNECTION_ERROR,
-                                       EWS_CONNECTION_ERROR_ACCESSDENIED,
-                                       "%s", diagnostics);
-                               goto exit;
-                       } else if (diagnostics && *diagnostics) {
-                               g_simple_async_result_set_error (
-                                       enode->simple,
-                                       EWS_CONNECTION_ERROR,
-                                       EWS_CONNECTION_ERROR_AUTHENTICATION_FAILED,
-                                       "%s", diagnostics);
-                               goto exit;
-                       }
-               }
-
-               g_simple_async_result_set_error (
-                       enode->simple,
-                       EWS_CONNECTION_ERROR,
-                       EWS_CONNECTION_ERROR_AUTHENTICATION_FAILED,
-                       _("Authentication failed"));
-               goto exit;
-       } else if (msg->status_code == SOUP_STATUS_CANT_RESOLVE ||
-                  msg->status_code == SOUP_STATUS_CANT_RESOLVE_PROXY ||
-                  msg->status_code == SOUP_STATUS_CANT_CONNECT ||
-                  msg->status_code == SOUP_STATUS_CANT_CONNECT_PROXY ||
-                  msg->status_code == SOUP_STATUS_IO_ERROR) {
-               g_simple_async_result_set_error (
-                       enode->simple,
-                       EWS_CONNECTION_ERROR,
-                       EWS_CONNECTION_ERROR_UNAVAILABLE,
-                       "%s", msg->reason_phrase);
-               goto exit;
-       }
-
-       response = e_soap_request_parse_response ((ESoapMessage *) msg);
-
-       if (response == NULL) {
-               g_simple_async_result_set_error (
-                       enode->simple,
-                       EWS_CONNECTION_ERROR,
-                       EWS_CONNECTION_ERROR_NORESPONSE,
-                       _("No response: %s"), msg->reason_phrase);
-               goto exit;
-       }
-
-       param = e_soap_response_get_first_parameter_by_name (response, "detail", NULL);
-       if (param)
-               param = e_soap_parameter_get_first_child_by_name (param, "ResponseCode");
-       if (param) {
-               gchar *value;
-
-               value = e_soap_parameter_get_string_value (param);
-               if (value && ews_get_error_code (value) == EWS_CONNECTION_ERROR_SERVERBUSY) {
-                       param = e_soap_response_get_first_parameter_by_name (response, "detail", NULL);
-                       if (param)
-                               param = e_soap_parameter_get_first_child_by_name (param, "MessageXml");
-                       if (param) {
-                               param = e_soap_parameter_get_first_child_by_name (param, "Value");
-                               if (param) {
-                                       g_free (value);
-
-                                       value = e_soap_parameter_get_property (param, "Name");
-                                       if (g_strcmp0 (value, "BackOffMilliseconds") == 0) {
-                                               wait_ms = e_soap_parameter_get_int_value (param);
-                                       }
-                               }
-                       }
-               }
-
-               g_free (value);
-       }
-
-       if (wait_ms > 0 && e_ews_connection_get_backoff_enabled (enode->cnc)) {
-               GCancellable *cancellable = enode->cancellable;
-               EFlag *flag;
-
-               if (cancellable)
-                       g_object_ref (cancellable);
-               g_object_ref (request);
-
-               flag = e_flag_new ();
-               while (wait_ms > 0 && !g_cancellable_is_cancelled (cancellable)) {
-                       gint64 now = g_get_monotonic_time ();
-                       gint left_minutes, left_seconds;
-
-                       left_minutes = wait_ms / 60000;
-                       left_seconds = (wait_ms / 1000) % 60;
-
-                       if (left_minutes > 0) {
-                               camel_operation_push_message (cancellable,
-                                       g_dngettext (GETTEXT_PACKAGE,
-                                               "Exchange server is busy, waiting to retry (%d:%02d minute)",
-                                               "Exchange server is busy, waiting to retry (%d:%02d 
minutes)", left_minutes),
-                                       left_minutes, left_seconds);
-                       } else {
-                               camel_operation_push_message (cancellable,
-                                       g_dngettext (GETTEXT_PACKAGE,
-                                               "Exchange server is busy, waiting to retry (%d second)",
-                                               "Exchange server is busy, waiting to retry (%d seconds)", 
left_seconds),
-                                       left_seconds);
-                       }
-
-                       e_flag_wait_until (flag, now + (G_TIME_SPAN_MILLISECOND * (wait_ms > 1000 ? 1000 : 
wait_ms)));
-
-                       now = g_get_monotonic_time () - now;
-                       now = now / G_TIME_SPAN_MILLISECOND;
-
-                       if (now >= wait_ms)
-                               wait_ms = 0;
-                       wait_ms -= now;
-
-                       camel_operation_pop_message (cancellable);
-               }
-
-               e_flag_free (flag);
-
-               g_object_unref (response);
-
-               if (g_cancellable_is_cancelled (cancellable)) {
-                       g_clear_object (&cancellable);
-                       g_object_unref (request);
-               } else {
-                       EwsNode *new_node;
-
-                       new_node = ews_node_new ();
-                       new_node->msg = E_SOAP_REQUEST (request); /* takes ownership */
-                       new_node->pri = enode->pri;
-                       new_node->cb = enode->cb;
-                       new_node->cnc = enode->cnc;
-                       new_node->simple = enode->simple;
-
-                       enode->simple = NULL;
-
-                       QUEUE_LOCK (enode->cnc);
-                       enode->cnc->priv->jobs = g_slist_prepend (enode->cnc->priv->jobs, new_node);
-                       QUEUE_UNLOCK (enode->cnc);
-
-                       if (cancellable) {
-                               new_node->cancellable = g_object_ref (cancellable);
-                               new_node->cancel_handler_id = g_cancellable_connect (
-                                       cancellable, G_CALLBACK (ews_cancel_request), new_node, NULL);
-                       }
-
-                       g_clear_object (&cancellable);
-               }
-
-               goto exit;
-       }
-
-       if (enode->cb != NULL)
-               enode->cb (response, enode->simple);
-
-       g_object_unref (response);
-
-exit:
-       if (enode->simple)
-               g_simple_async_result_complete_in_idle (enode->simple);
-
-       ews_active_job_done (enode->cnc, enode);
-}
-
-typedef gpointer (*ItemParser) (ESoapParameter *param);
-
-static void
-sync_xxx_response_cb (ESoapParameter *subparam,
-                      EwsAsyncData *async_data,
-                      ItemParser parser,
-                      const gchar *last_tag,
-                      const gchar *delete_id_tag)
-{
-       ESoapParameter *node;
-       gchar *new_sync_state = NULL, *value, *last;
-       GSList *items_created = NULL, *items_updated = NULL, *items_deleted = NULL;
-       gboolean includes_last_item;
-
-       node = e_soap_parameter_get_first_child_by_name (subparam, "SyncState");
-       new_sync_state = e_soap_parameter_get_string_value (node);
-
-       node = e_soap_parameter_get_first_child_by_name (subparam, last_tag);
-       last = e_soap_parameter_get_string_value (node);
-       /*
-        * Set the includes_last_item to TRUE as default.
-        * It can avoid an infinite loop in caller, when, for some reason,
-        * we don't receive the last_tag property from the server.
-        */
-       includes_last_item = g_strcmp0 (last, "false") != 0;
-       g_free (last);
-
-       node = e_soap_parameter_get_first_child_by_name (subparam, "Changes");
-
-       if (node) {
-               ESoapParameter *subparam1;
-               for (subparam1 = e_soap_parameter_get_first_child_by_name (node, "Create");
-                    subparam1 != NULL;
-                    subparam1 = e_soap_parameter_get_next_child_by_name (subparam1, "Create")) {
-                       GObject *object;
-
-                       object = parser (subparam1);
-                       if (object && (!E_IS_EWS_FOLDER (object) || !e_ews_folder_get_is_hidden (E_EWS_FOLDER 
(object))))
-                               items_created = g_slist_append (items_created, object);
-                       else
-                               g_clear_object (&object);
-               }
-
-               for (subparam1 = e_soap_parameter_get_first_child_by_name (node, "Update");
-                    subparam1 != NULL;
-                    subparam1 = e_soap_parameter_get_next_child_by_name (subparam1, "Update")) {
-                       GObject *object;
-
-                       object = parser (subparam1);
-                       if (object && (!E_IS_EWS_FOLDER (object) || !e_ews_folder_get_is_hidden (E_EWS_FOLDER 
(object))))
-                               items_updated = g_slist_append (items_updated, object);
-                       else
-                               g_clear_object (&object);
-               }
-                 /* Exchange 2007SP1 introduced <ReadFlagChange> which is basically identical
-                  * to <Update>; no idea why they thought it was a good idea. */
-               for (subparam1 = e_soap_parameter_get_first_child_by_name (node, "ReadFlagChange");
-                    subparam1 != NULL;
-                    subparam1 = e_soap_parameter_get_next_child_by_name (subparam1, "ReadFlagChange")) {
-                       GObject *object;
-
-                       object = parser (subparam1);
-                       if (object && (!E_IS_EWS_FOLDER (object) || !e_ews_folder_get_is_hidden (E_EWS_FOLDER 
(object))))
-                               items_updated = g_slist_append (items_updated, object);
-                       else
-                               g_clear_object (&object);
-               }
-
-               for (subparam1 = e_soap_parameter_get_first_child_by_name (node, "Delete");
-                    subparam1 != NULL;
-                    subparam1 = e_soap_parameter_get_next_child_by_name (subparam1, "Delete")) {
-                       ESoapParameter *folder_param;
-
-                       folder_param = e_soap_parameter_get_first_child_by_name (subparam1, delete_id_tag);
-                       value = e_soap_parameter_get_property (folder_param, "Id");
-                       items_deleted = g_slist_append (items_deleted, value);
-               }
-       }
-
-       async_data->items_created = items_created;
-       async_data->items_updated = items_updated;
-       async_data->items_deleted = items_deleted;
-       async_data->sync_state = new_sync_state;
-       async_data->includes_last_item = includes_last_item;
-}
-
-static void
-sync_hierarchy_response_cb (ESoapResponse *response,
-                            GSimpleAsyncResult *simple)
-{
-       EwsAsyncData *async_data;
-       ESoapParameter *param;
-       ESoapParameter *subparam;
-       GError *error = NULL;
-
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
-
-       /*
-        * During the first connection, we are able to get the current version of the Exchange server.
-        * For Addressbook/Calendar backends, we are ensuring it happens during the
-        * e_ews_connection_try_credentials_sync(), that calls e_e_ews_connection_get_folder_sync() and then
-        * we are able to get the current version of the server from this first response.
-        *
-        * For Camel, the first connection is done calling e_ews_connection_sync_folder_hierarchy_sync().
-        */
-       ews_discover_server_version (async_data->cnc, response);
-
-       param = e_soap_response_get_first_parameter_by_name (
-               response, "ResponseMessages", &error);
-
-       /* Sanity check */
-       g_return_if_fail (
-               (param != NULL && error == NULL) ||
-               (param == NULL && error != NULL));
-
-       if (error != NULL) {
-               g_simple_async_result_take_error (simple, error);
-               return;
-       }
-
-       subparam = e_soap_parameter_get_first_child (param);
-
-       while (subparam != NULL) {
-               const gchar *name = (const gchar *) subparam->name;
-
-               if (!ews_get_response_status (subparam, &error)) {
-                       g_simple_async_result_take_error (simple, error);
-                       return;
-               }
-
-               if (E_EWS_CONNECTION_UTILS_CHECK_ELEMENT (name, "SyncFolderHierarchyResponseMessage"))
-                       sync_xxx_response_cb (
-                               subparam, async_data,
-                               (ItemParser) e_ews_folder_new_from_soap_parameter,
-                               "IncludesLastFolderInRange", "FolderId");
-
-               subparam = e_soap_parameter_get_next_child (subparam);
-       }
-}
-
-static void
-sync_folder_items_response_cb (ESoapResponse *response,
-                               GSimpleAsyncResult *simple)
-{
-       EwsAsyncData *async_data;
-       ESoapParameter *param;
-       ESoapParameter *subparam;
-       GError *error = NULL;
-
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
-
-       param = e_soap_response_get_first_parameter_by_name (
-               response, "ResponseMessages", &error);
-
-       /* Sanity check */
-       g_return_if_fail (
-               (param != NULL && error == NULL) ||
-               (param == NULL && error != NULL));
-
-       if (error != NULL) {
-               g_simple_async_result_take_error (simple, error);
-               return;
-       }
-
-       subparam = e_soap_parameter_get_first_child (param);
-
-       while (subparam != NULL) {
-               const gchar *name = (const gchar *) subparam->name;
-
-               if (!ews_get_response_status (subparam, &error)) {
-                       g_simple_async_result_take_error (simple, error);
-                       return;
-               }
-
-               if (E_EWS_CONNECTION_UTILS_CHECK_ELEMENT (name, "SyncFolderItemsResponseMessage"))
-                       sync_xxx_response_cb (
-                               subparam, async_data,
-                               (ItemParser) e_ews_item_new_from_soap_parameter,
-                               "IncludesLastItemInRange", "ItemId");
-
-               subparam = e_soap_parameter_get_next_child (subparam);
-       }
-}
-
-static void
-ews_handle_folders_param (ESoapParameter *subparam,
-                          EwsAsyncData *async_data)
-{
-       ESoapParameter *node;
-       EEwsFolder *folder;
-
-       for (node = e_soap_parameter_get_first_child_by_name (subparam, "Folders");
-            node; node = e_soap_parameter_get_next_child_by_name (subparam, "Folders")) {
-               folder = e_ews_folder_new_from_soap_parameter (node);
-               if (!folder) continue;
-               async_data->items = g_slist_append (async_data->items, folder);
-       }
-}
-
-static void
-get_folder_response_cb (ESoapResponse *response,
-                        GSimpleAsyncResult *simple)
-{
-       EwsAsyncData *async_data;
-       ESoapParameter *param;
-       ESoapParameter *subparam;
-       GError *error = NULL;
-
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
-
-       /*
-        * During the first connection, we are able to get the current version of the Exchange server.
-        * For Addressbook/Calendar backends, we are ensuring it happens during the
-        * e_ews_connection_try_credentials_sync(), that calls e_e_ews_connection_get_folder_sync() and then
-        * we are able to get the current version of the server from this first response.
-        *
-        * For Camel, the first connection is done calling e_ews_connection_sync_folder_hierarchy_sync().
-        */
-       ews_discover_server_version (async_data->cnc, response);
-
-       param = e_soap_response_get_first_parameter_by_name (
-               response, "ResponseMessages", &error);
-
-       /* Sanity check */
-       g_return_if_fail (
-               (param != NULL && error == NULL) ||
-               (param == NULL && error != NULL));
-
-       if (error != NULL) {
-               g_simple_async_result_take_error (simple, error);
-               return;
-       }
-
-       subparam = e_soap_parameter_get_first_child (param);
-
-       while (subparam != NULL) {
-               const gchar *name = (const gchar *) subparam->name;
-
-               if (!ews_get_response_status (subparam, &error)) {
-                       if (g_strcmp0 (name, "GetFolderResponseMessage") == 0) {
-                               async_data->items = g_slist_append (async_data->items, 
e_ews_folder_new_from_error (error));
-                               g_clear_error (&error);
-                       } else {
-                               g_simple_async_result_take_error (simple, error);
-                               return;
-                       }
-               } else if (E_EWS_CONNECTION_UTILS_CHECK_ELEMENT (name, "GetFolderResponseMessage"))
-                       ews_handle_folders_param (subparam, async_data);
-
-               subparam = e_soap_parameter_get_next_child (subparam);
-       }
-}
-
-static void
-ews_handle_root_folder_param_items (ESoapParameter *subparam,
-                                   EwsAsyncData *async_data)
-{
-       ESoapParameter *node, *subparam1;
-       gchar *last, *total;
-       gint total_items;
-       EEwsItem *item;
-       gboolean includes_last_item;
-
-       node = e_soap_parameter_get_first_child_by_name (subparam, "RootFolder");
-       total = e_soap_parameter_get_property (node, "TotalItemsInView");
-       total_items = atoi (total);
-       g_free (total);
-       last = e_soap_parameter_get_property (node, "IncludesLastItemInRange");
-       /*
-        * Set the includes_last_item to TRUE as default.
-        * It can avoid an infinite loop in caller, when, for some reason,
-        * we don't receive the last_tag property from the server.
-        */
-       includes_last_item = g_strcmp0 (last, "false") != 0;
-       g_free (last);
-
-       node = e_soap_parameter_get_first_child_by_name (node, "Items");
-       for (subparam1 = e_soap_parameter_get_first_child (node);
-            subparam1; subparam1 = e_soap_parameter_get_next_child (subparam1)) {
-               item = e_ews_item_new_from_soap_parameter (subparam1);
-               if (!item) continue;
-               async_data->items = g_slist_append (async_data->items, item);
-       }
-       async_data->total_items = total_items;
-       async_data->includes_last_item = includes_last_item;
-}
-
-static void
-find_folder_items_response_cb (ESoapResponse *response,
-                               GSimpleAsyncResult *simple)
-{
-       EwsAsyncData *async_data;
-       ESoapParameter *param;
-       ESoapParameter *subparam;
-       GError *error = NULL;
-
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
-
-       param = e_soap_response_get_first_parameter_by_name (
-               response, "ResponseMessages", &error);
-
-       /* Sanity check */
-       g_return_if_fail (
-               (param != NULL && error == NULL) ||
-               (param == NULL && error != NULL));
-
-       if (error != NULL) {
-               g_simple_async_result_take_error (simple, error);
-               return;
-       }
-
-       subparam = e_soap_parameter_get_first_child (param);
-
-       while (subparam != NULL) {
-               const gchar *name = (const gchar *) subparam->name;
-
-               if (!ews_get_response_status (subparam, &error)) {
-                       g_simple_async_result_take_error (simple, error);
-                       return;
-               }
-
-               if (E_EWS_CONNECTION_UTILS_CHECK_ELEMENT (name, "FindItemResponseMessage"))
-                       ews_handle_root_folder_param_items (subparam, async_data);
-
-               subparam = e_soap_parameter_get_next_child (subparam);
-       }
-}
-
-/* Used for CreateItems and GetItems */
-static void
-ews_handle_items_param (ESoapParameter *subparam,
-                        EwsAsyncData *async_data,
-                        const GError *error)
-{
-       ESoapParameter *node;
-       EEwsItem *item;
-
-       for (node = e_soap_parameter_get_first_child_by_name (subparam, "Items");
-            node; node = e_soap_parameter_get_next_child_by_name (subparam, "Items")) {
-               if (node->children)
-                       item = e_ews_item_new_from_soap_parameter (node);
-               else
-                       item = NULL;
-               if (!item && error != NULL)
-                       item = e_ews_item_new_from_error (error);
-               if (!item) continue;
-               async_data->items = g_slist_append (async_data->items, item);
-       }
-}
-
-static void
-handle_get_items_response_cb (EwsAsyncData *async_data, ESoapParameter *param)
-{
-       ESoapParameter *subparam;
-       GError *error = NULL;
-
-       subparam = e_soap_parameter_get_first_child (param);
-
-       while (subparam != NULL) {
-               const gchar *name = (const gchar *) subparam->name;
-
-               if (g_str_has_suffix (name, "ResponseMessage")) {
-                       if (ews_get_response_status (subparam, &error))
-                               error = NULL;
-
-                       ews_handle_items_param (subparam, async_data, error);
-               } else {
-                       g_warning (
-                               "%s: Unexpected element <%s>",
-                               G_STRFUNC, name);
-               }
-
-               /* Do not stop on errors. */
-               if (error != NULL)
-                       g_clear_error (&error);
-
-               subparam = e_soap_parameter_get_next_child (subparam);
-       }
-}
-
-static void
-get_items_response_cb (ESoapResponse *response,
-                       GSimpleAsyncResult *simple)
+EEwsExtendedFieldURI *
+e_ews_extended_field_uri_new (void)
 {
-       EwsAsyncData *async_data;
-       ESoapParameter *param;
-       GError *error = NULL;
-
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
-
-       param = e_soap_response_get_first_parameter_by_name (
-               response, "ResponseMessages", &error);
-
-       /* Sanity check */
-       g_return_if_fail (
-               (param != NULL && error == NULL) ||
-               (param == NULL && error != NULL));
-
-       if (error != NULL) {
-               g_simple_async_result_take_error (simple, error);
-               return;
-       }
-
-       handle_get_items_response_cb (async_data, param);
+       return g_new0 (EEwsExtendedFieldURI, 1);
 }
 
-static void
-ews_handle_resolution_set_param (ESoapParameter *subparam,
-                                 EwsAsyncData *async_data)
+void
+e_ews_extended_field_uri_free (EEwsExtendedFieldURI *ex_field_uri)
 {
-       ESoapParameter *node;
-       gchar *prop;
-       gboolean includes_last_item;
-       GSList *mailboxes = NULL, *contact_items = NULL;
-
-       subparam = e_soap_parameter_get_first_child_by_name (subparam, "ResolutionSet");
-       prop = e_soap_parameter_get_property (subparam, "IncludesLastItemInRange");
-       /*
-        * Set the includes_last_item to TRUE as default.
-        * It can avoid an infinite loop in caller, when, for some reason,
-        * we don't receive the last_tag property from the server.
-        */
-       includes_last_item = g_strcmp0 (prop, "false") != 0;
-       g_free (prop);
-
-       for (subparam = e_soap_parameter_get_first_child_by_name (subparam, "Resolution");
-               subparam != NULL;
-               subparam = e_soap_parameter_get_next_child_by_name (subparam, "Resolution")) {
-               EwsMailbox *mb;
-
-               node = e_soap_parameter_get_first_child_by_name (subparam, "Mailbox");
-               mb = e_ews_item_mailbox_from_soap_param (node);
-               if (mb) {
-                       EEwsItem *contact_item;
-
-                       mailboxes = g_slist_prepend (mailboxes, mb);
-
-                       /* 'mailboxes' and 'contact_items' match 1:1, but if the contact information
-                        * wasn't found, then NULL is stored in the corresponding position */
-                       node = e_soap_parameter_get_first_child_by_name (subparam, "Contact");
-                       if (node) {
-                               contact_item = e_ews_item_new_from_soap_parameter (node);
-                               contact_items = g_slist_prepend (contact_items, contact_item);
-                       } else {
-                               contact_items = g_slist_prepend (contact_items, NULL);
-                       }
-               }
+       if (ex_field_uri != NULL) {
+               g_free (ex_field_uri->distinguished_prop_set_id);
+               g_free (ex_field_uri->prop_set_id);
+               g_free (ex_field_uri->prop_tag);
+               g_free (ex_field_uri->prop_name);
+               g_free (ex_field_uri->prop_id);
+               g_free (ex_field_uri->prop_type);
+               g_free (ex_field_uri);
        }
-
-       /* Reuse existing variables */
-       async_data->items = g_slist_reverse (mailboxes);
-       async_data->includes_last_item = includes_last_item;
-       async_data->items_created = g_slist_reverse (contact_items);
 }
 
-static void
-resolve_names_response_cb (ESoapResponse *response,
-                           GSimpleAsyncResult *simple)
+EEwsIndexedFieldURI *
+e_ews_indexed_field_uri_new (const gchar *uri,
+                            const gchar *index)
 {
-       EwsAsyncData *async_data;
-       ESoapParameter *param;
-       ESoapParameter *subparam;
-       GError *error = NULL;
-
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
-
-       param = e_soap_response_get_first_parameter_by_name (
-               response, "ResponseMessages", &error);
-
-       /* Sanity check */
-       g_return_if_fail (
-               (param != NULL && error == NULL) ||
-               (param == NULL && error != NULL));
-
-       if (error != NULL) {
-               g_simple_async_result_take_error (simple, error);
-               return;
-       }
-
-       subparam = e_soap_parameter_get_first_child (param);
-
-       while (subparam != NULL) {
-               const gchar *name = (const gchar *) subparam->name;
-
-               if (!ews_get_response_status (subparam, &error)) {
-                       g_simple_async_result_take_error (simple, error);
-                       return;
-               }
+       EEwsIndexedFieldURI *furi;
 
-               if (E_EWS_CONNECTION_UTILS_CHECK_ELEMENT (name, "ResolveNamesResponseMessage"))
-                       ews_handle_resolution_set_param (subparam, async_data);
+       furi = g_new0 (EEwsIndexedFieldURI, 1);
+       furi->field_uri = g_strdup (uri);
+       furi->field_index = g_strdup (index);
 
-               subparam = e_soap_parameter_get_next_child (subparam);
-       }
+       return furi;
 }
 
-static void
-ews_handle_dl_expansion_param (ESoapParameter *subparam,
-                               EwsAsyncData *async_data)
+void
+e_ews_indexed_field_uri_free (EEwsIndexedFieldURI *id_field_uri)
 {
-       gboolean includes_last_item;
-       GSList *mailboxes = NULL;
-       gchar *prop;
-
-       subparam = e_soap_parameter_get_first_child_by_name (subparam, "DLExpansion");
-       prop = e_soap_parameter_get_property (subparam, "IncludesLastItemInRange");
-       /*
-        * Set the includes_last_item to TRUE as default.
-        * It can avoid an infinite loop in caller, when, for some reason,
-        * we don't receive the last_tag property from the server.
-        */
-       includes_last_item = g_strcmp0 (prop, "false") != 0;
-       g_free (prop);
-
-       for (subparam = e_soap_parameter_get_first_child_by_name (subparam, "Mailbox");
-               subparam != NULL;
-               subparam = e_soap_parameter_get_next_child_by_name (subparam, "Mailbox")) {
-               EwsMailbox *mb;
-
-               mb = e_ews_item_mailbox_from_soap_param (subparam);
-               if (mb)
-                       mailboxes = g_slist_append (mailboxes, mb);
+       if (id_field_uri != NULL) {
+               g_free (id_field_uri->field_uri);
+               g_free (id_field_uri->field_index);
+               g_free (id_field_uri);
        }
-
-       /* Reuse existing variables */
-       async_data->items = mailboxes;
-       async_data->includes_last_item = includes_last_item;
 }
 
-static void
-expand_dl_response_cb (ESoapResponse *response,
-                       GSimpleAsyncResult *simple)
+EEwsAdditionalProps *
+e_ews_additional_props_new (void)
 {
-       EwsAsyncData *async_data;
-       ESoapParameter *param;
-       ESoapParameter *subparam;
-       GError *error = NULL;
-
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
-
-       param = e_soap_response_get_first_parameter_by_name (
-               response, "ResponseMessages", &error);
-
-       /* Sanity check */
-       g_return_if_fail (
-               (param != NULL && error == NULL) ||
-               (param == NULL && error != NULL));
-
-       if (error != NULL) {
-               g_simple_async_result_take_error (simple, error);
-               return;
-       }
-
-       subparam = e_soap_parameter_get_first_child (param);
-
-       while (subparam != NULL) {
-               const gchar *name = (const gchar *) subparam->name;
-
-               if (!ews_get_response_status (subparam, &error)) {
-                       g_simple_async_result_take_error (simple, error);
-                       return;
-               }
-
-               if (E_EWS_CONNECTION_UTILS_CHECK_ELEMENT (name, "ExpandDLResponseMessage"))
-                       ews_handle_dl_expansion_param (subparam, async_data);
-
-               subparam = e_soap_parameter_get_next_child (subparam);
-       }
+       return g_new0 (EEwsAdditionalProps, 1);
 }
 
-/* TODO scan all folders if we support creating multiple folders in the request */
-static void
-ews_handle_create_folders_param (ESoapParameter *soapparam,
-                                 EwsAsyncData *async_data)
+void
+e_ews_additional_props_free (EEwsAdditionalProps *add_props)
 {
-       ESoapParameter *param, *node;
-       EwsFolderId *fid = NULL;
-       GSList *fids = NULL;
-       const gchar *folder_element;
-
-       switch (async_data->folder_type) {
-               case E_EWS_FOLDER_TYPE_MAILBOX:
-               case E_EWS_FOLDER_TYPE_MEMOS:
-                       folder_element = "Folder";
-                       break;
-               case E_EWS_FOLDER_TYPE_CALENDAR:
-                       folder_element = "CalendarFolder";
-                       break;
-               case E_EWS_FOLDER_TYPE_CONTACTS:
-                       folder_element = "ContactsFolder";
-                       break;
-               case E_EWS_FOLDER_TYPE_SEARCH:
-                       folder_element = "SearchFolder";
-                       break;
-               case E_EWS_FOLDER_TYPE_TASKS:
-                       folder_element = "TasksFolder";
-                       break;
-               default:
-                       g_warn_if_reached ();
-                       folder_element = "Folder";
-                       break;
+       if (add_props != NULL) {
+               g_free (add_props->field_uri);
+               g_slist_free_full (add_props->extended_furis, (GDestroyNotify) e_ews_extended_field_uri_free);
+               g_slist_free_full (add_props->indexed_furis, (GDestroyNotify) e_ews_indexed_field_uri_free);
+               g_free (add_props);
        }
+}
 
-       node = e_soap_parameter_get_first_child_by_name (soapparam, "Folders");
-       node = e_soap_parameter_get_first_child_by_name (node, folder_element);
-       param = e_soap_parameter_get_first_child_by_name (node, "FolderId");
-
-       fid = g_new0 (EwsFolderId, 1);
-       fid->id = e_soap_parameter_get_property (param, "Id");
-       fid->change_key = e_soap_parameter_get_property (param, "ChangeKey");
-       fids = g_slist_append (fids, fid);
-
-       async_data->items_created = fids;
+static EwsNode *
+ews_node_new (void)
+{
+       return g_slice_new0 (EwsNode);
 }
 
 static void
-create_folder_response_cb (ESoapResponse *response,
-                           GSimpleAsyncResult *simple)
+autodiscover_parse_protocol (xmlNode *node,
+                             EwsUrls *urls)
 {
-       EwsAsyncData *async_data;
-       ESoapParameter *param;
-       ESoapParameter *subparam;
-       GError *error = NULL;
-
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
-
-       param = e_soap_response_get_first_parameter_by_name (
-               response, "ResponseMessages", &error);
-
-       /* Sanity check */
-       g_return_if_fail (
-               (param != NULL && error == NULL) ||
-               (param == NULL && error != NULL));
-
-       if (error != NULL) {
-               g_simple_async_result_take_error (simple, error);
-               return;
-       }
-
-       subparam = e_soap_parameter_get_first_child (param);
+       for (node = node->children; node; node = node->next) {
+               if (node->type == XML_ELEMENT_NODE &&
+                   !strcmp ((gchar *) node->name, "ASUrl")) {
+                       if (urls->as_url != NULL)
+                               xmlFree (urls->as_url);
 
-       while (subparam != NULL) {
-               const gchar *name = (const gchar *) subparam->name;
+                       urls->as_url = xmlNodeGetContent (node);
+               } else if (node->type == XML_ELEMENT_NODE &&
+                   !strcmp ((gchar *) node->name, "OABUrl")) {
+                       if (urls->oab_url != NULL)
+                               xmlFree (urls->oab_url);
 
-               if (!ews_get_response_status (subparam, &error)) {
-                       g_simple_async_result_take_error (simple, error);
-                       return;
+                       urls->oab_url = xmlNodeGetContent (node);
                }
 
-               if (E_EWS_CONNECTION_UTILS_CHECK_ELEMENT (name, "CreateFolderResponseMessage"))
-                       ews_handle_create_folders_param (subparam, async_data);
-
-               subparam = e_soap_parameter_get_next_child (subparam);
+               /* Once we find both, we can stop looking for the URLs */
+               if (urls->as_url && urls->oab_url)
+                       return;
        }
 }
 
-static gpointer
-e_ews_soup_thread (gpointer user_data)
+static xmlChar *
+autodiscover_get_protocol_type (xmlNode *node)
 {
-       EEwsConnection *cnc = user_data;
-
-       g_main_context_push_thread_default (cnc->priv->soup_context);
-       g_main_loop_run (cnc->priv->soup_loop);
-       g_main_context_pop_thread_default (cnc->priv->soup_context);
-
-       /* abort any pending operations */
-       soup_session_abort (cnc->priv->soup_session);
-
-       g_object_unref (cnc->priv->soup_session);
-       cnc->priv->soup_session = NULL;
+       for (node = node->children; node; node = node->next) {
+               if (node->type == XML_ELEMENT_NODE &&
+                   !strcmp ((gchar *) node->name, "Type")) {
+                       return xmlNodeGetContent (node);
+               }
+       }
 
        return NULL;
 }
 
-/*
- * e_ews_debug_handler:
- *
- * GLib debug message handler, which is passed all messages from g_debug() calls,
- * and decides whether to print them.
- */
-static void
-e_ews_debug_handler (const gchar *log_domain,
-                    GLogLevelFlags log_level,
-                    const gchar *message,
-                    gpointer user_data)
-{
-       if (e_ews_debug_get_log_level () >= 3)
-               g_log_default_handler (log_domain, log_level, message, NULL);
-}
-
-/*
- * e_ews_soup_log_print:
- *
- * Log printer for the libsoup logging functionality, which just marshal all soup log
- * output to the standard GLib logging framework (and thus to debug_handler(), above).
- */
-static void
-e_ews_soup_log_printer (SoupLogger *logger,
-                       SoupLoggerLogLevel level,
-                       char direction,
-                       const gchar *data,
-                       gpointer user_data)
+static gchar *
+autodiscover_dup_element_value (xmlNode *node,
+                               const gchar *element_name)
 {
-       const gchar *filtered_data = NULL;
+       for (node = node->children; node; node = node->next) {
+               if (node->type == XML_ELEMENT_NODE &&
+                   !g_strcmp0 ((gchar *) node->name, element_name)) {
+                       xmlChar *str = xmlNodeGetContent (node);
+                       gchar *res;
 
-       if (e_ews_debug_get_log_level () >= 3) {
-               if (direction == '>' && g_ascii_strncasecmp (data, "Host:", 5) == 0)
-                       filtered_data = "Host: <redacted>";
-               else if (direction == '>' && g_ascii_strncasecmp (data, "Authorization:", 14) == 0)
-                       filtered_data = "Authorization: <redacted>";
-               else if (direction == '<' && g_ascii_strncasecmp (data, "Set-Cookie:", 11) == 0)
-                       filtered_data = "Set-Cookie: <redacted>";
-               else
-                       filtered_data = data;
+                       res = g_strdup ((const gchar *) str);
+                       xmlFree (str);
+                       return res;
+               }
        }
 
-       g_debug ("%c %s", direction, filtered_data ? filtered_data : data);
+       return NULL;
 }
 
 static void
@@ -1939,63 +1079,6 @@ ews_connection_get_property (GObject *object,
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 }
 
-static void
-ews_connection_constructed (GObject *object)
-{
-       EEwsConnection *cnc = E_EWS_CONNECTION (object);
-       gint log_level;
-
-       /* Chain up to parent's method. */
-       G_OBJECT_CLASS (e_ews_connection_parent_class)->constructed (object);
-
-       cnc->priv->soup_thread = g_thread_new (NULL, e_ews_soup_thread, cnc);
-
-       cnc->priv->soup_session = soup_session_async_new_with_options (
-               SOUP_SESSION_TIMEOUT, 90,
-               SOUP_SESSION_SSL_STRICT, TRUE,
-               SOUP_SESSION_SSL_USE_SYSTEM_CA_FILE, TRUE,
-               SOUP_SESSION_ASYNC_CONTEXT, cnc->priv->soup_context,
-               SOUP_SESSION_MAX_CONNS, cnc->priv->concurrent_connections,
-               SOUP_SESSION_MAX_CONNS_PER_HOST, cnc->priv->concurrent_connections,
-               NULL);
-
-       /* Do not use G_BINDING_SYNC_CREATE because the property_lock is
-        * not initialized and we don't have a GProxyResolver yet anyway. */
-       e_binding_bind_property (
-               cnc, "proxy-resolver",
-               cnc->priv->soup_session, "proxy-resolver",
-               G_BINDING_DEFAULT);
-
-       cnc->priv->version = E_EWS_EXCHANGE_UNKNOWN;
-
-       log_level = e_ews_debug_get_log_level ();
-
-       if (log_level >= 2) {
-               SoupLogger *logger;
-               logger = soup_logger_new (SOUP_LOGGER_LOG_BODY);
-
-               if (log_level >= 3) {
-                       soup_logger_set_printer (logger, e_ews_soup_log_printer, NULL, NULL);
-                       g_log_set_handler (
-                               G_LOG_DOMAIN,
-                               G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING |
-                               G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO,
-                               e_ews_debug_handler, cnc);
-               }
-
-               soup_session_add_feature (
-                       cnc->priv->soup_session,
-                       SOUP_SESSION_FEATURE (logger));
-               g_object_unref (logger);
-       }
-
-       soup_session_add_feature_by_type (cnc->priv->soup_session,
-                                         SOUP_TYPE_COOKIE_JAR);
-
-       e_ews_connection_utils_prepare_auth_method (cnc->priv->soup_session,
-               camel_ews_settings_get_auth_mechanism (cnc->priv->settings));
-}
-
 static void
 ews_connection_dispose (GObject *object)
 {
@@ -2027,17 +1110,28 @@ ews_connection_dispose (GObject *object)
        }
        NOTIFICATION_UNLOCK (cnc);
 
-       if (cnc->priv->soup_session) {
-               g_main_loop_quit (cnc->priv->soup_loop);
-               g_thread_join (cnc->priv->soup_thread);
-               cnc->priv->soup_thread = NULL;
+       g_mutex_lock (&cnc->priv->soup.mutex);
+
+       if (cnc->priv->soup.main_loop) {
+               g_main_loop_quit (cnc->priv->soup.main_loop);
+
+               if (cnc->priv->soup.thread) {
+                       g_thread_join (cnc->priv->soup.thread);
+                       cnc->priv->soup.thread = NULL;
+               }
+
+               g_main_loop_unref (cnc->priv->soup.main_loop);
+               g_main_context_unref (cnc->priv->soup.main_context);
 
-               g_main_loop_unref (cnc->priv->soup_loop);
-               cnc->priv->soup_loop = NULL;
-               g_main_context_unref (cnc->priv->soup_context);
-               cnc->priv->soup_context = NULL;
+               cnc->priv->soup.main_loop = NULL;
+               cnc->priv->soup.main_context = NULL;
+
+               /* The soup thread creates and frees the session */
+               g_warn_if_fail (cnc->priv->soup.session == NULL);
        }
 
+       g_mutex_unlock (&cnc->priv->soup.mutex);
+
        g_clear_object (&cnc->priv->proxy_resolver);
        g_clear_object (&cnc->priv->source);
        g_clear_object (&cnc->priv->settings);
@@ -2081,6 +1175,9 @@ ews_connection_finalize (GObject *object)
        g_rec_mutex_clear (&cnc->priv->queue_lock);
        g_mutex_clear (&cnc->priv->notification_lock);
 
+       g_mutex_clear (&cnc->priv->soup.mutex);
+       g_cond_clear (&cnc->priv->soup.cond);
+
        /* Chain up to parent's finalize() method. */
        G_OBJECT_CLASS (e_ews_connection_parent_class)->finalize (object);
 }
@@ -2093,7 +1190,6 @@ e_ews_connection_class_init (EEwsConnectionClass *class)
        object_class = G_OBJECT_CLASS (class);
        object_class->set_property = ews_connection_set_property;
        object_class->get_property = ews_connection_get_property;
-       object_class->constructed = ews_connection_constructed;
        object_class->dispose = ews_connection_dispose;
        object_class->finalize = ews_connection_finalize;
 
@@ -2185,6 +1281,14 @@ e_ews_connection_class_init (EEwsConnectionClass *class)
                g_cclosure_marshal_VOID__STRING,
                G_TYPE_NONE, 1,
                G_TYPE_STRING);
+
+       if (e_ews_debug_get_log_level () >= 3) {
+               g_log_set_handler (
+                       G_LOG_DOMAIN,
+                       G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING |
+                       G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO,
+                       e_ews_debug_handler, NULL);
+       }
 }
 
 static void
@@ -2198,11 +1302,15 @@ e_ews_connection_init (EEwsConnection *cnc)
 {
        cnc->priv = e_ews_connection_get_instance_private (cnc);
 
-       cnc->priv->soup_context = g_main_context_new ();
-       cnc->priv->soup_loop = g_main_loop_new (cnc->priv->soup_context, FALSE);
+       g_mutex_init (&cnc->priv->soup.mutex);
+       g_cond_init (&cnc->priv->soup.cond);
+       cnc->priv->soup.main_context = g_main_context_new ();
+       cnc->priv->soup.main_loop = g_main_loop_new (cnc->priv->soup.main_context, FALSE);
+
        cnc->priv->backoff_enabled = TRUE;
        cnc->priv->disconnected_flag = FALSE;
        cnc->priv->concurrent_connections = 1;
+       cnc->priv->version = E_EWS_EXCHANGE_UNKNOWN;
 
        cnc->priv->subscriptions = g_hash_table_new_full (
                        g_direct_hash, g_direct_equal,
@@ -2729,7 +1837,7 @@ e_ews_connection_try_credentials_sync (EEwsConnection *cnc,
 
        if (local_error == NULL) {
                result = E_SOURCE_AUTHENTICATION_ACCEPTED;
-       } else if (g_error_matches (local_error, SOUP_HTTP_ERROR, SOUP_STATUS_SSL_FAILED) &&
+       } else if (g_error_matches (local_error, E_SOUP_SESSION_ERROR, SOUP_STATUS_SSL_FAILED) &&
                   e_ews_connection_get_ssl_error_details (cnc, out_certificate_pem, out_certificate_errors)) 
{
                result = E_SOURCE_AUTHENTICATION_ERROR_SSL_FAILED;
        } else {
@@ -2996,27 +2104,167 @@ e_ews_connection_dup_last_subscription_id (EEwsConnection *cnc)
 
        g_mutex_lock (&cnc->priv->property_lock);
 
-       res = g_strdup (cnc->priv->last_subscription_id);
+       res = g_strdup (cnc->priv->last_subscription_id);
+
+       g_mutex_unlock (&cnc->priv->property_lock);
+
+       return res;
+}
+
+void
+e_ews_connection_set_last_subscription_id (EEwsConnection *cnc,
+                                          const gchar *subscription_id)
+{
+       g_return_if_fail (E_IS_EWS_CONNECTION (cnc));
+
+       g_mutex_lock (&cnc->priv->property_lock);
+
+       if (g_strcmp0 (subscription_id, cnc->priv->last_subscription_id) != 0) {
+               g_free (cnc->priv->last_subscription_id);
+               cnc->priv->last_subscription_id = g_strdup (subscription_id);
+       }
+
+       g_mutex_unlock (&cnc->priv->property_lock);
+}
+
+static gboolean
+e_ews_process_generic_response (EEwsConnection *cnc,
+                               ESoapResponse *response,
+                               GError **error)
+{
+       ESoapParameter *param;
+       ESoapParameter *subparam;
+       GError *local_error = NULL;
+
+       param = e_soap_response_get_first_parameter_by_name (response, "ResponseMessages", &local_error);
+
+       /* Sanity check */
+       g_return_val_if_fail (
+               (param != NULL && local_error == NULL) ||
+               (param == NULL && local_error != NULL), FALSE);
+
+       if (local_error) {
+               g_propagate_error (error, local_error);
+               return FALSE;
+       }
+
+       subparam = e_soap_parameter_get_first_child (param);
+
+       while (subparam != NULL) {
+               if (!ews_get_response_status (subparam, error))
+                       return FALSE;
+
+               subparam = e_soap_parameter_get_next_child (subparam);
+       }
+
+       return TRUE;
+}
+
+typedef gpointer (*ItemParser) (ESoapParameter *param);
+
+static void
+e_ews_process_sync_xxx_response (ESoapParameter *subparam,
+                                ItemParser parser,
+                                const gchar *last_tag,
+                                const gchar *delete_id_tag,
+                                gchar **out_new_sync_state,
+                                gboolean *out_includes_last_item,
+                                GSList **out_items_created,
+                                GSList **out_items_updated,
+                                GSList **out_items_deleted)
+{
+       ESoapParameter *node;
+       gchar *new_sync_state = NULL, *value, *last;
+       GSList *items_created = NULL, *items_updated = NULL, *items_deleted = NULL;
+       gboolean includes_last_item;
+
+       node = e_soap_parameter_get_first_child_by_name (subparam, "SyncState");
+       new_sync_state = e_soap_parameter_get_string_value (node);
+
+       node = e_soap_parameter_get_first_child_by_name (subparam, last_tag);
+       last = e_soap_parameter_get_string_value (node);
+       /*
+        * Set the includes_last_item to TRUE as default.
+        * It can avoid an infinite loop in caller, when, for some reason,
+        * we don't receive the last_tag property from the server.
+        */
+       includes_last_item = g_strcmp0 (last, "false") != 0;
+       g_free (last);
+
+       node = e_soap_parameter_get_first_child_by_name (subparam, "Changes");
+
+       if (node) {
+               ESoapParameter *subparam1;
+               for (subparam1 = e_soap_parameter_get_first_child_by_name (node, "Create");
+                    subparam1 != NULL;
+                    subparam1 = e_soap_parameter_get_next_child_by_name (subparam1, "Create")) {
+                       GObject *object;
+
+                       object = parser (subparam1);
+                       if (object && (!E_IS_EWS_FOLDER (object) || !e_ews_folder_get_is_hidden (E_EWS_FOLDER 
(object))))
+                               items_created = g_slist_prepend (items_created, object);
+                       else
+                               g_clear_object (&object);
+               }
+
+               for (subparam1 = e_soap_parameter_get_first_child_by_name (node, "Update");
+                    subparam1 != NULL;
+                    subparam1 = e_soap_parameter_get_next_child_by_name (subparam1, "Update")) {
+                       GObject *object;
+
+                       object = parser (subparam1);
+                       if (object && (!E_IS_EWS_FOLDER (object) || !e_ews_folder_get_is_hidden (E_EWS_FOLDER 
(object))))
+                               items_updated = g_slist_prepend (items_updated, object);
+                       else
+                               g_clear_object (&object);
+               }
+                 /* Exchange 2007SP1 introduced <ReadFlagChange> which is basically identical
+                  * to <Update>; no idea why they thought it was a good idea. */
+               for (subparam1 = e_soap_parameter_get_first_child_by_name (node, "ReadFlagChange");
+                    subparam1 != NULL;
+                    subparam1 = e_soap_parameter_get_next_child_by_name (subparam1, "ReadFlagChange")) {
+                       GObject *object;
+
+                       object = parser (subparam1);
+                       if (object && (!E_IS_EWS_FOLDER (object) || !e_ews_folder_get_is_hidden (E_EWS_FOLDER 
(object))))
+                               items_updated = g_slist_prepend (items_updated, object);
+                       else
+                               g_clear_object (&object);
+               }
+
+               for (subparam1 = e_soap_parameter_get_first_child_by_name (node, "Delete");
+                    subparam1 != NULL;
+                    subparam1 = e_soap_parameter_get_next_child_by_name (subparam1, "Delete")) {
+                       ESoapParameter *folder_param;
 
-       g_mutex_unlock (&cnc->priv->property_lock);
+                       folder_param = e_soap_parameter_get_first_child_by_name (subparam1, delete_id_tag);
+                       value = e_soap_parameter_get_property (folder_param, "Id");
+                       items_deleted = g_slist_prepend (items_deleted, value);
+               }
+       }
 
-       return res;
-}
+       if (out_new_sync_state)
+               *out_new_sync_state = new_sync_state;
+       else
+               g_free (new_sync_state);
 
-void
-e_ews_connection_set_last_subscription_id (EEwsConnection *cnc,
-                                          const gchar *subscription_id)
-{
-       g_return_if_fail (E_IS_EWS_CONNECTION (cnc));
+       if (out_includes_last_item)
+               *out_includes_last_item = includes_last_item;
 
-       g_mutex_lock (&cnc->priv->property_lock);
+       if (out_items_created)
+               *out_items_created = g_slist_reverse (items_created);
+       else
+               g_slist_free_full (items_created, g_object_unref);
 
-       if (g_strcmp0 (subscription_id, cnc->priv->last_subscription_id) != 0) {
-               g_free (cnc->priv->last_subscription_id);
-               cnc->priv->last_subscription_id = g_strdup (subscription_id);
-       }
+       if (out_items_updated)
+               *out_items_updated = g_slist_reverse (items_updated);
+       else
+               g_slist_free_full (items_updated, g_object_unref);
 
-       g_mutex_unlock (&cnc->priv->property_lock);
+       if (out_items_deleted)
+               *out_items_deleted = g_slist_reverse (items_deleted);
+       else
+               g_slist_free_full (items_deleted, g_free);
 }
 
 static xmlDoc *
@@ -3160,7 +2408,7 @@ autodiscover_response_cb (SoupSession *session,
                        e_ews_connection_utils_expired_password_to_error (service_url, &error);
                } else {
                        g_set_error (
-                               &error, SOUP_HTTP_ERROR, status,
+                               &error, E_SOUP_SESSION_ERROR, status,
                                "%d %s", status, msg->reason_phrase);
 
                        if (status == SOUP_STATUS_SSL_FAILED)
@@ -3296,17 +2544,17 @@ autodiscover_response_cb (SoupSession *session,
        for (idx = 0; idx < 6; idx++) {
                if (ad->msgs[idx]) {
                        /* Preserve any Unauthorized/SSL failed errors */
-                       if (!g_error_matches (error, SOUP_HTTP_ERROR, SOUP_STATUS_NONE) &&
-                           !g_error_matches (ad->error, SOUP_HTTP_ERROR, SOUP_STATUS_UNAUTHORIZED) &&
-                           !g_error_matches (ad->error, SOUP_HTTP_ERROR, SOUP_STATUS_SSL_FAILED) &&
+                       if (!g_error_matches (error, E_SOUP_SESSION_ERROR, SOUP_STATUS_NONE) &&
+                           !g_error_matches (ad->error, E_SOUP_SESSION_ERROR, SOUP_STATUS_UNAUTHORIZED) &&
+                           !g_error_matches (ad->error, E_SOUP_SESSION_ERROR, SOUP_STATUS_SSL_FAILED) &&
                            (!ad->error ||
-                           g_error_matches (error, SOUP_HTTP_ERROR, SOUP_STATUS_UNAUTHORIZED) ||
-                           g_error_matches (error, SOUP_HTTP_ERROR, SOUP_STATUS_SSL_FAILED) ||
-                           g_error_matches (ad->error, SOUP_HTTP_ERROR, SOUP_STATUS_NONE) ||
-                           g_error_matches (ad->error, SOUP_HTTP_ERROR, SOUP_STATUS_CANT_RESOLVE) ||
-                           g_error_matches (ad->error, SOUP_HTTP_ERROR, SOUP_STATUS_CANT_RESOLVE_PROXY) ||
-                           g_error_matches (ad->error, SOUP_HTTP_ERROR, SOUP_STATUS_CANT_CONNECT) ||
-                           g_error_matches (ad->error, SOUP_HTTP_ERROR, SOUP_STATUS_CANT_CONNECT_PROXY))) {
+                           g_error_matches (error, E_SOUP_SESSION_ERROR, SOUP_STATUS_UNAUTHORIZED) ||
+                           g_error_matches (error, E_SOUP_SESSION_ERROR, SOUP_STATUS_SSL_FAILED) ||
+                           g_error_matches (ad->error, E_SOUP_SESSION_ERROR, SOUP_STATUS_NONE) ||
+                           g_error_matches (ad->error, E_SOUP_SESSION_ERROR, SOUP_STATUS_CANT_RESOLVE) ||
+                           g_error_matches (ad->error, E_SOUP_SESSION_ERROR, SOUP_STATUS_CANT_RESOLVE_PROXY) 
||
+                           g_error_matches (ad->error, E_SOUP_SESSION_ERROR, SOUP_STATUS_CANT_CONNECT) ||
+                           g_error_matches (ad->error, E_SOUP_SESSION_ERROR, 
SOUP_STATUS_CANT_CONNECT_PROXY))) {
                                g_clear_error (&ad->error);
                                ad->error = error;
                                error = NULL;
@@ -3321,17 +2569,17 @@ autodiscover_response_cb (SoupSession *session,
        }
 
        /* Preserve any Unauthorized/SSL failed errors */
-       if (!g_error_matches (error, SOUP_HTTP_ERROR, SOUP_STATUS_NONE) &&
-           !g_error_matches (ad->error, SOUP_HTTP_ERROR, SOUP_STATUS_UNAUTHORIZED) &&
-           !g_error_matches (ad->error, SOUP_HTTP_ERROR, SOUP_STATUS_SSL_FAILED) &&
+       if (!g_error_matches (error, E_SOUP_SESSION_ERROR, SOUP_STATUS_NONE) &&
+           !g_error_matches (ad->error, E_SOUP_SESSION_ERROR, SOUP_STATUS_UNAUTHORIZED) &&
+           !g_error_matches (ad->error, E_SOUP_SESSION_ERROR, SOUP_STATUS_SSL_FAILED) &&
            (!ad->error ||
-           g_error_matches (error, SOUP_HTTP_ERROR, SOUP_STATUS_UNAUTHORIZED) ||
-           g_error_matches (error, SOUP_HTTP_ERROR, SOUP_STATUS_SSL_FAILED) ||
-           g_error_matches (ad->error, SOUP_HTTP_ERROR, SOUP_STATUS_NONE) ||
-           g_error_matches (ad->error, SOUP_HTTP_ERROR, SOUP_STATUS_CANT_RESOLVE) ||
-           g_error_matches (ad->error, SOUP_HTTP_ERROR, SOUP_STATUS_CANT_RESOLVE_PROXY) ||
-           g_error_matches (ad->error, SOUP_HTTP_ERROR, SOUP_STATUS_CANT_CONNECT) ||
-           g_error_matches (ad->error, SOUP_HTTP_ERROR, SOUP_STATUS_CANT_CONNECT_PROXY))) {
+           g_error_matches (error, E_SOUP_SESSION_ERROR, SOUP_STATUS_UNAUTHORIZED) ||
+           g_error_matches (error, E_SOUP_SESSION_ERROR, SOUP_STATUS_SSL_FAILED) ||
+           g_error_matches (ad->error, E_SOUP_SESSION_ERROR, SOUP_STATUS_NONE) ||
+           g_error_matches (ad->error, E_SOUP_SESSION_ERROR, SOUP_STATUS_CANT_RESOLVE) ||
+           g_error_matches (ad->error, E_SOUP_SESSION_ERROR, SOUP_STATUS_CANT_RESOLVE_PROXY) ||
+           g_error_matches (ad->error, E_SOUP_SESSION_ERROR, SOUP_STATUS_CANT_CONNECT) ||
+           g_error_matches (ad->error, E_SOUP_SESSION_ERROR, SOUP_STATUS_CANT_CONNECT_PROXY))) {
                g_clear_error (&ad->error);
                ad->error = error;
                error = NULL;
@@ -3342,8 +2590,8 @@ autodiscover_response_cb (SoupSession *session,
        if (!g_cancellable_is_cancelled (ad->cancellable) &&
            (!ad->as_url || !ad->oab_url) && ad->n_redirects < 11 &&
            (ad->redirect_url || ad->redirect_addr) &&
-           !g_error_matches (ad->error, SOUP_HTTP_ERROR, SOUP_STATUS_UNAUTHORIZED) &&
-           !g_error_matches (ad->error, SOUP_HTTP_ERROR, SOUP_STATUS_SSL_FAILED)) {
+           !g_error_matches (ad->error, E_SOUP_SESSION_ERROR, SOUP_STATUS_UNAUTHORIZED) &&
+           !g_error_matches (ad->error, E_SOUP_SESSION_ERROR, SOUP_STATUS_SSL_FAILED)) {
                CamelEwsSettings *settings = NULL;
                gboolean re_scheduled;
                const gchar *host_url;
@@ -3548,8 +2796,8 @@ e_ews_autodiscover_ws_url_sync (ESource *source,
                                 GCancellable *cancellable,
                                 GError **error)
 {
-       EAsyncClosure *closure;
-       GAsyncResult *result;
+       ESoapRequest *request;
+       ESoapResponse *response;
        gboolean success;
 
        g_return_val_if_fail (CAMEL_IS_EWS_SETTINGS (settings), FALSE);
@@ -3565,7 +2813,17 @@ e_ews_autodiscover_ws_url_sync (ESource *source,
 
        success = e_ews_autodiscover_ws_url_finish (settings, result, out_certificate_pem, 
out_certificate_errors, error);
 
-       e_async_closure_free (closure);
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
+
+       if (!response) {
+               g_clear_object (&request);
+               return FALSE;
+       }
+
+       success = e_ews_process__response (cnc, response, , error);
+
+       g_clear_object (&request);
+       g_clear_object (&response);
 
        return success;
 }
@@ -3775,7 +3033,7 @@ e_ews_autodiscover_ws_url (ESource *source,
        host_url = camel_ews_settings_get_hosturl (settings);
 
        if (!e_ews_discover_prepare_messages_and_send (simple, email_address, host_url, &error)) {
-               g_simple_async_result_take_error (simple, error);
+               g_propagate_error (error, local_error);
                g_simple_async_result_complete_in_idle (simple);
        } else {
                g_clear_error (&error);
@@ -3830,7 +3088,7 @@ e_ews_autodiscover_ws_url_finish (CamelEwsSettings *settings,
        ad = g_simple_async_result_get_op_res_gpointer (simple);
 
        if (g_simple_async_result_propagate_error (simple, &local_error)) {
-               if (g_error_matches (local_error, SOUP_HTTP_ERROR, SOUP_STATUS_SSL_FAILED)) {
+               if (g_error_matches (local_error, E_SOUP_SESSION_ERROR, SOUP_STATUS_SSL_FAILED)) {
                        if (!e_ews_connection_get_ssl_error_details (ad->cnc, out_certificate_pem, 
out_certificate_errors)) {
                                if (out_certificate_pem)
                                        *out_certificate_pem = NULL;
@@ -4028,7 +3286,7 @@ oal_response_cb (SoupSession *soup_session,
                        }
                }
                g_simple_async_result_set_error (
-                       simple, SOUP_HTTP_ERROR,
+                       simple, E_SOUP_SESSION_ERROR,
                        soup_message->status_code,
                        "%d %s",
                        soup_message->status_code,
@@ -4111,8 +3369,8 @@ e_ews_connection_get_oal_list_sync (EEwsConnection *cnc,
                                     GCancellable *cancellable,
                                     GError **error)
 {
-       EAsyncClosure *closure;
-       GAsyncResult *result;
+       ESoapRequest *request;
+       ESoapResponse *response;
        gboolean success;
 
        g_return_val_if_fail (E_IS_EWS_CONNECTION (cnc), FALSE);
@@ -4127,7 +3385,17 @@ e_ews_connection_get_oal_list_sync (EEwsConnection *cnc,
        success = e_ews_connection_get_oal_list_finish (
                cnc, result, oals, error);
 
-       e_async_closure_free (closure);
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
+
+       if (!response) {
+               g_clear_object (&request);
+               return FALSE;
+       }
+
+       success = e_ews_process__response (cnc, response, , error);
+
+       g_clear_object (&request);
+       g_clear_object (&response);
 
        return success;
 }
@@ -4152,7 +3420,7 @@ e_ews_connection_get_oal_list (EEwsConnection *cnc,
                e_ews_connection_get_oal_list);
 
        if (!soup_message) {
-               g_simple_async_result_take_error (simple, error);
+               g_propagate_error (error, local_error);
                g_simple_async_result_complete_in_idle (simple);
                return;
        }
@@ -4205,30 +3473,18 @@ e_ews_connection_get_oal_list_finish (EEwsConnection *cnc,
        return TRUE;
 }
 
-/**
- * e_ews_connection_get_oal_detail 
- * @cnc: 
- * @oal_id: 
- * @oal_element: 
- * @elements: "Full" "Diff" "Template" are the possible values.
- * @cancellable: 
- * @error: 
- * 
- * 
- * Returns: 
- **/
 gboolean
 e_ews_connection_get_oal_detail_sync (EEwsConnection *cnc,
                                       const gchar *oal_id,
                                       const gchar *oal_element,
                                      const gchar *old_etag,
-                                      GSList **elements,
-                                     gchar **etag,
+                                      GSList **out_elements,
+                                     gchar **out_etag,
                                       GCancellable *cancellable,
                                       GError **error)
 {
-       EAsyncClosure *closure;
-       GAsyncResult *result;
+       ESoapRequest *request;
+       ESoapResponse *response;
        gboolean success;
 
        g_return_val_if_fail (E_IS_EWS_CONNECTION (cnc), FALSE);
@@ -4244,7 +3500,17 @@ e_ews_connection_get_oal_detail_sync (EEwsConnection *cnc,
        success = e_ews_connection_get_oal_detail_finish (
                cnc, result, elements, etag, error);
 
-       e_async_closure_free (closure);
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
+
+       if (!response) {
+               g_clear_object (&request);
+               return FALSE;
+       }
+
+       success = e_ews_process__response (cnc, response, , error);
+
+       g_clear_object (&request);
+       g_clear_object (&response);
 
        return success;
 }
@@ -4273,14 +3539,14 @@ e_ews_connection_get_oal_detail (EEwsConnection *cnc,
                e_ews_connection_get_oal_detail);
 
        if (!soup_message) {
-               g_simple_async_result_take_error (simple, error);
+               g_propagate_error (error, local_error);
                g_simple_async_result_complete_in_idle (simple);
                return;
        }
 
        if (etag && *etag)
-               soup_message_headers_append (soup_message_get_request_headers (soup_message),
-                                            "If-None-Match", etag);
+               soup_message_headers_replace (soup_message_get_request_headers (soup_message),
+                                             "If-None-Match", etag);
 
        data = g_slice_new0 (struct _oal_req_data);
        data->cnc = g_object_ref (cnc);
@@ -4359,7 +3625,7 @@ oal_download_response_cb (SoupSession *soup_session,
                g_unlink (data->cache_filename);
        } else if (soup_message->status_code != SOUP_STATUS_OK) {
                g_simple_async_result_set_error (
-                       simple, SOUP_HTTP_ERROR,
+                       simple, E_SOUP_SESSION_ERROR,
                        soup_message->status_code,
                        "%d %s",
                        soup_message->status_code,
@@ -4440,8 +3706,8 @@ e_ews_connection_download_oal_file_sync (EEwsConnection *cnc,
                                          GCancellable *cancellable,
                                          GError **error)
 {
-       EAsyncClosure *closure;
-       GAsyncResult *result;
+       ESoapRequest *request;
+       ESoapResponse *response;
        gboolean success;
 
        g_return_val_if_fail (E_IS_EWS_CONNECTION (cnc), FALSE);
@@ -4458,7 +3724,17 @@ e_ews_connection_download_oal_file_sync (EEwsConnection *cnc,
        success = e_ews_connection_download_oal_file_finish (
                cnc, result, error);
 
-       e_async_closure_free (closure);
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
+
+       if (!response) {
+               g_clear_object (&request);
+               return FALSE;
+       }
+
+       success = e_ews_process__response (cnc, response, , error);
+
+       g_clear_object (&request);
+       g_clear_object (&response);
 
        return success;
 }
@@ -4486,7 +3762,7 @@ e_ews_connection_download_oal_file (EEwsConnection *cnc,
                e_ews_connection_download_oal_file);
 
        if (!soup_message) {
-               g_simple_async_result_take_error (simple, error);
+               g_propagate_error (error, local_error);
                g_simple_async_result_complete_in_idle (simple);
                return;
        }
@@ -4673,36 +3949,74 @@ ews_write_sort_order_to_msg (ESoapRequest *request,
        e_soap_request_end_element (request);
 }
 
-/**
- * e_ews_connection_sync_folder_items:
- * @cnc: The EWS Connection
- * @pri: The priority associated with the request
- * @last_sync_state: To sync with the previous requests
- * @folder_id: The folder to which the items belong
- * @default_props: Can take one of the values: IdOnly,Default or AllProperties
- * @additional_props: Specify any additional properties to be fetched
- * @max_entries: Maximum number of items to be returned
- * @cancellable: a GCancellable to monitor cancelled operations
- * @callback: Responses are parsed and returned to this callback
- * @user_data: user data passed to callback
- **/
-void
-e_ews_connection_sync_folder_items (EEwsConnection *cnc,
-                                    gint pri,
-                                    const gchar *last_sync_state,
-                                    const gchar *fid,
-                                    const gchar *default_props,
-                                   const EEwsAdditionalProps *add_props,
-                                    guint max_entries,
-                                    GCancellable *cancellable,
-                                    GAsyncReadyCallback callback,
-                                    gpointer user_data)
+static gboolean
+e_ews_process_sync_folder_items_response (EEwsConnection *cnc,
+                                         ESoapResponse *response,
+                                         gchar **out_new_sync_state,
+                                         gboolean *out_includes_last_item,
+                                         GSList **out_items_created,
+                                         GSList **out_items_updated,
+                                         GSList **out_items_deleted,
+                                         GError **error)
+{
+       ESoapParameter *param;
+       ESoapParameter *subparam;
+       GError *local_error = NULL;
+
+       param = e_soap_response_get_first_parameter_by_name (response, "ResponseMessages", &lcoal_error);
+
+       /* Sanity check */
+       g_return_val_if_fail (
+               (param != NULL && local_error == NULL) ||
+               (param == NULL && local_error != NULL), FALSE);
+
+       if (local_error) {
+               g_propagate_error (error, local_error);
+               return FALSE;
+       }
+
+       subparam = e_soap_parameter_get_first_child (param);
+
+       while (subparam != NULL) {
+               const gchar *name = (const gchar *) subparam->name;
+
+               if (!ews_get_response_status (subparam, error))
+                       return FALSE;
+
+               if (E_EWS_CONNECTION_UTILS_CHECK_ELEMENT (name, "SyncFolderItemsResponseMessage")) {
+                       e_ews_process_sync_xxx_response (
+                               subparam,  (ItemParser) e_ews_item_new_from_soap_parameter,
+                               "IncludesLastItemInRange", "ItemId",
+                               out_new_sync_state, out_includes_last_item, out_items_created, 
out_items_updated, out_items_deleted);
+               }
+
+               subparam = e_soap_parameter_get_next_child (subparam);
+       }
+
+       return TRUE;
+}
+
+gboolean
+e_ews_connection_sync_folder_items_sync (EEwsConnection *cnc,
+                                         gint pri,
+                                         const gchar *old_sync_state,
+                                         const gchar *fid,
+                                         const gchar *default_props,
+                                        const EEwsAdditionalProps *add_props,
+                                         guint max_entries,
+                                         gchar **out_new_sync_state,
+                                         gboolean *out_includes_last_item,
+                                         GSList **out_items_created,
+                                         GSList **out_items_updated,
+                                         GSList **out_items_deleted,
+                                         GCancellable *cancellable,
+                                         GError **error)
 {
        ESoapRequest *request;
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
+       ESoapResponse *response;
+       gboolean success;
 
-       g_return_if_fail (cnc != NULL);
+       g_return_val_if_fail (cnc != NULL, FALSE);
 
        request = e_ews_request_new_with_header (
                cnc->priv->uri,
@@ -4733,91 +4047,19 @@ e_ews_connection_sync_folder_items (EEwsConnection *cnc,
        /* Complete the footer and print the request */
        e_ews_request_write_footer (request);
 
-       simple = g_simple_async_result_new (
-               G_OBJECT (cnc), callback, user_data,
-               e_ews_connection_sync_folder_items);
-
-       async_data = g_slice_new0 (EwsAsyncData);
-       g_simple_async_result_set_op_res_gpointer (
-               simple, async_data, (GDestroyNotify) async_data_free);
-
-       e_ews_connection_queue_request (
-               cnc, request, sync_folder_items_response_cb,
-               pri, cancellable, simple);
-
-       g_object_unref (simple);
-}
-
-gboolean
-e_ews_connection_sync_folder_items_finish (EEwsConnection *cnc,
-                                           GAsyncResult *result,
-                                           gchar **new_sync_state,
-                                           gboolean *includes_last_item,
-                                           GSList **items_created,
-                                           GSList **items_updated,
-                                           GSList **items_deleted,
-                                           GError **error)
-{
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (
-               result, G_OBJECT (cnc), e_ews_connection_sync_folder_items),
-               FALSE);
-
-       simple = G_SIMPLE_ASYNC_RESULT (result);
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
 
-       if (g_simple_async_result_propagate_error (simple, error))
+       if (!response) {
+               g_clear_object (&request);
                return FALSE;
+       }
 
-       *new_sync_state = async_data->sync_state;
-       *includes_last_item = async_data->includes_last_item;
-       *items_created = async_data->items_created;
-       *items_updated = async_data->items_updated;
-       *items_deleted = async_data->items_deleted;
-
-       return TRUE;
-}
-
-gboolean
-e_ews_connection_sync_folder_items_sync (EEwsConnection *cnc,
-                                         gint pri,
-                                         const gchar *old_sync_state,
-                                         const gchar *fid,
-                                         const gchar *default_props,
-                                        const EEwsAdditionalProps *add_props,
-                                         guint max_entries,
-                                         gchar **new_sync_state,
-                                         gboolean *includes_last_item,
-                                         GSList **items_created,
-                                         GSList **items_updated,
-                                         GSList **items_deleted,
-                                         GCancellable *cancellable,
-                                         GError **error)
-{
-       EAsyncClosure *closure;
-       GAsyncResult *result;
-       gboolean success;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-
-       closure = e_async_closure_new ();
-
-       e_ews_connection_sync_folder_items (
-               cnc, pri, old_sync_state, fid, default_props,
-               add_props, max_entries, cancellable,
-               e_async_closure_callback, closure);
-
-       result = e_async_closure_wait (closure);
-
-       success = e_ews_connection_sync_folder_items_finish (
-               cnc, result, new_sync_state, includes_last_item,
-               items_created, items_updated, items_deleted, error);
+       success = e_ews_process_sync_folder_items_response (cnc, response,
+               out_new_sync_state, out_includes_last_item, out_items_created,
+               out_items_updated, out_items_deleted, error);
 
-       e_async_closure_free (closure);
+       g_clear_object (&request);
+       g_clear_object (&response);
 
        return success;
 }
@@ -4857,42 +4099,95 @@ ews_connection_write_only_ids_restriction (ESoapRequest *request,
        }
 }
 
-/**
- * e_ews_connection_find_folder_items:
- * @cnc: The EWS Connection
- * @pri: The priority associated with the request
- * @fid: The folder id to which the items belong
- * @default_props: Can take one of the values: IdOnly,Default or AllProperties
- * @add_props: Specify any additional properties to be fetched
- * @sort_order: Specific sorting order for items
- * @query: evo query based on which items will be fetched
- * @only_ids: (element-type utf8) (nullable): a gchar * with item IDs, to check with only; can be %NULL
- * @type: type of folder
- * @convert_query_cb: a callback method to convert query to ews restiction
- * @cancellable: a GCancellable to monitor cancelled operations
- * @callback: Responses are parsed and returned to this callback
- * @user_data: user data passed to callback
- **/
-void
-e_ews_connection_find_folder_items (EEwsConnection *cnc,
-                                    gint pri,
-                                    EwsFolderId *fid,
-                                    const gchar *default_props,
-                                    const EEwsAdditionalProps *add_props,
-                                    EwsSortOrder *sort_order,
-                                    const gchar *query,
-                                   GPtrArray *only_ids, /* element-type utf8 */
-                                    EEwsFolderType type,
-                                    EwsConvertQueryCallback convert_query_cb,
-                                    GCancellable *cancellable,
-                                    GAsyncReadyCallback callback,
-                                    gpointer user_data)
+static gboolean
+e_ews_process_find_folder_items_response (EEwsConnection *cnc,
+                                         ESoapResponse *response,
+                                         gboolean *out_includes_last_item,
+                                         GSList **out_items,
+                                         GError **error)
+{
+       ESoapParameter *param;
+       ESoapParameter *subparam;
+       GError *local_error = NULL;
+
+       param = e_soap_response_get_first_parameter_by_name (response, "ResponseMessages", &local_error);
+
+       /* Sanity check */
+       g_return_val_if_fail (
+               (param != NULL && local_error == NULL) ||
+               (param == NULL && local_error != NULL), FALSE);
+
+       if (local_error != NULL) {
+               g_propagate_error (error, local_error);
+               return FALSE;
+       }
+
+       subparam = e_soap_parameter_get_first_child (param);
+
+       while (subparam != NULL) {
+               const gchar *name = (const gchar *) subparam->name;
+
+               if (!ews_get_response_status (subparam, error))
+                       return FALSE;
+
+               if (E_EWS_CONNECTION_UTILS_CHECK_ELEMENT (name, "FindItemResponseMessage")) {
+                       ESoapParameter *node, *subparam1;
+                       gchar *last, *total;
+                       EEwsItem *item;
+                       gboolean includes_last_item;
+
+                       node = e_soap_parameter_get_first_child_by_name (subparam, "RootFolder");
+                       last = e_soap_parameter_get_property (node, "IncludesLastItemInRange");
+                       /*
+                        * Set the includes_last_item to TRUE as default.
+                        * It can avoid an infinite loop in caller, when, for some reason,
+                        * we don't receive the last_tag property from the server.
+                        */
+                       includes_last_item = g_strcmp0 (last, "false") != 0;
+                       g_free (last);
+
+                       node = e_soap_parameter_get_first_child_by_name (node, "Items");
+                       for (subparam1 = e_soap_parameter_get_first_child (node);
+                            subparam1; subparam1 = e_soap_parameter_get_next_child (subparam1)) {
+                               item = e_ews_item_new_from_soap_parameter (subparam1);
+                               if (item)
+                                       *out_items = g_slist_prepend (*out_items, item);
+                       }
+
+                       if (out_includes_last_item)
+                               *out_includes_last_item = includes_last_item;
+               }
+
+               subparam = e_soap_parameter_get_next_child (subparam);
+       }
+
+       return TRUE;
+}
+
+gboolean
+e_ews_connection_find_folder_items_sync (EEwsConnection *cnc,
+                                         gint pri,
+                                         EwsFolderId *fid,
+                                         const gchar *default_props,
+                                         const EEwsAdditionalProps *add_props,
+                                         EwsSortOrder *sort_order,
+                                         const gchar *query,
+                                        GPtrArray *only_ids, /* element-type utf8 */
+                                         EEwsFolderType type,
+                                         gboolean *out_includes_last_item,
+                                         GSList **out_items,
+                                         EwsConvertQueryCallback convert_query_cb,
+                                         GCancellable *cancellable,
+                                         GError **error)
 {
        ESoapRequest *request;
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
+       ESoapResponse *response;
+       gboolean success;
 
-       g_return_if_fail (cnc != NULL);
+       g_return_val_if_fail (cnc != NULL, FALSE);
+       g_return_val_if_fail (out_items != NULL, FALSE);
+
+       *out_items = NULL;
 
        request = e_ews_request_new_with_header (
                cnc->priv->uri,
@@ -4948,100 +4243,89 @@ e_ews_connection_find_folder_items (EEwsConnection *cnc,
        /* Complete the footer and print the request */
        e_ews_request_write_footer (request);
 
-       simple = g_simple_async_result_new (
-               G_OBJECT (cnc), callback, user_data,
-               e_ews_connection_find_folder_items);
-
-       async_data = g_slice_new0 (EwsAsyncData);
-       g_simple_async_result_set_op_res_gpointer (
-               simple, async_data, (GDestroyNotify) async_data_free);
-
-       e_ews_connection_queue_request (
-               cnc, request, find_folder_items_response_cb,
-               pri, cancellable, simple);
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
 
-       g_object_unref (simple);
-}
+       if (!response) {
+               g_clear_object (&request);
+               return FALSE;
+       }
 
-gboolean
-e_ews_connection_find_folder_items_finish (EEwsConnection *cnc,
-                                           GAsyncResult *result,
-                                           gboolean *includes_last_item,
-                                           GSList **items,
-                                           GError **error)
-{
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
+       success = e_ews_process_find_folder_items_response (cnc, response, out_includes_last_item, out_items, 
error);
 
-       g_return_val_if_fail (cnc != NULL, FALSE);
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (
-               result, G_OBJECT (cnc), e_ews_connection_find_folder_items),
-               FALSE);
+       g_clear_object (&request);
+       g_clear_object (&response);
 
-       simple = G_SIMPLE_ASYNC_RESULT (result);
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
+       if (success) {
+               *out_items = g_slist_reverse (*out_items);
+       } else {
+               g_slist_free_full (*out_items, g_object_unref);
+               *out_items = NULL;
+       }
 
-       if (g_simple_async_result_propagate_error (simple, error))
-               return FALSE;
+       return success;
+}
 
-       *includes_last_item = async_data->includes_last_item;
-       *items = async_data->items;
+static gboolean
+e_ews_process_sync_hierarchy_response (EEwsConnection *cnc,
+                                      ESoapResponse *response,
+                                      gchar **out_new_sync_state,
+                                      gboolean *out_includes_last_item,
+                                      GSList **out_items_created,
+                                      GSList **out_items_updated,
+                                      GSList **out_items_deleted,
+                                      GError **error)
+{
+       ESoapParameter *param;
+       ESoapParameter *subparam;
+       GError *local_error = NULL;
 
-       return TRUE;
-}
+       param = e_soap_response_get_first_parameter_by_name (response, "ResponseMessages", &local_error);
 
-gboolean
-e_ews_connection_find_folder_items_sync (EEwsConnection *cnc,
-                                         gint pri,
-                                         EwsFolderId *fid,
-                                         const gchar *default_props,
-                                         const EEwsAdditionalProps *add_props,
-                                         EwsSortOrder *sort_order,
-                                         const gchar *query,
-                                        GPtrArray *only_ids, /* element-type utf8 */
-                                         EEwsFolderType type,
-                                         gboolean *includes_last_item,
-                                         GSList **items,
-                                         EwsConvertQueryCallback convert_query_cb,
-                                         GCancellable *cancellable,
-                                         GError **error)
-{
-       EAsyncClosure *closure;
-       GAsyncResult *result;
-       gboolean success;
+       /* Sanity check */
+       g_return_val_if_fail (
+               (param != NULL && local_error == NULL) ||
+               (param == NULL && lcoal_error != NULL), FALSE);
 
-       g_return_val_if_fail (cnc != NULL, FALSE);
+       if (local_error != NULL) {
+               g_propagate_error (error, local_error);
+               return FALSE;
+       }
 
-       closure = e_async_closure_new ();
+       subparam = e_soap_parameter_get_first_child (param);
 
-       e_ews_connection_find_folder_items (
-               cnc, pri, fid, default_props,
-               add_props, sort_order, query,
-               only_ids, type, convert_query_cb, NULL,
-               e_async_closure_callback, closure);
+       while (subparam != NULL) {
+               const gchar *name = (const gchar *) subparam->name;
 
-       result = e_async_closure_wait (closure);
+               if (!ews_get_response_status (subparam, error))
+                       return FALSE;
 
-       success = e_ews_connection_find_folder_items_finish (
-               cnc, result, includes_last_item, items, error);
+               if (E_EWS_CONNECTION_UTILS_CHECK_ELEMENT (name, "SyncFolderHierarchyResponseMessage")) {
+                       e_ews_process_sync_xxx_response (subparam, (ItemParser) 
e_ews_folder_new_from_soap_parameter,
+                               "IncludesLastFolderInRange", "FolderId",
+                               out_new_sync_state, out_includes_last_item, out_items_created, 
out_items_updated, out_items_deleted);
+               }
 
-       e_async_closure_free (closure);
+               subparam = e_soap_parameter_get_next_child (subparam);
+       }
 
-       return success;
+       return TRUE;
 }
 
-void
-e_ews_connection_sync_folder_hierarchy (EEwsConnection *cnc,
-                                        gint pri,
-                                        const gchar *sync_state,
-                                        GCancellable *cancellable,
-                                        GAsyncReadyCallback callback,
-                                        gpointer user_data)
+gboolean
+e_ews_connection_sync_folder_hierarchy_sync (EEwsConnection *cnc,
+                                             gint pri,
+                                            const gchar *old_sync_state,
+                                             gchar **out_new_sync_state,
+                                             gboolean *out_includes_last_folder,
+                                             GSList **out_folders_created,
+                                             GSList **out_folders_updated,
+                                             GSList **out_folders_deleted,
+                                             GCancellable *cancellable,
+                                             GError **error)
 {
        ESoapRequest *request;
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
+       ESoapResponse *response;
+       gboolean success;
 
        g_return_if_fail (cnc != NULL);
 
@@ -5069,91 +4353,18 @@ e_ews_connection_sync_folder_hierarchy (EEwsConnection *cnc,
 
        e_ews_request_write_footer (request);
 
-       simple = g_simple_async_result_new (
-               G_OBJECT (cnc), callback, user_data,
-               e_ews_connection_sync_folder_hierarchy);
-
-       async_data = g_slice_new0 (EwsAsyncData);
-       async_data->cnc = cnc;
-       g_simple_async_result_set_op_res_gpointer (
-               simple, async_data, (GDestroyNotify) async_data_free);
-
-       e_ews_connection_queue_request (
-               cnc, request, sync_hierarchy_response_cb,
-               pri, cancellable, simple);
-
-       g_object_unref (simple);
-}
-
-gboolean
-e_ews_connection_sync_folder_hierarchy_finish (EEwsConnection *cnc,
-                                               GAsyncResult *result,
-                                               gchar **sync_state,
-                                               gboolean *includes_last_folder,
-                                               GSList **folders_created,
-                                               GSList **folders_updated,
-                                               GSList **folders_deleted,
-                                               GError **error)
-{
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (
-               result, G_OBJECT (cnc), e_ews_connection_sync_folder_hierarchy),
-               FALSE);
-
-       simple = G_SIMPLE_ASYNC_RESULT (result);
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
 
-       if (g_simple_async_result_propagate_error (simple, error))
+       if (!response) {
+               g_clear_object (&request);
                return FALSE;
+       }
 
-       *sync_state = async_data->sync_state;
-       *includes_last_folder = async_data->includes_last_item;
-       *folders_created = async_data->items_created;
-       *folders_updated = async_data->items_updated;
-       *folders_deleted = async_data->items_deleted;
-
-       return TRUE;
-}
-
-gboolean
-e_ews_connection_sync_folder_hierarchy_sync (EEwsConnection *cnc,
-                                             gint pri,
-                                            const gchar *old_sync_state,
-                                             gchar **new_sync_state,
-                                             gboolean *includes_last_folder,
-                                             GSList **folders_created,
-                                             GSList **folders_updated,
-                                             GSList **folders_deleted,
-                                             GCancellable *cancellable,
-                                             GError **error)
-{
-       EAsyncClosure *closure;
-       GAsyncResult *result;
-       gboolean success;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-
-       closure = e_async_closure_new ();
-
-       e_ews_connection_sync_folder_hierarchy (
-               cnc, pri, old_sync_state, cancellable,
-               e_async_closure_callback, closure);
-
-       result = e_async_closure_wait (closure);
-
-       success = e_ews_connection_sync_folder_hierarchy_finish (
-               cnc, result, new_sync_state,
-               includes_last_folder,
-               folders_created,
-               folders_updated,
-               folders_deleted,
-               error);
+       success = e_ews_process_sync_hierarchy_response (cnc, response, out_new_sync_state, 
out_includes_last_item,
+               out_items_created, out_items_updated, out_items_deleted, error);
 
-       e_async_closure_free (closure);
+       g_clear_object (&request);
+       g_clear_object (&response);
 
        return success;
 }
@@ -5216,27 +4427,105 @@ e_ews_connection_satisfies_server_version (EEwsConnection *cnc,
        return cnc->priv->version >= version;
 }
 
-void
-e_ews_connection_get_items (EEwsConnection *cnc,
-                            gint pri,
-                            const GSList *ids,
-                            const gchar *default_props,
-                           const EEwsAdditionalProps *add_props,
-                            gboolean include_mime,
-                            const gchar *mime_directory,
-                           EEwsBodyType body_type,
-                            ESoapResponseProgressFn progress_fn,
-                            gpointer progress_data,
-                            GCancellable *cancellable,
-                            GAsyncReadyCallback callback,
-                            gpointer user_data)
+static gboolean
+e_ews_process_get_items_response (EEwsConnection *cnc,
+                                 ESoapResponse *response,
+                                 GSList **out_items,
+                                 GError *error)
+{
+       ESoapParameter *param;
+       ESoapParameter *subparam;
+       GError *local_error = NULL;
+
+       param = e_soap_response_get_first_parameter_by_name (response, "ResponseMessages", &local_error);
+
+       /* Sanity check */
+       g_return_val_if_fail (
+               (param != NULL && local_error == NULL) ||
+               (param == NULL && local_error != NULL), FALSE);
+
+       if (local_error) {
+               g_propagate_error (error, local_error);
+               return FALSE;
+       }
+
+       subparam = e_soap_parameter_get_first_child (param);
+
+       while (subparam != NULL) {
+               const gchar *name = (const gchar *) subparam->name;
+
+               if (g_str_has_suffix (name, "ResponseMessage")) {
+                       ESoapParameter *node;
+                       EEwsItem *item;
+
+                       if (ews_get_response_status (subparam, &local_error))
+                               local_error = NULL;
+
+                       for (node = e_soap_parameter_get_first_child_by_name (subparam, "Items");
+                            node;
+                            node = e_soap_parameter_get_next_child_by_name (subparam, "Items")) {
+                               if (node->children)
+                                       item = e_ews_item_new_from_soap_parameter (node);
+                               else
+                                       item = NULL;
+                               if (!item && local_error != NULL)
+                                       item = e_ews_item_new_from_error (local_error);
+                               if (item)
+                                       *out_items = g_slist_prepend (*out_items, item);
+                       }
+               } else {
+                       g_warning ("%s: Unexpected element <%s>", G_STRFUNC, name);
+               }
+
+               /* Do not stop on errors. */
+               g_clear_error (&local_error);
+
+               subparam = e_soap_parameter_get_next_child (subparam);
+       }
+
+       /* if there is only one item, then check whether it's an error */
+       if (*out_items && (*out_items)->data && !(*out_items)->next) {
+               EEwsItem *item = (*out_items)->data;
+
+               if (item && e_ews_item_get_item_type (item) == E_EWS_ITEM_TYPE_ERROR) {
+                       g_propagate_error (error, g_error_copy (e_ews_item_get_error (item)));
+
+                       g_slist_free_full (*out_items, g_object_unref);
+                       *out_items = NULL;
+
+                       return FALSE;
+               }
+       }
+
+       *out_items = g_slist_reverse (*out_items);
+
+       return TRUE;
+}
+
+gboolean
+e_ews_connection_get_items_sync (EEwsConnection *cnc,
+                                 gint pri,
+                                 const GSList *ids,
+                                 const gchar *default_props,
+                                const EEwsAdditionalProps *add_props,
+                                 gboolean include_mime,
+                                 const gchar *mime_directory,
+                                EEwsBodyType body_type,
+                                 GSList **out_items,
+                                 ESoapResponseProgressFn progress_fn,
+                                 gpointer progress_data,
+                                 GCancellable *cancellable,
+                                 GError **error)
 {
        ESoapRequest *request;
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
-       const GSList *l;
+       ESoapResponse *response;
+       const GSList *link;
+       gboolean success;
 
-       g_return_if_fail (cnc != NULL);
+       g_return_val_if_fail (cnc != NULL, FALSE);
+       g_return_val_if_fail (out_items != NULL, FALSE);
+
+       *out_items = NULL;
 
        request = e_ews_request_new_with_header (
                cnc->priv->uri,
@@ -5281,95 +4570,30 @@ e_ews_connection_get_items (EEwsConnection *cnc,
 
        e_soap_request_start_element (request, "ItemIds", "messages", NULL);
 
-       for (l = ids; l != NULL; l = g_slist_next (l))
-               e_ews_request_write_string_parameter_with_attribute (request, "ItemId", NULL, NULL, "Id", 
l->data);
+       for (link = ids; link; link = g_slist_next (link)) {
+               e_ews_request_write_string_parameter_with_attribute (request, "ItemId", NULL, NULL, "Id", 
link->data);
+       }
 
        e_soap_request_end_element (request);
 
        e_ews_request_write_footer (request);
 
-       simple = g_simple_async_result_new (
-               G_OBJECT (cnc), callback, user_data,
-               e_ews_connection_get_items);
-
-       async_data = g_slice_new0 (EwsAsyncData);
-       g_simple_async_result_set_op_res_gpointer (
-               simple, async_data, (GDestroyNotify) async_data_free);
-
-       e_ews_connection_queue_request (
-               cnc, request, get_items_response_cb,
-               pri, cancellable, simple);
-
-       g_object_unref (simple);
-}
-
-gboolean
-e_ews_connection_get_items_finish (EEwsConnection *cnc,
-                                   GAsyncResult *result,
-                                   GSList **items,
-                                   GError **error)
-{
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (
-               result, G_OBJECT (cnc), e_ews_connection_get_items),
-               FALSE);
-
-       simple = G_SIMPLE_ASYNC_RESULT (result);
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
 
-       if (g_simple_async_result_propagate_error (simple, error))
-               return FALSE;
-
-       if (!async_data->items) {
-               g_set_error_literal (error, EWS_CONNECTION_ERROR, EWS_CONNECTION_ERROR_ITEMNOTFOUND, _("No 
items found"));
+       if (!response) {
+               g_clear_object (&request);
                return FALSE;
        }
 
-       *items = async_data->items;
-
-       return TRUE;
-}
-
-gboolean
-e_ews_connection_get_items_sync (EEwsConnection *cnc,
-                                 gint pri,
-                                 const GSList *ids,
-                                 const gchar *default_props,
-                                const EEwsAdditionalProps *add_props,
-                                 gboolean include_mime,
-                                 const gchar *mime_directory,
-                                EEwsBodyType body_type,
-                                 GSList **items,
-                                 ESoapResponseProgressFn progress_fn,
-                                 gpointer progress_data,
-                                 GCancellable *cancellable,
-                                 GError **error)
-{
-       EAsyncClosure *closure;
-       GAsyncResult *result;
-       gboolean success;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-
-       closure = e_async_closure_new ();
-
-       e_ews_connection_get_items (
-               cnc, pri,ids, default_props,
-               add_props, include_mime,
-               mime_directory, body_type, progress_fn,
-               progress_data, cancellable,
-               e_async_closure_callback, closure);
-
-       result = e_async_closure_wait (closure);
+       success = e_ews_process_get_items_response (cnc, response, out_items, error);
 
-       success = e_ews_connection_get_items_finish (
-               cnc, result, items, error);
+       g_clear_object (&request);
+       g_clear_object (&response);
 
-       e_async_closure_free (closure);
+       if (!success) {
+               g_slist_free_full (*out_items, g_object_unref);
+               *out_items = NULL;
+       }
 
        return success;
 }
@@ -5416,56 +4640,23 @@ ews_affected_tasks_to_str (EwsAffectedTaskOccurrencesType affected_tasks)
        return NULL;
 }
 
-static void
-delete_item_response_cb (ESoapResponse *response,
-                         GSimpleAsyncResult *simple)
-{
-       ESoapParameter *param;
-       ESoapParameter *subparam;
-       GError *error = NULL;
-
-       param = e_soap_response_get_first_parameter_by_name (
-               response, "ResponseMessages", &error);
-
-       /* Sanity check */
-       g_return_if_fail (
-               (param != NULL && error == NULL) ||
-               (param == NULL && error != NULL));
-
-       if (error != NULL) {
-               g_simple_async_result_take_error (simple, error);
-               return;
-       }
-
-       subparam = e_soap_parameter_get_first_child (param);
-
-       while (subparam != NULL) {
-               if (!ews_get_response_status (subparam, &error)) {
-                       g_simple_async_result_take_error (simple, error);
-                       return;
-               }
-
-               subparam = e_soap_parameter_get_next_child (subparam);
-       }
-}
-
-void
-e_ews_connection_delete_items (EEwsConnection *cnc,
-                               gint pri,
-                               const GSList *ids,
-                               EwsDeleteType delete_type,
-                               EwsSendMeetingCancellationsType send_cancels,
-                               EwsAffectedTaskOccurrencesType affected_tasks,
-                               GCancellable *cancellable,
-                               GAsyncReadyCallback callback,
-                               gpointer user_data)
+gboolean
+e_ews_connection_delete_items_sync (EEwsConnection *cnc,
+                                    gint pri,
+                                    const GSList *ids,
+                                    EwsDeleteType delete_type,
+                                    EwsSendMeetingCancellationsType send_cancels,
+                                    EwsAffectedTaskOccurrencesType affected_tasks,
+                                    GCancellable *cancellable,
+                                    GError **error)
 {
        ESoapRequest *request;
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
-       const GSList *iter;
+       ESoapResponse *response;
+       gboolean success;
 
-       g_return_if_fail (cnc != NULL);
+       g_return_val_if_fail (cnc != NULL, FALSE);
+
+       closure = e_async_closure_new ();
 
        request = e_ews_request_new_with_header (
                cnc->priv->uri,
@@ -5487,46 +4678,46 @@ e_ews_connection_delete_items (EEwsConnection *cnc,
 
        e_soap_request_start_element (request, "ItemIds", "messages", NULL);
 
-       for (iter = ids; iter != NULL; iter = g_slist_next (iter))
+       for (iter = ids; iter != NULL; iter = g_slist_next (iter)) {
                e_ews_request_write_string_parameter_with_attribute (request, "ItemId", NULL, NULL, "Id", 
iter->data);
+       }
 
        e_soap_request_end_element (request);
 
        e_ews_request_write_footer (request);
 
-       simple = g_simple_async_result_new (
-               G_OBJECT (cnc), callback, user_data,
-               e_ews_connection_delete_items);
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
 
-       async_data = g_slice_new0 (EwsAsyncData);
-       g_simple_async_result_set_op_res_gpointer (
-               simple, async_data, (GDestroyNotify) async_data_free);
+       if (!response) {
+               g_clear_object (&request);
+               return FALSE;
+       }
 
-       e_ews_connection_queue_request (
-               cnc, request, delete_item_response_cb,
-               pri, cancellable, simple);
+       success = e_ews_process_generic_response (cnc, response, error);
 
-       g_object_unref (simple);
+       g_clear_object (&request);
+       g_clear_object (&response);
+
+       return success;
 }
 
-void
-e_ews_connection_delete_item (EEwsConnection *cnc,
-                              gint pri,
-                              EwsId *item_id,
-                              guint index,
-                              EwsDeleteType delete_type,
-                              EwsSendMeetingCancellationsType send_cancels,
-                              EwsAffectedTaskOccurrencesType affected_tasks,
-                              GCancellable *cancellable,
-                              GAsyncReadyCallback callback,
-                              gpointer user_data)
+gboolean
+e_ews_connection_delete_item_sync (EEwsConnection *cnc,
+                                   gint pri,
+                                   EwsId *id,
+                                   guint index,
+                                   EwsDeleteType delete_type,
+                                   EwsSendMeetingCancellationsType send_cancels,
+                                   EwsAffectedTaskOccurrencesType affected_tasks,
+                                   GCancellable *cancellable,
+                                   GError **error)
 {
        ESoapRequest *request;
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
+       ESoapResponse *response;
        gchar buffer[32];
+       gboolean success;
 
-       g_return_if_fail (cnc != NULL);
+       g_return_val_if_fail (cnc != NULL, FALSE);
 
        request = e_ews_request_new_with_header (
                cnc->priv->uri,
@@ -5568,103 +4759,17 @@ e_ews_connection_delete_item (EEwsConnection *cnc,
 
        e_ews_request_write_footer (request);
 
-       simple = g_simple_async_result_new (
-               G_OBJECT (cnc), callback, user_data,
-               e_ews_connection_delete_items);
-
-       async_data = g_slice_new0 (EwsAsyncData);
-       g_simple_async_result_set_op_res_gpointer (
-               simple, async_data, (GDestroyNotify) async_data_free);
-
-       e_ews_connection_queue_request (
-               cnc, request, delete_item_response_cb,
-               pri, cancellable, simple);
-
-       g_object_unref (simple);
-}
-
-gboolean
-e_ews_connection_delete_items_finish (EEwsConnection *cnc,
-                                      GAsyncResult *result,
-                                      GError **error)
-{
-       GSimpleAsyncResult *simple;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (
-               result, G_OBJECT (cnc), e_ews_connection_delete_items),
-               FALSE);
-
-       simple = G_SIMPLE_ASYNC_RESULT (result);
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
 
-       if (g_simple_async_result_propagate_error (simple, error))
+       if (!response) {
+               g_clear_object (&request);
                return FALSE;
+       }
 
-       return TRUE;
-}
-
-gboolean
-e_ews_connection_delete_items_sync (EEwsConnection *cnc,
-                                    gint pri,
-                                    const GSList *ids,
-                                    EwsDeleteType delete_type,
-                                    EwsSendMeetingCancellationsType send_cancels,
-                                    EwsAffectedTaskOccurrencesType affected_tasks,
-                                    GCancellable *cancellable,
-                                    GError **error)
-{
-       EAsyncClosure *closure;
-       GAsyncResult *result;
-       gboolean success;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-
-       closure = e_async_closure_new ();
-
-       e_ews_connection_delete_items (
-               cnc, pri, ids, delete_type,
-               send_cancels, affected_tasks, cancellable,
-               e_async_closure_callback, closure);
-
-       result = e_async_closure_wait (closure);
-
-       success = e_ews_connection_delete_items_finish (cnc, result, error);
-
-       e_async_closure_free (closure);
-
-       return success;
-}
-
-gboolean
-e_ews_connection_delete_item_sync (EEwsConnection *cnc,
-                                   gint pri,
-                                   EwsId *id,
-                                   guint index,
-                                   EwsDeleteType delete_type,
-                                   EwsSendMeetingCancellationsType send_cancels,
-                                   EwsAffectedTaskOccurrencesType affected_tasks,
-                                   GCancellable *cancellable,
-                                   GError **error)
-{
-       EAsyncClosure *closure;
-       GAsyncResult *result;
-       gboolean success;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-
-       closure = e_async_closure_new ();
-
-       e_ews_connection_delete_item (
-               cnc, pri, id, index, delete_type,
-               send_cancels, affected_tasks, cancellable,
-               e_async_closure_callback, closure);
-
-       result = e_async_closure_wait (closure);
-
-       success = e_ews_connection_delete_items_finish (cnc, result, error);
+       success = e_ews_process_generic_response (cnc, response, error);
 
-       e_async_closure_free (closure);
+       g_clear_object (&request);
+       g_clear_object (&response);
 
        return success;
 }
@@ -5812,26 +4917,25 @@ exit:
        return ret;
 }
 
-void
-e_ews_connection_update_items (EEwsConnection *cnc,
-                               gint pri,
-                               const gchar *conflict_res,
-                               const gchar *msg_disposition,
-                               const gchar *send_invites,
-                               const gchar *folder_id,
-                               EEwsRequestCreationCallback create_cb,
-                               gpointer create_user_data,
-                               GCancellable *cancellable,
-                               GAsyncReadyCallback callback,
-                               gpointer user_data)
+gboolean
+e_ews_connection_update_items_sync (EEwsConnection *cnc,
+                                    gint pri,
+                                    const gchar *conflict_res,
+                                    const gchar *msg_disposition,
+                                    const gchar *send_invites,
+                                    const gchar *folder_id,
+                                    EEwsRequestCreationCallback create_cb,
+                                    gpointer create_user_data,
+                                    GSList **out_items,
+                                    GCancellable *cancellable,
+                                    GError **error)
 {
        ESoapRequest *request;
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
+       ESoapResponse *response;
+       GSList *items = NULL;
        gboolean success;
-       GError *local_error = NULL;
 
-       g_return_if_fail (cnc != NULL);
+       g_return_val_if_fail (cnc != NULL, FALSE);
 
        request = e_ews_request_new_with_header (
                cnc->priv->uri,
@@ -5858,236 +4962,44 @@ e_ews_connection_update_items (EEwsConnection *cnc,
 
        e_soap_request_start_element (request, "ItemChanges", "messages", NULL);
 
-       success = create_cb (request, create_user_data, &local_error);
+       if (!create_cb (request, create_user_data, error)) {
+               g_clear_object (&request);
+               return FALSE;
+       }
 
        e_soap_request_end_element (request); /* ItemChanges */
 
        e_ews_request_write_footer (request);
 
-       simple = g_simple_async_result_new (
-               G_OBJECT (cnc), callback, user_data,
-               e_ews_connection_update_items);
-
-       async_data = g_slice_new0 (EwsAsyncData);
-       g_simple_async_result_set_op_res_gpointer (
-               simple, async_data, (GDestroyNotify) async_data_free);
-
-       if (!success) {
-               if (local_error)
-                       g_simple_async_result_take_error (simple, local_error);
-               g_simple_async_result_complete_in_idle (simple);
-               g_clear_object (&request);
-
        /*
         * We need to check for both namespaces, because, the message is being wrote without use the types
         * namespace. Maybe it is wrong, but the server doesn't complain about that. But this is the reason
         * for the first check. The second one, is related to "how it should be" accord with EWS 
specifications.
         */
-       } else if (!element_has_child (request, 
"/s:Envelope/s:Body/m:UpdateItem/m:ItemChanges/ItemChange/Updates") &&
-               !element_has_child (request, 
"/s:Envelope/s:Body/m:UpdateItem/m:ItemChanges/t:ItemChange/t:Updates")) {
-               g_simple_async_result_complete_in_idle (simple);
+       if (!element_has_child (request, "/s:Envelope/s:Body/m:UpdateItem/m:ItemChanges/ItemChange/Updates") 
&&
+           !element_has_child (request, 
"/s:Envelope/s:Body/m:UpdateItem/m:ItemChanges/t:ItemChange/t:Updates")) {
                g_clear_object (&request);
-       } else {
-               e_ews_connection_queue_request (
-                       cnc, request, get_items_response_cb,
-                       pri, cancellable, simple);
+               return TRUE;
        }
 
-       g_object_unref (simple);
-}
-
-gboolean
-e_ews_connection_update_items_finish (EEwsConnection *cnc,
-                                      GAsyncResult *result,
-                                      GSList **ids,
-                                      GError **error)
-{
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (
-               result, G_OBJECT (cnc), e_ews_connection_update_items),
-               FALSE);
-
-       simple = G_SIMPLE_ASYNC_RESULT (result);
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
-
-       if (g_simple_async_result_propagate_error (simple, error))
-               return FALSE;
-
-       /* if there is only one item, then check whether it's an error */
-       if (async_data->items && !async_data->items->next) {
-               EEwsItem *item = async_data->items->data;
-
-               if (item && e_ews_item_get_item_type (item) == E_EWS_ITEM_TYPE_ERROR) {
-                       if (error)
-                               *error = g_error_copy (e_ews_item_get_error (item));
-
-                       g_slist_free_full (async_data->items, g_object_unref);
-                       async_data->items = NULL;
-
-                       return FALSE;
-               }
-       }
-
-       if (ids)
-               *ids = async_data->items;
-       else
-               g_slist_free_full (async_data->items, g_object_unref);
-
-       return TRUE;
-}
-
-gboolean
-e_ews_connection_update_items_sync (EEwsConnection *cnc,
-                                    gint pri,
-                                    const gchar *conflict_res,
-                                    const gchar *msg_disposition,
-                                    const gchar *send_invites,
-                                    const gchar *folder_id,
-                                    EEwsRequestCreationCallback create_cb,
-                                    gpointer create_user_data,
-                                    GSList **ids,
-                                    GCancellable *cancellable,
-                                    GError **error)
-{
-       EAsyncClosure *closure;
-       GAsyncResult *result;
-       gboolean success;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-
-       closure = e_async_closure_new ();
-
-       e_ews_connection_update_items (
-               cnc, pri, conflict_res,
-               msg_disposition, send_invites,
-               folder_id, create_cb,
-               create_user_data, cancellable,
-               e_async_closure_callback, closure);
-
-       result = e_async_closure_wait (closure);
-
-       success = e_ews_connection_update_items_finish (
-               cnc, result, ids, error);
-
-       e_async_closure_free (closure);
-
-       return success;
-}
-
-void
-e_ews_connection_create_items (EEwsConnection *cnc,
-                               gint pri,
-                               const gchar *msg_disposition,
-                               const gchar *send_invites,
-                               const EwsFolderId *fid,
-                               EEwsRequestCreationCallback create_cb,
-                               gpointer create_user_data,
-                               GCancellable *cancellable,
-                               GAsyncReadyCallback callback,
-                               gpointer user_data)
-{
-       ESoapRequest *request;
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
-       gboolean success;
-       GError *local_error = NULL;
-
-       g_return_if_fail (cnc != NULL);
-
-       request = e_ews_request_new_with_header (
-               cnc->priv->uri,
-               cnc->priv->impersonate_user,
-               "CreateItem",
-               NULL,
-               NULL,
-               cnc->priv->version,
-               E_EWS_EXCHANGE_2007_SP1,
-               FALSE);
-
-       if (msg_disposition)
-               e_soap_request_add_attribute (request, "MessageDisposition", msg_disposition, NULL, NULL);
-       if (send_invites)
-               e_soap_request_add_attribute (request, "SendMeetingInvitations", send_invites, NULL, NULL);
-
-       if (fid) {
-               e_soap_request_start_element (request, "SavedItemFolderId", "messages", NULL);
-               e_ews_folder_id_append_to_msg (request, cnc->priv->email, fid);
-               e_soap_request_end_element (request);
-       }
-
-       e_soap_request_start_element (request, "Items", "messages", NULL);
-
-       success = create_cb (request, create_user_data, &local_error);
-
-       e_soap_request_end_element (request); /* Items */
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
 
-       e_ews_request_write_footer (request); /* CreateItem */
-
-       simple = g_simple_async_result_new (
-               G_OBJECT (cnc), callback, user_data,
-               e_ews_connection_create_items);
-
-       async_data = g_slice_new0 (EwsAsyncData);
-       g_simple_async_result_set_op_res_gpointer (
-               simple, async_data, (GDestroyNotify) async_data_free);
-
-       if (success) {
-               e_ews_connection_queue_request (
-                       cnc, request, get_items_response_cb,
-                       pri, cancellable, simple);
-       } else {
-               if (local_error)
-                       g_simple_async_result_take_error (simple, local_error);
-               g_simple_async_result_complete_in_idle (simple);
+       if (!response) {
                g_clear_object (&request);
-       }
-
-       g_object_unref (simple);
-}
-
-gboolean
-e_ews_connection_create_items_finish (EEwsConnection *cnc,
-                                      GAsyncResult *result,
-                                      GSList **ids,
-                                      GError **error)
-{
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (
-               result, G_OBJECT (cnc), e_ews_connection_create_items),
-               FALSE);
-
-       simple = G_SIMPLE_ASYNC_RESULT (result);
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
-
-       if (g_simple_async_result_propagate_error (simple, error))
                return FALSE;
+       }
 
-       /* if there is only one item, then check whether it's an error */
-       if (async_data->items && !async_data->items->next) {
-               EEwsItem *item = async_data->items->data;
-
-               if (item && e_ews_item_get_item_type (item) == E_EWS_ITEM_TYPE_ERROR) {
-                       if (error)
-                               *error = g_error_copy (e_ews_item_get_error (item));
-
-                       g_slist_free_full (async_data->items, g_object_unref);
-                       async_data->items = NULL;
+       success = e_ews_process_get_items_response (cnc, response, &items, error);
 
-                       return FALSE;
-               }
-       }
+       g_clear_object (&request);
+       g_clear_object (&response);
 
-       *ids = async_data->items;
+       if (success && out_items)
+               *out_items = items;
+       else
+               g_slist_free_full (items, g_object_unref);
 
-       return TRUE;
+       return success;
 }
 
 gboolean
@@ -6098,31 +5010,65 @@ e_ews_connection_create_items_sync (EEwsConnection *cnc,
                                     const EwsFolderId *fid,
                                     EEwsRequestCreationCallback create_cb,
                                     gpointer create_user_data,
-                                    GSList **ids,
+                                    GSList **out_items,
                                     GCancellable *cancellable,
                                     GError **error)
 {
-       EAsyncClosure *closure;
-       GAsyncResult *result;
+       ESoapRequest *request;
+       ESoapResponse *response;
+       GSList *items = NULL;
        gboolean success;
 
        g_return_val_if_fail (cnc != NULL, FALSE);
 
-       closure = e_async_closure_new ();
+       request = e_ews_request_new_with_header (
+               cnc->priv->uri,
+               cnc->priv->impersonate_user,
+               "CreateItem",
+               NULL,
+               NULL,
+               cnc->priv->version,
+               E_EWS_EXCHANGE_2007_SP1,
+               FALSE);
 
-       e_ews_connection_create_items (
-               cnc, pri, msg_disposition,
-               send_invites, fid,
-               create_cb, create_user_data,
-               cancellable,
-               e_async_closure_callback, closure);
+       if (msg_disposition)
+               e_soap_request_add_attribute (request, "MessageDisposition", msg_disposition, NULL, NULL);
+       if (send_invites)
+               e_soap_request_add_attribute (request, "SendMeetingInvitations", send_invites, NULL, NULL);
 
-       result = e_async_closure_wait (closure);
+       if (fid) {
+               e_soap_request_start_element (request, "SavedItemFolderId", "messages", NULL);
+               e_ews_folder_id_append_to_msg (request, cnc->priv->email, fid);
+               e_soap_request_end_element (request);
+       }
+
+       e_soap_request_start_element (request, "Items", "messages", NULL);
 
-       success = e_ews_connection_create_items_finish (
-               cnc, result, ids, error);
+       if (!create_cb (request, create_user_data, error)) {
+               g_clear_object (&request);
+               return FALSE;
+       }
+
+       e_soap_request_end_element (request); /* Items */
+
+       e_ews_request_write_footer (request); /* CreateItem */
+
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
 
-       e_async_closure_free (closure);
+       if (!response) {
+               g_clear_object (&request);
+               return FALSE;
+       }
+
+       success = e_ews_process_get_items_response (cnc, response, &items, error);
+
+       g_clear_object (&request);
+       g_clear_object (&response);
+
+       if (success && out_items)
+               *out_items = items;
+       else
+               g_slist_free_full (items, g_object_unref);
 
        return success;
 }
@@ -6146,22 +5092,108 @@ get_search_scope_str (EwsContactsSearchScope scope)
        }
 }
 
-void
-e_ews_connection_resolve_names (EEwsConnection *cnc,
-                                gint pri,
-                                const gchar *resolve_name,
-                                EwsContactsSearchScope scope,
-                                GSList *parent_folder_ids,
-                                gboolean fetch_contact_data,
-                                GCancellable *cancellable,
-                                GAsyncReadyCallback callback,
-                                gpointer user_data)
+static gboolean
+e_ews_process_resolve_names_response (EEwsConnection *cnc,
+                                     ESoapResponse *response,
+                                     gboolean *out_includes_last_item,
+                                     GSList **out_mailboxes,
+                                     GSList **out_contact_items,
+                                     GError **error)
+{
+       ESoapParameter *param;
+       ESoapParameter *subparam;
+       GError *local_error = NULL;
+
+       *out_includes_last_item = TRUE;
+       *out_contact_items = NULL;
+       *out_mailboxes = NULL;
+
+       param = e_soap_response_get_first_parameter_by_name (response, "ResponseMessages", &local_error);
+
+       /* Sanity check */
+       g_return_val_if_fail (
+               (param != NULL && local_error == NULL) ||
+               (param == NULL && local_error != NULL), FALSE);
+
+       if (local_error != NULL) {
+               g_propagate_error (error, local_error);
+               return FALSE;
+       }
+
+       subparam = e_soap_parameter_get_first_child (param);
+
+       while (subparam != NULL) {
+               const gchar *name = (const gchar *) subparam->name;
+
+               if (!ews_get_response_status (subparam, error)) {
+                       return FALSE;
+               }
+
+               if (E_EWS_CONNECTION_UTILS_CHECK_ELEMENT (name, "ResolveNamesResponseMessage")) {
+                       ESoapParameter *node;
+                       gchar *prop;
+                       gboolean includes_last_item;
+                       GSList *mailboxes = NULL, *contact_items = NULL;
+
+                       subparam = e_soap_parameter_get_first_child_by_name (subparam, "ResolutionSet");
+                       prop = e_soap_parameter_get_property (subparam, "IncludesLastItemInRange");
+                       /*
+                        * Set the includes_last_item to TRUE as default.
+                        * It can avoid an infinite loop in caller, when, for some reason,
+                        * we don't receive the last_tag property from the server.
+                        */
+                       *out_includes_last_item = g_strcmp0 (prop, "false") != 0;
+                       g_free (prop);
+
+                       for (subparam = e_soap_parameter_get_first_child_by_name (subparam, "Resolution");
+                            subparam != NULL;
+                            subparam = e_soap_parameter_get_next_child_by_name (subparam, "Resolution")) {
+                               EwsMailbox *mb;
+
+                               node = e_soap_parameter_get_first_child_by_name (subparam, "Mailbox");
+                               mb = e_ews_item_mailbox_from_soap_param (node);
+                               if (mb) {
+                                       EEwsItem *contact_item;
+
+                                       *out_mailboxes = g_slist_prepend (*out_mailboxes, mb);
+
+                                       /* 'mailboxes' and 'contact_items' match 1:1, but if the contact 
information
+                                        * wasn't found, then NULL is stored in the corresponding position */
+                                       node = e_soap_parameter_get_first_child_by_name (subparam, "Contact");
+                                       if (node) {
+                                               contact_item = e_ews_item_new_from_soap_parameter (node);
+                                               *out_contact_items = g_slist_prepend (*out_contact_items, 
contact_item);
+                                       } else {
+                                               *out_contact_items = g_slist_prepend (*out_contact_items, 
NULL);
+                                       }
+                               }
+                       }
+               }
+
+               subparam = e_soap_parameter_get_next_child (subparam);
+       }
+}
+
+gboolean
+e_ews_connection_resolve_names_sync (EEwsConnection *cnc,
+                                     gint pri,
+                                     const gchar *resolve_name,
+                                     EwsContactsSearchScope scope,
+                                     GSList *parent_folder_ids,
+                                     gboolean fetch_contact_data,
+                                     gboolean *out_includes_last_item,
+                                     GSList **out_mailboxes,
+                                     GSList **out_contact_items,
+                                     GCancellable *cancellable,
+                                     GError **error)
 {
        ESoapRequest *request;
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
+       ESoapResponse *response;
+       gboolean includes_last_item = TRUE;
+       GSList *mailboxes = NULL, *contact_items = NULL;
+       gboolean success;
 
-       g_return_if_fail (cnc != NULL);
+       g_return_val_if_fail (cnc != NULL, FALSE);
 
        request = e_ews_request_new_with_header (
                cnc->priv->uri,
@@ -6194,91 +5226,30 @@ e_ews_connection_resolve_names (EEwsConnection *cnc,
 
        e_ews_request_write_footer (request);
 
-       simple = g_simple_async_result_new (
-               G_OBJECT (cnc), callback, user_data,
-               e_ews_connection_resolve_names);
-
-       async_data = g_slice_new0 (EwsAsyncData);
-       g_simple_async_result_set_op_res_gpointer (
-               simple, async_data, (GDestroyNotify) async_data_free);
-
-       e_ews_connection_queue_request (
-               cnc, request, resolve_names_response_cb,
-               pri, cancellable, simple);
-
-       g_object_unref (simple);
-}
-
-gboolean
-e_ews_connection_resolve_names_finish (EEwsConnection *cnc,
-                                       GAsyncResult *result,
-                                       GSList **mailboxes,
-                                       GSList **contact_items,
-                                       gboolean *includes_last_item,
-                                       GError **error)
-{
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (
-               result, G_OBJECT (cnc), e_ews_connection_resolve_names),
-               FALSE);
-
-       simple = G_SIMPLE_ASYNC_RESULT (result);
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
 
-       if (g_simple_async_result_propagate_error (simple, error))
+       if (!response) {
+               g_clear_object (&request);
                return FALSE;
+       }
 
-       *includes_last_item = async_data->includes_last_item;
-
-       if (contact_items)
-               *contact_items = async_data->items_created;
-       else
-               e_util_free_nullable_object_slist (async_data->items_created);
-       *mailboxes = async_data->items;
-
-       return TRUE;
-}
-
-gboolean
-e_ews_connection_resolve_names_sync (EEwsConnection *cnc,
-                                     gint pri,
-                                     const gchar *resolve_name,
-                                     EwsContactsSearchScope scope,
-                                     GSList *parent_folder_ids,
-                                     gboolean fetch_contact_data,
-                                     GSList **mailboxes,
-                                     GSList **contact_items,
-                                     gboolean *includes_last_item,
-                                     GCancellable *cancellable,
-                                     GError **error)
-{
-       EAsyncClosure *closure;
-       GAsyncResult *result;
-       gboolean success;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-
-       closure = e_async_closure_new ();
+       success = e_ews_process_resolve_names_response (cnc, response, &includes_last_item, &mailboxes, 
&contact_items, error);
 
-       e_ews_connection_resolve_names (
-               cnc, pri, resolve_name,
-               scope, parent_folder_ids,
-               fetch_contact_data,
-               cancellable,
-               e_async_closure_callback, closure);
+       g_clear_object (&request);
+       g_clear_object (&response);
 
-       result = e_async_closure_wait (closure);
+       if (success && out_includes_last_item)
+               *out_includes_last_item = includes_last_item;
 
-       success = e_ews_connection_resolve_names_finish (
-               cnc, result,
-               mailboxes, contact_items,
-               includes_last_item, error);
+       if (success && out_mailboxes)
+               *out_mailboxes = g_slist_reverse (mailboxes);
+       else
+               g_slist_free_full (mailboxes, (GDestroyNotify) e_ews_mailbox_free);
 
-       e_async_closure_free (closure);
+       if (success && out_contact_items)
+               *out_contact_items = g_slist_reverse (contact_items);
+       else
+               e_util_free_nullable_object_slist (contact_items);
 
        return success;
 }
@@ -6311,8 +5282,8 @@ ews_connection_resolve_by_name (EEwsConnection *cnc,
        /* use the first error, not the guess-part error */
        e_ews_connection_resolve_names_sync (
                cnc, pri, usename,
-               EWS_SEARCH_AD_CONTACTS, NULL, TRUE, &mailboxes, &contacts,
-               &includes_last_item, cancellable, NULL);
+               EWS_SEARCH_AD_CONTACTS, NULL, TRUE, &includes_last_item, &mailboxes, &contacts,
+               cancellable, NULL);
 
        for (miter = mailboxes; miter; miter = miter->next) {
                const EwsMailbox *mailbox = miter->data;
@@ -6392,8 +5363,8 @@ e_ews_connection_ex_to_smtp_sync (EEwsConnection *cnc,
 
        e_ews_connection_resolve_names_sync (
                cnc, pri, ex_address,
-               EWS_SEARCH_AD_CONTACTS, NULL, TRUE, &mailboxes, &contacts,
-               &includes_last_item, cancellable, error);
+               EWS_SEARCH_AD_CONTACTS, NULL, TRUE, &includes_last_item, &mailboxes, &contacts,
+               cancellable, error);
 
        /* only one mailbox matches */
        if (mailboxes && !mailboxes->next && mailboxes->data) {
@@ -6448,233 +5419,135 @@ e_ews_connection_ex_to_smtp_sync (EEwsConnection *cnc,
        return *smtp_address != NULL;
 }
 
-void
-e_ews_connection_expand_dl (EEwsConnection *cnc,
-                            gint pri,
-                            const EwsMailbox *mb,
-                            GCancellable *cancellable,
-                            GAsyncReadyCallback callback,
-                            gpointer user_data)
-{
-       ESoapRequest *request;
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
-
-       g_return_if_fail (cnc != NULL);
-
-       request = e_ews_request_new_with_header (
-               cnc->priv->uri,
-               cnc->priv->impersonate_user,
-               "ExpandDL",
-               NULL,
-               NULL,
-               cnc->priv->version,
-               E_EWS_EXCHANGE_2007_SP1,
-               FALSE);
-
-       e_soap_request_start_element (request, "Mailbox", "messages", NULL);
-
-       if (mb->item_id) {
-               e_soap_request_start_element (request, "ItemId", NULL, NULL);
-
-               e_soap_request_add_attribute (request, "Id", mb->item_id->id, NULL, NULL);
-               e_soap_request_add_attribute (request, "ChangeKey", mb->item_id->change_key, NULL, NULL);
-
-               e_soap_request_end_element (request); /* Mailbox */
-
-       } else if (mb->email)
-               e_ews_request_write_string_parameter (request, "EmailAddress", NULL, mb->email);
-
-       e_soap_request_end_element (request); /* Mailbox */
-
-       e_ews_request_write_footer (request);
-
-       simple = g_simple_async_result_new (
-               G_OBJECT (cnc), callback, user_data,
-               e_ews_connection_expand_dl);
-
-       async_data = g_slice_new0 (EwsAsyncData);
-       g_simple_async_result_set_op_res_gpointer (
-               simple, async_data, (GDestroyNotify) async_data_free);
-
-       e_ews_connection_queue_request (
-               cnc, request, expand_dl_response_cb,
-               pri, cancellable, simple);
-
-       g_object_unref (simple);
-}
-
-/* includes_last_item does not make sense as expand_dl does not support recursive 
- * fetch, wierd */
-gboolean
-e_ews_connection_expand_dl_finish (EEwsConnection *cnc,
-                                   GAsyncResult *result,
-                                   GSList **mailboxes,
-                                   gboolean *includes_last_item,
-                                   GError **error)
-{
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (
-               result, G_OBJECT (cnc), e_ews_connection_expand_dl),
-               FALSE);
-
-       simple = G_SIMPLE_ASYNC_RESULT (result);
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
-
-       if (g_simple_async_result_propagate_error (simple, error))
-               return FALSE;
-
-       *includes_last_item = async_data->includes_last_item;
-       *mailboxes = async_data->items;
-
-       return TRUE;
-
-}
-
-gboolean
-e_ews_connection_expand_dl_sync (EEwsConnection *cnc,
-                                 gint pri,
-                                 const EwsMailbox *mb,
-                                 GSList **mailboxes,
-                                 gboolean *includes_last_item,
-                                 GCancellable *cancellable,
-                                 GError **error)
-{
-       EAsyncClosure *closure;
-       GAsyncResult *result;
-       gboolean success;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-
-       closure = e_async_closure_new ();
-
-       e_ews_connection_expand_dl (
-               cnc, pri, mb, cancellable,
-               e_async_closure_callback, closure);
-
-       result = e_async_closure_wait (closure);
-
-       success = e_ews_connection_expand_dl_finish (
-               cnc, result, mailboxes, includes_last_item, error);
-
-       e_async_closure_free (closure);
-
-       return success;
-}
-
-static void
-update_folder_response_cb (ESoapResponse *response,
-                           GSimpleAsyncResult *simple)
+static gboolean
+e_ews_process_expand_dl_response (EEwsConnectoon *cnc,
+                                 ESoapResponse *response,
+                                 gboolean *out_includes_last_item,
+                                 GSList *out_mailboxes,
+                                 GError **error)
 {
        ESoapParameter *param;
        ESoapParameter *subparam;
-       GError *error = NULL;
+       GError *local_error = NULL;
 
-       param = e_soap_response_get_first_parameter_by_name (
-               response, "ResponseMessages", &error);
+       *out_includes_last_item = TRUE;
+       *out_mailboxes = NULL;
+
+       param = e_soap_response_get_first_parameter_by_name (response, "ResponseMessages", &local_error);
 
        /* Sanity check */
-       g_return_if_fail (
-               (param != NULL && error == NULL) ||
-               (param == NULL && error != NULL));
+       g_return_val_if_fail (
+               (param != NULL && local_error == NULL) ||
+               (param == NULL && local_error != NULL), FALSE);
 
-       if (error != NULL) {
-               g_simple_async_result_take_error (simple, error);
-               return;
+       if (local_error) {
+               g_propagate_error (error, local_error);
+               return FALSE;
        }
 
        subparam = e_soap_parameter_get_first_child (param);
 
        while (subparam != NULL) {
-               if (!ews_get_response_status (subparam, &error)) {
-                       g_simple_async_result_take_error (simple, error);
-                       return;
+               const gchar *name = (const gchar *) subparam->name;
+
+               if (!ews_get_response_status (subparam, error))
+                       return FALSE;
+
+               if (E_EWS_CONNECTION_UTILS_CHECK_ELEMENT (name, "ExpandDLResponseMessage")) {
+                       gchar *prop;
+
+                       subparam = e_soap_parameter_get_first_child_by_name (subparam, "DLExpansion");
+                       prop = e_soap_parameter_get_property (subparam, "IncludesLastItemInRange");
+                       /*
+                        * Set the includes_last_item to TRUE as default.
+                        * It can avoid an infinite loop in caller, when, for some reason,
+                        * we don't receive the last_tag property from the server.
+                        */
+                       *out_includes_last_item = g_strcmp0 (prop, "false") != 0;
+                       g_free (prop);
+
+                       for (subparam = e_soap_parameter_get_first_child_by_name (subparam, "Mailbox");
+                               subparam != NULL;
+                               subparam = e_soap_parameter_get_next_child_by_name (subparam, "Mailbox")) {
+                               EwsMailbox *mb;
+
+                               mb = e_ews_item_mailbox_from_soap_param (subparam);
+                               if (mb)
+                                       *out_mailboxes = g_slist_prepend (*out_mailboxes, mb);
+                       }
                }
 
-               subparam = e_soap_parameter_get_next_child (param);
+               subparam = e_soap_parameter_get_next_child (subparam);
        }
+
+       return TRUE;
 }
 
-void
-e_ews_connection_update_folder (EEwsConnection *cnc,
-                                gint pri,
-                                EEwsRequestCreationCallback create_cb,
-                                gpointer create_user_data,
-                                GCancellable *cancellable,
-                                GAsyncReadyCallback callback,
-                                gpointer user_data)
+gboolean
+e_ews_connection_expand_dl_sync (EEwsConnection *cnc,
+                                 gint pri,
+                                 const EwsMailbox *mb,
+                                 gboolean *out_includes_last_item,
+                                 GSList **out_mailboxes,
+                                 GCancellable *cancellable,
+                                 GError **error)
 {
        ESoapRequest *request;
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
+       ESoapResponse *response;
+       gboolean includes_last_item = TRUE;
+       GSList *mailboxes = NULL;
        gboolean success;
-       GError *local_error = NULL;
 
-       g_return_if_fail (cnc != NULL);
+       g_return_val_if_fail (cnc != NULL, FALSE);
 
        request = e_ews_request_new_with_header (
                cnc->priv->uri,
                cnc->priv->impersonate_user,
-               "UpdateFolder",
+               "ExpandDL",
                NULL,
                NULL,
                cnc->priv->version,
                E_EWS_EXCHANGE_2007_SP1,
                FALSE);
 
-       e_soap_request_start_element (request, "FolderChanges", "messages", NULL);
+       e_soap_request_start_element (request, "Mailbox", "messages", NULL);
 
-       success = create_cb (request, create_user_data, &local_error);
+       if (mb->item_id) {
+               e_soap_request_start_element (request, "ItemId", NULL, NULL);
 
-       e_soap_request_end_element (request); /* FolderChanges */
+               e_soap_request_add_attribute (request, "Id", mb->item_id->id, NULL, NULL);
+               e_soap_request_add_attribute (request, "ChangeKey", mb->item_id->change_key, NULL, NULL);
 
-       e_ews_request_write_footer (request);
+               e_soap_request_end_element (request); /* Mailbox */
 
-       simple = g_simple_async_result_new (
-               G_OBJECT (cnc), callback, user_data,
-               e_ews_connection_update_folder);
+       } else if (mb->email)
+               e_ews_request_write_string_parameter (request, "EmailAddress", NULL, mb->email);
 
-       async_data = g_slice_new0 (EwsAsyncData);
-       g_simple_async_result_set_op_res_gpointer (
-               simple, async_data, (GDestroyNotify) async_data_free);
+       e_soap_request_end_element (request); /* Mailbox */
 
-       if (success) {
-               e_ews_connection_queue_request (
-                       cnc, request, update_folder_response_cb,
-                       pri, cancellable, simple);
-       } else {
-               if (local_error)
-                       g_simple_async_result_take_error (simple, local_error);
-               g_simple_async_result_complete_in_idle (simple);
+       e_ews_request_write_footer (request);
+
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
+
+       if (!response) {
                g_clear_object (&request);
+               return FALSE;
        }
 
-       g_object_unref (simple);
-}
-
-gboolean
-e_ews_connection_update_folder_finish (EEwsConnection *cnc,
-                                       GAsyncResult *result,
-                                       GError **error)
-{
-       GSimpleAsyncResult *simple;
+       success = e_ews_process_expand_dl_response (cnc, response, &includes_last_item, &mailboxes, error);
 
-       g_return_val_if_fail (cnc != NULL, FALSE);
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (
-               result, G_OBJECT (cnc), e_ews_connection_update_folder),
-               FALSE);
+       g_clear_object (&request);
+       g_clear_object (&response);
 
-       simple = G_SIMPLE_ASYNC_RESULT (result);
+       if (success && out_includes_last_item)
+               *out_includes_last_item = includes_last_item;
 
-       if (g_simple_async_result_propagate_error (simple, error))
-               return FALSE;
+       if (success && out_mailboxes)
+               *out_mailboxes = g_slist_reverse (mailboxes);
+       else
+               g_slist_free_full (mailboxes, (GDestroyNotify) e_ews_mailbox_free);
 
-       return TRUE;
+       return success;
 }
 
 gboolean
@@ -6685,74 +5558,62 @@ e_ews_connection_update_folder_sync (EEwsConnection *cnc,
                                      GCancellable *cancellable,
                                      GError **error)
 {
-       EAsyncClosure *closure;
-       GAsyncResult *result;
+       ESoapRequest *request;
+       ESoapResponse *response;
        gboolean success;
 
        g_return_val_if_fail (cnc != NULL, FALSE);
+       g_return_val_if_fail (create_cb != NULL, FALSE);
 
-       closure = e_async_closure_new ();
-
-       e_ews_connection_update_folder (
-               cnc, pri, create_cb, create_user_data, cancellable,
-               e_async_closure_callback, closure);
-
-       result = e_async_closure_wait (closure);
-
-       success = e_ews_connection_update_folder_finish (cnc, result, error);
+       request = e_ews_request_new_with_header (
+               cnc->priv->uri,
+               cnc->priv->impersonate_user,
+               "UpdateFolder",
+               NULL,
+               NULL,
+               cnc->priv->version,
+               E_EWS_EXCHANGE_2007_SP1,
+               FALSE);
 
-       e_async_closure_free (closure);
+       e_soap_request_start_element (request, "FolderChanges", "messages", NULL);
 
-       return success;
-}
+       if (!create_cb (request, create_user_data, error)) {
+               g_clear_obejct (&request);
+               return FALSE;
+       }
 
-static void
-move_folder_response_cb (ESoapResponse *response,
-                         GSimpleAsyncResult *simple)
-{
-       ESoapParameter *param;
-       ESoapParameter *subparam;
-       GError *error = NULL;
+       e_soap_request_end_element (request); /* FolderChanges */
 
-       param = e_soap_response_get_first_parameter_by_name (
-               response, "ResponseMessages", &error);
+       e_ews_request_write_footer (request);
 
-       /* Sanity check */
-       g_return_if_fail (
-               (param != NULL && error == NULL) ||
-               (param == NULL && error != NULL));
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
 
-       if (error != NULL) {
-               g_simple_async_result_take_error (simple, error);
-               return;
+       if (!response) {
+               g_clear_object (&request);
+               return FALSE;
        }
 
-       subparam = e_soap_parameter_get_first_child (param);
+       success = e_ews_process_generic_response (cnc, response, error);
 
-       while (subparam != NULL) {
-               if (!ews_get_response_status (subparam, &error)) {
-                       g_simple_async_result_take_error (simple, error);
-                       return;
-               }
+       g_clear_object (&request);
+       g_clear_object (&response);
 
-               subparam = e_soap_parameter_get_next_child (subparam);
-       }
+       return success;
 }
 
-void
-e_ews_connection_move_folder (EEwsConnection *cnc,
-                              gint pri,
-                              const gchar *to_folder,
-                              const gchar *folder,
-                              GCancellable *cancellable,
-                              GAsyncReadyCallback callback,
-                              gpointer user_data)
+gboolean
+e_ews_connection_move_folder_sync (EEwsConnection *cnc,
+                                   gint pri,
+                                   const gchar *to_folder,
+                                   const gchar *folder,
+                                   GCancellable *cancellable,
+                                   GError **error)
 {
        ESoapRequest *request;
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
+       ESoapResponse *response;
+       gboolean success;
 
-       g_return_if_fail (cnc != NULL);
+       g_return_val_if_fail (cnc != NULL, FALSE);
 
        request = e_ews_request_new_with_header (
                cnc->priv->uri,
@@ -6778,86 +5639,92 @@ e_ews_connection_move_folder (EEwsConnection *cnc,
 
        e_ews_request_write_footer (request);
 
-       simple = g_simple_async_result_new (
-               G_OBJECT (cnc), callback, user_data,
-               e_ews_connection_move_folder);
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
 
-       async_data = g_slice_new0 (EwsAsyncData);
-       g_simple_async_result_set_op_res_gpointer (
-               simple, async_data, (GDestroyNotify) async_data_free);
+       if (!response) {
+               g_clear_object (&request);
+               return FALSE;
+       }
 
-       e_ews_connection_queue_request (
-               cnc, request, move_folder_response_cb,
-               pri, cancellable, simple);
+       success = e_ews_process_generic_response (cnc, response, error);
 
-       g_object_unref (simple);
+       g_clear_object (&request);
+       g_clear_object (&response);
+
+       return success;
 }
 
-gboolean
-e_ews_connection_move_folder_finish (EEwsConnection *cnc,
-                                     GAsyncResult *result,
-                                     GError **error)
+static gboolean
+e_ews_process_get_folder_response (EEwsConnection *cnc,
+                                  ESoapResponse *response,
+                                  GSList **out_folders, /* EEwsFolder * */
+                                  GError **error)
 {
-       GSimpleAsyncResult *simple;
+       ESoapParameter *param;
+       ESoapParameter *subparam;
+       GError *local_error = NULL;
 
-       g_return_val_if_fail (cnc != NULL, FALSE);
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (
-               result, G_OBJECT (cnc), e_ews_connection_move_folder),
-               FALSE);
+       param = e_soap_response_get_first_parameter_by_name (response, "ResponseMessages", &local_error);
 
-       simple = G_SIMPLE_ASYNC_RESULT (result);
+       /* Sanity check */
+       g_return_val_if_fail (
+               (param != NULL && local_error == NULL) ||
+               (param == NULL && local_error != NULL), FALSE);
 
-       if (g_simple_async_result_propagate_error (simple, error))
+       if (local_error != NULL) {
+               g_propagate_error (error, local_error);
                return FALSE;
+       }
 
-       return TRUE;
-}
-
-gboolean
-e_ews_connection_move_folder_sync (EEwsConnection *cnc,
-                                   gint pri,
-                                   const gchar *to_folder,
-                                   const gchar *folder,
-                                   GCancellable *cancellable,
-                                   GError **error)
-{
-       EAsyncClosure *closure;
-       GAsyncResult *result;
-       gboolean success;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-
-       closure = e_async_closure_new ();
-
-       e_ews_connection_move_folder (
-               cnc, pri, to_folder, folder, cancellable,
-               e_async_closure_callback, closure);
+       subparam = e_soap_parameter_get_first_child (param);
 
-       result = e_async_closure_wait (closure);
+       while (subparam != NULL) {
+               const gchar *name = (const gchar *) subparam->name;
 
-       success = e_ews_connection_move_folder_finish (cnc, result, error);
+               if (!ews_get_response_status (subparam, &local_error)) {
+                       if (g_strcmp0 (name, "GetFolderResponseMessage") == 0) {
+                               if (out_folders)
+                                       *out_folders = g_slist_prepend (*out_folders, 
e_ews_folder_new_from_error (local_error));
+                               g_clear_error (&local_error);
+                       } else {
+                               g_propagate_error (error, local_error);
+                               return FALSE;
+                       }
+               } else if (E_EWS_CONNECTION_UTILS_CHECK_ELEMENT (name, "GetFolderResponseMessage") && 
out_folders) {
+                       ESoapParameter *node;
+                       EEwsFolder *folder;
+
+                       for (node = e_soap_parameter_get_first_child_by_name (subparam, "Folders");
+                            node;
+                            node = e_soap_parameter_get_next_child_by_name (subparam, "Folders")) {
+                               folder = e_ews_folder_new_from_soap_parameter (node);
+                               if (!folder)
+                                       continue;
+                               *out_folders = g_slist_prepend (*out_folders, folder);
+                       }
+               }
 
-       e_async_closure_free (closure);
+               subparam = e_soap_parameter_get_next_child (subparam);
+       }
 
-       return success;
+       return TRUE;
 }
 
-void
-e_ews_connection_get_folder (EEwsConnection *cnc,
-                             gint pri,
-                             const gchar *folder_shape,
-                             const EEwsAdditionalProps *add_props,
-                             GSList *folder_ids,
-                             GCancellable *cancellable,
-                             GAsyncReadyCallback callback,
-                             gpointer user_data)
+gboolean
+e_ews_connection_get_folder_sync (EEwsConnection *cnc,
+                                  gint pri,
+                                  const gchar *folder_shape,
+                                  const EEwsAdditionalProps *add_props,
+                                  GSList *folder_ids,
+                                  GSList **out_folders,
+                                  GCancellable *cancellable,
+                                  GError **error)
 {
        ESoapRequest *request;
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
+       ESoapResponse *response;
+       gboolean success;
 
-       g_return_if_fail (cnc != NULL);
+       g_return_val_if_fail (cnc != NULL, FALSE);
 
        request = e_ews_request_new_with_header (
                cnc->priv->uri,
@@ -6883,102 +5750,128 @@ e_ews_connection_get_folder (EEwsConnection *cnc,
 
        e_ews_request_write_footer (request);
 
-       simple = g_simple_async_result_new (
-               G_OBJECT (cnc), callback, user_data,
-               e_ews_connection_get_folder);
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
 
-       async_data = g_slice_new0 (EwsAsyncData);
-       async_data->cnc = cnc;
-       g_simple_async_result_set_op_res_gpointer (
-               simple, async_data, (GDestroyNotify) async_data_free);
+       if (!response) {
+               g_clear_object (&request);
+               return FALSE;
+       }
+
+       if (out_folders)
+               *out_folders = NULL;
+
+       success = e_ews_process_get_folder_response (cnc, response, out_folders, error);
 
-       e_ews_connection_queue_request (
-               cnc, request, get_folder_response_cb,
-               pri, cancellable, simple);
+       g_clear_object (&request);
+       g_clear_object (&response);
 
-       g_object_unref (simple);
+       if (success && out_folders) {
+               *out_folders = g_slist_reverse (*out_folders);
+       } else if (out_folders) {
+               g_slist_free_full (*out_folders, g_object_unref);
+               *out_folders = NULL;
+       }
+
+       return success;
 }
 
-gboolean
-e_ews_connection_get_folder_finish (EEwsConnection *cnc,
-                                    GAsyncResult *result,
-                                    GSList **folders,
-                                    GError **error)
+static gboolean
+e_ews_process_create_folder_response (EEwsConnecton *cnc,
+                                     ESoapResponse *response,
+                                     EEwsFolderType folder_type,
+                                     GSList *out_folder_ids, /* EwsFolderId * */
+                                     GError **error)
 {
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
+       ESoapParameter *param;
+       ESoapParameter *subparam;
+       GError *local_error = NULL;
 
-       g_return_val_if_fail (cnc != NULL, FALSE);
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (
-               result, G_OBJECT (cnc), e_ews_connection_get_folder),
-               FALSE);
+       *out_folder_ids = NULL;
 
-       simple = G_SIMPLE_ASYNC_RESULT (result);
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
+       param = e_soap_response_get_first_parameter_by_name (response, "ResponseMessages", &local_error);
 
-       if (g_simple_async_result_propagate_error (simple, error))
-               return FALSE;
+       /* Sanity check */
+       g_return_val_if_fail (
+               (param != NULL && local_error == NULL) ||
+               (param == NULL && local_error != NULL), FALSE);
 
-       if (folders != NULL)
-               *folders = async_data->items;
-       else
-               g_slist_free_full (async_data->items, g_object_unref);
+       if (local_error) {
+               g_propagate_error (error, local_error);
+               return;
+       }
 
-       return TRUE;
-}
+       subparam = e_soap_parameter_get_first_child (param);
 
-gboolean
-e_ews_connection_get_folder_sync (EEwsConnection *cnc,
-                                  gint pri,
-                                  const gchar *folder_shape,
-                                  const EEwsAdditionalProps *add_props,
-                                  GSList *folder_ids,
-                                  GSList **folders,
-                                  GCancellable *cancellable,
-                                  GError **error)
-{
-       EAsyncClosure *closure;
-       GAsyncResult *result;
-       gboolean success;
+       while (subparam != NULL) {
+               const gchar *name = (const gchar *) subparam->name;
 
-       g_return_val_if_fail (cnc != NULL, FALSE);
+               if (!ews_get_response_status (subparam, error))
+                       return FALSE;
 
-       closure = e_async_closure_new ();
+               if (E_EWS_CONNECTION_UTILS_CHECK_ELEMENT (name, "CreateFolderResponseMessage")) {
+                       ESoapParameter *param, *node;
+                       EwsFolderId *fid = NULL;
+                       GSList *fids = NULL;
+                       const gchar *folder_element;
 
-       e_ews_connection_get_folder (
-               cnc, pri, folder_shape, add_props,
-               folder_ids, cancellable,
-               e_async_closure_callback, closure);
+                       switch (folder_type) {
+                               case E_EWS_FOLDER_TYPE_MAILBOX:
+                               case E_EWS_FOLDER_TYPE_MEMOS:
+                                       folder_element = "Folder";
+                                       break;
+                               case E_EWS_FOLDER_TYPE_CALENDAR:
+                                       folder_element = "CalendarFolder";
+                                       break;
+                               case E_EWS_FOLDER_TYPE_CONTACTS:
+                                       folder_element = "ContactsFolder";
+                                       break;
+                               case E_EWS_FOLDER_TYPE_SEARCH:
+                                       folder_element = "SearchFolder";
+                                       break;
+                               case E_EWS_FOLDER_TYPE_TASKS:
+                                       folder_element = "TasksFolder";
+                                       break;
+                               default:
+                                       g_warn_if_reached ();
+                                       folder_element = "Folder";
+                                       break;
+                       }
 
-       result = e_async_closure_wait (closure);
+                       node = e_soap_parameter_get_first_child_by_name (soapparam, "Folders");
+                       node = e_soap_parameter_get_first_child_by_name (node, folder_element);
+                       param = e_soap_parameter_get_first_child_by_name (node, "FolderId");
 
-       success = e_ews_connection_get_folder_finish (
-               cnc, result, folders, error);
+                       fid = g_new0 (EwsFolderId, 1);
+                       fid->id = e_soap_parameter_get_property (param, "Id");
+                       fid->change_key = e_soap_parameter_get_property (param, "ChangeKey");
+                       *out_folder_ids = g_slist_prepend (*out_folder_ids, fid);
+               }
 
-       e_async_closure_free (closure);
+               subparam = e_soap_parameter_get_next_child (subparam);
+       }
 
-       return success;
+       return *out_folder_ids != NULL;
 }
 
-void
-e_ews_connection_create_folder (EEwsConnection *cnc,
-                                gint pri,
-                                const gchar *parent_folder_id,
-                                gboolean is_distinguished_id,
-                                const gchar *folder_name,
-                                EEwsFolderType folder_type,
-                                GCancellable *cancellable,
-                                GAsyncReadyCallback callback,
-                                gpointer user_data)
+gboolean
+e_ews_connection_create_folder_sync (EEwsConnection *cnc,
+                                     gint pri,
+                                     const gchar *parent_folder_id,
+                                     gboolean is_distinguished_id,
+                                     const gchar *folder_name,
+                                     EEwsFolderType folder_type,
+                                     EwsFolderId **out_folder_id,
+                                     GCancellable *cancellable,
+                                     GError **error)
 {
        ESoapRequest *request;
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
+       ESoapResponse *response;
+       GSList *folder_ids = NULL;
        const gchar *folder_element;
        const gchar *folder_class;
+       gboolean success;
 
-       g_return_if_fail (cnc != NULL);
+       g_return_val_if_fail (cnc != NULL, FALSE);
 
        request = e_ews_request_new_with_header (
                cnc->priv->uri,
@@ -7048,101 +5941,51 @@ e_ews_connection_create_folder (EEwsConnection *cnc,
 
        e_ews_request_write_footer (request);
 
-       simple = g_simple_async_result_new (
-               G_OBJECT (cnc), callback, user_data,
-               e_ews_connection_create_folder);
-
-       async_data = g_slice_new0 (EwsAsyncData);
-       async_data->folder_type = folder_type;
-
-       g_simple_async_result_set_op_res_gpointer (
-               simple, async_data, (GDestroyNotify) async_data_free);
-
-       e_ews_connection_queue_request (
-               cnc, request, create_folder_response_cb,
-               pri, cancellable, simple);
-
-       g_object_unref (simple);
-}
-
-gboolean
-e_ews_connection_create_folder_finish (EEwsConnection *cnc,
-                                       GAsyncResult *result,
-                                       EwsFolderId **fid,
-                                       GError **error)
-{
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (
-               result, G_OBJECT (cnc), e_ews_connection_create_folder),
-               FALSE);
-
-       simple = G_SIMPLE_ASYNC_RESULT (result);
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
 
-       if (g_simple_async_result_propagate_error (simple, error))
+       if (!response) {
+               g_clear_object (&request);
                return FALSE;
+       }
 
-       *fid = (EwsFolderId *) async_data->items_created->data;
-       g_slist_free (async_data->items_created);
-
-       return TRUE;
-}
-
-gboolean
-e_ews_connection_create_folder_sync (EEwsConnection *cnc,
-                                     gint pri,
-                                     const gchar *parent_folder_id,
-                                     gboolean is_distinguished_id,
-                                     const gchar *folder_name,
-                                     EEwsFolderType folder_type,
-                                     EwsFolderId **folder_id,
-                                     GCancellable *cancellable,
-                                     GError **error)
-{
-       EAsyncClosure *closure;
-       GAsyncResult *result;
-       gboolean success;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
+       success = e_ews_process_create_folder_response (cnc, response, folder_type, &folder_ids, error);
 
-       closure = e_async_closure_new ();
+       g_clear_object (&request);
+       g_clear_object (&response);
 
-       e_ews_connection_create_folder (
-               cnc, pri, parent_folder_id,
-               is_distinguished_id, folder_name,
-               folder_type, cancellable,
-               e_async_closure_callback, closure);
+       if (success) {
+               folder_ids = g_slist_reverse (folder_ids);
+               g_warn_if_fail (g_slist_length (folder_ids) <= 1);
 
-       result = e_async_closure_wait (closure);
+               if (out_folder_id)
+                       *out_folder_id = folder_ids ? folder_ids->data : NULL;
 
-       success = e_ews_connection_create_folder_finish (
-               cnc, result, folder_id, error);
+               if (folder_ids && out_folder_id)
+                       folder_ids->data = NULL;
+       }
 
-       e_async_closure_free (closure);
+       g_slist_free_full (folder_ids, (GDestroyNotify) e_ews_folder_id_free);
 
        return success;
 }
 
-void
-e_ews_connection_move_items (EEwsConnection *cnc,
-                             gint pri,
-                             const gchar *folder_id,
-                             gboolean docopy,
-                             const GSList *ids,
-                             GCancellable *cancellable,
-                             GAsyncReadyCallback callback,
-                             gpointer user_data)
+gboolean
+e_ews_connection_move_items_sync (EEwsConnection *cnc,
+                                  gint pri,
+                                  const gchar *folder_id,
+                                  gboolean docopy,
+                                  const GSList *ids,
+                                  GSList **out_items,
+                                  GCancellable *cancellable,
+                                  GError **error)
 {
        ESoapRequest *request;
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
-       const GSList *iter;
+       ESoapResponse *response;
+       const GSList *link;
+       GSList *items = NULL;
+       gboolean success;
 
-       g_return_if_fail (cnc != NULL);
+       g_return_val_if_fail (cnc != NULL, FALSE);
 
        if (docopy)
                request = e_ews_request_new_with_header (
@@ -7172,96 +6015,29 @@ e_ews_connection_move_items (EEwsConnection *cnc,
        e_soap_request_end_element (request); /* ToFolderId */
 
        e_soap_request_start_element (request, "ItemIds", "messages", NULL);
-       for (iter = ids; iter != NULL; iter = g_slist_next (iter))
-               e_ews_request_write_string_parameter_with_attribute (request, "ItemId", NULL, NULL, "Id", 
iter->data);
+       for (link = ids; link; link = g_slist_next (link)) {
+               e_ews_request_write_string_parameter_with_attribute (request, "ItemId", NULL, NULL, "Id", 
link->data);
+       }
        e_soap_request_end_element (request); /* ItemIds */
 
        e_ews_request_write_footer (request);
 
-       simple = g_simple_async_result_new (
-               G_OBJECT (cnc), callback, user_data,
-               e_ews_connection_move_items);
-
-       async_data = g_slice_new0 (EwsAsyncData);
-       g_simple_async_result_set_op_res_gpointer (
-               simple, async_data, (GDestroyNotify) async_data_free);
-
-       e_ews_connection_queue_request (
-               cnc, request, get_items_response_cb,
-               pri, cancellable, simple);
-
-       g_object_unref (simple);
-}
-
-gboolean
-e_ews_connection_move_items_finish (EEwsConnection *cnc,
-                                    GAsyncResult *result,
-                                    GSList **items,
-                                    GError **error)
-{
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (
-               result, G_OBJECT (cnc), e_ews_connection_move_items),
-               FALSE);
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
 
-       simple = G_SIMPLE_ASYNC_RESULT (result);
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
-
-       if (g_simple_async_result_propagate_error (simple, error))
+       if (!response) {
+               g_clear_object (&request);
                return FALSE;
-
-       /* if there is only one item, then check whether it's an error */
-       if (async_data->items && !async_data->items->next) {
-               EEwsItem *item = async_data->items->data;
-
-               if (item && e_ews_item_get_item_type (item) == E_EWS_ITEM_TYPE_ERROR) {
-                       if (error)
-                               *error = g_error_copy (e_ews_item_get_error (item));
-
-                       g_slist_free_full (async_data->items, g_object_unref);
-                       async_data->items = NULL;
-
-                       return FALSE;
-               }
        }
 
-       *items = async_data->items;
+       success = e_ews_process_get_items_response (cnc, response, &items, error);
 
-       return TRUE;
-}
-
-gboolean
-e_ews_connection_move_items_sync (EEwsConnection *cnc,
-                                  gint pri,
-                                  const gchar *folder_id,
-                                  gboolean docopy,
-                                  const GSList *ids,
-                                  GSList **items,
-                                  GCancellable *cancellable,
-                                  GError **error)
-{
-       EAsyncClosure *closure;
-       GAsyncResult *result;
-       gboolean success;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-
-       closure = e_async_closure_new ();
-
-       e_ews_connection_move_items (
-               cnc, pri, folder_id, docopy, ids, cancellable,
-               e_async_closure_callback, closure);
-
-       result = e_async_closure_wait (closure);
-
-       success = e_ews_connection_move_items_finish (
-               cnc, result, items, error);
+       g_clear_object (&request);
+       g_clear_object (&response);
 
-       e_async_closure_free (closure);
+       if (success && out_items)
+               *out_items = items;
+       else
+               g_slist_free_full (items, g_object_unref);
 
        return success;
 }
@@ -7335,143 +6111,6 @@ e_ews_connection_move_items_in_chunks_sync (EEwsConnection *cnc,
        return success;
 }
 
-static void
-delete_folder_response_cb (ESoapResponse *response,
-                           GSimpleAsyncResult *simple)
-{
-       ESoapParameter *param;
-       ESoapParameter *subparam;
-       GError *error = NULL;
-
-       param = e_soap_response_get_first_parameter_by_name (
-               response, "ResponseMessages", &error);
-
-       /* Sanity check */
-       g_return_if_fail (
-               (param != NULL && error == NULL) ||
-               (param == NULL && error != NULL));
-
-       if (error != NULL) {
-               g_simple_async_result_take_error (simple, error);
-               return;
-       }
-
-       subparam = e_soap_parameter_get_first_child (param);
-
-       while (subparam != NULL) {
-               if (!ews_get_response_status (subparam, &error)) {
-                       g_simple_async_result_take_error (simple, error);
-                       return;
-               }
-
-               subparam = e_soap_parameter_get_next_child (subparam);
-       }
-}
-
-/**
- * e_ews_connection_delete_folder:
- * @cnc:
- * @pri:
- * @folder_id: folder to be deleted
- * @is_distinguished_id:
- * @delete_type: "HardDelete", "SoftDelete", "MoveToDeletedItems"
- * @cancellable:
- * @callback:
- * @user_data:
- **/
-void
-e_ews_connection_delete_folder (EEwsConnection *cnc,
-                                gint pri,
-                                const gchar *folder_id,
-                                gboolean is_distinguished_id,
-                                const gchar *delete_type,
-                                GCancellable *cancellable,
-                                GAsyncReadyCallback callback,
-                                gpointer user_data)
-{
-       ESoapRequest *request;
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
-
-       g_return_if_fail (cnc != NULL);
-
-       request = e_ews_request_new_with_header (
-               cnc->priv->uri,
-               cnc->priv->impersonate_user,
-               "DeleteFolder",
-               "DeleteType",
-               delete_type,
-               cnc->priv->version,
-               E_EWS_EXCHANGE_2007_SP1,
-               FALSE);
-
-       e_soap_request_start_element (request, "FolderIds", "messages", NULL);
-
-       e_soap_request_start_element (request,
-                       is_distinguished_id ? "DistinguishedFolderId" : "FolderId",
-                       NULL,
-                       NULL);
-       e_soap_request_add_attribute (request, "Id", folder_id, NULL, NULL);
-
-       /* This element is required for delegate access */
-       if (is_distinguished_id && cnc->priv->email) {
-               e_soap_request_start_element (request, "Mailbox", NULL, NULL);
-               e_ews_request_write_string_parameter (request, "EmailAddress", NULL, cnc->priv->email);
-               e_soap_request_end_element (request);
-       }
-
-       e_soap_request_end_element (request); /* </DistinguishedFolderId> || </FolderId> */
-
-       e_soap_request_end_element (request); /* </FolderIds> */
-
-       e_ews_request_write_footer (request);
-
-       simple = g_simple_async_result_new (
-               G_OBJECT (cnc), callback, user_data,
-               e_ews_connection_delete_folder);
-
-       async_data = g_slice_new0 (EwsAsyncData);
-       g_simple_async_result_set_op_res_gpointer (
-               simple, async_data, (GDestroyNotify) async_data_free);
-
-       e_ews_connection_queue_request (
-               cnc, request, delete_folder_response_cb,
-               pri, cancellable, simple);
-
-       g_object_unref (simple);
-}
-
-gboolean
-e_ews_connection_delete_folder_finish (EEwsConnection *cnc,
-                                       GAsyncResult *result,
-                                       GError **error)
-{
-       GSimpleAsyncResult *simple;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (
-               result, G_OBJECT (cnc), e_ews_connection_delete_folder),
-               FALSE);
-
-       simple = G_SIMPLE_ASYNC_RESULT (result);
-
-       if (g_simple_async_result_propagate_error (simple, error))
-               return FALSE;
-
-       return TRUE;
-}
-
-/**
- * e_ews_connection_delete_folder_sync:
- * @cnc:
- * @pri:
- * @folder_id: folder to be deleted
- * @is_distinguished_id:
- * @delete_type: "HardDelete", "SoftDelete", "MoveToDeletedItems"
- * @cancellable:
- * @error:
- **/
 gboolean
 e_ews_connection_delete_folder_sync (EEwsConnection *cnc,
                                      gint pri,
@@ -7480,93 +6119,23 @@ e_ews_connection_delete_folder_sync (EEwsConnection *cnc,
                                      const gchar *delete_type,
                                      GCancellable *cancellable,
                                      GError **error)
-{
-       EAsyncClosure *closure;
-       GAsyncResult *result;
-       gboolean success;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-
-       closure = e_async_closure_new ();
-
-       e_ews_connection_delete_folder (
-               cnc, pri, folder_id,
-               is_distinguished_id,
-               delete_type,
-               cancellable,
-               e_async_closure_callback, closure);
-
-       result = e_async_closure_wait (closure);
-
-       success = e_ews_connection_delete_folder_finish (cnc, result, error);
-
-       e_async_closure_free (closure);
-
-       return success;
-}
-
-static void
-empty_folder_response_cb (ESoapResponse *response,
-                         GSimpleAsyncResult *simple)
-{
-       ESoapParameter *param;
-       ESoapParameter *subparam;
-       GError *error = NULL;
-
-       param = e_soap_response_get_first_parameter_by_name (
-               response, "ResponseMessages", &error);
-
-       /* Sanity check */
-       g_return_if_fail (
-               (param != NULL && error == NULL) ||
-               (param == NULL && error != NULL));
-
-       if (error != NULL) {
-               g_simple_async_result_take_error (simple, error);
-               return;
-       }
-
-       subparam = e_soap_parameter_get_first_child (param);
-
-       while (subparam != NULL) {
-               if (!ews_get_response_status (subparam, &error)) {
-                       g_simple_async_result_take_error (simple, error);
-                       return;
-               }
-
-               subparam = e_soap_parameter_get_next_child (subparam);
-       }
-}
-
-void
-e_ews_connection_empty_folder (EEwsConnection *cnc,
-                              gint pri,
-                              const gchar *folder_id,
-                              gboolean is_distinguished_id,
-                              const gchar *delete_type,
-                              gboolean delete_subfolders,
-                              GCancellable *cancellable,
-                              GAsyncReadyCallback callback,
-                              gpointer user_data)
 {
        ESoapRequest *request;
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
+       ESoapResponse *response;
+       gboolean success;
 
-       g_return_if_fail (cnc != NULL);
+       g_return_val_if_fail (cnc != NULL, FALSE);
 
        request = e_ews_request_new_with_header (
                cnc->priv->uri,
                cnc->priv->impersonate_user,
-               "EmptyFolder",
+               "DeleteFolder",
                "DeleteType",
                delete_type,
                cnc->priv->version,
-               E_EWS_EXCHANGE_2010,
+               E_EWS_EXCHANGE_2007_SP1,
                FALSE);
 
-       e_soap_request_add_attribute (request, "DeleteSubFolders", delete_subfolders ? "true" : "false", 
NULL, NULL);
-
        e_soap_request_start_element (request, "FolderIds", "messages", NULL);
 
        e_soap_request_start_element (request,
@@ -7588,40 +6157,19 @@ e_ews_connection_empty_folder (EEwsConnection *cnc,
 
        e_ews_request_write_footer (request);
 
-       simple = g_simple_async_result_new (
-               G_OBJECT (cnc), callback, user_data,
-               e_ews_connection_empty_folder);
-
-       async_data = g_slice_new0 (EwsAsyncData);
-       g_simple_async_result_set_op_res_gpointer (
-               simple, async_data, (GDestroyNotify) async_data_free);
-
-       e_ews_connection_queue_request (
-               cnc, request, empty_folder_response_cb,
-               pri, cancellable, simple);
-
-       g_object_unref (simple);
-}
-
-gboolean
-e_ews_connection_empty_folder_finish (EEwsConnection *cnc,
-                                     GAsyncResult *result,
-                                     GError **error)
-{
-       GSimpleAsyncResult *simple;
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
 
-       g_return_val_if_fail (cnc != NULL, FALSE);
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (
-               result, G_OBJECT (cnc), e_ews_connection_empty_folder),
-               FALSE);
+       if (!response) {
+               g_clear_object (&request);
+               return FALSE;
+       }
 
-       simple = G_SIMPLE_ASYNC_RESULT (result);
+       success = e_ews_process_generic_response (cnc, response, error);
 
-       if (g_simple_async_result_propagate_error (simple, error))
-               return FALSE;
+       g_clear_object (&request);
+       g_clear_object (&response);
 
-       return TRUE;
+       return success;
 }
 
 gboolean
@@ -7634,76 +6182,81 @@ e_ews_connection_empty_folder_sync (EEwsConnection *cnc,
                                    GCancellable *cancellable,
                                    GError **error)
 {
-       EAsyncClosure *closure;
-       GAsyncResult *result;
+       ESoapRequest *request;
+       ESoapResponse *response;
        gboolean success;
 
        g_return_val_if_fail (cnc != NULL, FALSE);
 
-       closure = e_async_closure_new ();
-
-       e_ews_connection_empty_folder (
-               cnc, pri, folder_id,
-               is_distinguished_id,
+       request = e_ews_request_new_with_header (
+               cnc->priv->uri,
+               cnc->priv->impersonate_user,
+               "EmptyFolder",
+               "DeleteType",
                delete_type,
-               delete_subfolder,
-               cancellable,
-               e_async_closure_callback, closure);
+               cnc->priv->version,
+               E_EWS_EXCHANGE_2010,
+               FALSE);
 
-       result = e_async_closure_wait (closure);
+       e_soap_request_add_attribute (request, "DeleteSubFolders", delete_subfolders ? "true" : "false", 
NULL, NULL);
 
-       success = e_ews_connection_empty_folder_finish (cnc, result, error);
+       e_soap_request_start_element (request, "FolderIds", "messages", NULL);
 
-       e_async_closure_free (closure);
+       e_soap_request_start_element (request,
+                       is_distinguished_id ? "DistinguishedFolderId" : "FolderId",
+                       NULL,
+                       NULL);
+       e_soap_request_add_attribute (request, "Id", folder_id, NULL, NULL);
 
-       return success;
-}
+       /* This element is required for delegate access */
+       if (is_distinguished_id && cnc->priv->email) {
+               e_soap_request_start_element (request, "Mailbox", NULL, NULL);
+               e_ews_request_write_string_parameter (request, "EmailAddress", NULL, cnc->priv->email);
+               e_soap_request_end_element (request);
+       }
 
-static void
-ews_handle_create_attachments_param (ESoapParameter *param,
-                                     EwsAsyncData *async_data)
-{
-       /* http://msdn.microsoft.com/en-us/library/aa565877%28v=EXCHG.80%29.aspx */
-       ESoapParameter *subparam, *attspara, *last_relevant = NULL, *attparam;
+       e_soap_request_end_element (request); /* </DistinguishedFolderId> || </FolderId> */
 
-       attspara = e_soap_parameter_get_first_child_by_name (param, "Attachments");
+       e_soap_request_end_element (request); /* </FolderIds> */
 
-       for (subparam = e_soap_parameter_get_first_child (attspara); subparam != NULL; subparam = 
e_soap_parameter_get_next_child (subparam)) {
-               if (!g_ascii_strcasecmp (e_soap_parameter_get_name (subparam), "FileAttachment")) {
-                       attparam = e_soap_parameter_get_first_child (subparam);
-                       last_relevant = attparam;
+       e_ews_request_write_footer (request);
 
-                       async_data->items = g_slist_append (async_data->items, e_soap_parameter_get_property 
(attparam, "Id"));
-               }
-       }
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
 
-       if (last_relevant != NULL) {
-               async_data->sync_state = e_soap_parameter_get_property (last_relevant, "RootItemChangeKey");
+       if (!response) {
+               g_clear_object (&request);
+               return FALSE;
        }
+
+       success = e_ews_process_generic_response (cnc, response, error);
+
+       g_clear_object (&request);
+       g_clear_object (&response);
+
+       return success;
 }
 
-static void
-create_attachments_response_cb (ESoapResponse *response,
-                                GSimpleAsyncResult *simple)
+static gboolean
+e_ews_process_create_attachments_response (EEwsConnection *cnc,
+                                          ESoapResponse *response,
+                                          gchar **out_change_key,
+                                          GSList **out_attachments_ids,
+                                          GError **error)
 {
-       EwsAsyncData *async_data;
        ESoapParameter *param;
        ESoapParameter *subparam;
-       GError *error = NULL;
-
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
+       GError *local_error = NULL;
 
-       param = e_soap_response_get_first_parameter_by_name (
-               response, "ResponseMessages", &error);
+       param = e_soap_response_get_first_parameter_by_name (response, "ResponseMessages", &local_error);
 
        /* Sanity check */
-       g_return_if_fail (
-               (param != NULL && error == NULL) ||
-               (param == NULL && error != NULL));
+       g_return_val_if_fail (
+               (param != NULL && local_error == NULL) ||
+               (param == NULL && local_error != NULL), FALSE);
 
-       if (error != NULL) {
-               g_simple_async_result_take_error (simple, error);
-               return;
+       if (local_error) {
+               g_propagate_error (error, local_error);
+               return FALSE;
        }
 
        subparam = e_soap_parameter_get_first_child (param);
@@ -7711,16 +6264,35 @@ create_attachments_response_cb (ESoapResponse *response,
        while (subparam != NULL) {
                const gchar *name = (const gchar *) subparam->name;
 
-               if (!ews_get_response_status (subparam, &error)) {
-                       g_simple_async_result_take_error (simple, error);
-                       return;
-               }
+               if (!ews_get_response_status (subparam, error))
+                       return FALSE;
 
-               if (E_EWS_CONNECTION_UTILS_CHECK_ELEMENT (name, "CreateAttachmentResponseMessage"))
-                       ews_handle_create_attachments_param (subparam, async_data);
+               if (E_EWS_CONNECTION_UTILS_CHECK_ELEMENT (name, "CreateAttachmentResponseMessage")) {
+                       /* http://msdn.microsoft.com/en-us/library/aa565877%28v=EXCHG.80%29.aspx */
+                       ESoapParameter *subparam, *attspara, *last_relevant = NULL, *attparam;
+
+                       attspara = e_soap_parameter_get_first_child_by_name (param, "Attachments");
+
+                       for (subparam = e_soap_parameter_get_first_child (attspara); subparam != NULL; 
subparam = e_soap_parameter_get_next_child (subparam)) {
+                               if (!g_ascii_strcasecmp (e_soap_parameter_get_name (subparam), 
"FileAttachment")) {
+                                       attparam = e_soap_parameter_get_first_child (subparam);
+                                       last_relevant = attparam;
+
+                                       if (out_attachments_ids)
+                                               *out_attachments_ids = g_slist_prepend (*out_attachments_ids, 
e_soap_parameter_get_property (attparam, "Id"));
+                               }
+                       }
+
+                       if (last_relevant != NULL && out_change_key) {
+                               g_free (*out_change_key);
+                               *out_change_key = e_soap_parameter_get_property (last_relevant, 
"RootItemChangeKey");
+                       }
+               }
 
                subparam = e_soap_parameter_get_next_child (subparam);
        }
+
+       return TRUE;
 }
 
 static gboolean
@@ -7793,32 +6365,30 @@ e_ews_connection_attach_file (ESoapRequest *request,
        return TRUE;
 }
 
-void
-e_ews_connection_create_attachments (EEwsConnection *cnc,
-                                     gint pri,
-                                     const EwsId *parent,
-                                     const GSList *files,
-                                    gboolean is_contact_photo,
-                                     GCancellable *cancellable,
-                                     GAsyncReadyCallback callback,
-                                     gpointer user_data)
+gboolean
+e_ews_connection_create_attachments_sync (EEwsConnection *cnc,
+                                         gint pri,
+                                         const EwsId *parent,
+                                         const GSList *files,
+                                         gboolean is_contact_photo,
+                                         gchar **out_change_key,
+                                         GSList **out_attachments_ids,
+                                         GCancellable *cancellable,
+                                         GError **error)
 {
        ESoapRequest *request;
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
-       const GSList *l;
-       GError *local_error = NULL;
+       ESoapResponse *response;
+       const GSList *link;
+       gboolean success;
 
-       g_return_if_fail (cnc != NULL);
-       g_return_if_fail (parent != NULL);
+       g_return_val_if_fail (cnc != NULL, FALSE);
+       g_return_val_if_fail (parent != NULL, FALSE);
 
-       simple = g_simple_async_result_new (
-               G_OBJECT (cnc), callback, user_data,
-               e_ews_connection_create_attachments);
+       if (out_change_key)
+               *out_change_key = NULL;
 
-       async_data = g_slice_new0 (EwsAsyncData);
-       g_simple_async_result_set_op_res_gpointer (
-               simple, async_data, (GDestroyNotify) async_data_free);
+       if (out_attachments_ids)
+               *out_attachments_ids = NULL;
 
        request = e_ews_request_new_with_header (
                cnc->priv->uri,
@@ -7839,135 +6409,68 @@ e_ews_connection_create_attachments (EEwsConnection *cnc,
        /* start interation over all items to get the attachemnts */
        e_soap_request_start_element (request, "Attachments", "messages", NULL);
 
-       for (l = files; l != NULL; l = g_slist_next (l))
-               if (!e_ews_connection_attach_file (request, l->data, is_contact_photo, &local_error)) {
-                       if (local_error != NULL)
-                               g_simple_async_result_take_error (simple, local_error);
-                       g_simple_async_result_complete_in_idle (simple);
-                       g_object_unref (simple);
-
-                       return;
+       for (link = files; link; link = g_slist_next (link)) {
+               if (!e_ews_connection_attach_file (request, link->data, is_contact_photo, error)) {
+                       g_clear_obejct (&request);
+                       return FALSE;
                }
+       }
 
        e_soap_request_end_element (request); /* "Attachments" */
 
        e_ews_request_write_footer (request);
 
-       e_ews_connection_queue_request (
-               cnc, request, create_attachments_response_cb,
-               pri, cancellable, simple);
-
-       g_object_unref (simple);
-}
-
-gboolean
-e_ews_connection_create_attachments_finish (EEwsConnection *cnc,
-                                            gchar **change_key,
-                                           GSList **attachments_ids,
-                                            GAsyncResult *result,
-                                            GError **error)
-{
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (
-               result, G_OBJECT (cnc), e_ews_connection_create_attachments),
-               FALSE);
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
 
-       simple = G_SIMPLE_ASYNC_RESULT (result);
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
-
-       if (g_simple_async_result_propagate_error (simple, error))
+       if (!response) {
+               g_clear_object (&request);
                return FALSE;
+       }
 
-       if (attachments_ids)
-               *attachments_ids = async_data->items;
-       else
-               g_slist_free_full (async_data->items, g_free);
-
-       if (change_key)
-               *change_key = async_data->sync_state;
-       else
-               g_free (async_data->sync_state);
-
-       return TRUE;
-}
-
-gboolean
-e_ews_connection_create_attachments_sync (EEwsConnection *cnc,
-                                          gint pri,
-                                          const EwsId *parent,
-                                          const GSList *files,
-                                         gboolean is_contact_photo,
-                                          gchar **change_key,
-                                         GSList **attachments_ids,
-                                          GCancellable *cancellable,
-                                          GError **error)
-{
-       EAsyncClosure *closure;
-       GAsyncResult *result;
-       gboolean ret;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-       g_return_val_if_fail (parent != NULL, FALSE);
-
-       closure = e_async_closure_new ();
-
-       e_ews_connection_create_attachments (
-               cnc, pri, parent, files, is_contact_photo, cancellable,
-               e_async_closure_callback, closure);
+       success = e_ews_process_create_attachments_response (cnc, response, out_change_key, 
out_attachments_ids, error);
 
-       result = e_async_closure_wait (closure);
+       g_clear_object (&request);
+       g_clear_object (&response);
 
-       ret = e_ews_connection_create_attachments_finish (
-               cnc, change_key, attachments_ids, result, error);
+       if (success) {
+               if (out_attachments_ids)
+                       *out_attachments_ids = g_slist_reverse (*out_attachments_ids);
+       } else {
+               if (out_change_key)
+                       g_clear_pointer (out_change_key, g_free);
 
-       e_async_closure_free (closure);
+               if (out_attachments_ids) {
+                       g_slist_free_full (*out_attachments_ids, g_free);
+                       *out_attachments_ids = NULL;
+               }
+       }
 
        return ret;
 }
 
-/* Delete attachemnts */
-static void
-ews_handle_root_item_id_param (ESoapParameter *subparam,
-                               EwsAsyncData *async_data)
-{
-       /* http://msdn.microsoft.com/en-us/library/aa580782%28v=EXCHG.80%29.aspx */
-       ESoapParameter *attspara;
-
-       attspara = e_soap_parameter_get_first_child_by_name (
-               subparam, "RootItemId");
-
-       if (attspara == NULL)
-               return;
-
-       async_data->sync_state = e_soap_parameter_get_property (attspara, "RootItemChangeKey");
-}
-
-static void
-delete_attachments_response_cb (ESoapResponse *response,
-                                GSimpleAsyncResult *simple)
+static gboolean
+e_ews_process_delete_attachments_response (EEwsConnecton *cnc
+                                          ESoapResponse *response,
+                                          gchar **out_new_change_key,
+                                          GError **error)
 {
-       EwsAsyncData *async_data;
        ESoapParameter *param;
        ESoapParameter *subparam;
-       GError *error = NULL;
+       GError *local_error = NULL;
 
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
+       if (out_new_change_key)
+               *out_new_change_key = NULL;
 
-       param = e_soap_response_get_first_parameter_by_name (
-               response, "ResponseMessages", &error);
+       param = e_soap_response_get_first_parameter_by_name (response, "ResponseMessages", &local_error);
 
        /* Sanity check */
-       g_return_if_fail (
-               (param != NULL && error == NULL) ||
-               (param == NULL && error != NULL));
+       g_return_val_if_fail (
+               (param != NULL && local_error == NULL) ||
+               (param == NULL && local_error != NULL), FALSE);
 
-       if (error != NULL) {
-               g_simple_async_result_take_error (simple, error);
-               return;
+       if (local_error) {
+               g_propagate_error (error, local_error);
+               return FALSE;
        }
 
        subparam = e_soap_parameter_get_first_child (param);
@@ -7975,32 +6478,39 @@ delete_attachments_response_cb (ESoapResponse *response,
        while (subparam != NULL) {
                const gchar *name = (const gchar *) subparam->name;
 
-               if (!ews_get_response_status (subparam, &error)) {
-                       g_simple_async_result_take_error (simple, error);
-                       return;
-               }
+               if (!ews_get_response_status (subparam, error))
+                       return FALSE;
 
-               if (E_EWS_CONNECTION_UTILS_CHECK_ELEMENT (name, "DeleteAttachmentResponseMessage"))
-                       ews_handle_root_item_id_param (subparam, async_data);
+               if (E_EWS_CONNECTION_UTILS_CHECK_ELEMENT (name, "DeleteAttachmentResponseMessage")) {
+                       /* http://msdn.microsoft.com/en-us/library/aa580782%28v=EXCHG.80%29.aspx */
+                       ESoapParameter *attspara;
+
+                       attspara = e_soap_parameter_get_first_child_by_name (subparam, "RootItemId");
+
+                       if (attspara != NULL && out_new_change_key)
+                               *out_new_change_key = e_soap_parameter_get_property (attspara, 
"RootItemChangeKey");
+               }
 
                subparam = e_soap_parameter_get_next_child (subparam);
        }
+
+       return TRUE;
 }
 
-void
-e_ews_connection_delete_attachments (EEwsConnection *cnc,
-                                     gint pri,
-                                     const GSList *attachments_ids,
-                                     GCancellable *cancellable,
-                                     GAsyncReadyCallback callback,
-                                     gpointer user_data)
+gboolean
+e_ews_connection_delete_attachments_sync (EEwsConnection *cnc,
+                                          gint pri,
+                                          const GSList *attachments_ids,
+                                         gchar **out_new_change_key,
+                                          GCancellable *cancellable,
+                                          GError **error)
 {
        ESoapRequest *request;
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
-       const GSList *l;
+       ESoapResponse *response;
+       const GSList *link;
+       gboolean success;
 
-       g_return_if_fail (cnc != NULL);
+       g_return_val_if_fail (cnc != NULL, FALSE);
 
        request = e_ews_request_new_with_header (
                cnc->priv->uri,
@@ -8015,143 +6525,57 @@ e_ews_connection_delete_attachments (EEwsConnection *cnc,
        /* start interation over all items to get the attachemnts */
        e_soap_request_start_element (request, "AttachmentIds", "messages", NULL);
 
-       for (l = attachments_ids; l != NULL; l = l->next) {
-               e_ews_request_write_string_parameter_with_attribute (request, "AttachmentId", NULL, NULL, 
"Id", l->data);
+       for (link = attachments_ids; link; link = g_slist_next (link)) {
+               e_ews_request_write_string_parameter_with_attribute (request, "AttachmentId", NULL, NULL, 
"Id", link->data);
        }
 
        e_soap_request_end_element (request); /* "AttachmentIds" */
 
        e_ews_request_write_footer (request);
 
-       simple = g_simple_async_result_new (
-               G_OBJECT (cnc), callback, user_data,
-               e_ews_connection_delete_attachments);
-
-       async_data = g_slice_new0 (EwsAsyncData);
-       g_simple_async_result_set_op_res_gpointer (
-               simple, async_data, (GDestroyNotify) async_data_free);
-
-       e_ews_connection_queue_request (
-               cnc, request, delete_attachments_response_cb,
-               pri, cancellable, simple);
-
-       g_object_unref (simple);
-}
-
-gboolean
-e_ews_connection_delete_attachments_finish (EEwsConnection *cnc,
-                                            GAsyncResult *result,
-                                           gchar **new_change_key,
-                                            GError **error)
-{
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (
-               result, G_OBJECT (cnc), e_ews_connection_delete_attachments),
-               FALSE);
-
-       simple = G_SIMPLE_ASYNC_RESULT (result);
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
-
-       if (g_simple_async_result_propagate_error (simple, error))
-               return FALSE;
-
-       if (new_change_key)
-               *new_change_key = async_data->sync_state;
-       else
-               g_free (async_data->sync_state);
-
-       return TRUE;
-}
-
-gboolean
-e_ews_connection_delete_attachments_sync (EEwsConnection *cnc,
-                                          gint pri,
-                                          const GSList *attachments_ids,
-                                         gchar **new_change_key,
-                                          GCancellable *cancellable,
-                                          GError **error)
-{
-       EAsyncClosure *closure;
-       GAsyncResult *result;
-       gboolean ret;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-
-       closure = e_async_closure_new ();
-
-       e_ews_connection_delete_attachments (
-               cnc, pri, attachments_ids, cancellable,
-               e_async_closure_callback, closure);
-
-       result = e_async_closure_wait (closure);
-
-       ret = e_ews_connection_delete_attachments_finish (
-               cnc, result, new_change_key, error);
-
-       e_async_closure_free (closure);
-
-       return ret;
-}
-
-static void
-ews_handle_attachments_param (ESoapParameter *param,
-                              EwsAsyncData *async_data)
-{
-       ESoapParameter *subparam, *attspara;
-       EEwsAttachmentInfo *info = NULL;
-       EEwsItem *item;
-       const gchar *name;
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
 
-       attspara = e_soap_parameter_get_first_child_by_name (param, "Attachments");
-
-       for (subparam = e_soap_parameter_get_first_child (attspara); subparam != NULL; subparam = 
e_soap_parameter_get_next_child (subparam)) {
-               name = e_soap_parameter_get_name (subparam);
+       if (!response) {
+               g_clear_object (&request);
+               return FALSE;
+       }
 
-               if (!g_ascii_strcasecmp (name, "ItemAttachment")) {
-                       item = e_ews_item_new_from_soap_parameter (subparam);
-                       info = e_ews_item_dump_mime_content (item, async_data->directory);
-                       g_clear_object (&item);
+       success = e_ews_process_delete_attachments_response (cnc, response, out_new_change_key, error);
 
-               } else if (!g_ascii_strcasecmp (name, "FileAttachment")) {
-                       info = e_ews_dump_file_attachment_from_soap_parameter (
-                                       subparam,
-                                       async_data->directory,
-                                       async_data->sync_state);
-               }
+       g_clear_object (&request);
+       g_clear_object (&response);
 
-               if (info)
-                       async_data->items = g_slist_append (async_data->items, info);
+       if (!success && out_new_change_key)
+               g_clear_pointer (out_new_change_key, g_free);
 
-               info = NULL;
-       }
+       return ret;
 }
 
-static void
-get_attachments_response_cb (ESoapResponse *response,
-                             GSimpleAsyncResult *simple)
+static gboolean
+e_ews_process_get_attachments_response (EEwsConnection *cnc,
+                                       ESoapResponse *response,
+                                       const gchar *uid,
+                                       const gchar *cache_directory,
+                                       GSList **out_attachments,
+                                       GError **error)
 {
-       EwsAsyncData *async_data;
        ESoapParameter *param;
        ESoapParameter *subparam;
-       GError *error = NULL;
+       GError *local_error = NULL;
 
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
+       if (out_attachments)
+               *out_attachments = NULL;
 
-       param = e_soap_response_get_first_parameter_by_name (
-               response, "ResponseMessages", &error);
+       param = e_soap_response_get_first_parameter_by_name (response, "ResponseMessages", &local_error);
 
        /* Sanity check */
-       g_return_if_fail (
-               (param != NULL && error == NULL) ||
-               (param == NULL && error != NULL));
+       g_return_val_if_fail (
+               (param != NULL && local_error == NULL) ||
+               (param == NULL && local_error != NULL), FALSE);
 
-       if (error != NULL) {
-               g_simple_async_result_take_error (simple, error);
-               return;
+       if (local_error) {
+               g_propagate_error (error, local_error);
+               return FALSE;
        }
 
        subparam = e_soap_parameter_get_first_child (param);
@@ -8159,37 +6583,69 @@ get_attachments_response_cb (ESoapResponse *response,
        while (subparam != NULL) {
                const gchar *name = (const gchar *) subparam->name;
 
-               if (!ews_get_response_status (subparam, &error)) {
-                       g_simple_async_result_take_error (simple, error);
-                       return;
-               }
+               if (!ews_get_response_status (subparam, error))
+                       return FALSE;
+
+               if (E_EWS_CONNECTION_UTILS_CHECK_ELEMENT (name, "GetAttachmentResponseMessage") && 
out_attachments) {
+                       ESoapParameter *subattsparam, *attspara;
+                       EEwsAttachmentInfo *info = NULL;
+                       EEwsItem *item;
+                       const gchar *name;
+
+                       attspara = e_soap_parameter_get_first_child_by_name (subparam, "Attachments");
+
+                       for (subattsparam = e_soap_parameter_get_first_child (attspara);
+                            subattsparam;
+                            subattsparam = e_soap_parameter_get_next_child (subattsparam)) {
+                               name = e_soap_parameter_get_name (subattsparam);
+
+                               if (!g_ascii_strcasecmp (name, "ItemAttachment")) {
+                                       item = e_ews_item_new_from_soap_parameter (subattsparam);
+                                       info = e_ews_item_dump_mime_content (item, async_data->directory);
+                                       g_clear_object (&item);
+
+                               } else if (!g_ascii_strcasecmp (name, "FileAttachment")) {
+                                       info = e_ews_dump_file_attachment_from_soap_parameter (
+                                                       subattsparam,
+                                                       cache_directory,
+                                                       uid);
+                               }
+
+                               if (info)
+                                       *out_attachments = g_slist_prepend (*out_attachments, info);
 
-               if (E_EWS_CONNECTION_UTILS_CHECK_ELEMENT (name, "GetAttachmentResponseMessage"))
-                       ews_handle_attachments_param (subparam, async_data);
+                               info = NULL;
+                       }
+               }
 
                subparam = e_soap_parameter_get_next_child (subparam);
        }
+
+       return TRUE;
 }
 
-void
-e_ews_connection_get_attachments (EEwsConnection *cnc,
-                                  gint pri,
-                                  const gchar *uid,
-                                  const GSList *ids,
-                                  const gchar *cache,
-                                  gboolean include_mime,
-                                  ESoapResponseProgressFn progress_fn,
-                                  gpointer progress_data,
-                                  GCancellable *cancellable,
-                                  GAsyncReadyCallback callback,
-                                  gpointer user_data)
+gboolean
+e_ews_connection_get_attachments_sync (EEwsConnection *cnc,
+                                       gint pri,
+                                       const gchar *uid,
+                                       const GSList *ids,
+                                       const gchar *cache_directory,
+                                       gboolean include_mime,
+                                       GSList **out_attachments,
+                                       ESoapResponseProgressFn progress_fn,
+                                       gpointer progress_data,
+                                       GCancellable *cancellable,
+                                       GError **error)
 {
        ESoapRequest *request;
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
-       const GSList *l;
+       ESoapResponse *response;
+       const GSList *link;
+       gboolean success;
 
-       g_return_if_fail (cnc != NULL);
+       g_return_val_if_fail (cnc != NULL, FALSE);
+       g_return_val_if_fail (out_attachments != NULL, FALSE);
+
+       *out_attachments = NULL;
 
        request = e_ews_request_new_with_header (
                cnc->priv->uri,
@@ -8205,10 +6661,10 @@ e_ews_connection_get_attachments (EEwsConnection *cnc,
        if (progress_fn && progress_data)
                e_soap_request_set_progress_fn (request, progress_fn, progress_data);
 
-       if (cache)
-               e_soap_request_store_node_data (request, "MimeContent Content", cache, TRUE);
+       if (cache_directory)
+               e_soap_request_store_node_data (request, "MimeContent Content", cache_directory, TRUE);
 
-       /* wrtie empty attachments shape, need to discover maybe usefull in some cases*/
+       /* write empty attachments shape, need to discover maybe usefull in some cases */
        e_soap_request_start_element (request, "AttachmentShape", "messages", NULL);
        e_ews_request_write_string_parameter (request, "IncludeMimeContent", NULL, "true");
        e_soap_request_end_element (request);
@@ -8216,98 +6672,39 @@ e_ews_connection_get_attachments (EEwsConnection *cnc,
        /* start interation over all items to get the attachemnts */
        e_soap_request_start_element (request, "AttachmentIds", "messages", NULL);
 
-       for (l = ids; l != NULL; l = g_slist_next (l))
-               e_ews_request_write_string_parameter_with_attribute (request, "AttachmentId", NULL, NULL, 
"Id", l->data);
+       for (link = ids; link; link = g_slist_next (link)) {
+               e_ews_request_write_string_parameter_with_attribute (request, "AttachmentId", NULL, NULL, 
"Id", link->data);
+       }
 
        e_soap_request_end_element (request);
 
        e_ews_request_write_footer (request);
 
-       simple = g_simple_async_result_new (
-               G_OBJECT (cnc), callback, user_data,
-               e_ews_connection_get_attachments);
-
-       async_data = g_slice_new0 (EwsAsyncData);
-       async_data->directory = cache;
-       async_data->sync_state = (gchar *) uid;
-       g_simple_async_result_set_op_res_gpointer (
-               simple, async_data, (GDestroyNotify) async_data_free);
-
-       e_ews_connection_queue_request (
-               cnc, request, get_attachments_response_cb,
-               pri, cancellable, simple);
-
-       g_object_unref (simple);
-}
-
-gboolean
-e_ews_connection_get_attachments_finish (EEwsConnection *cnc,
-                                         GAsyncResult *result,
-                                         GSList **items,
-                                         GError **error)
-{
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (
-               result, G_OBJECT (cnc), e_ews_connection_get_attachments),
-               FALSE);
-
-       simple = G_SIMPLE_ASYNC_RESULT (result);
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
 
-       if (g_simple_async_result_propagate_error (simple, error))
+       if (!response) {
+               g_clear_object (&request);
                return FALSE;
+       }
 
-       if (items)
-               *items = async_data->items;
-       else
-               g_slist_free_full (async_data->items, (GDestroyNotify) e_ews_attachment_info_free);
-
-       return TRUE;
-}
-
-gboolean
-e_ews_connection_get_attachments_sync (EEwsConnection *cnc,
-                                       gint pri,
-                                       const gchar *uid,
-                                       const GSList *ids,
-                                       const gchar *cache,
-                                       gboolean include_mime,
-                                       GSList **items,
-                                       ESoapResponseProgressFn progress_fn,
-                                       gpointer progress_data,
-                                       GCancellable *cancellable,
-                                       GError **error)
-{
-       EAsyncClosure *closure;
-       GAsyncResult *result;
-       gboolean ret;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-
-       closure = e_async_closure_new ();
-
-       e_ews_connection_get_attachments (
-               cnc, pri, uid, ids, cache, include_mime,
-               progress_fn, progress_data, cancellable,
-               e_async_closure_callback, closure);
-
-       result = e_async_closure_wait (closure);
+       success = e_ews_process_get_attachments_response (cnc, response, uid, cache_directory, 
out_attachments, error);
 
-       ret = e_ews_connection_get_attachments_finish (
-               cnc, result, items, error);
+       g_clear_object (&request);
+       g_clear_object (&response);
 
-       e_async_closure_free (closure);
+       if (out_attachments && success) {
+               *out_attachments = g_slist_reverse (*out_attachments);
+       } else if (out_attachments) {
+               g_slist_free_full (*out_attachments, (GDestroyNotify) e_ews_attachment_info_free);
+               *out_attachments = NULL;
+       }
 
-       return ret;
+       return success;
 }
 
 static void
 ews_handle_free_busy_view (ESoapParameter *param,
-                           EwsAsyncData *async_data)
+                          GSList **out_components)
 {
        /*parse the response to create a free_busy data
        http://msdn.microsoft.com / en - us / library / aa564001 % 28v = EXCHG.140 % 29.aspx */
@@ -8322,6 +6719,7 @@ ews_handle_free_busy_view (ESoapParameter *param,
        viewparam = e_soap_parameter_get_first_child_by_name (param, "FreeBusyView");
        if (!viewparam)
                return;
+
        vfb = i_cal_component_new_vfreebusy ();
        eventarray = e_soap_parameter_get_first_child_by_name (viewparam, "CalendarEventArray");
        for (event_param = eventarray ? e_soap_parameter_get_first_child (eventarray) : NULL;
@@ -8426,31 +6824,29 @@ ews_handle_free_busy_view (ESoapParameter *param,
                g_clear_object (&ipt);
        }
 
-       async_data->items = g_slist_append (async_data->items, vfb);
+       *out_components = g_slist_prepend (*out_components, vfb);
 }
 
-static void
-get_free_busy_response_cb (ESoapResponse *response,
-                           GSimpleAsyncResult *simple)
+static gboolean
+e_ews_process_get_free_busy_response (EEwsConnection *cnc
+                                     ESoapResponse *response,
+                                     GSList **out_components,
+                                     GError **error)
 {
-       EwsAsyncData *async_data;
        ESoapParameter *param;
        ESoapParameter *subparam;
-       GError *error = NULL;
-
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
+       GError *local_error = NULL;
 
-       param = e_soap_response_get_first_parameter_by_name (
-               response, "FreeBusyResponseArray", &error);
+       param = e_soap_response_get_first_parameter_by_name (response, "FreeBusyResponseArray", &local_error);
 
        /* Sanity check */
-       g_return_if_fail (
-               (param != NULL && error == NULL) ||
-               (param == NULL && error != NULL));
+       g_return_val_if_fail (
+               (param != NULL && local_error == NULL) ||
+               (param == NULL && local_error != NULL), FALSE);
 
-       if (error != NULL) {
-               g_simple_async_result_take_error (simple, error);
-               return;
+       if (local_error) {
+               g_propagate_error (error, local_error);
+               return FALSE;
        }
 
        subparam = e_soap_parameter_get_first_child (param);
@@ -8462,34 +6858,36 @@ get_free_busy_response_cb (ESoapResponse *response,
                        subparam, "ResponseMessage");
 
                if (subsubparam) {
-                       if (!ews_get_response_status (subsubparam, &error)) {
-                               g_simple_async_result_take_error (simple, error);
-                               return;
-                       }
+                       if (!ews_get_response_status (subsubparam, error))
+                               return FALSE;
 
-                       ews_handle_free_busy_view (subparam, async_data);
+                       if (out_components)
+                               ews_handle_free_busy_view (subparam, out_components);
                }
 
                subparam = e_soap_parameter_get_next_child (subparam);
        }
+
+       return TRUE;
 }
 
-void
-e_ews_connection_get_free_busy (EEwsConnection *cnc,
-                                gint pri,
-                                EEwsRequestCreationCallback free_busy_cb,
-                                gpointer free_busy_user_data,
-                                GCancellable *cancellable,
-                                GAsyncReadyCallback callback,
-                                gpointer user_data)
+gboolean
+e_ews_connection_get_free_busy_sync (EEwsConnection *cnc,
+                                     gint pri,
+                                     EEwsRequestCreationCallback free_busy_cb,
+                                     gpointer free_busy_user_data,
+                                     GSList **out_free_busy, /* ICalComponent * */
+                                     GCancellable *cancellable,
+                                     GError **error)
 {
        ESoapRequest *request;
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
+       ESoapResponse *response;
        gboolean success;
-       GError *local_error = NULL;
 
-       g_return_if_fail (cnc != NULL);
+       g_return_val_if_fail (cnc != NULL, FALSE);
+       g_return_val_if_fail (out_free_busy != NULL, FALSE);
+
+       *out_free_busy = NULL;
 
        request = e_ews_request_new_with_header (
                cnc->priv->uri,
@@ -8501,85 +6899,31 @@ e_ews_connection_get_free_busy (EEwsConnection *cnc,
                E_EWS_EXCHANGE_2007_SP1,
                FALSE);
 
-       success = free_busy_cb (request, free_busy_user_data, &local_error);
-
-       e_ews_request_write_footer (request); /*GetUserAvailabilityRequest  */
-
-       simple = g_simple_async_result_new (
-               G_OBJECT (cnc), callback, user_data,
-               e_ews_connection_get_free_busy);
-
-       async_data = g_slice_new0 (EwsAsyncData);
-       g_simple_async_result_set_op_res_gpointer (
-               simple, async_data, (GDestroyNotify) async_data_free);
-
-       if (success) {
-               e_ews_connection_queue_request (
-                       cnc, request, get_free_busy_response_cb,
-                       pri, cancellable, simple);
-       } else {
-               if (local_error)
-                       g_simple_async_result_take_error (simple, local_error);
-               g_simple_async_result_complete_in_idle (simple);
+       if (!free_busy_cb (request, free_busy_user_data, error)) {
                g_clear_object (&request);
+               return FALSE;
        }
 
-       g_object_unref (simple);
-}
-
-gboolean
-e_ews_connection_get_free_busy_finish (EEwsConnection *cnc,
-                                       GAsyncResult *result,
-                                       GSList **free_busy, /* ICalComponent * */
-                                       GError **error)
-{
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (
-               result, G_OBJECT (cnc), e_ews_connection_get_free_busy),
-               FALSE);
+       e_ews_request_write_footer (request);
 
-       simple = G_SIMPLE_ASYNC_RESULT (result);
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
 
-       if (g_simple_async_result_propagate_error (simple, error))
+       if (!response) {
+               g_clear_object (&request);
                return FALSE;
-       *free_busy = async_data->items;
-
-       return TRUE;
-}
-
-gboolean
-e_ews_connection_get_free_busy_sync (EEwsConnection *cnc,
-                                     gint pri,
-                                     EEwsRequestCreationCallback free_busy_cb,
-                                     gpointer free_busy_user_data,
-                                     GSList **free_busy, /* ICalComponent * */
-                                     GCancellable *cancellable,
-                                     GError **error)
-{
-       EAsyncClosure *closure;
-       GAsyncResult *result;
-       gboolean success;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-
-       closure = e_async_closure_new ();
-
-       e_ews_connection_get_free_busy (
-               cnc, pri, free_busy_cb,
-               free_busy_user_data, cancellable,
-               e_async_closure_callback, closure);
+       }
 
-       result = e_async_closure_wait (closure);
+       success = e_ews_process_get_free_busy_response (cnc, response, out_free_busy, error);
 
-       success = e_ews_connection_get_free_busy_finish (
-               cnc, result, free_busy, error);
+       g_clear_object (&request);
+       g_clear_object (&response);
 
-       e_async_closure_free (closure);
+       if (success && out_free_busy) {
+               *out_free_busy = g_slist_reverse (*out_free_busy);
+       } else if (out_free_busy) {
+               g_slist_free_full (*out_free_busy, g_object_unref);
+               *out_free_busy = NULL;
+       }
 
        return success;
 }
@@ -8604,7 +6948,7 @@ get_permission_from_string (const gchar *permission)
 
 static void
 ews_handle_delegate_user_param (ESoapParameter *param,
-                                EwsAsyncData *async_data)
+                               GSList **out_delegates)
 {
        ESoapParameter *subparam, *node, *child;
        EwsDelegateInfo *data;
@@ -8691,87 +7035,98 @@ ews_handle_delegate_user_param (ESoapParameter *param,
                g_free (value);
        }
 
-       async_data->items = g_slist_append (async_data->items, data);
+       *out_delegates = g_slist_prepend (*out_delegates, data);
 }
 
-static void
-get_delegate_response_cb (ESoapResponse *response,
-                          GSimpleAsyncResult *simple)
+static gboolean
+e_ews_process_get_delegate_response (EEwsConnection *cnc,
+                                    ESoapResponse *response,
+                                    EwsDelegateDeliver *out_deliver_to,
+                                    GSList **out_delegates,
+                                    GError **error)
 {
-       EwsAsyncData *async_data;
        ESoapParameter *param;
        ESoapParameter *subparam;
-       gchar *value;
-       GError *error = NULL;
-
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
+       GError *local_error = NULL;
 
-       if (ews_get_response_status (e_soap_response_get_parameter (response), &error))
-               param = e_soap_response_get_first_parameter_by_name (
-                       response, "DeliverMeetingRequests", &error);
+       if (ews_get_response_status (e_soap_response_get_parameter (response), &local_error))
+               param = e_soap_response_get_first_parameter_by_name (response, "DeliverMeetingRequests", 
&local_error);
        else
                param = NULL;
 
        /* Sanity check */
-       g_return_if_fail (
-               (param != NULL && error == NULL) ||
-               (param == NULL && error != NULL));
+       g_return_val_if_fail (
+               (param != NULL && local_error == NULL) ||
+               (param == NULL && local_error != NULL), FALSE);
 
-       if (error != NULL) {
-               g_simple_async_result_take_error (simple, error);
-               return;
+       if (local_error) {
+               g_propagate_error (error, local_error);
+               return FALSE;
        }
 
-       value = e_soap_parameter_get_string_value (param);
-       if (g_strcmp0 (value, "DelegatesOnly") == 0)
-               async_data->deliver_to = EwsDelegateDeliver_DelegatesOnly;
-       else if (g_strcmp0 (value, "DelegatesAndMe") == 0)
-               async_data->deliver_to = EwsDelegateDeliver_DelegatesAndMe;
-       else if (g_strcmp0 (value, "DelegatesAndSendInformationToMe") == 0)
-               async_data->deliver_to = EwsDelegateDeliver_DelegatesAndSendInformationToMe;
-       else {
-               g_message ("%s: Unknown deliver-to value '%s'", G_STRFUNC, value ? value : "[null]");
-               async_data->deliver_to = EwsDelegateDeliver_DelegatesAndSendInformationToMe;
-       }
-       g_free (value);
+       if (out_deliver_to) {
+               gchar *value;
+
+               value = e_soap_parameter_get_string_value (param);
+
+               if (g_strcmp0 (value, "DelegatesOnly") == 0)
+                       *out_deliver_to = EwsDelegateDeliver_DelegatesOnly;
+               else if (g_strcmp0 (value, "DelegatesAndMe") == 0)
+                       *out_deliver_to = EwsDelegateDeliver_DelegatesAndMe;
+               else if (g_strcmp0 (value, "DelegatesAndSendInformationToMe") == 0)
+                       *out_deliver_to = EwsDelegateDeliver_DelegatesAndSendInformationToMe;
+               else {
+                       g_message ("%s: Unknown deliver-to value '%s'", G_STRFUNC, value ? value : "[null]");
+                       *out_deliver_to = EwsDelegateDeliver_DelegatesAndSendInformationToMe;
+               }
+
+               g_free (value);
+       }
 
        param = e_soap_response_get_first_parameter_by_name (
                response, "ResponseMessages", NULL);
+
        /* it's OK to not have set any delegate */
        if (!param)
-               return;
+               return TRUE;
 
        subparam = e_soap_parameter_get_first_child (param);
 
        while (subparam != NULL) {
                const gchar *name = (const gchar *) subparam->name;
 
-               if (!ews_get_response_status (subparam, &error)) {
-                       g_simple_async_result_take_error (simple, error);
-                       return;
-               }
+               if (!ews_get_response_status (subparam, error))
+                       return FALSE;
 
-               if (E_EWS_CONNECTION_UTILS_CHECK_ELEMENT (name, "DelegateUserResponseMessageType"))
-                       ews_handle_delegate_user_param (subparam, async_data);
+               if (E_EWS_CONNECTION_UTILS_CHECK_ELEMENT (name, "DelegateUserResponseMessageType")) {
+                       ews_handle_delegate_user_param (subparam, out_delegates);
+               }
 
                subparam = e_soap_parameter_get_next_child (subparam);
        }
+
+       return TRUE;
 }
 
-void
-e_ews_connection_get_delegate (EEwsConnection *cnc,
-                               gint pri,
-                               const gchar *mail_id,
-                               gboolean include_permissions,
-                               GCancellable *cancellable,
-                               GAsyncReadyCallback callback,
-                               gpointer user_data)
+gboolean
+e_ews_connection_get_delegate_sync (EEwsConnection *cnc,
+                                    gint pri,
+                                    const gchar *mail_id,
+                                    gboolean include_permissions,
+                                    EwsDelegateDeliver *out_deliver_to,
+                                    GSList **out_delegates, /* EwsDelegateInfo * */
+                                    GCancellable *cancellable,
+                                    GError **error)
 {
        ESoapRequest *request;
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
+       ESoapResponse *response;
+       gboolean success;
 
-       g_return_if_fail (cnc != NULL);
+       g_return_val_if_fail (E_IS_EWS_CONNECTION (cnc), FALSE);
+       g_return_val_if_fail (out_deliver_to != NULL, FALSE);
+       g_return_val_if_fail (out_delegates != NULL, FALSE);
+
+       *out_delegates = NULL;
 
        request = e_ews_request_new_with_header (
                cnc->priv->uri,
@@ -8785,130 +7140,72 @@ e_ews_connection_get_delegate (EEwsConnection *cnc,
 
        e_soap_request_start_element (request, "Mailbox", "messages", NULL);
 
-       e_ews_request_write_string_parameter (request, "EmailAddress", NULL, mail_id ? mail_id : 
cnc->priv->email);
-
-       e_soap_request_end_element (request);
-
-       e_ews_request_write_footer (request);
-
-       simple = g_simple_async_result_new (
-               G_OBJECT (cnc), callback, user_data,
-               e_ews_connection_get_delegate);
-
-       async_data = g_slice_new0 (EwsAsyncData);
-       g_simple_async_result_set_op_res_gpointer (
-               simple, async_data, (GDestroyNotify) async_data_free);
-
-       e_ews_connection_queue_request (
-               cnc, request, get_delegate_response_cb,
-               pri, cancellable, simple);
-
-       g_object_unref (simple);
-}
-
-gboolean
-e_ews_connection_get_delegate_finish (EEwsConnection *cnc,
-                                      GAsyncResult *result,
-                                      EwsDelegateDeliver *deliver_to,
-                                      GSList **delegates, /* EwsDelegateInfo * */
-                                      GError **error)
-{
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-       g_return_val_if_fail (delegates != NULL, FALSE);
-       g_return_val_if_fail (deliver_to != NULL, FALSE);
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (
-               result, G_OBJECT (cnc), e_ews_connection_get_delegate),
-               FALSE);
-
-       simple = G_SIMPLE_ASYNC_RESULT (result);
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
-
-       if (g_simple_async_result_propagate_error (simple, error))
-               return FALSE;
-
-       *deliver_to = async_data->deliver_to;
-       *delegates = async_data->items;
-       async_data->items = NULL;
-
-       return TRUE;
-}
+       e_ews_request_write_string_parameter (request, "EmailAddress", NULL, mail_id ? mail_id : 
cnc->priv->email);
 
-gboolean
-e_ews_connection_get_delegate_sync (EEwsConnection *cnc,
-                                    gint pri,
-                                    const gchar *mail_id,
-                                    gboolean include_permissions,
-                                    EwsDelegateDeliver *deliver_to,
-                                    GSList **delegates, /* EwsDelegateInfo * */
-                                    GCancellable *cancellable,
-                                    GError **error)
-{
-       EAsyncClosure *closure;
-       GAsyncResult *result;
-       gboolean success;
+       e_soap_request_end_element (request);
 
-       g_return_val_if_fail (E_IS_EWS_CONNECTION (cnc), FALSE);
-       g_return_val_if_fail (deliver_to != NULL, FALSE);
-       g_return_val_if_fail (delegates != NULL, FALSE);
+       e_ews_request_write_footer (request);
 
-       closure = e_async_closure_new ();
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
 
-       e_ews_connection_get_delegate (
-               cnc, pri, mail_id,
-               include_permissions, cancellable,
-               e_async_closure_callback, closure);
+       if (!response) {
+               g_clear_object (&request);
+               return FALSE;
+       }
 
-       result = e_async_closure_wait (closure);
+       success = e_ews_process_get_delegate_response (cnc, response, out_deliver_to, out_delegates, error);
 
-       success = e_ews_connection_get_delegate_finish (
-               cnc, result, deliver_to, delegates, error);
+       g_clear_object (&request);
+       g_clear_object (&response);
 
-       e_async_closure_free (closure);
+       if (success) {
+               *out_delegates = g_slist_reverse (*out_delegates);
+       } else {
+               g_slist_free_full (*out_delegates, (GDestroyNotify) ews_delegate_info_free);
+               *out_delegates = NULL;
+       }
 
        return success;
 }
 
-static void
-update_delegate_response_cb (ESoapResponse *response,
-                             GSimpleAsyncResult *simple)
+static gboolean
+e_ews_process_update_delegate_response (EEwsConnection *cnc,
+                                       ESoapResponse *response,
+                                       GError **error)
 {
        ESoapParameter *param;
        ESoapParameter *subparam;
        GError *error = NULL;
 
-       if (ews_get_response_status (e_soap_response_get_parameter (response), &error)) {
-               param = e_soap_response_get_first_parameter_by_name (
-                       response, "ResponseMessages", NULL);
+       if (ews_get_response_status (e_soap_response_get_parameter (response), &local_error)) {
+               param = e_soap_response_get_first_parameter_by_name (response, "ResponseMessages", NULL);
                /* that's OK to not receive any ResponseMessages here */
                if (!param)
-                       return;
-       } else
+                       return TRUE;
+       } else {
                param = NULL;
+       }
 
        /* Sanity check */
-       g_return_if_fail (
-               (param != NULL && error == NULL) ||
-               (param == NULL && error != NULL));
+       g_return_val_if_fail (
+               (param != NULL && local_error == NULL) ||
+               (param == NULL && local_error != NULL), FALSE);
 
-       if (error != NULL) {
-               g_simple_async_result_take_error (simple, error);
-               return;
+       if (local_error) {
+               g_propagate_error (error, local_error);
+               return FALSE;
        }
 
        subparam = e_soap_parameter_get_first_child (param);
 
        while (subparam != NULL) {
-               if (!ews_get_response_status (subparam, &error)) {
-                       g_simple_async_result_take_error (simple, error);
-                       return;
-               }
+               if (!ews_get_response_status (subparam, error))
+                       return FALSE;
 
                subparam = e_soap_parameter_get_next_child (param);
        }
+
+       return TRUE;
 }
 
 static void
@@ -8933,22 +7230,21 @@ set_delegate_permission (ESoapRequest *request,
        e_ews_request_write_string_parameter (request, elem_name, NULL, level_name);
 }
 
-void
-e_ews_connection_add_delegate (EEwsConnection *cnc,
-                               gint pri,
-                               const gchar *mail_id,
-                               const GSList *delegates, /* EwsDelegateInfo * */
-                               GCancellable *cancellable,
-                               GAsyncReadyCallback callback,
-                               gpointer user_data)
+gboolean
+e_ews_connection_add_delegate_sync (EEwsConnection *cnc,
+                                    gint pri,
+                                    const gchar *mail_id,
+                                    const GSList *delegates, /* EwsDelegateInfo * */
+                                    GCancellable *cancellable,
+                                    GError **error)
 {
        ESoapRequest *request;
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
-       const GSList *iter;
+       ESoapResponse *response;
+       const GSList *link;
+       gboolean success;
 
-       g_return_if_fail (cnc != NULL);
-       g_return_if_fail (delegates != NULL);
+       g_return_val_if_fail (E_IS_EWS_CONNECTION (cnc), FALSE);
+       g_return_val_if_fail (delegates != NULL, FALSE);
 
        request = e_ews_request_new_with_header (
                cnc->priv->uri,
@@ -8965,8 +7261,8 @@ e_ews_connection_add_delegate (EEwsConnection *cnc,
        e_soap_request_end_element (request);
 
        e_soap_request_start_element (request, "DelegateUsers", "messages", NULL);
-       for (iter = delegates; iter; iter = iter->next) {
-               const EwsDelegateInfo *di = iter->data;
+       for (link = delegates; link; link = g_slist_next (link)) {
+               const EwsDelegateInfo *di = link->data;
 
                if (!di)
                        continue;
@@ -8996,85 +7292,36 @@ e_ews_connection_add_delegate (EEwsConnection *cnc,
 
        e_ews_request_write_footer (request);
 
-       simple = g_simple_async_result_new (
-               G_OBJECT (cnc), callback, user_data,
-               e_ews_connection_add_delegate);
-
-       async_data = g_slice_new0 (EwsAsyncData);
-       g_simple_async_result_set_op_res_gpointer (
-               simple, async_data, (GDestroyNotify) async_data_free);
-
-       e_ews_connection_queue_request (
-               cnc, request, update_delegate_response_cb,
-               pri, cancellable, simple);
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
 
-       g_object_unref (simple);
-}
-
-gboolean
-e_ews_connection_add_delegate_finish (EEwsConnection *cnc,
-                                      GAsyncResult *result,
-                                      GError **error)
-{
-       GSimpleAsyncResult *simple;
+       if (!response) {
+               g_clear_object (&request);
+               return FALSE;
+       }
 
-       g_return_val_if_fail (cnc != NULL, FALSE);
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (
-               result, G_OBJECT (cnc), e_ews_connection_add_delegate),
-               FALSE);
+       success = e_ews_process_update_delegate_response (cnc, response, error);
 
-       simple = G_SIMPLE_ASYNC_RESULT (result);
+       g_clear_object (&request);
+       g_clear_object (&response);
 
-       return !g_simple_async_result_propagate_error (simple, error);
+       return success;
 }
 
 gboolean
-e_ews_connection_add_delegate_sync (EEwsConnection *cnc,
-                                    gint pri,
-                                    const gchar *mail_id,
-                                    const GSList *delegates, /* EwsDelegateInfo * */
-                                    GCancellable *cancellable,
-                                    GError **error)
+e_ews_connection_remove_delegate_sync (EEwsConnection *cnc,
+                                       gint pri,
+                                       const gchar *mail_id,
+                                       const GSList *delegate_ids, /* EwsUserId * */
+                                       GCancellable *cancellable,
+                                       GError **error)
 {
-       EAsyncClosure *closure;
-       GAsyncResult *result;
+       ESoapRequest *request;
+       ESoapResponse *response;
+       const GSList *link;
        gboolean success;
 
        g_return_val_if_fail (E_IS_EWS_CONNECTION (cnc), FALSE);
-       g_return_val_if_fail (delegates != NULL, FALSE);
-
-       closure = e_async_closure_new ();
-
-       e_ews_connection_add_delegate (
-               cnc, pri, mail_id, delegates, cancellable,
-               e_async_closure_callback, closure);
-
-       result = e_async_closure_wait (closure);
-
-       success = e_ews_connection_add_delegate_finish (cnc, result, error);
-
-       e_async_closure_free (closure);
-
-       return success;
-}
-
-void
-e_ews_connection_remove_delegate (EEwsConnection *cnc,
-                                  gint pri,
-                                  const gchar *mail_id,
-                                  const GSList *delegate_ids, /* EwsUserId * */
-                                  GCancellable *cancellable,
-                                  GAsyncReadyCallback callback,
-                                  gpointer user_data)
-{
-       ESoapRequest *request;
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
-       const GSList *iter;
-
-       g_return_if_fail (cnc != NULL);
-       g_return_if_fail (delegate_ids != NULL);
+       g_return_val_if_fail (delegate_ids != NULL, FALSE);
 
        request = e_ews_request_new_with_header (
                cnc->priv->uri,
@@ -9091,7 +7338,8 @@ e_ews_connection_remove_delegate (EEwsConnection *cnc,
        e_soap_request_end_element (request);
 
        e_soap_request_start_element (request, "UserIds", "messages", NULL);
-       for (iter = delegate_ids; iter; iter = iter->next) {
+
+       for (link = delegate_ids; link; link = g_slist_next (link)) {
                const EwsUserId *user_id = iter->data;
 
                if (!user_id)
@@ -9106,85 +7354,36 @@ e_ews_connection_remove_delegate (EEwsConnection *cnc,
 
        e_ews_request_write_footer (request);
 
-       simple = g_simple_async_result_new (
-               G_OBJECT (cnc), callback, user_data,
-               e_ews_connection_remove_delegate);
-
-       async_data = g_slice_new0 (EwsAsyncData);
-       g_simple_async_result_set_op_res_gpointer (
-               simple, async_data, (GDestroyNotify) async_data_free);
-
-       e_ews_connection_queue_request (
-               cnc, request, update_delegate_response_cb,
-               pri, cancellable, simple);
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
 
-       g_object_unref (simple);
-}
-
-gboolean
-e_ews_connection_remove_delegate_finish (EEwsConnection *cnc,
-                                         GAsyncResult *result,
-                                         GError **error)
-{
-       GSimpleAsyncResult *simple;
+       if (!response) {
+               g_clear_object (&request);
+               return FALSE;
+       }
 
-       g_return_val_if_fail (cnc != NULL, FALSE);
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (
-               result, G_OBJECT (cnc), e_ews_connection_remove_delegate),
-               FALSE);
+       success = e_ews_process_update_delegate_response (cnc, response, error);
 
-       simple = G_SIMPLE_ASYNC_RESULT (result);
+       g_clear_object (&request);
+       g_clear_object (&response);
 
-       return !g_simple_async_result_propagate_error (simple, error);
+       return success;
 }
 
 gboolean
-e_ews_connection_remove_delegate_sync (EEwsConnection *cnc,
+e_ews_connection_update_delegate_sync (EEwsConnection *cnc,
                                        gint pri,
                                        const gchar *mail_id,
-                                       const GSList *delegate_ids, /* EwsUserId * */
+                                       EwsDelegateDeliver deliver_to,
+                                       const GSList *delegates, /* EwsDelegateInfo * */
                                        GCancellable *cancellable,
                                        GError **error)
 {
-       EAsyncClosure *closure;
-       GAsyncResult *result;
+       ESoapRequest *request;
+       ESoapResponse *response;
+       const GSList *link;
        gboolean success;
 
        g_return_val_if_fail (E_IS_EWS_CONNECTION (cnc), FALSE);
-       g_return_val_if_fail (delegate_ids != NULL, FALSE);
-
-       closure = e_async_closure_new ();
-
-       e_ews_connection_remove_delegate (
-               cnc, pri, mail_id, delegate_ids, cancellable,
-               e_async_closure_callback, closure);
-
-       result = e_async_closure_wait (closure);
-
-       success = e_ews_connection_remove_delegate_finish (cnc, result, error);
-
-       e_async_closure_free (closure);
-
-       return success;
-}
-
-void
-e_ews_connection_update_delegate (EEwsConnection *cnc,
-                                  gint pri,
-                                  const gchar *mail_id,
-                                  EwsDelegateDeliver deliver_to,
-                                  const GSList *delegates, /* EwsDelegateInfo * */
-                                  GCancellable *cancellable,
-                                  GAsyncReadyCallback callback,
-                                  gpointer user_data)
-{
-       ESoapRequest *request;
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
-       const GSList *iter;
-
-       g_return_if_fail (cnc != NULL);
 
        request = e_ews_request_new_with_header (
                cnc->priv->uri,
@@ -9202,8 +7401,9 @@ e_ews_connection_update_delegate (EEwsConnection *cnc,
 
        if (delegates) {
                e_soap_request_start_element (request, "DelegateUsers", "messages", NULL);
-               for (iter = delegates; iter; iter = iter->next) {
-                       const EwsDelegateInfo *di = iter->data;
+
+               for (link = delegates; link; link = g_slist_next (link)) {
+                       const EwsDelegateInfo *di = link->data;
 
                        if (!di)
                                continue;
@@ -9239,91 +7439,41 @@ e_ews_connection_update_delegate (EEwsConnection *cnc,
 
        e_ews_request_write_footer (request);
 
-       simple = g_simple_async_result_new (
-               G_OBJECT (cnc), callback, user_data,
-               e_ews_connection_update_delegate);
-
-       async_data = g_slice_new0 (EwsAsyncData);
-       g_simple_async_result_set_op_res_gpointer (
-               simple, async_data, (GDestroyNotify) async_data_free);
-
-       e_ews_connection_queue_request (
-               cnc, request, update_delegate_response_cb,
-               pri, cancellable, simple);
-
-       g_object_unref (simple);
-}
-
-gboolean
-e_ews_connection_update_delegate_finish (EEwsConnection *cnc,
-                                         GAsyncResult *result,
-                                         GError **error)
-{
-       GSimpleAsyncResult *simple;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (
-               result, G_OBJECT (cnc), e_ews_connection_update_delegate),
-               FALSE);
-
-       simple = G_SIMPLE_ASYNC_RESULT (result);
-
-       return !g_simple_async_result_propagate_error (simple, error);
-}
-
-gboolean
-e_ews_connection_update_delegate_sync (EEwsConnection *cnc,
-                                       gint pri,
-                                       const gchar *mail_id,
-                                       EwsDelegateDeliver deliver_to,
-                                       const GSList *delegates, /* EwsDelegateInfo * */
-                                       GCancellable *cancellable,
-                                       GError **error)
-{
-       EAsyncClosure *closure;
-       GAsyncResult *result;
-       gboolean success;
-
-       g_return_val_if_fail (E_IS_EWS_CONNECTION (cnc), FALSE);
-
-       closure = e_async_closure_new ();
-
-       e_ews_connection_update_delegate (
-               cnc, pri, mail_id, deliver_to, delegates, cancellable,
-               e_async_closure_callback, closure);
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
 
-       result = e_async_closure_wait (closure);
+       if (!response) {
+               g_clear_object (&request);
+               return FALSE;
+       }
 
-       success = e_ews_connection_update_delegate_finish (cnc, result, error);
+       success = e_ews_process_update_delegate_response (cnc, response, error);
 
-       e_async_closure_free (closure);
+       g_clear_object (&request);
+       g_clear_object (&response);
 
        return success;
 }
 
-static void
-get_folder_permissions_response_cb (ESoapResponse *response,
-                                    GSimpleAsyncResult *simple)
+static gboolean
+e_ews_process_get_folder_permissions_response (EEwsConnection *cnc,
+                                              ESoapResponse *response,
+                                              GSList **out_permissions,
+                                              GError **error)
 {
-       EwsAsyncData *async_data;
        ESoapParameter *param;
        ESoapParameter *subparam;
-       GError *error = NULL;
-
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
+       GError *local_error = NULL;
 
-       param = e_soap_response_get_first_parameter_by_name (
-               response, "ResponseMessages", &error);
+       param = e_soap_response_get_first_parameter_by_name (response, "ResponseMessages", &local_error);
 
        /* Sanity check */
-       g_return_if_fail (
-               (param != NULL && error == NULL) ||
-               (param == NULL && error != NULL));
+       g_return_val_if_fail (
+               (param != NULL && local_error == NULL) ||
+               (param == NULL && local_error != NULL), FALSE);
 
-       if (error != NULL) {
-               g_simple_async_result_take_error (simple, error);
-               return;
+       if (local_error) {
+               g_propagate_error (error, local_error);
+               return FALSE;
        }
 
        subparam = e_soap_parameter_get_first_child (param);
@@ -9331,10 +7481,8 @@ get_folder_permissions_response_cb (ESoapResponse *response,
        while (subparam != NULL) {
                const gchar *name = (const gchar *) subparam->name;
 
-               if (!ews_get_response_status (subparam, &error)) {
-                       g_simple_async_result_take_error (simple, error);
-                       return;
-               }
+               if (ews_get_response_status (subparam, error))
+                       return FALSE;
 
                if (E_EWS_CONNECTION_UTILS_CHECK_ELEMENT (name, "GetFolderResponseMessage")) {
                        ESoapParameter *node;
@@ -9347,7 +7495,7 @@ get_folder_permissions_response_cb (ESoapResponse *response,
                                if (node && node->name && g_str_has_suffix ((const gchar *) node->name, 
"Folder")) {
                                        node = e_soap_parameter_get_first_child_by_name (node, 
"PermissionSet");
                                        if (node) {
-                                               async_data->items = e_ews_permissions_from_soap_param (node);
+                                               *out_permissions = e_ews_permissions_from_soap_param (node);
                                        }
                                }
                        }
@@ -9357,22 +7505,28 @@ get_folder_permissions_response_cb (ESoapResponse *response,
 
                subparam = e_soap_parameter_get_next_child (subparam);
        }
+
+       return TRUE;
 }
 
-void
-e_ews_connection_get_folder_permissions (EEwsConnection *cnc,
-                                         gint pri,
-                                         EwsFolderId *folder_id,
-                                         GCancellable *cancellable,
-                                         GAsyncReadyCallback callback,
-                                         gpointer user_data)
+/* free permissions with e_ews_permissions_free() */
+gboolean
+e_ews_connection_get_folder_permissions_sync (EEwsConnection *cnc,
+                                              gint pri,
+                                              EwsFolderId *folder_id,
+                                              GSList **out_permissions,
+                                              GCancellable *cancellable,
+                                              GError **error)
 {
        ESoapRequest *request;
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
+       ESoapResponse *response;
+       gboolean success;
 
-       g_return_if_fail (cnc != NULL);
-       g_return_if_fail (folder_id != NULL);
+       g_return_val_if_fail (E_IS_EWS_CONNECTION (cnc), FALSE);
+       g_return_val_if_fail (folder_id != NULL, FALSE);
+       g_return_val_if_fail (out_permissions != NULL, FALSE);
+
+       *out_permissions = NULL;
 
        request = e_ews_request_new_with_header (
                cnc->priv->uri,
@@ -9393,105 +7547,48 @@ e_ews_connection_get_folder_permissions (EEwsConnection *cnc,
 
        e_soap_request_start_element (request, "FolderIds", "messages", NULL);
        e_ews_folder_id_append_to_msg (request, cnc->priv->email, folder_id);
-       e_soap_request_end_element (request);
-
-       e_ews_request_write_footer (request);
-
-       simple = g_simple_async_result_new (
-               G_OBJECT (cnc), callback, user_data,
-               e_ews_connection_get_folder_permissions);
-
-       async_data = g_slice_new0 (EwsAsyncData);
-       g_simple_async_result_set_op_res_gpointer (
-               simple, async_data, (GDestroyNotify) async_data_free);
-
-       e_ews_connection_queue_request (
-               cnc, request, get_folder_permissions_response_cb,
-               pri, cancellable, simple);
+       e_soap_request_end_element (request);
 
-       g_object_unref (simple);
-}
+       e_ews_request_write_footer (request);
 
-/* free permissions with e_ews_permissions_free() */
-gboolean
-e_ews_connection_get_folder_permissions_finish (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                GSList **permissions,
-                                                GError **error)
-{
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
 
-       g_return_val_if_fail (cnc != NULL, FALSE);
-       g_return_val_if_fail (permissions != NULL, FALSE);
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (
-               result, G_OBJECT (cnc), e_ews_connection_get_folder_permissions),
-               FALSE);
+       if (!response) {
+               g_clear_object (&request);
+               return FALSE;
+       }
 
-       simple = G_SIMPLE_ASYNC_RESULT (result);
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
+       success = e_ews_process_get_folder_permissions_response (cnc, response, out_permissions, error);
 
-       if (g_simple_async_result_propagate_error (simple, error))
-               return FALSE;
+       g_clear_object (&request);
+       g_clear_object (&response);
 
-       *permissions = async_data->items;
+       if (!success) {
+               e_ews_permissions_free (*out_permissions);
+               *out_permissions = NULL;
+       }
 
-       return TRUE;
+       return success;
 }
 
-/* free permissions with e_ews_permissions_free() */
 gboolean
-e_ews_connection_get_folder_permissions_sync (EEwsConnection *cnc,
+e_ews_connection_set_folder_permissions_sync (EEwsConnection *cnc,
                                               gint pri,
                                               EwsFolderId *folder_id,
-                                              GSList **permissions,
+                                              EEwsFolderType folder_type,
+                                              const GSList *permissions,
                                               GCancellable *cancellable,
                                               GError **error)
 {
-       EAsyncClosure *closure;
-       GAsyncResult *result;
+       ESoapRequest *request;
+       ESoapResponse *response;
+       const GSList *link;
        gboolean success;
 
        g_return_val_if_fail (E_IS_EWS_CONNECTION (cnc), FALSE);
        g_return_val_if_fail (folder_id != NULL, FALSE);
        g_return_val_if_fail (permissions != NULL, FALSE);
 
-       closure = e_async_closure_new ();
-
-       e_ews_connection_get_folder_permissions (
-               cnc, pri, folder_id, cancellable,
-               e_async_closure_callback, closure);
-
-       result = e_async_closure_wait (closure);
-
-       success = e_ews_connection_get_folder_permissions_finish (
-               cnc, result, permissions, error);
-
-       e_async_closure_free (closure);
-
-       return success;
-}
-
-void
-e_ews_connection_set_folder_permissions (EEwsConnection *cnc,
-                                         gint pri,
-                                         EwsFolderId *folder_id,
-                                         EEwsFolderType folder_type,
-                                         const GSList *permissions,
-                                         GCancellable *cancellable,
-                                         GAsyncReadyCallback callback,
-                                         gpointer user_data)
-{
-       ESoapRequest *request;
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
-       const GSList *iter;
-
-       g_return_if_fail (cnc != NULL);
-       g_return_if_fail (folder_id != NULL);
-       g_return_if_fail (permissions != NULL);
-
        request = e_ews_request_new_with_header (
                cnc->priv->uri,
                cnc->priv->impersonate_user,
@@ -9533,8 +7630,8 @@ e_ews_connection_set_folder_permissions (EEwsConnection *cnc,
        else
                e_soap_request_start_element (request, "Permissions", NULL, NULL);
 
-       for (iter = permissions; iter; iter = iter->next) {
-               EEwsPermission *perm = iter->data;
+       for (link = permissions; link; link = g_slist_next (link)) {
+               EEwsPermission *perm = link->data;
                const gchar *perm_level_name;
 
                if (!perm)
@@ -9611,121 +7708,64 @@ e_ews_connection_set_folder_permissions (EEwsConnection *cnc,
 
        e_ews_request_write_footer (request);
 
-       simple = g_simple_async_result_new (
-               G_OBJECT (cnc), callback, user_data,
-               e_ews_connection_set_folder_permissions);
-
-       async_data = g_slice_new0 (EwsAsyncData);
-       g_simple_async_result_set_op_res_gpointer (
-               simple, async_data, (GDestroyNotify) async_data_free);
-
-       e_ews_connection_queue_request (
-               cnc, request, update_folder_response_cb,
-               pri, cancellable, simple);
-
-       g_object_unref (simple);
-}
-
-gboolean
-e_ews_connection_set_folder_permissions_finish (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                GError **error)
-{
-       GSimpleAsyncResult *simple;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (
-               result, G_OBJECT (cnc), e_ews_connection_set_folder_permissions),
-               FALSE);
-
-       simple = G_SIMPLE_ASYNC_RESULT (result);
-
-       return !g_simple_async_result_propagate_error (simple, error);
-}
-
-gboolean
-e_ews_connection_set_folder_permissions_sync (EEwsConnection *cnc,
-                                              gint pri,
-                                              EwsFolderId *folder_id,
-                                              EEwsFolderType folder_type,
-                                              const GSList *permissions,
-                                              GCancellable *cancellable,
-                                              GError **error)
-{
-       EAsyncClosure *closure;
-       GAsyncResult *result;
-       gboolean success;
-
-       g_return_val_if_fail (E_IS_EWS_CONNECTION (cnc), FALSE);
-       g_return_val_if_fail (folder_id != NULL, FALSE);
-       g_return_val_if_fail (permissions != NULL, FALSE);
-
-       closure = e_async_closure_new ();
-
-       e_ews_connection_set_folder_permissions (
-               cnc, pri, folder_id, folder_type, permissions, cancellable,
-               e_async_closure_callback, closure);
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
 
-       result = e_async_closure_wait (closure);
+       if (!response) {
+               g_clear_object (&request);
+               return FALSE;
+       }
 
-       success = e_ews_connection_set_folder_permissions_finish (
-               cnc, result, error);
+       success = e_ews_process_generic_response (cnc, response, error);
 
-       e_async_closure_free (closure);
+       g_clear_object (&request);
+       g_clear_object (&response);
 
        return success;
 }
 
-static void
-get_password_expiration_response_cb (ESoapResponse *response,
-                                     GSimpleAsyncResult *simple)
+static gboolean
+e_ews_process_get_password_expiration_response (EEwsConnection *cnc,
+                                               ESoapResponse *response,
+                                               gchar **out_exp_date,
+                                               GError **error)
 {
-       EwsAsyncData *async_data;
        ESoapParameter *param;
-       gchar *exp_date;
-       GError *error = NULL;
-
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
+       GError *local_error = NULL;
 
-       param = e_soap_response_get_first_parameter_by_name (
-               response, "PasswordExpirationDate", &error);
+       param = e_soap_response_get_first_parameter_by_name (response, "PasswordExpirationDate", 
&local_error);
 
        /* Sanity check */
-       g_return_if_fail (
-               (param != NULL && error == NULL) ||
-               (param == NULL && error != NULL));
+       g_return_val_if_fail (
+               (param != NULL && local_error == NULL) ||
+               (param == NULL && local_error != NULL), FALSE);
 
-       if (error != NULL) {
-               g_simple_async_result_take_error (simple, error);
-               return;
+       if (local_error) {
+               g_propagate_error (error, local_error);
+               return FALSE;
        }
 
-       exp_date = e_soap_parameter_get_string_value (param);
+       if (out_exp_date)
+               *out_exp_date = e_soap_parameter_get_string_value (param);
 
-       async_data->items = g_slist_append (async_data->items, exp_date);
+       return TRUE;
 }
 
-/**
- * e_ews_connection_get_password_expiration
- * @cnc:
- * @pri:
- * @mail_id: mail is for which password expiration is requested
- * @cb:
- * @cancellable:
- * @user_data:
- **/
-void
-e_ews_connection_get_password_expiration (EEwsConnection *cnc,
-                                          gint pri,
-                                          const gchar *mail_id,
-                                          GCancellable *cancellable,
-                                          GAsyncReadyCallback callback,
-                                          gpointer user_data)
+gboolean
+e_ews_connection_get_password_expiration_sync (EEwsConnection *cnc,
+                                               gint pri,
+                                               const gchar *mail_id,
+                                               gchar **out_exp_date,
+                                               GCancellable *cancellable,
+                                               GError **error)
 {
        ESoapRequest *request;
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
+       ESoapResponse *response;
+       gboolean success;
+
+       g_return_val_if_fail (E_IS_EWS_CONNECTION (cnc), FALSE);
+       g_return_val_if_fail (out_exp_date != NULL, FALSE);
+
+       *out_exp_date = NULL;
 
        request = e_ews_request_new_with_header (
                cnc->priv->uri,
@@ -9736,114 +7776,49 @@ e_ews_connection_get_password_expiration (EEwsConnection *cnc,
                cnc->priv->version,
                E_EWS_EXCHANGE_2010_SP2,
                FALSE);
-       e_ews_request_write_string_parameter (request, "MailboxSmtpAddress", NULL, mail_id ? mail_id : 
cnc->priv->email);
-       e_ews_request_write_footer (request);
-
-       simple = g_simple_async_result_new (
-               G_OBJECT (cnc), callback, user_data,
-               e_ews_connection_get_password_expiration);
-
-       async_data = g_slice_new0 (EwsAsyncData);
-       g_simple_async_result_set_op_res_gpointer (
-               simple, async_data, (GDestroyNotify) async_data_free);
 
-       e_ews_connection_queue_request (
-               cnc, request, get_password_expiration_response_cb,
-               pri, cancellable, simple);
-
-       g_object_unref (simple);
-}
-
-gboolean
-e_ews_connection_get_password_expiration_finish (EEwsConnection *cnc,
-                                                 GAsyncResult *result,
-                                                 gchar **exp_date,
-                                                 GError **error)
-{
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
+       e_ews_request_write_string_parameter (request, "MailboxSmtpAddress", NULL, mail_id ? mail_id : 
cnc->priv->email);
 
-       g_return_val_if_fail (exp_date != NULL, FALSE);
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (
-               result, G_OBJECT (cnc), e_ews_connection_get_password_expiration),
-               FALSE);
+       e_ews_request_write_footer (request);
 
-       simple = G_SIMPLE_ASYNC_RESULT (result);
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
 
-       if (g_simple_async_result_propagate_error (simple, error))
+       if (!response) {
+               g_clear_object (&request);
                return FALSE;
+       }
 
-       g_return_val_if_fail (async_data->items != NULL, FALSE);
-
-       *exp_date = async_data->items->data;
-       g_slist_free (async_data->items);
-
-       return TRUE;
-}
-
-/**
- * e_ews_connection_get_password_expiration_sync
- * @cnc:
- * @pri:
- * @mail_id: mail id for which password expiration is requested
- * @cancellable:
- * @error:
- **/
-gboolean
-e_ews_connection_get_password_expiration_sync (EEwsConnection *cnc,
-                                               gint pri,
-                                               const gchar *mail_id,
-                                               gchar **exp_date,
-                                               GCancellable *cancellable,
-                                               GError **error)
-{
-       EAsyncClosure *closure;
-       GAsyncResult *result;
-       gboolean success;
-
-       g_return_val_if_fail (E_IS_EWS_CONNECTION (cnc), FALSE);
-       g_return_val_if_fail (exp_date != NULL, FALSE);
-
-       closure = e_async_closure_new ();
-
-       e_ews_connection_get_password_expiration (
-               cnc, pri, mail_id, cancellable,
-               e_async_closure_callback, closure);
-
-       result = e_async_closure_wait (closure);
+       success = e_ews_process_get_password_expiration_response (cnc, response, out_exp_date, error);
 
-       success = e_ews_connection_get_password_expiration_finish (
-               cnc, result, exp_date, error);
+       g_clear_object (&request);
+       g_clear_object (&response);
 
-       e_async_closure_free (closure);
+       if (!success)
+               g_clear_pointer (out_exp_date, g_free);
 
        return success;
 }
 
-static void
-get_folder_info_response_cb (ESoapResponse *response,
-                             GSimpleAsyncResult *simple)
+static gboolean
+e_ews_process_get_folder_info_response (EEwsConnection *cnc,
+                                       ESoapResponse *response,
+                                       EEwsFolder **out_folder,
+                                       GError **error)
 {
-       EwsAsyncData *async_data;
        ESoapParameter *param;
        ESoapParameter *subparam;
-       GError *error = NULL;
-
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
+       GError *local_error = NULL;
 
-       param = e_soap_response_get_first_parameter_by_name (
-               response, "ResponseMessages", &error);
+       param = e_soap_response_get_first_parameter_by_name (response, "ResponseMessages", &local_error);
 
        /* Sanity check */
-       g_return_if_fail (
-               (param != NULL && error == NULL) ||
-               (param == NULL && error != NULL));
+       g_return_val_if_fail (
+               (param != NULL && local_error == NULL) ||
+               (param == NULL && local_error != NULL), FALSE);
 
-       if (error != NULL) {
-               g_simple_async_result_take_error (simple, error);
-               return;
+       if (local_error) {
+               g_propagate_error (error, local_error);
+               return FALSE;
        }
 
        subparam = e_soap_parameter_get_first_child (param);
@@ -9851,44 +7826,43 @@ get_folder_info_response_cb (ESoapResponse *response,
        while (subparam != NULL) {
                const gchar *name = (const gchar *) subparam->name;
 
-               if (!ews_get_response_status (subparam, &error)) {
-                       g_simple_async_result_take_error (simple, error);
-                       return;
-               }
+               if (!ews_get_response_status (subparam, error))
+                       return FALSE;
 
                if (E_EWS_CONNECTION_UTILS_CHECK_ELEMENT (name, "GetFolderResponseMessage")) {
                        ESoapParameter *node;
 
                        node = e_soap_parameter_get_first_child_by_name (subparam, "Folders");
-                       if (node) {
-                               EEwsFolder *folder = e_ews_folder_new_from_soap_parameter (node);
-
-                               if (folder)
-                                       async_data->items = g_slist_prepend (NULL, folder);
-                       }
+                       if (node && out_folder)
+                               *out_folder = e_ews_folder_new_from_soap_parameter (node);
 
                        break;
                }
 
                subparam = e_soap_parameter_get_next_child (subparam);
        }
+
+       return TRUE;
 }
 
-void
-e_ews_connection_get_folder_info (EEwsConnection *cnc,
-                                  gint pri,
-                                  const gchar *mail_id,
-                                  const EwsFolderId *folder_id,
-                                  GCancellable *cancellable,
-                                  GAsyncReadyCallback callback,
-                                  gpointer user_data)
+gboolean
+e_ews_connection_get_folder_info_sync (EEwsConnection *cnc,
+                                       gint pri,
+                                       const gchar *mail_id,
+                                       const EwsFolderId *folder_id,
+                                       EEwsFolder **out_folder,
+                                       GCancellable *cancellable,
+                                       GError **error)
 {
        ESoapRequest *request;
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
+       ESoapResponse *response;
+       gboolean success;
 
-       g_return_if_fail (cnc != NULL);
-       g_return_if_fail (folder_id != NULL);
+       g_return_val_if_fail (E_IS_EWS_CONNECTION (cnc), FALSE);
+       g_return_val_if_fail (folder_id != NULL, FALSE);
+       g_return_val_if_fail (out_folder != NULL, FALSE);
+
+       *out_folder = NULL;
 
        request = e_ews_request_new_with_header (
                cnc->priv->uri,
@@ -9914,143 +7888,48 @@ e_ews_connection_get_folder_info (EEwsConnection *cnc,
 
        e_ews_request_write_footer (request);
 
-       simple = g_simple_async_result_new (
-               G_OBJECT (cnc), callback, user_data,
-               e_ews_connection_get_folder_info);
-
-       async_data = g_slice_new0 (EwsAsyncData);
-       g_simple_async_result_set_op_res_gpointer (
-               simple, async_data, (GDestroyNotify) async_data_free);
-
-       e_ews_connection_queue_request (
-               cnc, request, get_folder_info_response_cb,
-               pri, cancellable, simple);
-
-       g_object_unref (simple);
-}
-
-gboolean
-e_ews_connection_get_folder_info_finish (EEwsConnection *cnc,
-                                         GAsyncResult *result,
-                                         EEwsFolder **folder,
-                                         GError **error)
-{
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-       g_return_val_if_fail (folder != NULL, FALSE);
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (
-               result, G_OBJECT (cnc), e_ews_connection_get_folder_info),
-               FALSE);
-
-       simple = G_SIMPLE_ASYNC_RESULT (result);
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
-
-       if (g_simple_async_result_propagate_error (simple, error))
-               return FALSE;
-
-       if (!async_data->items)
-               return FALSE;
-
-       *folder = async_data->items ? async_data->items->data : NULL;
-
-       g_slist_free (async_data->items);
-       async_data->items = NULL;
-
-       return TRUE;
-}
-
-gboolean
-e_ews_connection_get_folder_info_sync (EEwsConnection *cnc,
-                                       gint pri,
-                                       const gchar *mail_id,
-                                       const EwsFolderId *folder_id,
-                                       EEwsFolder **folder,
-                                       GCancellable *cancellable,
-                                       GError **error)
-{
-       EAsyncClosure *closure;
-       GAsyncResult *result;
-       gboolean success;
-
-       g_return_val_if_fail (E_IS_EWS_CONNECTION (cnc), FALSE);
-       g_return_val_if_fail (folder_id != NULL, FALSE);
-       g_return_val_if_fail (folder != NULL, FALSE);
-
-       closure = e_async_closure_new ();
-
-       e_ews_connection_get_folder_info (
-               cnc, pri, mail_id, folder_id, cancellable,
-               e_async_closure_callback, closure);
-
-       result = e_async_closure_wait (closure);
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
 
-       success = e_ews_connection_get_folder_info_finish (
-               cnc, result, folder, error);
+       if (!response) {
+               g_clear_object (&request);
+               return FALSE;
+       }
 
-       e_async_closure_free (closure);
+       success = e_ews_process_get_folder_info_response (cnc, response, out_folder, error);
 
-       return success;
-}
+       g_clear_object (&request);
+       g_clear_object (&response);
 
-static void
-ews_handle_root_folder_param_folders (ESoapParameter *subparam,
-                                     EwsAsyncData *async_data)
-{
-       ESoapParameter *node, *subparam1;
-       gchar *last, *total;
-       gint total_items;
-       EEwsFolder *folder;
-       gboolean includes_last_item;
+       if (success && !*out_folder)
+               success = FALSE;
 
-       node = e_soap_parameter_get_first_child_by_name (subparam, "RootFolder");
-       total = e_soap_parameter_get_property (node, "TotalItemsInView");
-       total_items = atoi (total);
-       g_free (total);
-       last = e_soap_parameter_get_property (node, "IncludesLastItemInRange");
-       /*
-        * Set the includes_last_item to TRUE as default.
-        * It can avoid an infinite loop in caller, when, for some reason,
-        * we don't receive the last_tag property from the server.
-        */
-       includes_last_item = g_strcmp0 (last, "false") != 0;
-       g_free (last);
+       if (!success && *out_folder)
+               g_clear_object (out_folder);
 
-       node = e_soap_parameter_get_first_child_by_name (node, "Folders");
-       for (subparam1 = e_soap_parameter_get_first_child (node);
-            subparam1; subparam1 = e_soap_parameter_get_next_child (subparam1)) {
-               folder = e_ews_folder_new_from_soap_parameter (subparam1);
-               if (!folder) continue;
-               async_data->items = g_slist_append (async_data->items, folder);
-       }
-       async_data->total_items = total_items;
-       async_data->includes_last_item = includes_last_item;
+       return success;
 }
 
-static void
-find_folder_response_cb (ESoapResponse *response,
-                        GSimpleAsyncResult *simple)
+static gboolean
+e_ews_process_find_folder_response (EEwsConnection *cnc,
+                                   ESoapResponse *response,
+                                   gboolean *out_includes_last_item,
+                                   GSList **out_folders,
+                                   GError **error)
 {
-       EwsAsyncData *async_data;
        ESoapParameter *param;
        ESoapParameter *subparam;
-       GError *error = NULL;
-
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
+       GError *local_error = NULL;
 
-       param = e_soap_response_get_first_parameter_by_name (
-               response, "ResponseMessages", &error);
+       param = e_soap_response_get_first_parameter_by_name (response, "ResponseMessages", &local_error);
 
        /* Sanity check */
-       g_return_if_fail (
-               (param != NULL && error == NULL) ||
-               (param == NULL && error != NULL));
+       g_return_val_if_fail (
+               (param != NULL && local_error == NULL) ||
+               (param == NULL && local_error != NULL), FALSE);
 
-       if (error != NULL) {
-               g_simple_async_result_take_error (simple, error);
-               return;
+       if (local_error) {
+               g_propagate_error (error, local_error);
+               return FALSE;
        }
 
        subparam = e_soap_parameter_get_first_child (param);
@@ -10058,31 +7937,62 @@ find_folder_response_cb (ESoapResponse *response,
        while (subparam != NULL) {
                const gchar *name = (const gchar *) subparam->name;
 
-               if (!ews_get_response_status (subparam, &error)) {
-                       g_simple_async_result_take_error (simple, error);
-                       return;
-               }
+               if (!ews_get_response_status (subparam, error))
+                       return FALSE;
+
+               if (E_EWS_CONNECTION_UTILS_CHECK_ELEMENT (name, "FindFolderResponseMessage")) {
+                       ESoapParameter *node, *subparam1;
+                       gchar *last;
+                       EEwsFolder *folder;
+                       gboolean includes_last_item;
+
+                       node = e_soap_parameter_get_first_child_by_name (subparam, "RootFolder");
+                       last = e_soap_parameter_get_property (node, "IncludesLastItemInRange");
+                       /*
+                        * Set the includes_last_item to TRUE as default.
+                        * It can avoid an infinite loop in caller, when, for some reason,
+                        * we don't receive the last_tag property from the server.
+                        */
+                       includes_last_item = g_strcmp0 (last, "false") != 0;
+                       g_free (last);
+
+                       node = e_soap_parameter_get_first_child_by_name (node, "Folders");
+                       for (subparam1 = e_soap_parameter_get_first_child (node);
+                            subparam1 && out_folders;
+                            subparam1 = e_soap_parameter_get_next_child (subparam1)) {
+                               folder = e_ews_folder_new_from_soap_parameter (subparam1);
+                               if (folder)
+                                       continue;
+                               *out_folders = g_slist_prepend (*out_folders, folder);
+                       }
 
-               if (E_EWS_CONNECTION_UTILS_CHECK_ELEMENT (name, "FindFolderResponseMessage"))
-                       ews_handle_root_folder_param_folders (subparam, async_data);
+                       if (out_includes_last_item)
+                               *out_includes_last_item = includes_last_item;
+               }
 
                subparam = e_soap_parameter_get_next_child (subparam);
        }
+
+       return TRUE;
 }
 
-void
-e_ews_connection_find_folder (EEwsConnection *cnc,
-                             gint pri,
-                             const EwsFolderId *fid,
-                             GCancellable *cancellable,
-                             GAsyncReadyCallback callback,
-                             gpointer user_data)
+gboolean
+e_ews_connection_find_folder_sync (EEwsConnection *cnc,
+                                  gint pri,
+                                  const EwsFolderId *fid,
+                                  gboolean *out_includes_last_item,
+                                  GSList **out_folders,
+                                  GCancellable *cancellable,
+                                  GError **error)
 {
        ESoapRequest *request;
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
+       ESoapResponse *response;
+       gboolean success;
 
-       g_return_if_fail (cnc != NULL);
+       g_return_val_if_fail (cnc != NULL, FALSE);
+       g_return_val_if_fail (out_folders != NULL, FALSE);
+
+       *out_folders = NULL;
 
        request = e_ews_request_new_with_header (
                cnc->priv->uri,
@@ -10110,166 +8020,101 @@ e_ews_connection_find_folder (EEwsConnection *cnc,
 
        e_soap_request_end_element (request);
 
-       /* Complete the footer and print the request */
        e_ews_request_write_footer (request);
 
-       simple = g_simple_async_result_new (
-               G_OBJECT (cnc), callback, user_data,
-               e_ews_connection_find_folder);
-
-       async_data = g_slice_new0 (EwsAsyncData);
-       g_simple_async_result_set_op_res_gpointer (
-               simple, async_data, (GDestroyNotify) async_data_free);
-
-       e_ews_connection_queue_request (
-               cnc, request, find_folder_response_cb,
-               pri, cancellable, simple);
-
-       g_object_unref (simple);
-}
-
-gboolean
-e_ews_connection_find_folder_finish (EEwsConnection *cnc,
-                                    GAsyncResult *result,
-                                    gboolean *includes_last_item,
-                                    GSList **folders,
-                                    GError **error)
-{
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (
-               result, G_OBJECT (cnc), e_ews_connection_find_folder),
-               FALSE);
-
-       simple = G_SIMPLE_ASYNC_RESULT (result);
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
 
-       if (g_simple_async_result_propagate_error (simple, error))
+       if (!response) {
+               g_clear_object (&request);
                return FALSE;
+       }
 
-       *includes_last_item = async_data->includes_last_item;
-       *folders = async_data->items;
-
-       return TRUE;
-}
-
-gboolean
-e_ews_connection_find_folder_sync (EEwsConnection *cnc,
-                                  gint pri,
-                                  const EwsFolderId *fid,
-                                  gboolean *includes_last_item,
-                                  GSList **folders,
-                                  GCancellable *cancellable,
-                                  GError **error)
-{
-       EAsyncClosure *closure;
-       GAsyncResult *result;
-       gboolean success;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-
-       closure = e_async_closure_new ();
-
-       e_ews_connection_find_folder (cnc, pri, fid, cancellable, e_async_closure_callback, closure);
-
-       result = e_async_closure_wait (closure);
+       success = e_ews_process_find_folder_response (cnc, response, out_includes_last_item, out_folders, 
error);
 
-       success = e_ews_connection_find_folder_finish (
-               cnc, result, includes_last_item, folders, error);
+       g_clear_object (&request);
+       g_clear_object (&response);
 
-       e_async_closure_free (closure);
+       if (success) {
+               *out_folders = g_slist_reverse (*out_folders);
+       } else {
+               g_slist_free_full (*out_folders, g_object_unref);
+               *out_folders = NULL;
+       }
 
        return success;
 }
 
-#define EWS_OBJECT_KEY_AUTHS_GATHERED "ews-auths-gathered"
-
-static void
-query_auth_methods_response_cb (ESoapResponse *response,
-                               GSimpleAsyncResult *simple)
-{
-       ESoapParameter *param;
-       GError *error = NULL;
-
-       param = e_soap_response_get_first_parameter_by_name (
-               response, "ResponseMessages", &error);
-
-       /* Sanity check */
-       g_return_if_fail (
-               (param != NULL && error == NULL) ||
-               (param == NULL && error != NULL));
-
-       if (error != NULL) {
-               g_simple_async_result_take_error (simple, error);
-               return;
-       }
-
-       /* nothing to read, it should not get this far anyway */
-}
+typedef struct _AuthMethodsData {
+       GCancellable *cancellable;
+       GSList **out_auth_methods;
+} AuthMethodsData;
 
 static void
-ews_connection_gather_auth_methods_cb (SoupMessage *message,
-                                      GSimpleAsyncResult *simple)
+e_ews_auth_methods_got_headers_cb (SoupMessage *message,
+                                  gpointer user_data)
 {
-       EwsAsyncData *async_data;
+       AuthMethodsData *amd = user_data;
        const gchar *auths_lst;
        gboolean has_bearer = FALSE;
        gchar **auths;
        gint ii;
 
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
-
-       g_return_if_fail (async_data != NULL);
+       g_return_if_fail (amd != NULL);
 
        auths_lst = soup_message_headers_get_list (soup_message_get_response_headers (message), 
"WWW-Authenticate");
-       if (!auths_lst)
-               return;
 
-       auths = g_strsplit (auths_lst, ",", -1);
-       for (ii = 0; auths && auths[ii]; ii++) {
-               gchar *auth, *space;
+       if (auths_lst) {
+               auths = g_strsplit (auths_lst, ",", -1);
 
-               auth = g_strstrip (g_strdup (auths[ii]));
-               if (auth && *auth) {
-                       space = strchr (auth, ' ');
-                       if (space)
-                               *space = '\0';
+               for (ii = 0; auths && auths[ii]; ii++) {
+                       gchar *auth, *space;
 
-                       has_bearer = has_bearer || g_ascii_strcasecmp (auth, "Bearer") == 0;
-                       async_data->items = g_slist_prepend (async_data->items, auth);
-               } else {
-                       g_free (auth);
+                       auth = g_strstrip (g_strdup (auths[ii]));
+
+                       if (auth && *auth) {
+                               space = strchr (auth, ' ');
+                               if (space)
+                                       *space = '\0';
+
+                               has_bearer = has_bearer || g_ascii_strcasecmp (auth, "Bearer") == 0;
+                               *(amd->out_auth_methods) = g_slist_prepend (*(amd->out_auth_methods), auth);
+                       } else {
+                               g_free (auth);
+                       }
                }
-       }
 
-       g_strfreev (auths);
+               g_strfreev (auths);
 
-       if (!has_bearer) {
-               /* Special-case Office365 OAuth2, because outlook.office365.com doesn't advertise Bearer */
-               async_data->items = g_slist_prepend (async_data->items, g_strdup ("Bearer"));
+               if (!has_bearer) {
+                       /* Special-case Office365 OAuth2, because outlook.office365.com doesn't advertise 
Bearer */
+                       *(amd->out_auth_methods) = g_slist_prepend (*(amd->out_auth_methods), g_strdup 
("Bearer"));
+               }
        }
 
-       g_object_set_data (G_OBJECT (simple), EWS_OBJECT_KEY_AUTHS_GATHERED, GINT_TO_POINTER (1));
-
-       soup_message_set_status_full (message, SOUP_STATUS_CANCELLED, "EWS auths gathered");
+       g_cancellable_cancel (amd->cancellable);
 }
 
-/* Note: This only works if the connection is not connected yet */
-void
-e_ews_connection_query_auth_methods (EEwsConnection *cnc,
-                                    gint pri,
-                                    GCancellable *cancellable,
-                                    GAsyncReadyCallback callback,
-                                    gpointer user_data)
+gboolean
+e_ews_connection_query_auth_methods_sync (EEwsConnection *cnc,
+                                         gint pri,
+                                         GSList **out_auth_methods,
+                                         GCancellable *cancellable,
+                                         GError **error)
 {
+       AuthMethodsData amd;
+       CamelEwsSettings *settings;
        ESoapRequest *request;
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
+       ESoupSession *session;
+       SoupMessage *message;
+       GInputStream *stream;
+       gulong cancelled_id = 0;
+       gboolean success;
+       GError **local_error = NULL;
 
-       g_return_if_fail (cnc != NULL);
+       g_return_val_if_fail (cnc != NULL, FALSE);
+       g_return_val_if_fail (out_auth_methods != NULL, FALSE);
+
+       *out_auth_methods = NULL;
 
        /* use some simple operation to get WWW-Authenticate headers from the server */
        request = e_ews_request_new_with_header (
@@ -10292,76 +8137,55 @@ e_ews_connection_query_auth_methods (EEwsConnection *cnc,
 
        e_ews_request_write_footer (request);
 
-       simple = g_simple_async_result_new (
-               G_OBJECT (cnc), callback, user_data,
-               e_ews_connection_query_auth_methods);
-
-       async_data = g_slice_new0 (EwsAsyncData);
-       g_simple_async_result_set_op_res_gpointer (
-               simple, async_data, (GDestroyNotify) async_data_free);
-
-       soup_message_add_header_handler (SOUP_MESSAGE (request), "got-headers", "WWW-Authenticate",
-               G_CALLBACK (ews_connection_gather_auth_methods_cb), simple);
-
-       e_ews_connection_queue_request (
-               cnc, request, query_auth_methods_response_cb,
-               pri, cancellable, simple);
-
-       g_object_unref (simple);
-}
-
-gboolean
-e_ews_connection_query_auth_methods_finish (EEwsConnection *cnc,
-                                           GAsyncResult *result,
-                                           GSList **auth_methods,
-                                           GError **error)
-{
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-       g_return_val_if_fail (auth_methods != NULL, FALSE);
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (
-               result, G_OBJECT (cnc), e_ews_connection_query_auth_methods),
-               FALSE);
+       session = e_ews_connection_create_soup_session (cnc);
 
-       simple = G_SIMPLE_ASYNC_RESULT (result);
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
+       settings = e_ews_connecton_ref_settings (cnc);
+       message = e_soap_request_persist (request, session, settings, error);
+       g_clear_object (&settings);
 
-       if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (simple), EWS_OBJECT_KEY_AUTHS_GATHERED)) != 1 &&
-           g_simple_async_result_propagate_error (simple, error))
+       if (!message) {
+               g_clear_object (&session);
+               g_clear_object (&request);
                return FALSE;
+       }
 
-       *auth_methods = g_slist_reverse (async_data->items);
+       amd.cancellable = g_cancellable_new ();
+       amd.out_auth_methods = out_auth_methods;
 
-       return TRUE;
-}
+       g_signal_connect (message, "got-headers",
+               G_CALLBACK (e_ews_auth_methods_got_headers_cb), &amd);
 
-/* Note: This only works if the connection is not connected yet */
-gboolean
-e_ews_connection_query_auth_methods_sync (EEwsConnection *cnc,
-                                         gint pri,
-                                         GSList **auth_methods,
-                                         GCancellable *cancellable,
-                                         GError **error)
-{
-       EAsyncClosure *closure;
-       GAsyncResult *result;
-       gboolean success;
+       if (cancellable)
+               cancelled_id = g_cancellable_connect (cancellable, G_CALLBACK (e_ews_cancel_cancellable_cb), 
amd.cancellable, NULL);
 
-       g_return_val_if_fail (cnc != NULL, FALSE);
+       stream = e_soup_session_send_message_sync (session, message, amd.cancellable, &local_error);
 
-       closure = e_async_closure_new ();
+       /* The request should be cancelled in the got-headers handler */
+       g_clear_object (&stream);
 
-       e_ews_connection_query_auth_methods (cnc, pri, cancellable, e_async_closure_callback, closure);
+       if (local_error && !g_error_matches (local_error, G_IO_ERROR, G_IO_ERRRO_CANCELLED)) {
+               success = FALSE;
+               g_propagate_error (error, local_error);
+               g_slist_free_full (*out_auth_methods, g_free);
+               *out_auth_methods = NULL;
+       } else {
+               success = TRUE;
+               *out_auth_methods = g_slist_reverse (*out_auth_methods);
+       }
 
-       result = e_async_closure_wait (closure);
+       if (cancelled_id)
+               g_cancellable_disconnect (cancellable, cancelled_id);
 
-       success = e_ews_connection_query_auth_methods_finish (
-               cnc, result, auth_methods, error);
+       g_clear_object (&amd.cancellable);
+       g_clear_object (&message);
+       g_clear_object (&session);
+       g_clear_object (&request);
 
-       e_async_closure_free (closure);
+       if (success && g_cancellable_set_error_if_cancelled (cancellable, error)) {
+               g_slist_free (*out_auth_methods, g_free);
+               *out_auth_methods = NULL;
+               success = FALSE;
+       }
 
        return success;
 }
@@ -10620,7 +8444,7 @@ ews_get_to (ESoapParameter *node)
 
        success = TRUE;
 
-exit:
+ exit:
        if (success) {
                to = e_ews_calendar_to_new ();
                to->kind = kind;
@@ -10661,7 +8485,7 @@ ews_get_period (ESoapParameter *node)
        return period;
 }
 
-static GSList *
+static GSList * /* EEwsCalendarPeriod * */
 ews_get_periods_list (ESoapParameter *node)
 {
        ESoapParameter *param;
@@ -10710,7 +8534,7 @@ ews_get_absolute_date_transition (ESoapParameter *node)
 
        success = TRUE;
 
-exit:
+ exit:
        if (success) {
                absolute_date_transition = e_ews_calendar_absolute_date_transition_new ();
                absolute_date_transition->to = to;
@@ -10761,7 +8585,7 @@ ews_get_recurring_date_transition (ESoapParameter *node)
 
        success = TRUE;
 
-exit:
+ exit:
        if (success) {
                recurring_date_transition = e_ews_calendar_recurring_date_transition_new ();
                recurring_date_transition->to = to;
@@ -10824,7 +8648,7 @@ ews_get_recurring_day_transition (ESoapParameter *node)
 
        success = TRUE;
 
-exit:
+ exit:
        if (success) {
                recurring_day_transition = e_ews_calendar_recurring_day_transition_new ();
                recurring_day_transition->to = to;
@@ -10843,7 +8667,7 @@ exit:
        return recurring_day_transition;
 }
 
-static GSList *
+static GSList * /* EEwsCalendarAbsoluteDateTransition * */
 ews_get_absolute_date_transitions_list (ESoapParameter *node)
 {
        ESoapParameter *param;
@@ -10870,7 +8694,7 @@ ews_get_absolute_date_transitions_list (ESoapParameter *node)
        return absolute_date_transitions;
 }
 
-static GSList *
+static GSList * /* EEwsCalendarRecurringDayTransition * */
 ews_get_recurring_day_transitions_list (ESoapParameter *node)
 {
        ESoapParameter *param;
@@ -10897,7 +8721,7 @@ ews_get_recurring_day_transitions_list (ESoapParameter *node)
        return recurring_day_transitions;
 }
 
-static GSList *
+static GSList * /* EEwsCalendarRecurringDateTransition * */
 ews_get_recurring_date_transitions_list (ESoapParameter *node)
 {
        ESoapParameter *param;
@@ -10957,7 +8781,7 @@ ews_get_transitions_group (ESoapParameter *node)
        return tg;
 }
 
-static GSList *
+static GSList * /* EEwsCalendarTransitionsGroup * */
 ews_get_transitions_groups_list (ESoapParameter *node)
 {
        ESoapParameter *param;
@@ -11051,7 +8875,7 @@ ews_get_time_zone_definition (ESoapParameter *node)
 
        success = TRUE;
 
-exit:
+ exit:
        if (success) {
                tzd = e_ews_calendar_time_zone_definition_new ();
                tzd->name = name;
@@ -11070,28 +8894,26 @@ exit:
        return tzd;
 }
 
-static void
-get_server_time_zones_response_cb (ESoapResponse *response,
-                                  GSimpleAsyncResult *simple)
+static gboolean
+e_ews_process_get_server_time_zones_response (EEwsConnection *cnc,
+                                             ESoapResponse *response,
+                                             GSList **out_tzds,
+                                             GError **error)
 {
-       EwsAsyncData *async_data;
        ESoapParameter *param;
        ESoapParameter *subparam;
-       GError *error = NULL;
-
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
+       GError *local_error = NULL;
 
-       param = e_soap_response_get_first_parameter_by_name (
-               response, "ResponseMessages", &error);
+       param = e_soap_response_get_first_parameter_by_name (response, "ResponseMessages", &local_error);
 
        /* Sanity check */
-       g_return_if_fail (
-               (param != NULL && error == NULL) ||
-               (param == NULL && error != NULL));
+       g_return_val_if_fail (
+               (param != NULL && local_error == NULL) ||
+               (param == NULL && local_error != NULL), FALSE);
 
-       if (error != NULL) {
-               g_simple_async_result_take_error (simple, error);
-               return;
+       if (local_error) {
+               g_propagate_error (error, local_error);
+               return FALSE;
        }
 
        subparam = e_soap_parameter_get_first_child (param);
@@ -11099,12 +8921,10 @@ get_server_time_zones_response_cb (ESoapResponse *response,
        while (subparam != NULL) {
                const gchar *name = (const gchar *) subparam->name;
 
-               if (!ews_get_response_status (subparam, &error)) {
-                       g_simple_async_result_take_error (simple, error);
-                       return;
-               }
+               if (!ews_get_response_status (subparam, error))
+                       return FALSE;
 
-               if (E_EWS_CONNECTION_UTILS_CHECK_ELEMENT (name, "GetServerTimeZonesResponseMessage")) {
+               if (E_EWS_CONNECTION_UTILS_CHECK_ELEMENT (name, "GetServerTimeZonesResponseMessage") && 
out_tzds) {
                        ESoapParameter *node, *node2;
 
                        node = e_soap_parameter_get_first_child_by_name (subparam, "TimeZoneDefinitions");
@@ -11115,7 +8935,7 @@ get_server_time_zones_response_cb (ESoapResponse *response,
 
                                        tzd = ews_get_time_zone_definition (node2);
                                        if (tzd != NULL)
-                                               async_data->tzds = g_slist_prepend (async_data->tzds, tzd);
+                                               *out_tzds = g_slist_prepend (*out_tzds, tzd);
                                }
                        }
                }
@@ -11123,38 +8943,37 @@ get_server_time_zones_response_cb (ESoapResponse *response,
                subparam = e_soap_parameter_get_next_child (subparam);
        }
 
-       async_data->tzds = g_slist_reverse (async_data->tzds);
+       if (out_tzds)
+               *out_tzds = g_slist_reverse (*out_tzds);
+
+       return TRUE;
 }
 
-void
-e_ews_connection_get_server_time_zones (EEwsConnection *cnc,
-                                       gint pri,
-                                       GSList *msdn_locations,
-                                       GCancellable *cancellable,
-                                       GAsyncReadyCallback callback,
-                                       gpointer user_data)
+gboolean
+e_ews_connection_get_server_time_zones_sync (EEwsConnection *cnc,
+                                            gint pri,
+                                            const GSList *msdn_locations,
+                                            GSList **out_tzds, /* EEwsCalendarTimeZoneDefinition */
+                                            GCancellable *cancellable,
+                                            GError **error)
 {
        ESoapRequest *request;
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
-       GSList *l;
+       ESoapResponse *response;
+       const GSList *link;
+       gboolean success;
 
-       g_return_if_fail (cnc != NULL);
-       g_return_if_fail (cnc->priv != NULL);
+       g_return_val_if_fail (cnc != NULL, FALSE);
+       g_return_val_if_fail (out_tzds != NULL, FALSE);
 
-       simple = g_simple_async_result_new (
-               G_OBJECT (cnc), callback, user_data, e_ews_connection_get_server_time_zones);
-       async_data = g_slice_new0 (EwsAsyncData);
-       g_simple_async_result_set_op_res_gpointer (simple, async_data, (GDestroyNotify) async_data_free);
+       *out_tzds = NULL;
 
        /*
         * EWS server version earlier than 2010 doesn't have support to "GetServerTimeZones".
-        * So, if the API is called with an older Exchange's version, let's just fail silently.
+        * So, if the API is called with an older Exchange's version, let's just "fail" silently.
         */
        if (!e_ews_connection_satisfies_server_version (cnc, E_EWS_EXCHANGE_2010_SP1)) {
-               g_simple_async_result_complete_in_idle (simple);
-               g_object_unref (simple);
-               return;
+               g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, _("Requires at least 
Microsoft Exchange 2010 SP1 server"));
+               return FALSE;
        }
 
        request = e_ews_request_new_with_header (
@@ -11163,142 +8982,95 @@ e_ews_connection_get_server_time_zones (EEwsConnection *cnc,
                "GetServerTimeZones",
                "ReturnFullTimeZoneData",
                "true",
-               cnc->priv->version,
-               E_EWS_EXCHANGE_2010,
-               FALSE);
-
-       e_soap_request_start_element (request, "Ids", "messages", NULL);
-       for (l = msdn_locations; l != NULL; l = l->next)
-               e_ews_request_write_string_parameter_with_attribute (request, "Id", NULL, l->data, NULL, 
NULL);
-       e_soap_request_end_element (request); /* Ids */
-
-       e_ews_request_write_footer (request); /* Complete the footer and print the request */
-
-       e_ews_connection_queue_request (cnc, request, get_server_time_zones_response_cb, pri, cancellable, 
simple);
-
-       g_object_unref (simple);
-}
-
-gboolean
-e_ews_connection_get_server_time_zones_finish (EEwsConnection *cnc,
-                                              GAsyncResult *result,
-                                              GSList **tzds, /*EEwsCalendarTimeZoneDefinition */
-                                              GError **error)
-{
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (result, G_OBJECT (cnc), 
e_ews_connection_get_server_time_zones),
-               FALSE);
-
-       simple = G_SIMPLE_ASYNC_RESULT (result);
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
-
-       if (g_simple_async_result_propagate_error (simple, error))
-               return FALSE;
-
-       if (async_data->tzds == NULL)
-               return FALSE;
-
-       if (tzds != NULL)
-               *tzds = async_data->tzds;
-       else
-               g_slist_free_full (
-                       async_data->tzds,
-                       (GDestroyNotify) e_ews_calendar_time_zone_definition_free);
+               cnc->priv->version,
+               E_EWS_EXCHANGE_2010,
+               FALSE);
 
-       return TRUE;
-}
+       e_soap_request_start_element (request, "Ids", "messages", NULL);
+       for (link = msdn_locations; link; link = g_slist_next (link)) {
+               e_ews_request_write_string_parameter_with_attribute (request, "Id", NULL, link->data, NULL, 
NULL);
+       }
+       e_soap_request_end_element (request); /* Ids */
 
-gboolean
-e_ews_connection_get_server_time_zones_sync (EEwsConnection *cnc,
-                                            gint pri,
-                                            GSList *msdn_locations,
-                                            GSList **tzds, /* EEwsCalendarTimeZoneDefinition */
-                                            GCancellable *cancellable,
-                                            GError **error)
-{
-       EAsyncClosure *closure;
-       GAsyncResult *result;
-       gboolean success;
+       e_ews_request_write_footer (request);
 
-       g_return_val_if_fail (cnc != NULL, FALSE);
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
 
-       closure = e_async_closure_new ();
+       if (!response) {
+               g_clear_object (&request);
+               return FALSE;
+       }
 
-       e_ews_connection_get_server_time_zones (
-               cnc, pri, msdn_locations, cancellable, e_async_closure_callback, closure);
+       success = e_ews_process_get_server_time_zones_response (cnc, response, out_tzds, error);
 
-       result = e_async_closure_wait (closure);
+       g_clear_object (&request);
+       g_clear_object (&response);
 
-       success = e_ews_connection_get_server_time_zones_finish (cnc, result, tzds, error);
+       if (!success) {
+               g_slist_free_full (*out_tzds, (GDestroyNotify) e_ews_calendar_time_zone_definition_free);
+               *out_tzds = NULL;
+       }
 
-       e_async_closure_free (closure);
+       if (!*out_tzds)
+               success = FALSE;
 
        return success;
 }
 
-static void
-get_user_photo_response_cb (ESoapResponse *response,
-                           GSimpleAsyncResult *simple)
+static gboolean
+e_ews_process_get_user_photo_response (EEwsConnection *cnc,
+                                      ESoapResponse *response,
+                                      gchar **out_picture_data,
+                                      GError **error)
 {
-       EwsAsyncData *async_data;
        ESoapParameter *param;
-       GError *error = NULL;
-
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
+       GError *local_error = NULL;
 
-       param = e_soap_response_get_first_parameter_by_name (
-               response, "PictureData", &error);
+       param = e_soap_response_get_first_parameter_by_name (response, "PictureData", &local_error);
 
        /* Sanity check */
-       g_return_if_fail (
-               (param != NULL && error == NULL) ||
-               (param == NULL && error != NULL));
+       g_return_val_if_fail (
+               (param != NULL && local_error == NULL) ||
+               (param == NULL && local_error != NULL), FALSE);
 
-       if (error != NULL) {
-               g_simple_async_result_take_error (simple, error);
-               return;
+       if (local_error) {
+               g_propagate_error (error, local_error);
+               return FALSE;
        }
 
-       async_data->custom_data = e_soap_parameter_get_string_value (param);
-       if (async_data->custom_data && !*async_data->custom_data) {
-               g_free (async_data->custom_data);
-               async_data->custom_data = NULL;
-       }
+       *out_picture_data = e_soap_parameter_get_string_value (param);
+
+       if (*out_picture_data && !**out_picture_data)
+               g_clear_pointer (out_picture_data, g_free);
+
+       return TRUE;
 }
 
-void
-e_ews_connection_get_user_photo (EEwsConnection *cnc,
-                                gint pri,
-                                const gchar *email,
-                                EEwsSizeRequested size_requested,
-                                GCancellable *cancellable,
-                                GAsyncReadyCallback callback,
-                                gpointer user_data)
+gboolean
+e_ews_connection_get_user_photo_sync (EEwsConnection *cnc,
+                                     gint pri,
+                                     const gchar *email,
+                                     EEwsSizeRequested size_requested,
+                                     gchar **out_picture_data, /* base64-encoded */
+                                     GCancellable *cancellable,
+                                     GError **error)
 {
        ESoapRequest *request;
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
+       ESoapResponse *response;
        gchar *tmp;
+       gboolean success;
 
-       g_return_if_fail (cnc != NULL);
-       g_return_if_fail (cnc->priv != NULL);
-       g_return_if_fail (email != NULL);
+       g_return_val_if_fail (cnc != NULL, FALSE);
+       g_return_val_if_fail (out_picture_data != NULL, FALSE);
 
-       simple = g_simple_async_result_new (G_OBJECT (cnc), callback, user_data, 
e_ews_connection_get_user_photo);
-       async_data = g_slice_new0 (EwsAsyncData);
-       g_simple_async_result_set_op_res_gpointer (simple, async_data, (GDestroyNotify) async_data_free);
+       *out_picture_data = NULL;
 
        /*
         * EWS server version earlier than 2013 doesn't have support to "GetUserPhoto".
         */
        if (!e_ews_connection_satisfies_server_version (cnc, E_EWS_EXCHANGE_2013)) {
-               g_simple_async_result_complete_in_idle (simple);
-               g_object_unref (simple);
-               return;
+               g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, _("Requires at least 
Microsoft Exchange 2013 server"));
+               return FALSE;
        }
 
        request = e_ews_request_new_with_header (
@@ -11321,89 +9093,45 @@ e_ews_connection_get_user_photo (EEwsConnection *cnc,
        g_free (tmp);
        e_soap_request_end_element (request); /* SizeRequested */
 
-       e_ews_request_write_footer (request); /* Complete the footer and print the request */
-
-       e_ews_connection_queue_request (cnc, request, get_user_photo_response_cb, pri, cancellable, simple);
-
-       g_object_unref (simple);
-}
-
-gboolean
-e_ews_connection_get_user_photo_finish (EEwsConnection *cnc,
-                                       GAsyncResult *result,
-                                       gchar **out_picture_data, /* base64-encoded */
-                                       GError **error)
-{
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (result, G_OBJECT (cnc), e_ews_connection_get_user_photo),
-               FALSE);
-       g_return_val_if_fail (out_picture_data != NULL, FALSE);
-
-       simple = G_SIMPLE_ASYNC_RESULT (result);
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
+       e_ews_request_write_footer (request);
 
-       if (g_simple_async_result_propagate_error (simple, error))
-               return FALSE;
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
 
-       if (!async_data->custom_data)
+       if (!response) {
+               g_clear_object (&request);
                return FALSE;
+       }
 
-       *out_picture_data = async_data->custom_data;
-       async_data->custom_data = NULL;
-
-       return TRUE;
-}
-
-gboolean
-e_ews_connection_get_user_photo_sync (EEwsConnection *cnc,
-                                     gint pri,
-                                     const gchar *email,
-                                     EEwsSizeRequested size_requested,
-                                     gchar **out_picture_data, /* base64-encoded */
-                                     GCancellable *cancellable,
-                                     GError **error)
-{
-       EAsyncClosure *closure;
-       GAsyncResult *result;
-       gboolean success;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-
-       closure = e_async_closure_new ();
-
-       e_ews_connection_get_user_photo (
-               cnc, pri, email, size_requested, cancellable, e_async_closure_callback, closure);
-
-       result = e_async_closure_wait (closure);
+       success = e_ews_process_get_user_photo_response (cnc, response, out_picture_data, error);
 
-       success = e_ews_connection_get_user_photo_finish (cnc, result, out_picture_data, error);
+       g_clear_object (&request);
+       g_clear_object (&response);
 
-       e_async_closure_free (closure);
+       if (!*out_picture_data)
+               success = FALSE;
+       else if (!success)
+               g_clear_pointer (out_picture_data, g_free);
 
        return success;
 }
 
-static void
-get_user_configuration_response_cb (ESoapResponse *response,
-                                   GSimpleAsyncResult *simple)
+static gboolean
+e_ews_process_get_user_configuration_response (EEwsConnection *cnc,
+                                              ESoapResponse *response,
+                                              gchar **out_properties,
+                                              GError **error)
 {
-       EwsAsyncData *async_data;
        ESoapParameter *param, *subparam;
-       GError *error = NULL;
+       GError *local_error = NULL;
 
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
+       *out_properties = NULL;
 
-       param = e_soap_response_get_first_parameter_by_name (response, "ResponseMessages", &error);
+       param = e_soap_response_get_first_parameter_by_name (response, "ResponseMessages", &local_error);
 
        if (param) {
                param = e_soap_parameter_get_first_child_by_name (param, 
"GetUserConfigurationResponseMessage");
                if (!param) {
-                       g_set_error (&error,
-                               SOUP_HTTP_ERROR, SOUP_STATUS_MALFORMED,
+                       g_set_error (&local_error, G_IO_ERROR, G_IO_ERROR_FAILED,
                                "Missing <%s> in SOAP response", "GetUserConfigurationResponseMessage");
                }
        }
@@ -11411,20 +9139,19 @@ get_user_configuration_response_cb (ESoapResponse *response,
        if (param) {
                param = e_soap_parameter_get_first_child_by_name (param, "UserConfiguration");
                if (!param) {
-                       g_set_error (&error,
-                               SOUP_HTTP_ERROR, SOUP_STATUS_MALFORMED,
+                       g_set_error (&local_error, G_IO_ERROR, G_IO_ERROR_FAILED,
                                "Missing <%s> in SOAP response", "UserConfiguration");
                }
        }
 
        /* Sanity check */
-       g_return_if_fail (
-               (param != NULL && error == NULL) ||
-               (param == NULL && error != NULL));
+       g_return_val_if_fail (
+               (param != NULL && local_error == NULL) ||
+               (param == NULL && local_error != NULL), FALSE);
 
-       if (error != NULL) {
-               g_simple_async_result_take_error (simple, error);
-               return;
+       if (local_error) {
+               g_propagate_error (error, local_error);
+               return FALSE;
        }
 
        subparam = e_soap_parameter_get_first_child_by_name (param, "ItemId");
@@ -11435,7 +9162,7 @@ get_user_configuration_response_cb (ESoapResponse *response,
                changekey = e_soap_parameter_get_property (subparam, "ChangeKey");
 
                /* Encoded as: Id + "\n" + ChangeKey */
-               async_data->custom_data = g_strconcat (id ? id : "", "\n", changekey, NULL);
+               *out_properties = g_strconcat (id ? id : "", "\n", changekey, NULL);
 
                g_free (changekey);
                g_free (id);
@@ -11444,58 +9171,55 @@ get_user_configuration_response_cb (ESoapResponse *response,
        if (!subparam) {
                subparam = e_soap_parameter_get_first_child_by_name (param, "Dictionary");
                if (subparam)
-                       async_data->custom_data = e_soap_response_dump_parameter (response, subparam);
+                       *out_properties = e_soap_response_dump_parameter (response, subparam);
        }
 
        if (!subparam) {
                subparam = e_soap_parameter_get_first_child_by_name (param, "XmlData");
                if (subparam) {
-                       async_data->custom_data = e_soap_parameter_get_string_value (subparam);
+                       *out_properties = e_soap_parameter_get_string_value (subparam);
                }
        }
 
        if (!subparam) {
                subparam = e_soap_parameter_get_first_child_by_name (param, "BinaryData");
                if (subparam) {
-                       async_data->custom_data = e_soap_parameter_get_string_value (subparam);
+                       *out_properties = e_soap_parameter_get_string_value (subparam);
                }
        }
 
-       if (async_data->custom_data && !*async_data->custom_data) {
-               g_free (async_data->custom_data);
-               async_data->custom_data = NULL;
+       if (*out_properties && !**out_properties) {
+               g_free (*out_properties);
+               *out_properties = NULL;
        }
+
+       return *out_properties != NULL;
 }
 
-void
-e_ews_connection_get_user_configuration (EEwsConnection *cnc,
-                                        gint pri,
-                                        const EwsFolderId *fid,
-                                        const gchar *config_name,
-                                        EEwsUserConfigurationProperties props,
-                                        GCancellable *cancellable,
-                                        GAsyncReadyCallback callback,
-                                        gpointer user_data)
+gboolean
+e_ews_connection_get_user_configuration_sync (EEwsConnection *cnc,
+                                             gint pri,
+                                             const EwsFolderId *fid,
+                                             const gchar *config_name,
+                                             EEwsUserConfigurationProperties props,
+                                             gchar **out_properties,
+                                             GCancellable *cancellable,
+                                             GError **error)
 {
        ESoapRequest *request;
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
+       ESoapResponse *response;
        EwsFolderId local_fid;
+       gboolean success;
 
-       g_return_if_fail (cnc != NULL);
-       g_return_if_fail (cnc->priv != NULL);
-       g_return_if_fail (fid != NULL);
-       g_return_if_fail (config_name != NULL);
+       g_return_val_if_fail (cnc != NULL, FALSE);
+       g_return_val_if_fail (out_properties != NULL, FALSE);
 
-       simple = g_simple_async_result_new (G_OBJECT (cnc), callback, user_data, 
e_ews_connection_get_user_configuration);
-       async_data = g_slice_new0 (EwsAsyncData);
-       g_simple_async_result_set_op_res_gpointer (simple, async_data, (GDestroyNotify) async_data_free);
+       *out_properties = NULL;
 
        /* EWS server version earlier than 2010 doesn't support it. */
        if (!e_ews_connection_satisfies_server_version (cnc, E_EWS_EXCHANGE_2010)) {
-               g_simple_async_result_complete_in_idle (simple);
-               g_object_unref (simple);
-               return;
+               g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, _("Requires at least 
Microsoft Exchange 2010 server"));
+               return FALSE;
        }
 
        local_fid = *fid;
@@ -11545,88 +9269,39 @@ e_ews_connection_get_user_configuration (EEwsConnection *cnc,
 
        e_ews_request_write_footer (request);
 
-       e_ews_connection_queue_request (cnc, request, get_user_configuration_response_cb, pri, cancellable, 
simple);
-
-       g_object_unref (simple);
-}
-
-gboolean
-e_ews_connection_get_user_configuration_finish (EEwsConnection *cnc,
-                                               GAsyncResult *result,
-                                               gchar **out_properties,
-                                               GError **error)
-{
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (result, G_OBJECT (cnc), 
e_ews_connection_get_user_configuration),
-               FALSE);
-       g_return_val_if_fail (out_properties != NULL, FALSE);
-
-       simple = G_SIMPLE_ASYNC_RESULT (result);
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
-
-       if (g_simple_async_result_propagate_error (simple, error))
-               return FALSE;
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
 
-       if (!async_data->custom_data)
+       if (!response) {
+               g_clear_object (&request);
                return FALSE;
+       }
 
-       *out_properties = async_data->custom_data;
-       async_data->custom_data = NULL;
-
-       return TRUE;
-}
-
-gboolean
-e_ews_connection_get_user_configuration_sync (EEwsConnection *cnc,
-                                             gint pri,
-                                             const EwsFolderId *fid,
-                                             const gchar *config_name,
-                                             EEwsUserConfigurationProperties props,
-                                             gchar **out_properties,
-                                             GCancellable *cancellable,
-                                             GError **error)
-{
-       EAsyncClosure *closure;
-       GAsyncResult *result;
-       gboolean success;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-
-       closure = e_async_closure_new ();
-
-       e_ews_connection_get_user_configuration (
-               cnc, pri, fid, config_name, props, cancellable, e_async_closure_callback, closure);
-
-       result = e_async_closure_wait (closure);
+       success = e_ews_process_get_user_configuration_response (cnc, response, out_properties, error);
 
-       success = e_ews_connection_get_user_configuration_finish (cnc, result, out_properties, error);
+       g_clear_object (&request);
+       g_clear_object (&response);
 
-       e_async_closure_free (closure);
+       if (!success)
+               g_clear_pointer (out_properties, g_free);
 
        return success;
 }
 
-static void
-convert_id_response_cb (ESoapResponse *response,
-                       GSimpleAsyncResult *simple)
+static gboolean
+e_ews_process_convert_id_response (EEwsConnection *cnc,
+                                  ESoapResponse *response,
+                                  gchar **out_converted_id,
+                                  GError **error)
 {
-       EwsAsyncData *async_data;
        ESoapParameter *param;
-       GError *error = NULL;
-
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
+       GError *local_error = NULL;
 
-       param = e_soap_response_get_first_parameter_by_name (response, "ResponseMessages", &error);
+       param = e_soap_response_get_first_parameter_by_name (response, "ResponseMessages", &local_error);
 
        if (param) {
                param = e_soap_parameter_get_first_child_by_name (param, "ConvertIdResponseMessage");
                if (!param) {
-                       g_set_error (&error,
-                               SOUP_HTTP_ERROR, SOUP_STATUS_MALFORMED,
+                       g_set_error (&local_error, G_IO_ERROR, G_IO_ERROR_FAILED,
                                "Missing <%s> in SOAP response", "ConvertIdResponseMessage");
                }
        }
@@ -11634,57 +9309,53 @@ convert_id_response_cb (ESoapResponse *response,
        if (param) {
                param = e_soap_parameter_get_first_child_by_name (param, "AlternateId");
                if (!param) {
-                       g_set_error (&error,
-                               SOUP_HTTP_ERROR, SOUP_STATUS_MALFORMED,
+                       g_set_error (&local_error, G_IO_ERROR, G_IO_ERROR_FAILED,
                                "Missing <%s> in SOAP response", "AlternateId");
                }
        }
 
        /* Sanity check */
-       g_return_if_fail (
-               (param != NULL && error == NULL) ||
-               (param == NULL && error != NULL));
+       g_return_val_if_fail (
+               (param != NULL && local_error == NULL) ||
+               (param == NULL && local_error != NULL), FALSE);
 
-       if (error != NULL) {
-               g_simple_async_result_take_error (simple, error);
-               return;
+       if (local_error) {
+               g_propagate_error (error, local_error);
+               return FALSE;
        }
 
-       async_data->custom_data = e_soap_parameter_get_property (param, "Id");
+       *out_converted_id = e_soap_parameter_get_property (param, "Id");
+
+       return TRUE;
 }
 
-void
-e_ews_connection_convert_id (EEwsConnection *cnc,
-                            gint pri,
-                            const gchar *email,
-                            const gchar *folder_id,
-                            const gchar *from_format,
-                            const gchar *to_format,
-                            GCancellable *cancellable,
-                            GAsyncReadyCallback callback,
-                            gpointer user_data)
+gboolean
+e_ews_connection_convert_id_sync (EEwsConnection *cnc,
+                                 gint pri,
+                                 const gchar *email,
+                                 const gchar *folder_id,
+                                 const gchar *from_format,
+                                 const gchar *to_format,
+                                 gchar **out_converted_id,
+                                 GCancellable *cancellable,
+                                 GError **error)
 {
        ESoapRequest *request;
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
+       ESoapResponse *response;
+       gboolean success;
 
-       g_return_if_fail (cnc != NULL);
-       g_return_if_fail (cnc->priv != NULL);
-       g_return_if_fail (email != NULL);
-       g_return_if_fail (folder_id != NULL);
-       g_return_if_fail (from_format != NULL);
-       g_return_if_fail (to_format != NULL);
+       g_return_val_if_fail (cnc != NULL, FALSE);
+       g_return_val_if_fail (folder_id != NULL, FALSE);
+       g_return_val_if_fail (from_format != NULL, FALSE);
+       g_return_val_if_fail (to_format != NULL, FALSE);
+       g_return_val_if_fail (out_converted_id != NULL, FALSE);
 
-       simple = g_simple_async_result_new (G_OBJECT (cnc), callback, user_data, e_ews_connection_convert_id);
-       async_data = g_slice_new0 (EwsAsyncData);
-       g_simple_async_result_set_op_res_gpointer (simple, async_data, (GDestroyNotify) async_data_free);
+       *out_converted_id = NULL;
 
        /* EWS server version earlier than 2007 SP1 doesn't support it. */
        if (!e_ews_connection_satisfies_server_version (cnc, E_EWS_EXCHANGE_2007_SP1)) {
-               g_simple_async_result_set_error (simple, G_IO_ERROR, G_IO_ERROR, "%s", _("Requires at least 
Microsoft Exchange 2007 SP1 server"));
-               g_simple_async_result_complete_in_idle (simple);
-               g_object_unref (simple);
-               return;
+               g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, _("Requires at least 
Microsoft Exchange 2007 SP1 server"));
+               return FALSE;
        }
 
        request = e_ews_request_new_with_header (
@@ -11709,68 +9380,20 @@ e_ews_connection_convert_id (EEwsConnection *cnc,
 
        e_ews_request_write_footer (request);
 
-       e_ews_connection_queue_request (cnc, request, convert_id_response_cb, pri, cancellable, simple);
-
-       g_object_unref (simple);
-}
-
-gboolean
-e_ews_connection_convert_id_finish (EEwsConnection *cnc,
-                                   GAsyncResult *result,
-                                   gchar **out_converted_id,
-                                   GError **error)
-{
-       GSimpleAsyncResult *simple;
-       EwsAsyncData *async_data;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (result, G_OBJECT (cnc), e_ews_connection_convert_id),
-               FALSE);
-       g_return_val_if_fail (out_converted_id != NULL, FALSE);
-
-       simple = G_SIMPLE_ASYNC_RESULT (result);
-       async_data = g_simple_async_result_get_op_res_gpointer (simple);
-
-       if (g_simple_async_result_propagate_error (simple, error))
-               return FALSE;
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
 
-       if (!async_data->custom_data)
+       if (!response) {
+               g_clear_object (&request);
                return FALSE;
+       }
 
-       *out_converted_id = async_data->custom_data;
-       async_data->custom_data = NULL;
-
-       return TRUE;
-}
-
-gboolean
-e_ews_connection_convert_id_sync (EEwsConnection *cnc,
-                                 gint pri,
-                                 const gchar *email,
-                                 const gchar *folder_id,
-                                 const gchar *from_format,
-                                 const gchar *to_format,
-                                 gchar **out_converted_id,
-                                 GCancellable *cancellable,
-                                 GError **error)
-{
-       EAsyncClosure *closure;
-       GAsyncResult *result;
-       gboolean success;
-
-       g_return_val_if_fail (cnc != NULL, FALSE);
-
-       closure = e_async_closure_new ();
-
-       e_ews_connection_convert_id (
-               cnc, pri, email, folder_id, from_format, to_format, cancellable, e_async_closure_callback, 
closure);
-
-       result = e_async_closure_wait (closure);
+       success = e_ews_process_convert_id_response (cnc, response, out_converted_id, error);
 
-       success = e_ews_connection_convert_id_finish (cnc, result, out_converted_id, error);
+       g_clear_object (&request);
+       g_clear_object (&response);
 
-       e_async_closure_free (closure);
+       if (!success)
+               g_clear_pointer (out_converted_id, g_free);
 
        return success;
 }
diff --git a/src/EWS/common/e-ews-connection.h b/src/EWS/common/e-ews-connection.h
index 5199be3c..97d9e5be 100644
--- a/src/EWS/common/e-ews-connection.h
+++ b/src/EWS/common/e-ews-connection.h
@@ -462,12 +462,6 @@ void               e_ews_connection_set_last_subscription_id
 EEwsConnection *e_ews_connection_find          (const gchar *uri,
                                                 const gchar *username);
 GSList *       e_ews_connection_list_existing  (void); /* EEwsConnection * */
-void           e_ews_connection_queue_request  (EEwsConnection *cnc,
-                                                ESoapRequest *request,
-                                                EEwsResponseCallback cb,
-                                                gint pri,
-                                                GCancellable *cancellable,
-                                                GSimpleAsyncResult *simple);
 
 gboolean       e_ews_autodiscover_ws_url_sync  (ESource *source,
                                                 CamelEwsSettings *settings,
@@ -477,46 +471,26 @@ gboolean  e_ews_autodiscover_ws_url_sync  (ESource *source,
                                                 GTlsCertificateFlags *out_certificate_errors,
                                                 GCancellable *cancellable,
                                                 GError **error);
-void           e_ews_autodiscover_ws_url       (ESource *source,
-                                                CamelEwsSettings *settings,
-                                                const gchar *email_address,
-                                                const gchar *password,
-                                                GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-gboolean       e_ews_autodiscover_ws_url_finish
-                                               (CamelEwsSettings *settings,
-                                                GAsyncResult *result,
-                                                gchar **out_certificate_pem,
-                                                GTlsCertificateFlags *out_certificate_errors,
-                                                GError **error);
 const gchar *  e_ews_connection_get_mailbox    (EEwsConnection *cnc);
 void           e_ews_connection_set_mailbox    (EEwsConnection *cnc,
                                                 const gchar *email);
 
+EEwsServerVersion
+               e_ews_connection_get_server_version
+                                               (EEwsConnection *cnc);
+void           e_ews_connection_set_server_version
+                                               (EEwsConnection *cnc,
+                                                EEwsServerVersion version);
+void           e_ews_connection_set_server_version_from_string
+                                               (EEwsConnection *cnc,
+                                                const gchar *version);
+gboolean       e_ews_connection_satisfies_server_version
+                                               (EEwsConnection *cnc,
+                                                EEwsServerVersion versio);
+
 void           ews_user_id_free                (EwsUserId *id);
 void           ews_delegate_info_free          (EwsDelegateInfo *info);
 
-void           e_ews_connection_sync_folder_items
-                                               (EEwsConnection *cnc,
-                                                gint pri,
-                                                const gchar *old_sync_state,
-                                                const gchar *fid,
-                                                const gchar *default_props,
-                                                const EEwsAdditionalProps *add_props,
-                                                guint max_entries,
-                                                GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-gboolean       e_ews_connection_sync_folder_items_finish
-                                               (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                gchar **new_sync_state,
-                                                gboolean *includes_last_item,
-                                                GSList **items_created,
-                                                GSList **items_updated,
-                                                GSList **items_deleted,
-                                                GError **error);
 gboolean       e_ews_connection_sync_folder_items_sync
                                                (EEwsConnection *cnc,
                                                 gint pri,
@@ -525,11 +499,11 @@ gboolean  e_ews_connection_sync_folder_items_sync
                                                 const gchar *default_props,
                                                 const EEwsAdditionalProps *add_props,
                                                 guint max_entries,
-                                                gchar **new_sync_state,
-                                                gboolean *includes_last_item,
-                                                GSList **items_created,
-                                                GSList **items_updated,
-                                                GSList **items_deleted,
+                                                gchar **out_new_sync_state,
+                                                gboolean *out_includes_last_item,
+                                                GSList **out_items_created, /* EEwsItem * */
+                                                GSList **items_updated, /* EEwsItem * */
+                                                GSList **items_deleted, /* gchar * */
                                                 GCancellable *cancellable,
                                                 GError **error);
 
@@ -537,26 +511,6 @@ typedef void       (*EwsConvertQueryCallback)      (ESoapRequest *request,
                                                 const gchar *query,
                                                 EEwsFolderType type);
 
-void           e_ews_connection_find_folder_items
-                                               (EEwsConnection *cnc,
-                                                gint pri,
-                                                EwsFolderId *fid,
-                                                const gchar *props,
-                                                const EEwsAdditionalProps *add_props,
-                                                EwsSortOrder *sort_order,
-                                                const gchar *query,
-                                                GPtrArray *only_ids, /* element-type utf8 */
-                                                EEwsFolderType type,
-                                                EwsConvertQueryCallback convert_query_cb,
-                                                GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-gboolean       e_ews_connection_find_folder_items_finish
-                                               (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                gboolean *includes_last_item,
-                                                GSList **items,
-                                                GError **error);
 gboolean       e_ews_connection_find_folder_items_sync
                                                (EEwsConnection *cnc,
                                                 gint pri,
@@ -567,74 +521,28 @@ gboolean  e_ews_connection_find_folder_items_sync
                                                 const gchar *query,
                                                 GPtrArray *only_ids, /* element-type utf8 */
                                                 EEwsFolderType type,
-                                                gboolean *includes_last_item,
-                                                GSList **items,
+                                                gboolean *out_includes_last_item,
+                                                GSList **out_items, /* EEwsItem * */
                                                 EwsConvertQueryCallback convert_query_cb,
                                                 GCancellable *cancellable,
                                                 GError **error);
-
-EEwsServerVersion
-               e_ews_connection_get_server_version
-                                               (EEwsConnection *cnc);
-void           e_ews_connection_set_server_version
-                                               (EEwsConnection *cnc,
-                                                EEwsServerVersion version);
-void           e_ews_connection_set_server_version_from_string
-                                               (EEwsConnection *cnc,
-                                                const gchar *version);
-gboolean       e_ews_connection_satisfies_server_version
-                                               (EEwsConnection *cnc,
-                                                EEwsServerVersion versio);
-
-void           e_ews_connection_get_items      (EEwsConnection *cnc,
-                                                gint pri,
-                                                const GSList *ids,
-                                                const gchar *default_props,
-                                                const EEwsAdditionalProps *add_props,
-                                                gboolean include_mime,
-                                                const gchar *mime_directory,
-                                                EEwsBodyType body_type,
-                                                ESoapResponseProgressFn progress_fn,
-                                                gpointer progress_data,
-                                                GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-gboolean       e_ews_connection_get_items_finish
-                                               (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                GSList **items,
-                                                GError **error);
 gboolean       e_ews_connection_get_items_sync (EEwsConnection *cnc,
                                                 gint pri,
-                                                const GSList *ids,
+                                                const GSList *ids, /* gchar * */
                                                 const gchar *default_props,
                                                 const EEwsAdditionalProps *add_props,
                                                 gboolean include_mime,
                                                 const gchar *mime_directory,
                                                 EEwsBodyType body_type,
-                                                GSList **items,
+                                                GSList **out_items, /* EEwsItem * */
                                                 ESoapResponseProgressFn progress_fn,
                                                 gpointer progress_data,
                                                 GCancellable *cancellable,
                                                 GError **error);
-
-void           e_ews_connection_delete_items   (EEwsConnection *cnc,
-                                                gint pri,
-                                                const GSList *ids,
-                                                EwsDeleteType delete_type,
-                                                EwsSendMeetingCancellationsType send_cancels,
-                                                EwsAffectedTaskOccurrencesType affected_tasks,
-                                                GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-gboolean       e_ews_connection_delete_items_finish
-                                               (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                GError **error);
 gboolean       e_ews_connection_delete_items_sync
                                                (EEwsConnection *cnc,
                                                 gint pri,
-                                                const GSList *ids,
+                                                const GSList *ids, /* gchar * */
                                                 EwsDeleteType delete_type,
                                                 EwsSendMeetingCancellationsType send_cancels,
                                                 EwsAffectedTaskOccurrencesType affected_tasks,
@@ -643,22 +551,12 @@ gboolean  e_ews_connection_delete_items_sync
 gboolean       e_ews_connection_delete_items_in_chunks_sync
                                                (EEwsConnection *cnc,
                                                 gint pri,
-                                                const GSList *ids,
+                                                const GSList *ids, /* gchar * */
                                                 EwsDeleteType delete_type,
                                                 EwsSendMeetingCancellationsType send_cancels,
                                                 EwsAffectedTaskOccurrencesType affected_tasks,
                                                 GCancellable *cancellable,
                                                 GError **error);
-void           e_ews_connection_delete_item    (EEwsConnection *cnc,
-                                                gint pri,
-                                                EwsId *id,
-                                                guint index,
-                                                EwsDeleteType delete_type,
-                                                EwsSendMeetingCancellationsType send_cancels,
-                                                EwsAffectedTaskOccurrencesType affected_tasks,
-                                                GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
 gboolean       e_ews_connection_delete_item_sync
                                                (EEwsConnection *cnc,
                                                 gint pri,
@@ -669,23 +567,6 @@ gboolean   e_ews_connection_delete_item_sync
                                                 EwsAffectedTaskOccurrencesType affected_tasks,
                                                 GCancellable *cancellable,
                                                 GError **error);
-
-void           e_ews_connection_update_items   (EEwsConnection *cnc,
-                                                gint pri,
-                                                const gchar *conflict_res,
-                                                const gchar *msg_disposition,
-                                                const gchar *send_invites,
-                                                const gchar *folder_id,
-                                                EEwsRequestCreationCallback create_cb,
-                                                gpointer create_user_data,
-                                                GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-gboolean       e_ews_connection_update_items_finish
-                                               (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                GSList **ids,
-                                                GError **error);
 gboolean       e_ews_connection_update_items_sync
                                                (EEwsConnection *cnc,
                                                 gint pri,
@@ -695,24 +576,8 @@ gboolean   e_ews_connection_update_items_sync
                                                 const gchar *folder_id,
                                                 EEwsRequestCreationCallback create_cb,
                                                 gpointer create_user_data,
-                                                GSList **ids,
-                                                GCancellable *cancellable,
-                                                GError **error);
-
-void           e_ews_connection_create_items   (EEwsConnection *cnc,
-                                                gint pri,
-                                                const gchar *msg_disposition,
-                                                const gchar *send_invites,
-                                                const EwsFolderId *fid,
-                                                EEwsRequestCreationCallback create_cb,
-                                                gpointer create_user_data,
+                                                GSList **out_items, /* EEwsItem * */
                                                 GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-gboolean       e_ews_connection_create_items_finish
-                                               (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                GSList **ids,
                                                 GError **error);
 gboolean       e_ews_connection_create_items_sync
                                                (EEwsConnection *cnc,
@@ -722,26 +587,9 @@ gboolean   e_ews_connection_create_items_sync
                                                 const EwsFolderId *fid,
                                                 EEwsRequestCreationCallback create_cb,
                                                 gpointer create_user_data,
-                                                GSList **ids,
+                                                GSList **out_items, /* EEwsItem * */
                                                 GCancellable *cancellable,
                                                 GError **error);
-
-void           e_ews_connection_sync_folder_hierarchy
-                                               (EEwsConnection *cnc,
-                                                gint pri,
-                                                const gchar *sync_state,
-                                                GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-gboolean       e_ews_connection_sync_folder_hierarchy_finish
-                                               (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                gchar **sync_state,
-                                                gboolean *includes_last_folder,
-                                                GSList **folders_created,
-                                                GSList **folders_updated,
-                                                GSList **folders_deleted,
-                                                GError **error);
 gboolean       e_ews_connection_sync_folder_hierarchy_sync
                                                (EEwsConnection *cnc,
                                                 gint pri,
@@ -753,23 +601,6 @@ gboolean   e_ews_connection_sync_folder_hierarchy_sync
                                                 GSList **folders_deleted,
                                                 GCancellable *cancellable,
                                                 GError **error);
-
-void           e_ews_connection_resolve_names  (EEwsConnection *cnc,
-                                                gint pri,
-                                                const gchar *resolve_name,
-                                                EwsContactsSearchScope scope,
-                                                GSList *parent_folder_ids,
-                                                gboolean fetch_contact_data,
-                                                GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-gboolean       e_ews_connection_resolve_names_finish
-                                               (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                GSList **mailboxes,
-                                                GSList **contact_items,
-                                                gboolean *includes_last_item,
-                                                GError **error);
 gboolean       e_ews_connection_resolve_names_sync
                                                (EEwsConnection *cnc,
                                                 gint pri,
@@ -777,32 +608,18 @@ gboolean  e_ews_connection_resolve_names_sync
                                                 EwsContactsSearchScope scope,
                                                 GSList *parent_folder_ids,
                                                 gboolean fetch_contact_data,
-                                                GSList **mailboxes,
-                                                GSList **contact_items,
-                                                gboolean *includes_last_item,
+                                                gboolean *out_includes_last_item,
+                                                GSList **out_mailboxes, /* EwsMailbox * */
+                                                GSList **out_contact_items, /* EEwsItem * */
                                                 GCancellable *cancellable,
                                                 GError **error);
-
-void           e_ews_connection_expand_dl      (EEwsConnection *cnc,
-                                                gint pri,
-                                                const EwsMailbox *mb,
-                                                GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-gboolean       e_ews_connection_expand_dl_finish
-                                               (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                GSList **mailboxes,
-                                                gboolean *includes_last_item,
-                                                GError **error);
 gboolean       e_ews_connection_expand_dl_sync (EEwsConnection *cnc,
                                                 gint pri,
                                                 const EwsMailbox *mb,
-                                                GSList **mailboxes,
-                                                gboolean *includes_last_item,
+                                                gboolean *out_includes_last_item,
+                                                GSList **out_mailboxes, /* EwsMailbox * */
                                                 GCancellable *cancellable,
                                                 GError **error);
-
 gboolean       e_ews_connection_ex_to_smtp_sync
                                                (EEwsConnection *cnc,
                                                 gint pri,
@@ -811,21 +628,6 @@ gboolean   e_ews_connection_ex_to_smtp_sync
                                                 gchar **smtp_address,
                                                 GCancellable *cancellable,
                                                 GError **error);
-
-void           e_ews_connection_create_folder  (EEwsConnection *cnc,
-                                                gint pri,
-                                                const gchar *parent_folder_id,
-                                                gboolean is_distinguished_id,
-                                                const gchar *folder_name,
-                                                EEwsFolderType folder_type,
-                                                GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-gboolean       e_ews_connection_create_folder_finish
-                                               (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                EwsFolderId **folder_id,
-                                                GError **error);
 gboolean       e_ews_connection_create_folder_sync
                                                (EEwsConnection *cnc,
                                                 gint pri,
@@ -833,22 +635,9 @@ gboolean   e_ews_connection_create_folder_sync
                                                 gboolean is_distinguished_id,
                                                 const gchar *folder_name,
                                                 EEwsFolderType folder_type,
-                                                EwsFolderId **folder_id,
+                                                EwsFolderId **out_folder_id,
                                                 GCancellable *cancellable,
                                                 GError **error);
-
-void           e_ews_connection_delete_folder  (EEwsConnection *cnc,
-                                                gint pri,
-                                                const gchar *folder_id,
-                                                gboolean is_distinguished_id,
-                                                const gchar *delete_type,
-                                                GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-gboolean       e_ews_connection_delete_folder_finish
-                                               (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                GError **error);
 gboolean       e_ews_connection_delete_folder_sync
                                                (EEwsConnection *cnc,
                                                 gint pri,
@@ -857,20 +646,6 @@ gboolean   e_ews_connection_delete_folder_sync
                                                 const gchar *delete_type,
                                                 GCancellable *cancellable,
                                                 GError **error);
-
-void           e_ews_connection_empty_folder   (EEwsConnection *cnc,
-                                                gint pri,
-                                                const gchar *folder_id,
-                                                gboolean is_distinguished_id,
-                                                const gchar *delete_type,
-                                                gboolean delete_subfolders,
-                                                GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-gboolean       e_ews_connection_empty_folder_finish
-                                               (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                GError **error);
 gboolean       e_ews_connection_empty_folder_sync
                                                (EEwsConnection *cnc,
                                                 gint pri,
@@ -880,18 +655,6 @@ gboolean   e_ews_connection_empty_folder_sync
                                                 gboolean delete_subfolders,
                                                 GCancellable *cancellable,
                                                 GError **error);
-
-void           e_ews_connection_update_folder  (EEwsConnection *cnc,
-                                                gint pri,
-                                                EEwsRequestCreationCallback create_cb,
-                                                gpointer create_user_data,
-                                                GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-gboolean       e_ews_connection_update_folder_finish
-                                               (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                GError **error);
 gboolean       e_ews_connection_update_folder_sync
                                                (EEwsConnection *cnc,
                                                 gint pri,
@@ -899,18 +662,6 @@ gboolean   e_ews_connection_update_folder_sync
                                                 gpointer create_user_data,
                                                 GCancellable *cancellable,
                                                 GError **error);
-
-void           e_ews_connection_move_folder    (EEwsConnection *cnc,
-                                                gint pri,
-                                                const gchar *to_folder,
-                                                const gchar *folder,
-                                                GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-gboolean       e_ews_connection_move_folder_finish
-                                               (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                GError **error);
 gboolean       e_ews_connection_move_folder_sync
                                                (EEwsConnection *cnc,
                                                 gint pri,
@@ -918,50 +669,22 @@ gboolean  e_ews_connection_move_folder_sync
                                                 const gchar *folder,
                                                 GCancellable *cancellable,
                                                 GError **error);
-
-void           e_ews_connection_get_folder     (EEwsConnection *cnc,
-                                                gint pri,
-                                                const gchar *folder_shape,
-                                                const EEwsAdditionalProps *add_props,
-                                                GSList *folder_ids,
-                                                GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-gboolean       e_ews_connection_get_folder_finish
-                                               (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                GSList **folders,
-                                                GError **error);
 gboolean       e_ews_connection_get_folder_sync
                                                (EEwsConnection *cnc,
                                                 gint pri,
                                                 const gchar *folder_shape,
                                                 const EEwsAdditionalProps *add_props,
-                                                GSList *folder_ids,
-                                                GSList **folders,
-                                                GCancellable *cancellable,
-                                                GError **error);
-
-void           e_ews_connection_move_items     (EEwsConnection *cnc,
-                                                gint pri,
-                                                const gchar *folder_id,
-                                                gboolean docopy,
-                                                const GSList *ids,
+                                                GSList *folder_ids, /* EwsFolderId * */
+                                                GSList **out_folders, /* EEwsFolder * */
                                                 GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-gboolean       e_ews_connection_move_items_finish
-                                               (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                GSList **items,
                                                 GError **error);
 gboolean       e_ews_connection_move_items_sync
                                                (EEwsConnection *cnc,
                                                 gint pri,
                                                 const gchar *folder_id,
                                                 gboolean docopy,
-                                                const GSList *ids,
-                                                GSList **items_ret,
+                                                const GSList *ids, /* gchar * */
+                                                GSList **out_items, /* EEwsItem * */
                                                 GCancellable *cancellable,
                                                 GError **error);
 gboolean       e_ews_connection_move_items_in_chunks_sync
@@ -969,142 +692,59 @@ gboolean e_ews_connection_move_items_in_chunks_sync
                                                 gint pri,
                                                 const gchar *folder_id,
                                                 gboolean docopy,
-                                                const GSList *ids,
-                                                GSList **items,
+                                                const GSList *ids, /* gchar * */
+                                                GSList **out_items, /* EEwsItems * */
                                                 GCancellable *cancellable,
                                                 GError **error);
-
-void           e_ews_connection_create_attachments
-                                               (EEwsConnection *cnc,
-                                                gint pri,
-                                                const EwsId *parent,
-                                                const GSList *files,
-                                                gboolean is_contact_photo,
-                                                GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-gboolean       e_ews_connection_create_attachments_finish
-                                               (EEwsConnection *cnc,
-                                                gchar **change_key,
-                                                GSList **attachments_ids,
-                                                GAsyncResult *result,
-                                                GError **error);
 gboolean       e_ews_connection_create_attachments_sync
                                                (EEwsConnection *cnc,
                                                 gint pri,
                                                 const EwsId *parent,
-                                                const GSList *files,
+                                                const GSList *files, /* EEwsAttachmentInfo * */
                                                 gboolean is_contact_photo,
-                                                gchar **change_key,
-                                                GSList **attachments_ids,
+                                                gchar **out_change_key,
+                                                GSList **out_attachments_ids, /* gchar * */
                                                 GCancellable *cancellable,
                                                 GError **error);
-
-void           e_ews_connection_delete_attachments
-                                               (EEwsConnection *cnc,
-                                                gint pri,
-                                                const GSList *attachments_ids,
-                                                GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-gboolean       e_ews_connection_delete_attachments_finish
-                                               (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                gchar **new_change_key,
-                                                GError **error);
 gboolean       e_ews_connection_delete_attachments_sync
                                                (EEwsConnection *cnc,
                                                 gint pri,
-                                                const GSList *attachments_ids,
-                                                gchar **new_change_key,
+                                                const GSList *attachments_ids, /* gchar * */
+                                                gchar **out_new_change_key,
                                                 GCancellable *cancellable,
                                                 GError **error);
-
-void           e_ews_connection_get_attachments
-                                               (EEwsConnection *cnc,
-                                                gint pri,
-                                                const gchar *comp_uid,
-                                                const GSList *ids,
-                                                const gchar *cache,
-                                                gboolean include_mime,
-                                                ESoapResponseProgressFn progress_fn,
-                                                gpointer progress_data,
-                                                GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-gboolean       e_ews_connection_get_attachments_finish
-                                               (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                GSList **items,
-                                                GError **error);
 gboolean       e_ews_connection_get_attachments_sync
                                                (EEwsConnection *cnc,
                                                 gint pri,
-                                                const gchar *comp_uid,
-                                                const GSList *ids,
-                                                const gchar *cache,
+                                                const gchar *uid,
+                                                const GSList *ids, /* const gchar * */
+                                                const gchar *cache_directory,
                                                 gboolean include_mime,
-                                                GSList **items,
+                                                GSList **out_attachments, /* EEwsAttachmentInfo * */
                                                 ESoapResponseProgressFn progress_fn,
                                                 gpointer progress_data,
                                                 GCancellable *cancellable,
                                                 GError **error);
-
 gboolean       e_ews_connection_get_oal_list_sync
                                                (EEwsConnection *cnc,
-                                                GSList **oals,
+                                                GSList **out_oals,
                                                 GCancellable *cancellable,
                                                 GError **error);
-void           e_ews_connection_get_oal_list   (EEwsConnection *cnc,
-                                                GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-gboolean       e_ews_connection_get_oal_list_finish
-                                               (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                GSList **oals,
-                                                GError **error);
 gboolean       e_ews_connection_get_oal_detail_sync
                                                (EEwsConnection *cnc,
                                                 const gchar *oal_id,
                                                 const gchar *oal_element,
                                                 const gchar *old_etag,
-                                                GSList **elements,
-                                                gchar **etag,
+                                                GSList **out_elements,
+                                                gchar **out_etag,
                                                 GCancellable *cancellable,
                                                 GError **error);
-void           e_ews_connection_get_oal_detail (EEwsConnection *cnc,
-                                                const gchar *oal_id,
-                                                const gchar *oal_element,
-                                                const gchar *etag,
-                                                GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-gboolean       e_ews_connection_get_oal_detail_finish
-                                               (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                GSList **elements,
-                                                gchar **etag,
-                                                GError **error);
-
-void           e_ews_connection_get_free_busy  (EEwsConnection *cnc,
-                                                gint pri,
-                                                EEwsRequestCreationCallback free_busy_cb,
-                                                gpointer free_busy_user_data,
-                                                GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-gboolean       e_ews_connection_get_free_busy_finish
-                                               (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                GSList **free_busy, /* ICalComponent * */
-                                                GError **error);
 gboolean       e_ews_connection_get_free_busy_sync
                                                (EEwsConnection *cnc,
                                                 gint pri,
                                                 EEwsRequestCreationCallback free_busy_cb,
                                                 gpointer create_user_data,
-                                                GSList **free_busy, /* ICalComponent * */
+                                                GSList **out_free_busy, /* ICalComponent * */
                                                 GCancellable *cancellable,
                                                 GError **error);
 gboolean       e_ews_connection_download_oal_file_sync
@@ -1114,51 +754,14 @@ gboolean e_ews_connection_download_oal_file_sync
                                                 gpointer progress_data,
                                                 GCancellable *cancellable,
                                                 GError **error);
-void           e_ews_connection_download_oal_file
-                                               (EEwsConnection *cnc,
-                                                const gchar *cache_filename,
-                                                ESoapResponseProgressFn progress_fn,
-                                                gpointer progress_data,
-                                                GCancellable *cancellable,
-                                                GAsyncReadyCallback cb,
-                                                gpointer user_data);
-gboolean       e_ews_connection_download_oal_file_finish
-                                               (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                GError **error);
-
-void           e_ews_connection_get_delegate   (EEwsConnection *cnc,
-                                                gint pri,
-                                                const gchar *mail_id,
-                                                gboolean include_permissions,
-                                                GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-gboolean       e_ews_connection_get_delegate_finish
-                                               (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                EwsDelegateDeliver *deliver_to,
-                                                GSList **delegates, /* EwsDelegateInfo * */
-                                                GError **error);
 gboolean       e_ews_connection_get_delegate_sync
                                                (EEwsConnection *cnc,
                                                 gint pri,
                                                 const gchar *mail_id,
                                                 gboolean include_permissions,
-                                                EwsDelegateDeliver *deliver_to,
-                                                GSList **delegates, /* EwsDelegateInfo * */
-                                                GCancellable *cancellable,
-                                                GError **error);
-void           e_ews_connection_add_delegate   (EEwsConnection *cnc,
-                                                gint pri,
-                                                const gchar *mail_id,
-                                                const GSList *delegates, /* EwsDelegateInfo * */
+                                                EwsDelegateDeliver *out_deliver_to,
+                                                GSList **out_delegates, /* EwsDelegateInfo * */
                                                 GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-gboolean       e_ews_connection_add_delegate_finish
-                                               (EEwsConnection *cnc,
-                                                GAsyncResult *result,
                                                 GError **error);
 gboolean       e_ews_connection_add_delegate_sync
                                                (EEwsConnection *cnc,
@@ -1167,18 +770,6 @@ gboolean  e_ews_connection_add_delegate_sync
                                                 const GSList *delegates, /* EwsDelegateInfo * */
                                                 GCancellable *cancellable,
                                                 GError **error);
-void           e_ews_connection_remove_delegate
-                                               (EEwsConnection *cnc,
-                                                gint pri,
-                                                const gchar *mail_id,
-                                                const GSList *delegate_ids, /* EwsUserId * */
-                                                GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-gboolean       e_ews_connection_remove_delegate_finish
-                                               (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                GError **error);
 gboolean       e_ews_connection_remove_delegate_sync
                                                (EEwsConnection *cnc,
                                                 gint pri,
@@ -1186,19 +777,6 @@ gboolean  e_ews_connection_remove_delegate_sync
                                                 const GSList *delegate_ids, /* EwsUserId * */
                                                 GCancellable *cancellable,
                                                 GError **error);
-void           e_ews_connection_update_delegate
-                                               (EEwsConnection *cnc,
-                                                gint pri,
-                                                const gchar *mail_id,
-                                                EwsDelegateDeliver deliver_to,
-                                                const GSList *delegates, /* EwsDelegateInfo * */
-                                                GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-gboolean       e_ews_connection_update_delegate_finish
-                                               (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                GError **error);
 gboolean       e_ews_connection_update_delegate_sync
                                                (EEwsConnection *cnc,
                                                 gint pri,
@@ -1207,125 +785,48 @@ gboolean        e_ews_connection_update_delegate_sync
                                                 const GSList *delegates, /* EwsDelegateInfo * */
                                                 GCancellable *cancellable,
                                                 GError **error);
-void           e_ews_connection_get_folder_permissions
-                                               (EEwsConnection *cnc,
-                                                gint pri,
-                                                EwsFolderId *folder_id,
-                                                GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-gboolean       e_ews_connection_get_folder_permissions_finish
-                                               (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                GSList **permissions,
-                                                GError **error);
 gboolean       e_ews_connection_get_folder_permissions_sync
                                                (EEwsConnection *cnc,
                                                 gint pri,
                                                 EwsFolderId *folder_id,
-                                                GSList **permissions,
+                                                GSList **out_permissions, /* EEwsPermission * */
                                                 GCancellable *cancellable,
                                                 GError **error);
-void           e_ews_connection_set_folder_permissions
-                                               (EEwsConnection *cnc,
-                                                gint pri,
-                                                EwsFolderId *folder_id,
-                                                EEwsFolderType folder_type,
-                                                const GSList *permissions,
-                                                GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-gboolean       e_ews_connection_set_folder_permissions_finish
-                                               (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                GError **error);
 gboolean       e_ews_connection_set_folder_permissions_sync
                                                (EEwsConnection *cnc,
                                                 gint pri,
                                                 EwsFolderId *folder_id,
                                                 EEwsFolderType folder_type,
-                                                const GSList *permissions,
-                                                GCancellable *cancellable,
-                                                GError **error);
-
-void           e_ews_connection_get_password_expiration
-                                               (EEwsConnection *cnc,
-                                                gint pri,
-                                                const gchar *mail_id,
+                                                const GSList *permissions, /* EEwsPermission * */
                                                 GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-
-gboolean       e_ews_connection_get_password_expiration_finish
-                                               (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                gchar **exp_date,
                                                 GError **error);
-
 gboolean       e_ews_connection_get_password_expiration_sync
                                                (EEwsConnection *cnc,
                                                 gint pri,
                                                 const gchar *mail_id,
-                                                gchar **exp_date,
-                                                GCancellable *cancellable,
-                                                GError **error);
-
-void           e_ews_connection_get_folder_info
-                                               (EEwsConnection *cnc,
-                                                gint pri,
-                                                const gchar *mail_id,
-                                                const EwsFolderId *folder_id,
+                                                gchar **out_exp_date,
                                                 GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-gboolean       e_ews_connection_get_folder_info_finish
-                                               (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                EEwsFolder **folder,
                                                 GError **error);
 gboolean       e_ews_connection_get_folder_info_sync
                                                (EEwsConnection *cnc,
                                                 gint pri,
                                                 const gchar *mail_id,
                                                 const EwsFolderId *folder_id,
-                                                EEwsFolder **folder,
-                                                GCancellable *cancellable,
-                                                GError **error);
-void           e_ews_connection_find_folder    (EEwsConnection *cnc,
-                                                gint pri,
-                                                const EwsFolderId *fid,
+                                                EEwsFolder **out_folder,
                                                 GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-gboolean       e_ews_connection_find_folder_finish
-                                               (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                gboolean *includes_last_item,
-                                                GSList **folders,
                                                 GError **error);
 gboolean       e_ews_connection_find_folder_sync
                                                (EEwsConnection *cnc,
                                                 gint pri,
                                                 const EwsFolderId *fid,
-                                                gboolean *includes_last_item,
-                                                GSList **folders,
+                                                gboolean *out_includes_last_item,
+                                                GSList **out_folders, /* EEwsFolder * */
                                                 GCancellable *cancellable,
                                                 GError **error);
-void           e_ews_connection_query_auth_methods
-                                               (EEwsConnection *cnc,
-                                                gint pri,
-                                                GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-gboolean       e_ews_connection_query_auth_methods_finish
-                                               (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                GSList **auth_methods,
-                                                GError **error);
 gboolean       e_ews_connection_query_auth_methods_sync
                                                (EEwsConnection *cnc,
                                                 gint pri,
-                                                GSList **auth_methods,
+                                                GSList **out_auth_methods, /* gchar * */
                                                 GCancellable *cancellable,
                                                 GError **error);
 void           e_ews_connection_enable_notifications_sync
@@ -1335,37 +836,13 @@ void             e_ews_connection_enable_notifications_sync
 void           e_ews_connection_disable_notifications_sync
                                                (EEwsConnection *cnc,
                                                 guint subscription_key);
-void           e_ews_connection_get_server_time_zones
-                                               (EEwsConnection *cnc,
-                                                gint pri,
-                                                GSList *msdn_locations,
-                                                GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-gboolean       e_ews_connection_get_server_time_zones_finish
-                                               (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                GSList **tzds, /* EEwsCalendarTimeZoneDefinition */
-                                                GError **error);
 gboolean       e_ews_connection_get_server_time_zones_sync
                                                (EEwsConnection *cnc,
                                                 gint pri,
-                                                GSList *msdn_locations,
-                                                GSList **tzds, /* EEwsCalendarTimeZoneDefinition */
+                                                const GSList *msdn_locations, /* gchar * */
+                                                GSList **out_tzds, /* EEwsCalendarTimeZoneDefinition */
                                                 GCancellable *cancellable,
                                                 GError **error);
-void           e_ews_connection_get_user_photo (EEwsConnection *cnc,
-                                                gint pri,
-                                                const gchar *email,
-                                                EEwsSizeRequested size_requested,
-                                                GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-gboolean       e_ews_connection_get_user_photo_finish
-                                               (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                gchar **out_picture_data, /* base64-encoded */
-                                                GError **error);
 gboolean       e_ews_connection_get_user_photo_sync
                                                (EEwsConnection *cnc,
                                                 gint pri,
@@ -1374,20 +851,6 @@ gboolean  e_ews_connection_get_user_photo_sync
                                                 gchar **out_picture_data, /* base64-encoded */
                                                 GCancellable *cancellable,
                                                 GError **error);
-void           e_ews_connection_get_user_configuration
-                                               (EEwsConnection *cnc,
-                                                gint pri,
-                                                const EwsFolderId *fid,
-                                                const gchar *config_name,
-                                                EEwsUserConfigurationProperties props,
-                                                GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-gboolean       e_ews_connection_get_user_configuration_finish
-                                               (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                gchar **out_properties,
-                                                GError **error);
 gboolean       e_ews_connection_get_user_configuration_sync
                                                (EEwsConnection *cnc,
                                                 gint pri,
@@ -1397,20 +860,6 @@ gboolean  e_ews_connection_get_user_configuration_sync
                                                 gchar **out_properties,
                                                 GCancellable *cancellable,
                                                 GError **error);
-void           e_ews_connection_convert_id     (EEwsConnection *cnc,
-                                                gint pri,
-                                                const gchar *email,
-                                                const gchar *folder_id,
-                                                const gchar *from_format,
-                                                const gchar *to_format,
-                                                GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-gboolean       e_ews_connection_convert_id_finish
-                                               (EEwsConnection *cnc,
-                                                GAsyncResult *result,
-                                                gchar **out_converted_id,
-                                                GError **error);
 gboolean       e_ews_connection_convert_id_sync(EEwsConnection *cnc,
                                                 gint pri,
                                                 const gchar *email,
diff --git a/src/EWS/common/e-soap-request.c b/src/EWS/common/e-soap-request.c
index 1d35ecb0..6e55ac76 100644
--- a/src/EWS/common/e-soap-request.c
+++ b/src/EWS/common/e-soap-request.c
@@ -23,6 +23,9 @@ struct _ESoapRequestPrivate {
        gchar *method;
        GUri *uri;
 
+       gchar *certificate_pem;
+       GTlsCertificateFlags certificate_errors;
+
        /* Serialization fields */
        xmlParserCtxtPtr ctxt;
        xmlDocPtr doc;
@@ -44,6 +47,7 @@ soap_request_finalize (GObject *object)
 
        g_clear_pointer (&req->priv->method, g_free);
        g_clear_pointer (&req->priv->uri, g_uri_unref);
+       g_clear_pointer (&req->priv->certificate_pem, g_free);
 
        g_clear_pointer (&req->priv->doc, xmlFreeDoc);
        g_clear_pointer (&req->priv->action, g_free);
@@ -853,16 +857,20 @@ e_soap_request_get_xml_doc (ESoapRequest *req)
 /**
  * e_soap_request_persist:
  * @req: the #ESoapRequest.
+ * @soup_session: an #ESoupSession to create the #SoupMessage for
  * @settings: a #CamelEwsSettings object, to read User-Agent header information from
+ * @error: (optional) (out): return location for a #GError, or %NULL
  *
  * Writes the serialized XML tree to the #SoupMessage's buffer.
  *
- * Returns: (transfer full): a #SoupMessage containing the SOAP request at its
- *    request body.
+ * Returns: (nullable) (transfer full): a #SoupMessage containing the SOAP request
+ *    as its request body, or %NULL on error.
  */
 SoupMessage *
 e_soap_request_persist (ESoapRequest *req,
-                       CamelEwsSettings *settings)
+                       ESoupSession *soup_session,
+                       CamelEwsSettings *settings,
+                       GError **error)
 {
        SoupMessage *message;
        xmlChar *body;
@@ -870,7 +878,7 @@ e_soap_request_persist (ESoapRequest *req,
 
        g_return_if_fail (E_IS_SOAP_REQUEST (req));
 
-       message = soup_message_new_from_uri (req->priv->method, req->priv->uri);
+       message = e_soup_session_new_message_from_uri (soup_session, req->priv->method, req->priv->uri, 
error);
 
        if (!message)
                return NULL;
@@ -882,9 +890,65 @@ e_soap_request_persist (ESoapRequest *req,
 
        e_ews_connection_utils_set_user_agent_header (message, settings);
 
-       soup_message_headers_append (
+       soup_message_headers_replace (
                soup_message_get_request_headers (message),
                "Connection", "Keep-Alive");
 
        return message;
 }
+
+/**
+ * e_soap_request_take_tls_error_details:
+ * @req: an #ESoapRequest
+ * @certificate_pem: (transfer full) (nullable): a certificate in PEM format as string, or %NULL
+ * @certificate_errors: a %GTlsCertificateFlags describing the errors
+ *
+ * Set the TLS/SSL error details for the @req. Read it back
+ * with e_soap_request_get_tls_error_details().
+ *
+ * The function assumes ownership of the @certificate_pem.
+ **/
+void
+e_soap_request_take_tls_error_details (ESoapRequest *req,
+                                      gchar *certificate_pem,
+                                      GTlsCertificateFlags certificate_errors)
+{
+       g_return_if_fail (E_IS_SOAP_REQUEST (req));
+
+       g_clear_pointer (&req->priv->certificate_pem, g_free);
+
+       req->priv->certificate_pem = certificate_pem;
+       req->priv->certificate_errors = certificate_errors;
+}
+
+/**
+ * e_soap_request_get_tls_error_details:
+ * @req: an #ESoapRequest
+ * @out_certificate_pem: (out) (transfer none) (optional) (nullable): the certificatete in PEM format as 
string, or %NULL if not set
+ * @out_certificate_errors: (out) (optional): certificate errors, or 0 when none set
+ *
+ * Retries previously set TLS error details by e_soap_request_take_tls_error_details().
+ * The @out_certificate_pem is owned by the @req and is valid until the @req is freed
+ * or another call to e_soap_request_take_tls_error_details() is made.
+ *
+ * Returns: %TRUE, when the certificate PEM was set and the requested arguments
+ *    populated; %FALSE otherwise
+ **/
+gboolean
+e_soap_request_get_tls_error_details (ESoapRequest *req,
+                                     const gchar **out_certificate_pem,
+                                     GTlsCertificateFlags *out_certificate_errors)
+{
+       g_return_val_if_fail (E_IS_SOAP_REQUEST (req), FALSE);
+
+       if (!req->priv->certificate_pem)
+               return FALSE;
+
+       if (out_certificate_pem)
+               *out_certificate_pem = req->priv->certificate_pem;
+
+       if (out_certificate_errors)
+               *out_certificate_errors = req->priv->certificate_errors;
+
+       return TRUE;
+}
diff --git a/src/EWS/common/e-soap-request.h b/src/EWS/common/e-soap-request.h
index fefce364..d716f1a0 100644
--- a/src/EWS/common/e-soap-request.h
+++ b/src/EWS/common/e-soap-request.h
@@ -10,6 +10,7 @@
 #include <time.h>
 #include <libxml/tree.h>
 #include <libsoup/soup-message.h>
+#include <libedataserver/libedataserver.h>
 #include "camel-ews-settings.h"
 #include "e-soap-response.h"
 
@@ -128,7 +129,17 @@ const gchar *      e_soap_request_get_namespace_prefix
                                                 const gchar *ns_uri);
 xmlDocPtr      e_soap_request_get_xml_doc      (ESoapRequest *req);
 SoupMessage *  e_soap_request_persist          (ESoapRequest *req,
-                                                CamelEwsSettings *settings);
+                                                ESoupSession *soup_session,
+                                                CamelEwsSettings *settings,
+                                                GError **error);
+void           e_soap_request_take_tls_error_details
+                                               (ESoapRequest *req,
+                                                gchar *certificate_pem,
+                                                GTlsCertificateFlags certificate_errors);
+gboolean       e_soap_request_get_tls_error_details
+                                               (ESoapRequest *req,
+                                                const gchar **out_certificate_pem,
+                                                GTlsCertificateFlags *out_certificate_errors);
 
 G_END_DECLS
 
diff --git a/src/EWS/evolution/e-ews-search-user.c b/src/EWS/evolution/e-ews-search-user.c
index 1b32d1b5..17485a3e 100644
--- a/src/EWS/evolution/e-ews-search-user.c
+++ b/src/EWS/evolution/e-ews-search-user.c
@@ -226,8 +226,8 @@ search_thread (gpointer user_data)
 
                if (e_ews_connection_resolve_names_sync (
                        sid->conn, EWS_PRIORITY_MEDIUM, sid->search_text,
-                       EWS_SEARCH_AD, NULL, FALSE, &mailboxes, NULL,
-                       &sid->includes_last_item, sid->cancellable, &error)) {
+                       EWS_SEARCH_AD, NULL, FALSE, &sid->includes_last_item, &mailboxes, NULL,
+                       sid->cancellable, &error)) {
                        GSList *iter;
 
                        sid->found_contacts = 0;
diff --git a/src/EWS/evolution/e-ews-subscribe-foreign-folder.c 
b/src/EWS/evolution/e-ews-subscribe-foreign-folder.c
index 45263da6..c7c29fe9 100644
--- a/src/EWS/evolution/e-ews-subscribe-foreign-folder.c
+++ b/src/EWS/evolution/e-ews-subscribe-foreign-folder.c
@@ -794,7 +794,7 @@ e_ews_subscribe_foreign_folder_resolve_name_sync (EEwsConnection *cnc,
 
        if (!e_ews_connection_resolve_names_sync (cnc, G_PRIORITY_DEFAULT,
                name, EWS_SEARCH_AD, NULL, FALSE,
-               &mailboxes, NULL, &includes_last_item,
+               &includes_last_item, &mailboxes, NULL,
                cancellable, &local_error)) {
                if (g_error_matches (local_error, EWS_CONNECTION_ERROR, 
EWS_CONNECTION_ERROR_NAMERESOLUTIONNORESULTS) ||
                    g_error_matches (local_error, EWS_CONNECTION_ERROR, 
EWS_CONNECTION_ERROR_NAMERESOLUTIONNOMAILBOX)) {


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