Blob Blame History Raw
diff -up evolution-3.12.11/e-util/e-auth-combo-box.c.best-auth-method-suggest evolution-3.12.11/e-util/e-auth-combo-box.c
--- evolution-3.12.11/e-util/e-auth-combo-box.c.best-auth-method-suggest	2014-03-24 10:25:23.000000000 +0100
+++ evolution-3.12.11/e-util/e-auth-combo-box.c	2015-05-04 18:53:04.660198169 +0200
@@ -214,6 +214,29 @@ e_auth_combo_box_set_provider (EAuthComb
 	auth_combo_box_rebuild_model (combo_box);
 }
 
+static gint
+e_auth_combo_box_get_preference_level (const gchar *authproto)
+{
+	/* In order of preference, from the least to the best */
+	const gchar *protos[] = {
+		"CRAM-MD5",
+		"DIGEST-MD5",
+		"NTLM",
+		"GSSAPI"
+	};
+	gint ii;
+
+	if (!authproto)
+		return -1;
+
+	for (ii = 0; ii < G_N_ELEMENTS (protos); ii++) {
+		if (g_ascii_strcasecmp (protos[ii], authproto) == 0)
+			return ii;
+	}
+
+	return -1;
+}
+
 void
 e_auth_combo_box_update_available (EAuthComboBox *combo_box,
                                    GList *available_authtypes)
@@ -223,6 +246,7 @@ e_auth_combo_box_update_available (EAuth
 	GtkTreeIter iter;
 	gint active_index;
 	gint available_index = -1;
+	gint chosen_preference_level = -1;
 	gint index = 0;
 	gboolean iter_set;
 
@@ -237,6 +261,7 @@ e_auth_combo_box_update_available (EAuth
 	while (iter_set) {
 		CamelServiceAuthType *authtype;
 		gboolean available;
+		gint preference_level = -1;
 
 		gtk_tree_model_get (
 			model, &iter, COLUMN_AUTHTYPE, &authtype, -1);
@@ -248,11 +273,16 @@ e_auth_combo_box_update_available (EAuth
 			GTK_LIST_STORE (model), &iter,
 			COLUMN_STRIKETHROUGH, !available, -1);
 
+		if (authtype)
+			preference_level = e_auth_combo_box_get_preference_level (authtype->authproto);
+
 		if (index == active_index && !available)
 			active_index = -1;
 
-		if (available && available_index == -1)
+		if (available && (available_index == -1 || chosen_preference_level < preference_level)) {
 			available_index = index;
+			chosen_preference_level = preference_level;
+		}
 
 		iter_set = gtk_tree_model_iter_next (model, &iter);
 		index++;
@@ -263,3 +293,44 @@ e_auth_combo_box_update_available (EAuth
 	if (active_index == -1 && available_index != -1)
 		gtk_combo_box_set_active (gtk_combo_box, available_index);
 }
+
+void
+e_auth_combo_box_pick_highest_available (EAuthComboBox *combo_box)
+{
+	GtkComboBox *gtk_combo_box;
+	GtkTreeModel *model;
+	GtkTreeIter iter;
+	gint highest_available_index = -1, index = 0;
+	gint chosen_preference_level = -1;
+
+	g_return_if_fail (E_IS_AUTH_COMBO_BOX (combo_box));
+
+	gtk_combo_box = GTK_COMBO_BOX (combo_box);
+	model = gtk_combo_box_get_model (gtk_combo_box);
+
+	if (gtk_tree_model_get_iter_first (model, &iter)) {
+		do {
+			CamelServiceAuthType *authtype = NULL;
+			gboolean unavailable = TRUE;
+			gint preference_level = -1;
+
+			gtk_tree_model_get (model, &iter,
+				COLUMN_STRIKETHROUGH, &unavailable,
+				COLUMN_AUTHTYPE, &authtype,
+				-1);
+
+			if (authtype)
+				preference_level = e_auth_combo_box_get_preference_level (authtype->authproto);
+
+			if (!unavailable && (highest_available_index == -1 || chosen_preference_level < preference_level)) {
+				highest_available_index = index;
+				chosen_preference_level = preference_level;
+			}
+
+			index++;
+		} while (gtk_tree_model_iter_next (model, &iter));
+	}
+
+	if (highest_available_index != -1)
+		gtk_combo_box_set_active (gtk_combo_box, highest_available_index);
+}
diff -up evolution-3.12.11/e-util/e-auth-combo-box.h.best-auth-method-suggest evolution-3.12.11/e-util/e-auth-combo-box.h
--- evolution-3.12.11/e-util/e-auth-combo-box.h.best-auth-method-suggest	2014-03-24 10:25:23.000000000 +0100
+++ evolution-3.12.11/e-util/e-auth-combo-box.h	2015-05-04 18:53:04.660198169 +0200
@@ -67,6 +67,8 @@ void		e_auth_combo_box_set_provider	(EAu
 void		e_auth_combo_box_update_available
 						(EAuthComboBox *combo_box,
 						 GList *available_authtypes);
+void		e_auth_combo_box_pick_highest_available
+						(EAuthComboBox *combo_box);
 
 G_END_DECLS
 
diff -up evolution-3.12.11/mail/e-mail-config-auth-check.c.best-auth-method-suggest evolution-3.12.11/mail/e-mail-config-auth-check.c
--- evolution-3.12.11/mail/e-mail-config-auth-check.c.best-auth-method-suggest	2014-07-17 12:48:14.000000000 +0200
+++ evolution-3.12.11/mail/e-mail-config-auth-check.c	2015-05-04 18:53:04.660198169 +0200
@@ -103,6 +103,8 @@ mail_config_auth_check_update_done_cb (G
 		e_auth_combo_box_update_available (
 			E_AUTH_COMBO_BOX (auth_check->priv->combo_box),
 			available_authtypes);
+		e_auth_combo_box_pick_highest_available (E_AUTH_COMBO_BOX (auth_check->priv->combo_box));
+
 		g_list_free (available_authtypes);
 	}
 
@@ -334,6 +336,16 @@ mail_config_auth_check_constructed (GObj
 	backend = e_mail_config_auth_check_get_backend (auth_check);
 	provider = e_mail_config_service_backend_get_provider (backend);
 
+	text = _("Check for Supported Types");
+	widget = gtk_button_new_with_label (text);
+	gtk_box_pack_start (GTK_BOX (object), widget, FALSE, FALSE, 0);
+	gtk_widget_show (widget);
+
+	g_signal_connect (
+		widget, "clicked",
+		G_CALLBACK (mail_config_auth_check_clicked_cb),
+		auth_check);
+
 	widget = e_auth_combo_box_new ();
 	e_auth_combo_box_set_provider (E_AUTH_COMBO_BOX (widget), provider);
 	gtk_box_pack_start (GTK_BOX (object), widget, FALSE, FALSE, 0);
@@ -346,16 +358,6 @@ mail_config_auth_check_constructed (GObj
 		G_BINDING_BIDIRECTIONAL |
 		G_BINDING_SYNC_CREATE);
 
-	text = _("Check for Supported Types");
-	widget = gtk_button_new_with_label (text);
-	gtk_box_pack_start (GTK_BOX (object), widget, FALSE, FALSE, 0);
-	gtk_widget_show (widget);
-
-	g_signal_connect (
-		widget, "clicked",
-		G_CALLBACK (mail_config_auth_check_clicked_cb),
-		auth_check);
-
 	mail_config_auth_check_init_mechanism (auth_check);
 }