[gnome-online-accounts] imap-smtp: Export the SASL mechanism used for SMTP
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-online-accounts] imap-smtp: Export the SASL mechanism used for SMTP
- Date: Mon, 3 Feb 2014 14:10:52 +0000 (UTC)
commit 8da87488477b8a8b94cdba406bc2bea5f487860a
Author: Debarshi Ray <debarshir gnome org>
Date: Mon Feb 3 14:22:12 2014 +0100
imap-smtp: Export the SASL mechanism used for SMTP
Not well tested because I lost my test account.
Fixes: https://bugzilla.gnome.org/720262
src/goabackend/goaimapsmtpprovider.c | 27 +++++++++++++++++++++++++--
src/goabackend/goasmtpauth.c | 30 +++++++++++++++++++++---------
src/goabackend/goasmtpauth.h | 4 +++-
3 files changed, 49 insertions(+), 12 deletions(-)
---
diff --git a/src/goabackend/goaimapsmtpprovider.c b/src/goabackend/goaimapsmtpprovider.c
index 6917f25..22d24c9 100644
--- a/src/goabackend/goaimapsmtpprovider.c
+++ b/src/goabackend/goaimapsmtpprovider.c
@@ -1,6 +1,6 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/*
- * Copyright (C) 2011, 2013 Red Hat, Inc.
+ * Copyright (C) 2011, 2013, 2014 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -123,6 +123,8 @@ build_object (GoaProvider *provider,
gboolean imap_use_tls;
gboolean ret;
gboolean smtp_accept_ssl_errors;
+ gboolean smtp_auth_login;
+ gboolean smtp_auth_plain;
gboolean smtp_use_auth;
gboolean smtp_use_ssl;
gboolean smtp_use_tls;
@@ -140,6 +142,8 @@ build_object (GoaProvider *provider,
imap_host = NULL;
imap_username = NULL;
name = NULL;
+ smtp_auth_login = FALSE;
+ smtp_auth_plain = FALSE;
smtp_host = NULL;
smtp_username = NULL;
@@ -196,6 +200,15 @@ build_object (GoaProvider *provider,
smtp_username = g_key_file_get_string (key_file, group, "SmtpUserName", NULL);
if (smtp_username == NULL)
smtp_username = g_strdup (g_get_user_name ());
+
+ smtp_auth_login = g_key_file_get_boolean (key_file, group, "SmtpAuthLogin", NULL);
+ smtp_auth_plain = g_key_file_get_boolean (key_file, group, "SmtpAuthPlain", NULL);
+ /* For backwards compatibility: if authentication is
+ * used, assume PLAIN as the SASL scheme if nothing is
+ * specified.
+ */
+ if (!smtp_auth_login && !smtp_auth_plain)
+ smtp_auth_plain = TRUE;
}
smtp_use_ssl = g_key_file_get_boolean (key_file, group, "SmtpUseSsl", NULL);
smtp_use_tls = g_key_file_get_boolean (key_file, group, "SmtpUseTls", NULL);
@@ -215,6 +228,8 @@ build_object (GoaProvider *provider,
"smtp-host", smtp_host,
"smtp-user-name", smtp_username,
"smtp-use-auth", smtp_use_auth,
+ "smtp-auth-login", smtp_auth_login,
+ "smtp-auth-plain", smtp_auth_plain,
"smtp-use-ssl", smtp_use_ssl,
"smtp-use-tls", smtp_use_tls,
"smtp-accept-ssl-errors", smtp_accept_ssl_errors,
@@ -890,6 +905,8 @@ add_account (GoaProvider *provider,
GoaTlsType smtp_tls_type;
gboolean imap_accept_ssl_errors;
gboolean smtp_accept_ssl_errors;
+ gboolean smtp_auth_login;
+ gboolean smtp_auth_plain;
gboolean smtp_use_auth;
const gchar *email_address;
const gchar *encryption;
@@ -1086,6 +1103,8 @@ add_account (GoaProvider *provider,
g_main_loop_run (data.loop);
smtp_use_auth = goa_mail_auth_is_needed (smtp_auth);
+ smtp_auth_login = goa_smtp_auth_is_login (GOA_SMTP_AUTH (smtp_auth));
+ smtp_auth_plain = goa_smtp_auth_is_plain (GOA_SMTP_AUTH (smtp_auth));
if (g_cancellable_is_cancelled (data.cancellable))
{
@@ -1149,7 +1168,11 @@ add_account (GoaProvider *provider,
g_variant_builder_add (&details, "{ss}", "SmtpHost", smtp_server);
g_variant_builder_add (&details, "{ss}", "SmtpUseAuth", (smtp_use_auth) ? "true" : "false");
if (smtp_use_auth)
- g_variant_builder_add (&details, "{ss}", "SmtpUserName", smtp_username);
+ {
+ g_variant_builder_add (&details, "{ss}", "SmtpUserName", smtp_username);
+ g_variant_builder_add (&details, "{ss}", "SmtpAuthLogin", (smtp_auth_login) ? "true" : "false");
+ g_variant_builder_add (&details, "{ss}", "SmtpAuthPlain", (smtp_auth_plain) ? "true" : "false");
+ }
g_variant_builder_add (&details, "{ss}",
"SmtpUseSsl", (smtp_tls_type == GOA_TLS_TYPE_SSL) ? "true" : "false");
g_variant_builder_add (&details, "{ss}",
diff --git a/src/goabackend/goasmtpauth.c b/src/goabackend/goasmtpauth.c
index 4b11a24..a6bae35 100644
--- a/src/goabackend/goasmtpauth.c
+++ b/src/goabackend/goasmtpauth.c
@@ -1,6 +1,6 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/*
- * Copyright (C) 2011, 2013 Red Hat, Inc.
+ * Copyright (C) 2011, 2013, 2014 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -54,6 +54,8 @@ struct _GoaSmtpAuth
GoaObject *object;
gboolean auth_supported;
gboolean greeting_absent;
+ gboolean login_supported;
+ gboolean plain_supported;
gchar *domain;
gchar *username;
gchar *password;
@@ -560,6 +562,20 @@ goa_smtp_auth_new (GoaProvider *provider,
/* ---------------------------------------------------------------------------------------------------- */
+gboolean
+goa_smtp_auth_is_login (GoaSmtpAuth *auth)
+{
+ return auth->login_supported;
+}
+
+gboolean
+goa_smtp_auth_is_plain (GoaSmtpAuth *auth)
+{
+ return auth->plain_supported;
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
static gboolean
goa_smtp_auth_is_needed (GoaMailAuth *_auth)
{
@@ -577,8 +593,6 @@ goa_smtp_auth_run_sync (GoaMailAuth *_auth,
GoaSmtpAuth *auth = GOA_SMTP_AUTH (_auth);
GDataInputStream *input;
GDataOutputStream *output;
- gboolean login_supported;
- gboolean plain_supported;
gboolean ret;
gchar *auth_arg_base64;
gchar *auth_arg_plain;
@@ -588,8 +602,6 @@ goa_smtp_auth_run_sync (GoaMailAuth *_auth,
gchar *response;
gsize auth_arg_plain_len;
- login_supported = FALSE;
- plain_supported = FALSE;
auth_arg_base64 = NULL;
auth_arg_plain = NULL;
domain = NULL;
@@ -642,9 +654,9 @@ goa_smtp_auth_run_sync (GoaMailAuth *_auth,
{
auth->auth_supported = TRUE;
if (strstr (response, "PLAIN") != NULL)
- plain_supported = TRUE;
+ auth->plain_supported = TRUE;
else if (strstr (response, "LOGIN") != NULL)
- login_supported = TRUE;
+ auth->login_supported = TRUE;
}
if (response[3] == '-')
@@ -657,7 +669,7 @@ goa_smtp_auth_run_sync (GoaMailAuth *_auth,
ret = TRUE;
goto out;
}
- else if (!login_supported && !plain_supported)
+ else if (!auth->login_supported && !auth->plain_supported)
{
g_set_error (error,
GOA_ERROR,
@@ -669,7 +681,7 @@ goa_smtp_auth_run_sync (GoaMailAuth *_auth,
/* Try different SASL mechanisms */
- if (plain_supported)
+ if (auth->plain_supported)
{
/* AUTH PLAIN */
diff --git a/src/goabackend/goasmtpauth.h b/src/goabackend/goasmtpauth.h
index cb60e48..3bdffc3 100644
--- a/src/goabackend/goasmtpauth.h
+++ b/src/goabackend/goasmtpauth.h
@@ -1,6 +1,6 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/*
- * Copyright (C) 2011, 2013 Red Hat, Inc.
+ * Copyright (C) 2011, 2013, 2014 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -48,6 +48,8 @@ GoaMailAuth *goa_smtp_auth_new (GoaProvider *provider,
const gchar *domain,
const gchar *user_name,
const gchar *password);
+gboolean goa_smtp_auth_is_login (GoaSmtpAuth *auth);
+gboolean goa_smtp_auth_is_plain (GoaSmtpAuth *auth);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]