Adapt to changes in built-in OAuth2 implementation in evolution-data-server
This commit is contained in:
@ -16,8 +16,6 @@
|
||||
<chapter>
|
||||
<title>Classes</title>
|
||||
<xi:include href="xml/camel-null-store.xml"/>
|
||||
<xi:include href="xml/camel-sasl-xoauth2.xml"/>
|
||||
<xi:include href="xml/camel-sasl-oauth2-google.xml"/>
|
||||
<xi:include href="xml/e-mail-junk-filter.xml"/>
|
||||
<xi:include href="xml/e-mail-session.xml"/>
|
||||
<xi:include href="xml/em-filter-folder-element.xml"/>
|
||||
|
@ -304,8 +304,6 @@ src/e-util/gal-view-instance-save-as-dialog.c
|
||||
[type: gettext/glade]src/e-util/gal-view-instance-save-as-dialog.ui
|
||||
src/e-util/widgets.error.xml
|
||||
src/libemail-engine/camel-null-store.c
|
||||
src/libemail-engine/camel-sasl-oauth2-google.c
|
||||
src/libemail-engine/camel-sasl-xoauth2.c
|
||||
src/libemail-engine/e-mail-folder-utils.c
|
||||
src/libemail-engine/e-mail-session.c
|
||||
src/libemail-engine/e-mail-session-utils.c
|
||||
|
@ -951,7 +951,7 @@ collection_account_wizard_write_changes_thread (ESimpleAsyncResult *result,
|
||||
if (!text || !*text)
|
||||
e_source_backend_set_backend_name (E_SOURCE_BACKEND (collection_extension), "none");
|
||||
|
||||
google_supported = e_source_credentials_google_is_supported ();
|
||||
google_supported = e_oauth2_services_is_oauth2_alias (e_source_registry_get_oauth2_services (wizard->priv->registry), "Google");
|
||||
|
||||
for (ii = 0; ii <= E_CONFIG_LOOKUP_RESULT_LAST_KIND; ii++) {
|
||||
source = wizard->priv->sources[ii];
|
||||
|
@ -7,8 +7,6 @@ set(DEPENDENCIES
|
||||
|
||||
set(SOURCES
|
||||
camel-null-store.c
|
||||
camel-sasl-oauth2-google.c
|
||||
camel-sasl-xoauth2.c
|
||||
e-mail-folder-utils.c
|
||||
e-mail-junk-filter.c
|
||||
e-mail-session-utils.c
|
||||
@ -30,8 +28,6 @@ set(SOURCES
|
||||
set(HEADERS
|
||||
libemail-engine.h
|
||||
camel-null-store.h
|
||||
camel-sasl-oauth2-google.h
|
||||
camel-sasl-xoauth2.h
|
||||
e-mail-engine-enums.h
|
||||
e-mail-folder-utils.h
|
||||
e-mail-junk-filter.h
|
||||
|
@ -1,116 +0,0 @@
|
||||
/*
|
||||
* camel-sasl-oauth2-google.c
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "evolution-config.h"
|
||||
|
||||
#include <glib/gi18n-lib.h>
|
||||
|
||||
#include "camel-sasl-oauth2-google.h"
|
||||
|
||||
#include <libemail-engine/e-mail-session.h>
|
||||
|
||||
static CamelServiceAuthType sasl_oauth2_google_auth_type = {
|
||||
N_("OAuth2 Google"),
|
||||
N_("This option will use an OAuth 2.0 "
|
||||
"access token to connect to the Google server"),
|
||||
"Google",
|
||||
TRUE
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (CamelSaslOAuth2Google, camel_sasl_oauth2_google, CAMEL_TYPE_SASL)
|
||||
|
||||
static void
|
||||
sasl_oauth2_google_append_request (GByteArray *byte_array,
|
||||
const gchar *user,
|
||||
const gchar *access_token)
|
||||
{
|
||||
GString *request;
|
||||
|
||||
g_return_if_fail (user != NULL);
|
||||
g_return_if_fail (access_token != NULL);
|
||||
|
||||
/* Compared to OAuth 1.0, this step is trivial. */
|
||||
|
||||
/* The request is easier to assemble with a GString. */
|
||||
request = g_string_sized_new (512);
|
||||
|
||||
g_string_append (request, "user=");
|
||||
g_string_append (request, user);
|
||||
g_string_append_c (request, 1);
|
||||
g_string_append (request, "auth=Bearer ");
|
||||
g_string_append (request, access_token);
|
||||
g_string_append_c (request, 1);
|
||||
g_string_append_c (request, 1);
|
||||
|
||||
/* Copy the GString content to the GByteArray. */
|
||||
g_byte_array_append (
|
||||
byte_array, (guint8 *) request->str, request->len);
|
||||
|
||||
g_string_free (request, TRUE);
|
||||
}
|
||||
|
||||
static GByteArray *
|
||||
sasl_oauth2_google_challenge_sync (CamelSasl *sasl,
|
||||
GByteArray *token,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
GByteArray *byte_array = NULL;
|
||||
CamelService *service;
|
||||
CamelSettings *settings;
|
||||
gchar *access_token = NULL;
|
||||
|
||||
service = camel_sasl_get_service (sasl);
|
||||
settings = camel_service_ref_settings (service);
|
||||
access_token = camel_service_dup_password (service);
|
||||
|
||||
if (access_token) {
|
||||
CamelNetworkSettings *network_settings;
|
||||
gchar *user;
|
||||
|
||||
network_settings = CAMEL_NETWORK_SETTINGS (settings);
|
||||
user = camel_network_settings_dup_user (network_settings);
|
||||
|
||||
byte_array = g_byte_array_new ();
|
||||
sasl_oauth2_google_append_request (byte_array, user, access_token);
|
||||
|
||||
g_free (user);
|
||||
}
|
||||
|
||||
g_free (access_token);
|
||||
|
||||
g_object_unref (settings);
|
||||
|
||||
/* IMAP and SMTP services will Base64-encode the request. */
|
||||
|
||||
return byte_array;
|
||||
}
|
||||
|
||||
static void
|
||||
camel_sasl_oauth2_google_class_init (CamelSaslOAuth2GoogleClass *class)
|
||||
{
|
||||
CamelSaslClass *sasl_class;
|
||||
|
||||
sasl_class = CAMEL_SASL_CLASS (class);
|
||||
sasl_class->auth_type = &sasl_oauth2_google_auth_type;
|
||||
sasl_class->challenge_sync = sasl_oauth2_google_challenge_sync;
|
||||
}
|
||||
|
||||
static void
|
||||
camel_sasl_oauth2_google_init (CamelSaslOAuth2Google *sasl)
|
||||
{
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
/*
|
||||
* camel-sasl-oauth2-google.h
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#if !defined (__LIBEMAIL_ENGINE_H_INSIDE__) && !defined (LIBEMAIL_ENGINE_COMPILATION)
|
||||
#error "Only <libemail-engine/libemail-engine.h> should be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef CAMEL_SASL_OAUTH2_GOOGLE_H
|
||||
#define CAMEL_SASL_OAUTH2_GOOGLE_H
|
||||
|
||||
#include <camel/camel.h>
|
||||
|
||||
/* Standard GObject macros */
|
||||
#define CAMEL_TYPE_SASL_OAUTH2_GOOGLE \
|
||||
(camel_sasl_oauth2_google_get_type ())
|
||||
#define CAMEL_SASL_OAUTH2_GOOGLE(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST \
|
||||
((obj), CAMEL_TYPE_SASL_OAUTH2_GOOGLE, CamelSaslOAuth2Google))
|
||||
#define CAMEL_SASL_OAUTH2_GOOGLE_CLASS(cls) \
|
||||
(G_TYPE_CHECK_CLASS_CAST \
|
||||
((cls), CAMEL_TYPE_SASL_OAUTH2_GOOGLE, CamelSaslOAuth2GoogleClass))
|
||||
#define CAMEL_IS_SASL_OAUTH2_GOOGLE(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE \
|
||||
((obj), CAMEL_TYPE_SASL_OAUTH2_GOOGLE))
|
||||
#define CAMEL_IS_SASL_OAUTH2_GOOGLE_CLASS(cls) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE \
|
||||
((cls), CAMEL_TYPE_SASL_OAUTH2_GOOGLE))
|
||||
#define CAMEL_SASL_OAUTH2_GOOGLE_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS \
|
||||
((obj), CAMEL_TYPE_SASL_OAUTH2_GOOGLE, CamelSaslOAuth2GoogleClass))
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _CamelSaslOAuth2Google CamelSaslOAuth2Google;
|
||||
typedef struct _CamelSaslOAuth2GoogleClass CamelSaslOAuth2GoogleClass;
|
||||
typedef struct _CamelSaslOAuth2GooglePrivate CamelSaslOAuth2GooglePrivate;
|
||||
|
||||
struct _CamelSaslOAuth2Google {
|
||||
CamelSasl parent;
|
||||
CamelSaslOAuth2GooglePrivate *priv;
|
||||
};
|
||||
|
||||
struct _CamelSaslOAuth2GoogleClass {
|
||||
CamelSaslClass parent_class;
|
||||
};
|
||||
|
||||
GType camel_sasl_oauth2_google_get_type (void) G_GNUC_CONST;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* CAMEL_SASL_OAUTH2_GOOGLE_H */
|
@ -1,132 +0,0 @@
|
||||
/*
|
||||
* camel-sasl-xoauth2.c
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "evolution-config.h"
|
||||
|
||||
#include <glib/gi18n-lib.h>
|
||||
|
||||
#include "camel-sasl-xoauth2.h"
|
||||
|
||||
#include <libemail-engine/e-mail-session.h>
|
||||
|
||||
static CamelServiceAuthType sasl_xoauth2_auth_type = {
|
||||
N_("OAuth2"),
|
||||
N_("This option will use an OAuth 2.0 "
|
||||
"access token to connect to the server"),
|
||||
"XOAUTH2",
|
||||
FALSE
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (CamelSaslXOAuth2, camel_sasl_xoauth2, CAMEL_TYPE_SASL)
|
||||
|
||||
static void
|
||||
sasl_xoauth2_append_request (GByteArray *byte_array,
|
||||
const gchar *user,
|
||||
const gchar *access_token)
|
||||
{
|
||||
GString *request;
|
||||
|
||||
g_return_if_fail (user != NULL);
|
||||
g_return_if_fail (access_token != NULL);
|
||||
|
||||
/* Compared to OAuth 1.0, this step is trivial. */
|
||||
|
||||
/* The request is easier to assemble with a GString. */
|
||||
request = g_string_sized_new (512);
|
||||
|
||||
g_string_append (request, "user=");
|
||||
g_string_append (request, user);
|
||||
g_string_append_c (request, 1);
|
||||
g_string_append (request, "auth=Bearer ");
|
||||
g_string_append (request, access_token);
|
||||
g_string_append_c (request, 1);
|
||||
g_string_append_c (request, 1);
|
||||
|
||||
/* Copy the GString content to the GByteArray. */
|
||||
g_byte_array_append (
|
||||
byte_array, (guint8 *) request->str, request->len);
|
||||
|
||||
g_string_free (request, TRUE);
|
||||
}
|
||||
|
||||
static GByteArray *
|
||||
sasl_xoauth2_challenge_sync (CamelSasl *sasl,
|
||||
GByteArray *token,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
GByteArray *byte_array = NULL;
|
||||
CamelService *service;
|
||||
CamelSession *session;
|
||||
CamelSettings *settings;
|
||||
ESourceRegistry *registry;
|
||||
ESource *source;
|
||||
const gchar *uid;
|
||||
gchar *access_token = NULL;
|
||||
gboolean success;
|
||||
|
||||
service = camel_sasl_get_service (sasl);
|
||||
session = camel_service_ref_session (service);
|
||||
settings = camel_service_ref_settings (service);
|
||||
|
||||
uid = camel_service_get_uid (service);
|
||||
registry = e_mail_session_get_registry (E_MAIL_SESSION (session));
|
||||
source = e_source_registry_ref_source (registry, uid);
|
||||
g_return_val_if_fail (source != NULL, NULL);
|
||||
|
||||
success = e_source_get_oauth2_access_token_sync (
|
||||
source, cancellable, &access_token, NULL, error);
|
||||
|
||||
if (success) {
|
||||
CamelNetworkSettings *network_settings;
|
||||
gchar *user;
|
||||
|
||||
network_settings = CAMEL_NETWORK_SETTINGS (settings);
|
||||
user = camel_network_settings_dup_user (network_settings);
|
||||
|
||||
byte_array = g_byte_array_new ();
|
||||
sasl_xoauth2_append_request (byte_array, user, access_token);
|
||||
|
||||
g_free (user);
|
||||
}
|
||||
|
||||
g_free (access_token);
|
||||
|
||||
g_object_unref (source);
|
||||
g_object_unref (settings);
|
||||
g_object_unref (session);
|
||||
|
||||
/* IMAP and SMTP services will Base64-encode the request. */
|
||||
|
||||
return byte_array;
|
||||
}
|
||||
|
||||
static void
|
||||
camel_sasl_xoauth2_class_init (CamelSaslXOAuth2Class *class)
|
||||
{
|
||||
CamelSaslClass *sasl_class;
|
||||
|
||||
sasl_class = CAMEL_SASL_CLASS (class);
|
||||
sasl_class->auth_type = &sasl_xoauth2_auth_type;
|
||||
sasl_class->challenge_sync = sasl_xoauth2_challenge_sync;
|
||||
}
|
||||
|
||||
static void
|
||||
camel_sasl_xoauth2_init (CamelSaslXOAuth2 *sasl)
|
||||
{
|
||||
}
|
||||
|
@ -1,66 +0,0 @@
|
||||
/*
|
||||
* camel-sasl-xoauth2.h
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#if !defined (__LIBEMAIL_ENGINE_H_INSIDE__) && !defined (LIBEMAIL_ENGINE_COMPILATION)
|
||||
#error "Only <libemail-engine/libemail-engine.h> should be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef CAMEL_SASL_XOAUTH2_H
|
||||
#define CAMEL_SASL_XOAUTH2_H
|
||||
|
||||
#include <camel/camel.h>
|
||||
|
||||
/* Standard GObject macros */
|
||||
#define CAMEL_TYPE_SASL_XOAUTH2 \
|
||||
(camel_sasl_xoauth2_get_type ())
|
||||
#define CAMEL_SASL_XOAUTH2(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST \
|
||||
((obj), CAMEL_TYPE_SASL_XOAUTH2, CamelSaslXOAuth2))
|
||||
#define CAMEL_SASL_XOAUTH2_CLASS(cls) \
|
||||
(G_TYPE_CHECK_CLASS_CAST \
|
||||
((cls), CAMEL_TYPE_SASL_XOAUTH2, CamelSaslXOAuth2Class))
|
||||
#define CAMEL_IS_SASL_XOAUTH2(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE \
|
||||
((obj), CAMEL_TYPE_SASL_XOAUTH2))
|
||||
#define CAMEL_IS_SASL_XOAUTH2_CLASS(cls) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE \
|
||||
((cls), CAMEL_TYPE_SASL_XOAUTH2))
|
||||
#define CAMEL_SASL_XOAUTH2_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS \
|
||||
((obj), CAMEL_TYPE_SASL_XOAUTH2, CamelSaslXOAuth2Class))
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _CamelSaslXOAuth2 CamelSaslXOAuth2;
|
||||
typedef struct _CamelSaslXOAuth2Class CamelSaslXOAuth2Class;
|
||||
typedef struct _CamelSaslXOAuth2Private CamelSaslXOAuth2Private;
|
||||
|
||||
struct _CamelSaslXOAuth2 {
|
||||
CamelSasl parent;
|
||||
CamelSaslXOAuth2Private *priv;
|
||||
};
|
||||
|
||||
struct _CamelSaslXOAuth2Class {
|
||||
CamelSaslClass parent_class;
|
||||
};
|
||||
|
||||
GType camel_sasl_xoauth2_get_type (void) G_GNUC_CONST;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* CAMEL_SASL_XOAUTH2_H */
|
||||
|
@ -47,10 +47,6 @@
|
||||
/* This is our hack, not part of libcamel. */
|
||||
#include "camel-null-store.h"
|
||||
|
||||
/* These too, though it's less of a hack. */
|
||||
#include "camel-sasl-xoauth2.h"
|
||||
#include "camel-sasl-oauth2-google.h"
|
||||
|
||||
#include "e-mail-session.h"
|
||||
#include "e-mail-folder-utils.h"
|
||||
#include "e-mail-utils.h"
|
||||
@ -1198,7 +1194,7 @@ mail_session_add_service (CamelSession *session,
|
||||
if (CAMEL_IS_SERVICE (service)) {
|
||||
ESource *source;
|
||||
ESource *tmp_source;
|
||||
gboolean is_google = FALSE;
|
||||
EOAuth2Service *oauth2_service;
|
||||
|
||||
/* Each CamelService has a corresponding ESource. */
|
||||
source = e_source_registry_ref_source (registry, uid);
|
||||
@ -1227,32 +1223,17 @@ mail_session_add_service (CamelSession *session,
|
||||
* if necessary. */
|
||||
camel_service_migrate_files (service);
|
||||
|
||||
if (e_source_has_extension (source, E_SOURCE_EXTENSION_AUTHENTICATION)) {
|
||||
ESourceAuthentication *auth_extension;
|
||||
const gchar *host;
|
||||
/* Kind of hack, to add also correct OAuth2 SASL implementation */
|
||||
oauth2_service = e_oauth2_services_find (e_source_registry_get_oauth2_services (registry), source);
|
||||
if (oauth2_service) {
|
||||
CamelServiceAuthType *auth_type;
|
||||
|
||||
auth_extension = e_source_get_extension (source, E_SOURCE_EXTENSION_AUTHENTICATION);
|
||||
host = e_source_authentication_get_host (auth_extension);
|
||||
auth_type = camel_sasl_authtype (e_oauth2_service_get_name (oauth2_service));
|
||||
if (auth_type) {
|
||||
CamelProvider *provider;
|
||||
|
||||
is_google = host && (
|
||||
e_util_utf8_strstrcase (host, "gmail.com") != NULL ||
|
||||
e_util_utf8_strstrcase (host, "googlemail.com") != NULL);
|
||||
}
|
||||
|
||||
g_object_unref (source);
|
||||
|
||||
/* Kind of hack for the custom SASL authentication unknown to Camel. */
|
||||
if (is_google) {
|
||||
CamelProvider *provider;
|
||||
CamelSaslOAuth2GoogleClass *oauth2_google_class;
|
||||
|
||||
oauth2_google_class = g_type_class_ref (CAMEL_TYPE_SASL_OAUTH2_GOOGLE);
|
||||
provider = camel_service_get_provider (service);
|
||||
|
||||
if (provider && oauth2_google_class) {
|
||||
CamelServiceAuthType *auth_type = oauth2_google_class->parent_class.auth_type;
|
||||
|
||||
if (!g_list_find (provider->authtypes, auth_type))
|
||||
provider = camel_service_get_provider (service);
|
||||
if (provider && !g_list_find (provider->authtypes, auth_type))
|
||||
provider->authtypes = g_list_append (provider->authtypes, auth_type);
|
||||
}
|
||||
}
|
||||
@ -1531,6 +1512,60 @@ mail_session_forward_to_sync (CamelSession *session,
|
||||
return success;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
mail_session_get_oauth2_access_token_sync (CamelSession *session,
|
||||
CamelService *service,
|
||||
gchar **out_access_token,
|
||||
gint *out_expires_in,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
EMailSession *mail_session;
|
||||
ESource *source, *cred_source;
|
||||
GError *local_error = NULL;
|
||||
gboolean success;
|
||||
|
||||
g_return_val_if_fail (E_IS_MAIL_SESSION (session), FALSE);
|
||||
g_return_val_if_fail (CAMEL_IS_SERVICE (service), FALSE);
|
||||
|
||||
mail_session = E_MAIL_SESSION (session);
|
||||
source = e_source_registry_ref_source (mail_session->priv->registry, camel_service_get_uid (service));
|
||||
if (!source) {
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
|
||||
_("Corresponding source for service with UID “%s” not found"),
|
||||
camel_service_get_uid (service));
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
cred_source = e_source_registry_find_extension (mail_session->priv->registry, source, E_SOURCE_EXTENSION_COLLECTION);
|
||||
if (cred_source && !e_util_can_use_collection_as_credential_source (cred_source, source)) {
|
||||
g_clear_object (&cred_source);
|
||||
}
|
||||
|
||||
success = e_source_get_oauth2_access_token_sync (cred_source ? cred_source : source, cancellable, out_access_token, out_expires_in, &local_error);
|
||||
|
||||
/* The Connection Refused error can be returned when the OAuth2 token is expired or
|
||||
when its refresh failed for some reason. In that case change the error domain/code,
|
||||
thus the other Camel/mail code understands it. */
|
||||
if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_CONNECTION_REFUSED) ||
|
||||
g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) {
|
||||
local_error->domain = CAMEL_SERVICE_ERROR;
|
||||
local_error->code = CAMEL_SERVICE_ERROR_CANT_AUTHENTICATE;
|
||||
|
||||
e_source_invoke_credentials_required_sync (cred_source ? cred_source : source,
|
||||
E_SOURCE_CREDENTIALS_REASON_REJECTED, NULL, 0, local_error, cancellable, NULL);
|
||||
}
|
||||
|
||||
if (local_error)
|
||||
g_propagate_error (error, local_error);
|
||||
|
||||
g_clear_object (&cred_source);
|
||||
g_object_unref (source);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
static EMVFolderContext *
|
||||
mail_session_create_vfolder_context (EMailSession *session)
|
||||
{
|
||||
@ -1557,6 +1592,7 @@ e_mail_session_class_init (EMailSessionClass *class)
|
||||
session_class->get_password = mail_session_get_password;
|
||||
session_class->forget_password = mail_session_forget_password;
|
||||
session_class->forward_to_sync = mail_session_forward_to_sync;
|
||||
session_class->get_oauth2_access_token_sync = mail_session_get_oauth2_access_token_sync;
|
||||
|
||||
class->create_vfolder_context = mail_session_create_vfolder_context;
|
||||
|
||||
@ -1695,10 +1731,6 @@ e_mail_session_class_init (EMailSessionClass *class)
|
||||
|
||||
/* Make sure ESourceCamel picks up the "none" provider. */
|
||||
e_source_camel_generate_subtype ("none", CAMEL_TYPE_SETTINGS);
|
||||
|
||||
/* Make sure CamelSasl picks up our mechanisms. */
|
||||
g_type_ensure (CAMEL_TYPE_SASL_XOAUTH2);
|
||||
g_type_ensure (CAMEL_TYPE_SASL_OAUTH2_GOOGLE);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -21,7 +21,6 @@
|
||||
#define __LIBEMAIL_ENGINE_H_INSIDE__
|
||||
|
||||
#include <libemail-engine/camel-null-store.h>
|
||||
#include <libemail-engine/camel-sasl-xoauth2.h>
|
||||
#include <libemail-engine/e-mail-engine-enums.h>
|
||||
#include <libemail-engine/e-mail-engine-enumtypes.h>
|
||||
#include <libemail-engine/e-mail-folder-utils.h>
|
||||
|
@ -132,7 +132,7 @@ cal_config_google_commit_changes (ESourceConfigBackend *backend,
|
||||
authentication_extension = e_source_get_extension (
|
||||
scratch_source, E_SOURCE_EXTENSION_AUTHENTICATION);
|
||||
|
||||
can_google_auth = e_source_credentials_google_is_supported () &&
|
||||
can_google_auth = e_module_cal_config_google_is_supported (backend, NULL) &&
|
||||
g_strcmp0 (e_source_authentication_get_method (authentication_extension), "OAuth2") != 0;
|
||||
|
||||
/* The backend name is actually "caldav" even though the
|
||||
|
@ -64,7 +64,7 @@ cal_config_gtasks_allow_creation (ESourceConfigBackend *backend)
|
||||
return FALSE;
|
||||
|
||||
source = e_source_config_get_original_source (config);
|
||||
if (!source && e_source_credentials_google_is_supported ())
|
||||
if (!source && e_module_cal_config_google_is_supported (backend, NULL))
|
||||
return TRUE;
|
||||
|
||||
if (!e_source_has_extension (source, E_SOURCE_EXTENSION_TASK_LIST))
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include <libedataserverui/libedataserverui.h>
|
||||
|
||||
#include "module-cal-config-google.h"
|
||||
#include "e-google-chooser-button.h"
|
||||
|
||||
#define E_GOOGLE_CHOOSER_BUTTON_GET_PRIVATE(obj) \
|
||||
@ -196,7 +197,7 @@ google_chooser_button_clicked (GtkButton *button)
|
||||
webdav_extension = e_source_get_extension (priv->source, E_SOURCE_EXTENSION_WEBDAV_BACKEND);
|
||||
|
||||
uri = e_source_webdav_dup_soup_uri (webdav_extension);
|
||||
can_google_auth = e_source_credentials_google_is_supported () &&
|
||||
can_google_auth = e_module_cal_config_google_is_supported (NULL, registry) &&
|
||||
g_strcmp0 (e_source_authentication_get_method (authentication_extension), "OAuth2") != 0;
|
||||
|
||||
e_google_chooser_button_construct_default_uri (uri, e_source_authentication_get_user (authentication_extension));
|
||||
|
@ -20,6 +20,19 @@
|
||||
#include "e-google-chooser-button.h"
|
||||
#include "module-cal-config-google.h"
|
||||
|
||||
gboolean
|
||||
e_module_cal_config_google_is_supported (ESourceConfigBackend *backend,
|
||||
ESourceRegistry *registry)
|
||||
{
|
||||
if (!backend && !registry)
|
||||
return FALSE;
|
||||
|
||||
if (!registry)
|
||||
registry = e_source_config_get_registry (e_source_config_backend_get_config (backend));
|
||||
|
||||
return registry && e_oauth2_services_is_oauth2_alias (e_source_registry_get_oauth2_services (registry), "Google");
|
||||
}
|
||||
|
||||
/* Module Entry Points */
|
||||
void e_module_load (GTypeModule *type_module);
|
||||
void e_module_unload (GTypeModule *type_module);
|
||||
|
@ -18,8 +18,11 @@
|
||||
|
||||
#include <glib.h>
|
||||
#include <libebackend/libebackend.h>
|
||||
#include "e-util/e-util.h"
|
||||
|
||||
void e_cal_config_google_type_register (GTypeModule *type_module);
|
||||
void e_cal_config_gtasks_type_register (GTypeModule *type_module);
|
||||
gboolean e_module_cal_config_google_is_supported (ESourceConfigBackend *backend,
|
||||
ESourceRegistry *registry);
|
||||
void e_cal_config_google_type_register (GTypeModule *type_module);
|
||||
void e_cal_config_gtasks_type_register (GTypeModule *type_module);
|
||||
|
||||
#endif /* MODULE_CAL_CONFIG_GOOGLE_H */
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include <libedataserver/libedataserver.h>
|
||||
#include <mail/e-mail-config-summary-page.h>
|
||||
#include "shell/e-shell.h"
|
||||
|
||||
#include "e-mail-config-google-summary.h"
|
||||
|
||||
@ -98,6 +99,23 @@ mail_config_google_summary_is_applicable (EMailConfigSummaryPage *page)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
mail_config_google_summary_is_oauth2_supported (void)
|
||||
{
|
||||
EShell *shell;
|
||||
ESourceRegistry *registry;
|
||||
|
||||
shell = e_shell_get_default ();
|
||||
if (!shell)
|
||||
return FALSE;
|
||||
|
||||
registry = e_shell_get_registry (shell);
|
||||
if (!registry)
|
||||
return FALSE;
|
||||
|
||||
return e_oauth2_services_is_oauth2_alias (e_source_registry_get_oauth2_services (registry), "Google");
|
||||
}
|
||||
|
||||
static void
|
||||
mail_config_google_summary_refresh_cb (EMailConfigSummaryPage *page,
|
||||
EMailConfigGoogleSummary *extension)
|
||||
@ -132,7 +150,7 @@ mail_config_google_summary_commit_changes_cb (EMailConfigSummaryPage *page,
|
||||
toggle_button = GTK_TOGGLE_BUTTON (extension->priv->calendar_toggle);
|
||||
calendar_active = gtk_toggle_button_get_active (toggle_button);
|
||||
|
||||
if (e_source_credentials_google_is_supported ()) {
|
||||
if (mail_config_google_summary_is_oauth2_supported ()) {
|
||||
toggle_button = GTK_TOGGLE_BUTTON (extension->priv->contacts_toggle);
|
||||
contacts_active = gtk_toggle_button_get_active (toggle_button);
|
||||
} else {
|
||||
@ -142,7 +160,7 @@ mail_config_google_summary_commit_changes_cb (EMailConfigSummaryPage *page,
|
||||
/* If the user declined both Calendar and Contacts, do nothing,
|
||||
but set the Google/OAuth2 authentication for the sources. */
|
||||
if (!calendar_active && !contacts_active) {
|
||||
if (e_source_credentials_google_is_supported ()) {
|
||||
if (mail_config_google_summary_is_oauth2_supported ()) {
|
||||
source = e_mail_config_summary_page_get_account_source (page);
|
||||
auth_extension = e_source_get_extension (source, E_SOURCE_EXTENSION_AUTHENTICATION);
|
||||
e_source_authentication_set_method (auth_extension, "Google");
|
||||
@ -180,7 +198,7 @@ mail_config_google_summary_commit_changes_cb (EMailConfigSummaryPage *page,
|
||||
auth_extension = e_source_get_extension (source, E_SOURCE_EXTENSION_AUTHENTICATION);
|
||||
e_source_authentication_set_host (auth_extension, "");
|
||||
|
||||
if (e_source_credentials_google_is_supported ()) {
|
||||
if (mail_config_google_summary_is_oauth2_supported ()) {
|
||||
e_source_authentication_set_user (auth_extension, user);
|
||||
e_source_authentication_set_method (auth_extension, "Google");
|
||||
}
|
||||
@ -297,7 +315,7 @@ mail_config_google_summary_constructed (GObject *object)
|
||||
extension->priv->calendar_toggle = widget; /* not referenced */
|
||||
gtk_widget_show (widget);
|
||||
|
||||
if (e_source_credentials_google_is_supported ()) {
|
||||
if (mail_config_google_summary_is_oauth2_supported ()) {
|
||||
text = _("Add Google Con_tacts to this account");
|
||||
widget = gtk_check_button_new_with_mnemonic (text);
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
|
||||
@ -321,7 +339,7 @@ mail_config_google_summary_constructed (GObject *object)
|
||||
gtk_label_set_use_markup (GTK_LABEL (widget), TRUE);
|
||||
gtk_widget_set_margin_left (widget, 12);
|
||||
gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
|
||||
if (e_source_credentials_google_is_supported ())
|
||||
if (mail_config_google_summary_is_oauth2_supported ())
|
||||
gtk_grid_attach (GTK_GRID (container), widget, 0, 3, 1, 1);
|
||||
else
|
||||
gtk_grid_attach (GTK_GRID (container), widget, 0, 2, 1, 1);
|
||||
@ -344,7 +362,7 @@ mail_config_google_summary_constructed (GObject *object)
|
||||
collection_extension, "calendar-enabled",
|
||||
G_BINDING_SYNC_CREATE);
|
||||
|
||||
if (e_source_credentials_google_is_supported ())
|
||||
if (mail_config_google_summary_is_oauth2_supported ())
|
||||
e_binding_bind_property (
|
||||
extension->priv->contacts_toggle, "active",
|
||||
collection_extension, "contacts-enabled",
|
||||
|
Reference in New Issue
Block a user