ews_config_lookup_worker_result_from_settings (EConfigLookupWorker *lookup_worker,
					       EConfigLookup *config_lookup,
					       const gchar *email_address,
					       CamelEwsSettings *ews_settings,
					       const ENamedParameters *params)
{
	const gchar *url;

	g_return_if_fail (E_IS_EWS_CONFIG_LOOKUP (lookup_worker));
	g_return_if_fail (E_IS_CONFIG_LOOKUP (config_lookup));
	g_return_if_fail (CAMEL_IS_EWS_SETTINGS (ews_settings));

	url = camel_ews_settings_get_hosturl (ews_settings);
	if (url && *url) {
		EConfigLookupResult *lookup_result;
		GString *description;
		gchar *tmp, *ptr, *user;
		const gchar *extension_name;
		SoupURI *suri;

		extension_name = e_source_camel_get_extension_name ("ews");

		tmp = g_strdup (email_address);
		ptr = tmp ? strchr (tmp, '@') : NULL;
		if (ptr)
			*ptr = '\0';

		if (!tmp || !*tmp) {
			g_free (tmp);
			tmp = NULL;
		}

		user = tmp;

		suri = soup_uri_new (url);

		description = g_string_new ("");

		if (user && *user)
			g_string_append_printf (description, _("User: %s"), user);

		if (description->len)
			g_string_append_c (description, '\n');

		g_string_append_printf (description, _("Host URL: %s"), url);

		url = camel_ews_settings_get_oaburl (ews_settings);
		if (url && *url) {
			g_string_append_c (description, '\n');
			g_string_append_printf (description, _("OAB URL: %s"), url);
		}

		lookup_result = e_ews_config_lookup_result_new (E_CONFIG_LOOKUP_RESULT_COLLECTION,
			E_CONFIG_LOOKUP_RESULT_PRIORITY_IMAP - 100, /* This is better than IMAP */
			"ews",
			_("Exchange Web Services"),
			description->str,
			params && e_named_parameters_exists (params, E_CONFIG_LOOKUP_PARAM_PASSWORD) &&
			e_named_parameters_exists (params, E_CONFIG_LOOKUP_PARAM_REMEMBER_PASSWORD) ?
			e_named_parameters_get (params, E_CONFIG_LOOKUP_PARAM_PASSWORD) : NULL);

		e_config_lookup_result_simple_add_string (lookup_result, E_SOURCE_EXTENSION_COLLECTION,
			"backend-name", "ews");

		e_config_lookup_result_simple_add_string (lookup_result, extension_name,
			"hosturl", camel_ews_settings_get_hosturl (ews_settings));

		e_config_lookup_result_simple_add_string (lookup_result, extension_name,
			"oaburl", camel_ews_settings_get_oaburl (ews_settings));

		if (user && *user) {
			e_config_lookup_result_simple_add_string (lookup_result,
				E_SOURCE_EXTENSION_COLLECTION,
				"identity", user);

			e_config_lookup_result_simple_add_string (lookup_result,
				E_SOURCE_EXTENSION_AUTHENTICATION,
				"user", user);
		}

		if (suri && suri->host && *suri->host) {
			e_config_lookup_result_simple_add_string (lookup_result,
				E_SOURCE_EXTENSION_AUTHENTICATION,
				"host", suri->host);
		}

		if (suri && suri->port) {
			e_config_lookup_result_simple_add_uint (lookup_result,
				E_SOURCE_EXTENSION_AUTHENTICATION,
				"port", suri->port);
		}

		e_config_lookup_add_result (config_lookup, lookup_result);

		g_string_free (description, TRUE);
		g_free (user);
		if (suri)
			soup_uri_free (suri);
	}
}
ews_config_lookup_worker_result_from_settings (EConfigLookupWorker *lookup_worker,
					       EConfigLookup *config_lookup,
					       const gchar *email_address,
					       CamelEwsSettings *ews_settings,
					       const ENamedParameters *params)
{
	const gchar *url;

	g_return_if_fail (E_IS_EWS_CONFIG_LOOKUP (lookup_worker));
	g_return_if_fail (E_IS_CONFIG_LOOKUP (config_lookup));
	g_return_if_fail (CAMEL_IS_EWS_SETTINGS (ews_settings));

	url = camel_ews_settings_get_hosturl (ews_settings);
	if (url && *url) {
		EConfigLookupResult *lookup_result;
		GString *description;
		gchar *tmp, *ptr, *user;
		const gchar *extension_name;
		SoupURI *suri;

		extension_name = e_source_camel_get_extension_name ("ews");

		tmp = g_strdup (email_address);
		ptr = tmp ? strchr (tmp, '@') : NULL;
		if (ptr)
			*ptr = '\0';

		if (!tmp || !*tmp) {
			g_free (tmp);
			tmp = NULL;
		}

		user = tmp;

		suri = soup_uri_new (url);

		description = g_string_new ("");

		if (user && *user)
			g_string_append_printf (description, _("User: %s"), user);

		if (description->len)
			g_string_append_c (description, '\n');

		g_string_append_printf (description, _("Host URL: %s"), url);

		url = camel_ews_settings_get_oaburl (ews_settings);
		if (url && *url) {
			g_string_append_c (description, '\n');
			g_string_append_printf (description, _("OAB URL: %s"), url);
		}

		lookup_result = e_ews_config_lookup_result_new (E_CONFIG_LOOKUP_RESULT_COLLECTION,
			E_CONFIG_LOOKUP_RESULT_PRIORITY_IMAP - 100,  
			"ews",
			_("Exchange Web Services"),
			description->str,
			params && e_named_parameters_exists (params, E_CONFIG_LOOKUP_PARAM_PASSWORD) &&
			e_named_parameters_exists (params, E_CONFIG_LOOKUP_PARAM_REMEMBER_PASSWORD) ?
			e_named_parameters_get (params, E_CONFIG_LOOKUP_PARAM_PASSWORD) : NULL);

		e_config_lookup_result_simple_add_string (lookup_result, E_SOURCE_EXTENSION_COLLECTION,
			"backend-name", "ews");

		e_config_lookup_result_simple_add_string (lookup_result, extension_name,
			"hosturl", camel_ews_settings_get_hosturl (ews_settings));

		e_config_lookup_result_simple_add_string (lookup_result, extension_name,
			"oaburl", camel_ews_settings_get_oaburl (ews_settings));

		if (user && *user) {
			e_config_lookup_result_simple_add_string (lookup_result,
				E_SOURCE_EXTENSION_COLLECTION,
				"identity", user);

			e_config_lookup_result_simple_add_string (lookup_result,
				E_SOURCE_EXTENSION_AUTHENTICATION,
				"user", user);
		}

		if (suri && suri->host && *suri->host) {
			e_config_lookup_result_simple_add_string (lookup_result,
				E_SOURCE_EXTENSION_AUTHENTICATION,
				"host", suri->host);
		}

		if (suri && suri->port) {
			e_config_lookup_result_simple_add_uint (lookup_result,
				E_SOURCE_EXTENSION_AUTHENTICATION,
				"port", suri->port);
		}

		e_config_lookup_add_result (config_lookup, lookup_result);

		g_string_free (description, TRUE);
		g_free (user);
		if (suri)
			soup_uri_free (suri);
	}
}