Blame SOURCES/evolution-3.12.11-best-auth-method-suggest.patch

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