[evolution-data-server] Bug #310978 - USENET always requires authentication



commit 39e7f2f20358dce876a4b3f4b7f5698d104fe7b2
Author: Milan Crha <mcrha redhat com>
Date:   Thu Oct 18 12:48:30 2012 +0200

    Bug #310978 - USENET always requires authentication

 camel/providers/nntp/camel-nntp-provider.c |   19 ++++++++++++++++-
 camel/providers/nntp/camel-nntp-store.c    |   29 +++++++++++++++++++++------
 2 files changed, 39 insertions(+), 9 deletions(-)
---
diff --git a/camel/providers/nntp/camel-nntp-provider.c b/camel/providers/nntp/camel-nntp-provider.c
index 6b73d54..acf6dca 100644
--- a/camel/providers/nntp/camel-nntp-provider.c
+++ b/camel/providers/nntp/camel-nntp-provider.c
@@ -81,24 +81,39 @@ static CamelProvider news_provider = {
 	/* ... */
 };
 
+CamelServiceAuthType camel_nntp_anonymous_authtype = {
+	N_("Anonymous"),
+
+	N_("This option will connect to the NNTP server anonymously, without "
+	   "authentication."),
+
+	"ANONYMOUS",
+	FALSE
+};
+
 CamelServiceAuthType camel_nntp_password_authtype = {
 	N_("Password"),
 
 	N_("This option will authenticate with the NNTP server using a "
 	   "plaintext password."),
 
-	"",
+	"PLAIN",
 	TRUE
 };
 
 void
 camel_provider_module_init (void)
 {
+	GList *auth_types;
+
+	auth_types = g_list_append (NULL, &camel_nntp_anonymous_authtype);
+	auth_types = g_list_append (auth_types, &camel_nntp_password_authtype);
+
 	news_provider.object_types[CAMEL_PROVIDER_STORE] = camel_nntp_store_get_type ();
 
 	news_provider.url_hash = nntp_url_hash;
 	news_provider.url_equal = nntp_url_equal;
-	news_provider.authtypes = g_list_append (NULL, &camel_nntp_password_authtype);
+	news_provider.authtypes = auth_types;
 	news_provider.translation_domain = GETTEXT_PACKAGE;
 
 	camel_provider_register (&news_provider);
diff --git a/camel/providers/nntp/camel-nntp-store.c b/camel/providers/nntp/camel-nntp-store.c
index ebdc1b4..acf908f 100644
--- a/camel/providers/nntp/camel-nntp-store.c
+++ b/camel/providers/nntp/camel-nntp-store.c
@@ -256,9 +256,7 @@ connect_to_server (CamelService *service,
 	gboolean retval = FALSE;
 	guchar *buf;
 	guint len;
-	gchar *host;
-	gchar *path;
-	gchar *user;
+	gchar *host, *path, *user, *mechanism;
 
 	session = camel_service_get_session (service);
 	user_cache_dir = camel_service_get_user_cache_dir (service);
@@ -268,6 +266,7 @@ connect_to_server (CamelService *service,
 	network_settings = CAMEL_NETWORK_SETTINGS (settings);
 	host = camel_network_settings_dup_host (network_settings);
 	user = camel_network_settings_dup_user (network_settings);
+	mechanism = camel_network_settings_dup_auth_mechanism (network_settings);
 
 	g_object_unref (settings);
 
@@ -304,8 +303,17 @@ connect_to_server (CamelService *service,
 		goto fail;
 	}
 
-	/* if we have username, try it here */
-	if (user != NULL && *user != '\0') {
+	/* backward compatibility, empty 'mechanism' is a non-migrated account */
+	if ((user != NULL && *user != '\0' && (!mechanism || !*mechanism)) ||
+	    (mechanism && *mechanism && g_strcmp0 (mechanism, "ANONYMOUS") != 0)) {
+
+		if (!user || !*user) {
+			g_set_error_literal (
+				error, CAMEL_SERVICE_ERROR,
+				CAMEL_SERVICE_ERROR_CANT_AUTHENTICATE,
+				_("Cannot authenticate without a username"));
+			goto fail;
+		}
 
 		/* XXX No SASL support. */
 		if (!camel_session_authenticate_sync (
@@ -335,6 +343,7 @@ connect_to_server (CamelService *service,
 fail:
 	g_free (host);
 	g_free (user);
+	g_free (mechanism);
 
 	return retval;
 }
@@ -467,6 +476,7 @@ nntp_store_get_name (CamelService *service,
 	return name;
 }
 
+extern CamelServiceAuthType camel_nntp_anonymous_authtype;
 extern CamelServiceAuthType camel_nntp_password_authtype;
 
 static CamelAuthenticationResult
@@ -495,7 +505,7 @@ nntp_store_authenticate_sync (CamelService *service,
 
 	g_object_unref (settings);
 
-	if (user == NULL) {
+	if (!user || !*user) {
 		g_set_error_literal (
 			error, CAMEL_SERVICE_ERROR,
 			CAMEL_SERVICE_ERROR_CANT_AUTHENTICATE,
@@ -547,7 +557,12 @@ nntp_store_query_auth_types_sync (CamelService *service,
                                   GCancellable *cancellable,
                                   GError **error)
 {
-	return g_list_append (NULL, &camel_nntp_password_authtype);
+	GList *auth_types;
+
+	auth_types = g_list_append (NULL, &camel_nntp_anonymous_authtype);
+	auth_types = g_list_append (auth_types, &camel_nntp_password_authtype);
+
+	return auth_types;
 }
 
 static CamelFolder *



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]