[evolution] Bug 695693 - Handle <authentication> tags during auto-configuration



commit b1b884763ee8bc7ce42f44d5a4f7f9ee1fec0555
Author: Matthew Barnes <mbarnes redhat com>
Date:   Tue Mar 12 08:32:13 2013 -0400

    Bug 695693 - Handle <authentication> tags during auto-configuration

 mail/e-mail-autoconfig.c                         |   44 ++++++++++++++++++++-
 modules/mail-config/e-mail-config-smtp-backend.c |   31 +++++++++++++++-
 2 files changed, 71 insertions(+), 4 deletions(-)
---
diff --git a/mail/e-mail-autoconfig.c b/mail/e-mail-autoconfig.c
index 69b7329..61fe0c6 100644
--- a/mail/e-mail-autoconfig.c
+++ b/mail/e-mail-autoconfig.c
@@ -89,6 +89,7 @@ struct _EMailAutoconfigResult {
        gchar *user;
        gchar *host;
        guint16 port;
+       gchar *auth_mechanism;
        CamelNetworkSecurityMethod security_method;
 };
 
@@ -281,10 +282,43 @@ mail_autoconfig_parse_text (GMarkupParseContext *context,
                                CAMEL_NETWORK_SECURITY_METHOD_STARTTLS_ON_STANDARD_PORT;
                        closure->result->set = TRUE;
                }
-       }
 
-       /* FIXME Not handling <authentication> elements.
-        *       Unclear how some map to SASL mechanisms. */
+       } else if (g_str_equal (element_name, "authentication")) {
+               gboolean use_plain_auth = FALSE;
+
+               /* "password-cleartext" and "plain" are synonymous. */
+
+               if (g_str_equal (string->str, "password-cleartext"))
+                       use_plain_auth = TRUE;
+
+               if (g_str_equal (string->str, "plain"))
+                       use_plain_auth = TRUE;
+
+               if (use_plain_auth) {
+                       gchar *auth_mechanism = NULL;
+
+                       /* The exact auth name depends on the protocol. */
+
+                       /* Leave this NULL for IMAP so Camel
+                        * will issue an IMAP LOGIN command. */
+                       if (closure->result == &priv->imap_result)
+                               auth_mechanism = NULL;
+
+                       /* Leave this NULL for POP3 so Camel
+                        * will issue POP3 USER/PASS commands. */
+                       if (closure->result == &priv->pop3_result)
+                               auth_mechanism = NULL;
+
+                       if (closure->result == &priv->smtp_result)
+                               auth_mechanism = g_strdup ("LOGIN");
+
+                       closure->result->auth_mechanism = auth_mechanism;
+                       closure->result->set = TRUE;
+               }
+
+               /* XXX Other <authentication> values not handled,
+                *     but they are corner cases for the most part. */
+       }
 
        g_string_free (string, TRUE);
 }
@@ -429,6 +463,7 @@ mail_autoconfig_set_details (EMailAutoconfig *autoconfig,
                "user", result->user,
                "host", result->host,
                "port", result->port,
+               "auth-mechanism", result->auth_mechanism,
                "security-method", result->security_method,
                NULL);
 
@@ -493,10 +528,13 @@ mail_autoconfig_finalize (GObject *object)
 
        g_free (priv->imap_result.user);
        g_free (priv->imap_result.host);
+       g_free (priv->imap_result.auth_mechanism);
        g_free (priv->pop3_result.user);
        g_free (priv->pop3_result.host);
+       g_free (priv->pop3_result.auth_mechanism);
        g_free (priv->smtp_result.user);
        g_free (priv->smtp_result.host);
+       g_free (priv->smtp_result.auth_mechanism);
 
        /* Chain up to parent's finalize() method. */
        G_OBJECT_CLASS (e_mail_autoconfig_parent_class)->finalize (object);
diff --git a/modules/mail-config/e-mail-config-smtp-backend.c 
b/modules/mail-config/e-mail-config-smtp-backend.c
index ac54cd4..c78c017 100644
--- a/modules/mail-config/e-mail-config-smtp-backend.c
+++ b/modules/mail-config/e-mail-config-smtp-backend.c
@@ -289,11 +289,40 @@ static gboolean
 mail_config_smtp_backend_auto_configure (EMailConfigServiceBackend *backend,
                                          EMailAutoconfig *autoconfig)
 {
+       EMailConfigSmtpBackendPrivate *priv;
        ESource *source;
+       CamelSettings *settings;
+       const gchar *mechanism;
 
        source = e_mail_config_service_backend_get_source (backend);
 
-       return e_mail_autoconfig_set_smtp_details (autoconfig, source);
+       if (!e_mail_autoconfig_set_smtp_details (autoconfig, source))
+               return FALSE;
+
+       /* XXX Need to set the authentication widgets to match the
+        *     auto-configured settings or else the auto-configured
+        *     settings will be overwritten in commit_changes().
+        *
+        *     It's not good enough to just set an auto-configured
+        *     flag and skip the widget checks in commit_changes()
+        *     if the flag is TRUE, since the user may revise the
+        *     SMTP settings before committing. */
+
+       priv = E_MAIL_CONFIG_SMTP_BACKEND_GET_PRIVATE (backend);
+
+       settings = e_mail_config_service_backend_get_settings (backend);
+
+       mechanism = camel_network_settings_get_auth_mechanism (
+               CAMEL_NETWORK_SETTINGS (settings));
+
+       gtk_toggle_button_set_active (
+               GTK_TOGGLE_BUTTON (priv->auth_required_toggle),
+               (mechanism != NULL));
+
+       if (mechanism != NULL)
+               e_mail_config_auth_check_set_active_mechanism (
+                       E_MAIL_CONFIG_AUTH_CHECK (priv->auth_check),
+                       mechanism);
 }
 
 static gboolean


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