+static gint
+get_serverport_incoming(ModestProtocolType protocol,
+ ModestProtocolType security)
+{
+ int serverport_incoming = 0;
+
+ /* We don't check for SMTP here as that is impossible for an incoming server. */
+ if ((security == modest_protocol_registry_get_none_connection_type_id ()) ||
+ (security == modest_protocol_registry_get_tls_connection_type_id ()) ||
+ (security == modest_protocol_registry_get_tlsop_connection_type_id ())) {
+
+ if (protocol == MODEST_PROTOCOLS_STORE_IMAP) {
+ serverport_incoming = 143;
+ } else if (protocol == MODEST_PROTOCOLS_STORE_POP) {
+ serverport_incoming = 110;
+ }
+ } else if (security == modest_protocol_registry_get_ssl_connection_type_id ()) {
+ if (protocol == MODEST_PROTOCOLS_STORE_IMAP) {
+ serverport_incoming = 993;
+ } else if (protocol == MODEST_PROTOCOLS_STORE_POP) {
+ serverport_incoming = 995;
+ }
+ }
+
+ return serverport_incoming;
+}
+
+static GList*
+check_for_supported_auth_methods (ModestAccountAssistant* self)
+{
+ GError *error = NULL;
+ ModestProtocolType protocol;
+ const gchar* hostname;
+ const gchar* username;
+ gchar *store_protocol_name, *store_security_name;
+ ModestProtocolType security_protocol;
+ int port_num;
+ GList *list_auth_methods;
+ ModestAccountAssistantPrivate *priv;
+ ModestProtocolRegistry *registry;
+ ModestProtocol *proto;
+
+ priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE (self);
+ hostname = gtk_entry_get_text(GTK_ENTRY(priv->store_server_widget));
+ username = gtk_entry_get_text(GTK_ENTRY(priv->username));
+ store_protocol_name = gtk_combo_box_get_active_text (GTK_COMBO_BOX (priv->store_protocol_combo));
+ registry = modest_runtime_get_protocol_registry ();
+ proto = modest_protocol_registry_get_protocol_by_name (registry,
+ MODEST_PROTOCOL_REGISTRY_STORE_PROTOCOLS,
+ store_protocol_name);
+ protocol = modest_protocol_get_type_id (proto);
+
+ g_free (store_protocol_name);
+ store_security_name = gtk_combo_box_get_active_text (GTK_COMBO_BOX (priv->store_security_combo));
+
+ proto = modest_protocol_registry_get_protocol_by_name (registry,
+ MODEST_PROTOCOL_REGISTRY_CONNECTION_PROTOCOLS,
+ store_security_name);
+ security_protocol = modest_protocol_get_type_id (proto);
+ g_free (store_security_name);
+ port_num = get_serverport_incoming(protocol, security_protocol);
+ list_auth_methods = modest_utils_get_supported_secure_authentication_methods (protocol, hostname, port_num,
+ username, GTK_WINDOW (self), &error);
+
+ if (list_auth_methods) {
+ /* TODO: Select the correct method */
+ GList* list = NULL;
+ GList* method;
+ for (method = list_auth_methods; method != NULL; method = g_list_next(method)) {
+ ModestProtocolType auth = (ModestProtocolType) (GPOINTER_TO_INT(method->data));
+ if (modest_protocol_registry_protocol_type_is_secure (registry, auth)) {
+ list = g_list_append(list, GINT_TO_POINTER(auth));
+ }
+ }
+
+ g_list_free(list_auth_methods);
+
+ if (list)
+ return list;
+ }
+
+ if(error != NULL)
+ g_error_free(error);
+
+ return NULL;
+}
+
+static ModestProtocolType check_first_supported_auth_method(ModestAccountAssistant* self)
+{
+ ModestProtocolType result = MODEST_PROTOCOLS_AUTH_PASSWORD;
+
+ GList* methods = check_for_supported_auth_methods(self);
+ if (methods)
+ {
+ /* Use the first one: */
+ result = (ModestProtocolType) (GPOINTER_TO_INT(methods->data));
+ g_list_free(methods);
+ }
+
+ return result;
+}
+
+/**
+ * save_to_settings:
+ * @self: a #ModestEasysetupWizardDialog
+ *
+ * takes information from all the wizard and stores it in settings
+ */
+static void
+save_to_settings (ModestAccountAssistant *self)
+{
+ ModestAccountAssistantPrivate *priv = MODEST_ACCOUNT_ASSISTANT_GET_PRIVATE (self);
+ gchar* display_name;
+ const gchar *username, *password;
+ gchar *store_hostname, *transport_hostname;
+ guint store_port, transport_port;
+ ModestProtocolType store_protocol, transport_protocol;
+ ModestProtocolType store_security, transport_security;
+ ModestProtocolType store_auth_protocol, transport_auth_protocol;
+ ModestServerAccountSettings *store_settings, *transport_settings;
+ const gchar *fullname, *email_address;
+
+ /* username and password (for both incoming and outgoing): */
+ username = gtk_entry_get_text (GTK_ENTRY (priv->username));
+ password = gtk_entry_get_text (GTK_ENTRY (priv->password));
+
+ /* Incoming server: */
+ /* Note: We need something as default for the ModestTransportStoreProtocol* values,
+ * or modest_account_mgr_add_server_account will fail. */
+ store_port = 0;
+ store_protocol = MODEST_PROTOCOLS_STORE_POP;
+ store_security = MODEST_PROTOCOLS_CONNECTION_NONE;
+ store_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
+
+ /* Use custom pages because no preset was specified: */
+ store_hostname = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->store_server_widget) ));
+ store_protocol = modest_combo_box_get_active_id (MODEST_COMBO_BOX (priv->store_protocol_combo));
+ store_security = modest_combo_box_get_active_id (MODEST_COMBO_BOX (priv->store_security_combo));
+
+ /* The UI spec says:
+ * If secure authentication is unchecked, allow sending username and password also as plain text.
+ * If secure authentication is checked, require one of the secure methods during
+ * connection: SSL, TLS, CRAM-MD5 etc. */
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->store_secure_auth)) &&
+ !modest_protocol_registry_protocol_type_is_secure(modest_runtime_get_protocol_registry (),
+ store_security)) {
+ store_auth_protocol = check_first_supported_auth_method (self);
+ } else {
+ store_auth_protocol = MODEST_PROTOCOLS_AUTH_PASSWORD;
+ }
+
+ /* now we store the store account settings */
+ store_settings = modest_account_settings_get_store_settings (priv->settings);
+ modest_server_account_settings_set_hostname (store_settings, store_hostname);
+ modest_server_account_settings_set_username (store_settings, username);
+ modest_server_account_settings_set_password (store_settings, password);
+ modest_server_account_settings_set_protocol (store_settings, store_protocol);
+ modest_server_account_settings_set_security_protocol (store_settings, store_security);
+ modest_server_account_settings_set_auth_protocol (store_settings, store_auth_protocol);
+ if (store_port != 0)
+ modest_server_account_settings_set_port (store_settings, store_port);
+
+ g_object_unref (store_settings);
+ g_free (store_hostname);
+
+ /* Outgoing server: */
+ transport_hostname = NULL;
+ transport_protocol = MODEST_PROTOCOLS_STORE_POP;
+ transport_security = MODEST_PROTOCOLS_CONNECTION_NONE;
+ transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
+ transport_port = 0;
+
+ transport_hostname = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->transport_server_widget) ));
+ transport_protocol = MODEST_PROTOCOLS_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
+ transport_security = modest_combo_box_get_active_id (MODEST_COMBO_BOX (priv->transport_security_combo));
+ transport_auth_protocol = modest_combo_box_get_active_id (MODEST_COMBO_BOX (priv->transport_secure_auth_combo));
+
+ /* now we transport the transport account settings */
+ transport_settings = modest_account_settings_get_transport_settings (priv->settings);
+ modest_server_account_settings_set_hostname (transport_settings, transport_hostname);
+ modest_server_account_settings_set_username (transport_settings, username);
+ modest_server_account_settings_set_password (transport_settings, password);
+ modest_server_account_settings_set_protocol (transport_settings, transport_protocol);
+ modest_server_account_settings_set_security_protocol (transport_settings, transport_security);
+ modest_server_account_settings_set_auth_protocol (transport_settings, transport_auth_protocol);
+ if (transport_port != 0)
+ modest_server_account_settings_set_port (transport_settings, transport_port);
+
+ g_object_unref (transport_settings);
+ g_free (transport_hostname);
+
+ fullname = gtk_entry_get_text (GTK_ENTRY (priv->fullname));
+ email_address = gtk_entry_get_text (GTK_ENTRY (priv->email));
+ modest_account_settings_set_fullname (priv->settings, fullname);
+ modest_account_settings_set_email_address (priv->settings, email_address);
+ /* we don't set retrieve type to preserve advanced settings if any. By default account settings
+ are set to headers only */
+
+ display_name = get_entered_account_title (self);
+ modest_account_settings_set_display_name (priv->settings, display_name);
+ g_free (display_name);