get_delegate_response_cb (ESoapResponse *response,
                          GSimpleAsyncResult *simple)
{
	EwsAsyncData *async_data;
	ESoapParameter *param;
	ESoapParameter *subparam;
	gchar *value;
	GError *error = NULL;

	async_data = g_simple_async_result_get_op_res_gpointer (simple);

	if (ews_get_response_status (e_soap_response_get_parameter (response), &error))
		param = e_soap_response_get_first_parameter_by_name (
			response, "DeliverMeetingRequests", &error);
	else
		param = NULL;

	/* 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;
	}

	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);

	param = e_soap_response_get_first_parameter_by_name (
		response, "ResponseMessages", NULL);
	/* it's OK to not have set any delegate */
	if (!param)
		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, "DelegateUserResponseMessageType"))
			ews_handle_delegate_user_param (subparam, async_data);

		subparam = e_soap_parameter_get_next_child (subparam);
	}
}
get_delegate_response_cb (ESoapResponse *response,
                          GSimpleAsyncResult *simple)
{
	EwsAsyncData *async_data;
	ESoapParameter *param;
	ESoapParameter *subparam;
	gchar *value;
	GError *error = NULL;

	async_data = g_simple_async_result_get_op_res_gpointer (simple);

	if (ews_get_response_status (e_soap_response_get_parameter (response), &error))
		param = e_soap_response_get_first_parameter_by_name (
			response, "DeliverMeetingRequests", &error);
	else
		param = NULL;

	 
	g_return_if_fail (
		(param != NULL && error == NULL) ||
		(param == NULL && error != NULL));

	if (error != NULL) {
		g_simple_async_result_take_error (simple, error);
		return;
	}

	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);

	param = e_soap_response_get_first_parameter_by_name (
		response, "ResponseMessages", NULL);
	 
	if (!param)
		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, "DelegateUserResponseMessageType"))
			ews_handle_delegate_user_param (subparam, async_data);

		subparam = e_soap_parameter_get_next_child (subparam);
	}
}