static void
owa_authenticate_user(GtkWidget *button, EConfig *config)
{
    EMConfigTargetAccount *target_account = (EMConfigTargetAccount *)config->target;
    E2kAutoconfigResult result;
    CamelURL *url=NULL;
    gboolean remember_password;
    char *url_string, *key;
    const char *source_url, *id_name, *owa_url;
    char *at, *user;
    gboolean valid = FALSE;
    ExchangeParams *exchange_params;

    exchange_params = g_new0 (ExchangeParams, 1);
    exchange_params->host = NULL;
    exchange_params->ad_server = NULL;
    exchange_params->mailbox = NULL;
    exchange_params->owa_path = NULL;
    exchange_params->is_ntlm = TRUE;

    source_url = e_account_get_string (target_account->account, E_ACCOUNT_SOURCE_URL);

    if (source_url && source_url[0] != '\0')
        url = camel_url_new(source_url, NULL);
    if (url && url->user == NULL) {
        id_name = e_account_get_string (target_account->account, E_ACCOUNT_ID_ADDRESS);
        if (id_name) {
            at = strchr(id_name, '@');
            user = g_alloca(at-id_name+1);
            memcpy(user, id_name, at-id_name);
            user[at-id_name] = 0;
            camel_url_set_user (url, user);
        }
    }

    /* validate_user() CALLS GTK!!!

       THIS IS TOTALLY UNNACCEPTABLE!!!!!!!!

       It must use camel_session_ask_password, and it should return an exception for any problem,
       which should then be shown using e-error */

    owa_url = camel_url_get_param (url, "owa_url");
    if (camel_url_get_param (url, "authmech"))
        exchange_params->is_ntlm = TRUE;
    else
        exchange_params->is_ntlm = FALSE;
    camel_url_set_authmech (url, exchange_params->is_ntlm ? "NTLM" : "Basic");

    key = camel_url_to_string (url, CAMEL_URL_HIDE_PASSWORD | CAMEL_URL_HIDE_PARAMS);
    /* Supress the trailing slash */
    key [strlen(key) -1] = 0;

    valid =  e2k_validate_user (owa_url, key, &url->user, exchange_params,
                                &remember_password, &result,
                                GTK_WINDOW (gtk_widget_get_toplevel (button)));
    g_free (key);

    if (!valid && result != E2K_AUTOCONFIG_CANCELLED)
        print_error (owa_url, result);

    camel_url_set_host (url, valid ? exchange_params->host : "");


    if (valid)
        camel_url_set_param (url, "save-passwd", remember_password? "true" : "false");

    camel_url_set_param (url, "ad_server", valid ? exchange_params->ad_server: NULL);
    camel_url_set_param (url, "mailbox", valid ? exchange_params->mailbox : NULL);
    camel_url_set_param (url, "owa_path", valid ? exchange_params->owa_path : NULL);

    g_free (exchange_params->owa_path);
    g_free (exchange_params->mailbox);
    g_free (exchange_params->host);
    g_free (exchange_params->ad_server);
    g_free (exchange_params);

    if (valid) {
        url_string = camel_url_to_string (url, 0);
        e_account_set_string (target_account->account, E_ACCOUNT_SOURCE_URL, url_string);
        e_account_set_string (target_account->account, E_ACCOUNT_TRANSPORT_URL, url_string);
        e_account_set_bool (target_account->account, E_ACCOUNT_SOURCE_SAVE_PASSWD, remember_password);
        g_free (url_string);
    }
    camel_url_free (url);
}
ECalComponent*
kolab_cal_util_fb_new_ecalcomp_from_request (KolabUtilHttpJob *job,
                                             Kolab_conv_freebusy_type listtype,
                                             GError **err)
{
	CamelURL *camel_url = NULL;
	gchar *url_string = NULL;
	gchar *servername = NULL;
	gboolean use_ssl = FALSE;
	gssize nbytes = 0;
	ECalComponent *ecalcomp = NULL;
	GError *tmp_err = NULL;

	/* preconditions */
	g_assert (job != NULL);
	g_assert (job->buffer == NULL);
	g_return_val_if_fail (err == NULL || *err == NULL, NULL);

	url_string = camel_url_to_string (job->url, 0);
	g_assert (url_string != NULL);

	servername = g_strdup (job->url->host);
	use_ssl = kolab_util_http_protocol_is_ssl (url_string);

	g_free (url_string);

	url_string = kolabconv_cal_util_freebusy_new_fb_url (servername,
	                                                     job->url->user,
	                                                     use_ssl,
	                                                     listtype);
	g_assert (url_string != NULL);
	g_debug ("%s: \n\t\t\t\t%s", __func__, url_string);

	/* FIXME create a new extended CamelURL from url_string
	 *
	 * - merge the old and the new CamelURL
	 * - pay attention to passwd,authmech,... set
	 *   on the original CamelURL
	 *
	 */
	camel_url = camel_url_new (url_string, NULL);
	g_assert (camel_url != NULL);
	g_free (url_string);
	camel_url_set_user (camel_url, job->url->user);
	/* TODO authmech ? */

	camel_url_set_port (camel_url, job->url->port);
	if (job->url->query) camel_url_set_query (camel_url, job->url->query);
	if (job->url->fragment) camel_url_set_fragment (camel_url, job->url->fragment);
	camel_url_free (job->url);
	job->url = camel_url;

	job->buffer = g_byte_array_new ();
	g_assert (job->buffer != NULL);

	/* issue HTTP GET request */
	nbytes = kolab_util_http_get (job, &tmp_err);
	if (tmp_err != NULL)
		goto skip;

	job->nbytes = nbytes; /* save number of bytes read since buffer will be destroyed */
	g_debug ("%s: read %d bytes", __func__, nbytes);

	/* create new ECalComponent */
	ecalcomp = kolabconv_cal_util_freebusy_ecalcomp_new_from_ics ((gchar*)(job->buffer->data),
	                                                              nbytes,
	                                                              &tmp_err);
 skip:
	if ((ecalcomp == NULL) && (tmp_err != NULL))
		g_propagate_error (err, tmp_err);

	g_byte_array_unref (job->buffer);
	job->buffer = NULL;
	g_free (servername);

	/* postconditions */
	g_assert (job->buffer == NULL);

	return ecalcomp;
}