[evolution-data-server] Addressbook: Switch from GData Contacts API to CardDAV API for Google books



commit d63a1ce3921a6a6c573a6a70dbf2e152adf74c3f
Author: Milan Crha <mcrha redhat com>
Date:   Thu Jun 3 17:43:27 2021 +0200

    Addressbook: Switch from GData Contacts API to CardDAV API for Google books
    
    The GData Contacts API is going to be shut down [1], thus move to
    the CardDAV API, which the Google server supports too.
    
    [1] https://developers.google.com/contacts/v3/announcement
    
    Related to https://gitlab.gnome.org/GNOME/libgdata/-/issues/42

 po/POTFILES.in                                     |    2 -
 src/addressbook/backends/CMakeLists.txt            |    4 -
 .../backends/carddav/e-book-backend-carddav.c      |    3 +-
 src/addressbook/backends/google/CMakeLists.txt     |  100 --
 .../google/e-book-backend-google-factory.c         |   78 -
 .../backends/google/e-book-backend-google.c        | 1371 ---------------
 .../backends/google/e-book-backend-google.h        |   63 -
 .../backends/google/e-book-google-utils.c          | 1747 --------------------
 .../backends/google/e-book-google-utils.h          |   69 -
 .../backends/google/tests/CMakeLists.txt           |   38 -
 .../backends/google/tests/phone-numbers.c          |  125 --
 src/modules/google-backend/module-google-backend.c |  141 +-
 .../evolution-source-registry-migrate-tweaks.c     |   51 +
 13 files changed, 65 insertions(+), 3727 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 9a25ab509..111edaa5d 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -4,8 +4,6 @@
 src/addressbook/backends/carddav/e-book-backend-carddav.c
 src/addressbook/backends/file/e-book-backend-file.c
 src/addressbook/backends/file/e-book-backend-file-migrate-bdb.c
-src/addressbook/backends/google/e-book-backend-google.c
-src/addressbook/backends/google/e-book-google-utils.c
 src/addressbook/backends/ldap/e-book-backend-ldap.c
 src/addressbook/libebook-contacts/e-book-contacts-utils.c
 src/addressbook/libebook-contacts/e-contact.c
diff --git a/src/addressbook/backends/CMakeLists.txt b/src/addressbook/backends/CMakeLists.txt
index dced9968e..f38ad6ac1 100644
--- a/src/addressbook/backends/CMakeLists.txt
+++ b/src/addressbook/backends/CMakeLists.txt
@@ -1,10 +1,6 @@
 add_subdirectory(carddav)
 add_subdirectory(file)
 
-if(ENABLE_GOOGLE)
-       add_subdirectory(google)
-endif(ENABLE_GOOGLE)
-
 if(HAVE_LDAP)
        add_subdirectory(ldap)
 endif(HAVE_LDAP)
diff --git a/src/addressbook/backends/carddav/e-book-backend-carddav.c 
b/src/addressbook/backends/carddav/e-book-backend-carddav.c
index 0f587eaef..faf90b127 100644
--- a/src/addressbook/backends/carddav/e-book-backend-carddav.c
+++ b/src/addressbook/backends/carddav/e-book-backend-carddav.c
@@ -165,7 +165,8 @@ ebb_carddav_connect_sync (EBookMetaBackend *meta_backend,
                                }
 
                                g_free (path);
-                       } else if (soup_uri->host && e_util_utf8_strstrcase (soup_uri->host, 
".googleusercontent.com")) {
+                       } else if (soup_uri->host && (e_util_utf8_strstrcase (soup_uri->host, 
".googleusercontent.com") ||
+                                                     e_util_utf8_strstrcase (soup_uri->host, 
".googleapis.com"))) {
                                g_clear_error (&local_error);
                                success = TRUE;
 
diff --git a/src/modules/google-backend/module-google-backend.c 
b/src/modules/google-backend/module-google-backend.c
index 2b1fcf473..01fc05b9b 100644
--- a/src/modules/google-backend/module-google-backend.c
+++ b/src/modules/google-backend/module-google-backend.c
@@ -50,11 +50,6 @@
 #define GOOGLE_SMTP_PORT               465
 #define GOOGLE_SMTP_SECURITY_METHOD    METHOD (SSL_ON_ALTERNATE_PORT)
 
-/* Contacts Configuration Details */
-#define GOOGLE_CONTACTS_BACKEND_NAME   "google"
-#define GOOGLE_CONTACTS_HOST           "www.google.com"
-#define GOOGLE_CONTACTS_RESOURCE_ID    "Contacts"
-
 /* Tasks Configuration Details */
 #define GOOGLE_TASKS_BACKEND_NAME      "gtasks"
 
@@ -489,6 +484,7 @@ google_backend_authenticate_sync (EBackend *backend,
        GList *sources;
        ENamedParameters *credentials_copy = NULL;
        const gchar *calendar_url;
+       const gchar *contacts_url = NULL;
 
        g_return_val_if_fail (collection != NULL, E_SOURCE_AUTHENTICATION_ERROR);
 
@@ -538,8 +534,14 @@ google_backend_authenticate_sync (EBackend *backend,
                }
        }
 
-       if (e_source_collection_get_calendar_enabled (collection_extension) && calendar_url) {
-               result = e_webdav_collection_backend_discover_sync (E_WEBDAV_COLLECTION_BACKEND (backend), 
calendar_url, NULL,
+       if (!e_source_collection_get_calendar_enabled (collection_extension))
+               calendar_url = NULL;
+
+       if (e_source_collection_get_contacts_enabled (collection_extension))
+               contacts_url = "https://www.googleapis.com/.well-known/carddav";;
+
+       if (calendar_url || contacts_url) {
+               result = e_webdav_collection_backend_discover_sync (E_WEBDAV_COLLECTION_BACKEND (backend), 
calendar_url, contacts_url,
                        credentials, out_certificate_pem, out_certificate_errors, cancellable, error);
        } else {
                result = E_SOURCE_AUTHENTICATION_ACCEPTED;
@@ -616,78 +618,13 @@ google_backend_authenticate_sync (EBackend *backend,
        return result;
 }
 
-static void
-google_backend_add_contacts (ECollectionBackend *backend)
-{
-       ESource *source;
-       ESource *collection_source;
-       ESourceRegistryServer *server;
-       ESourceExtension *extension;
-       ESourceCollection *collection_extension;
-       const gchar *backend_name;
-       const gchar *extension_name;
-       const gchar *resource_id;
-
-       collection_source = e_backend_get_source (E_BACKEND (backend));
-
-       resource_id = GOOGLE_CONTACTS_RESOURCE_ID;
-       source = e_collection_backend_new_child (backend, resource_id);
-       e_source_set_display_name (source, _("Contacts"));
-
-       /* Add the address book source to the collection. */
-       collection_extension = e_source_get_extension (
-               collection_source, E_SOURCE_EXTENSION_COLLECTION);
-
-       /* Configure the address book source. */
-
-       backend_name = GOOGLE_CONTACTS_BACKEND_NAME;
-
-       extension_name = E_SOURCE_EXTENSION_ADDRESS_BOOK;
-       extension = e_source_get_extension (source, extension_name);
-
-       e_source_backend_set_backend_name (
-               E_SOURCE_BACKEND (extension), backend_name);
-
-       extension_name = E_SOURCE_EXTENSION_AUTHENTICATION;
-       extension = e_source_get_extension (source, extension_name);
-
-       e_source_authentication_set_host (
-               E_SOURCE_AUTHENTICATION (extension),
-               GOOGLE_CONTACTS_HOST);
-
-       e_binding_bind_property (
-               collection_extension, "identity",
-               extension, "user",
-               G_BINDING_SYNC_CREATE);
-
-       server = e_collection_backend_ref_server (backend);
-       e_source_registry_server_add_source (server, source);
-       g_object_unref (server);
-
-       g_object_unref (source);
-}
-
-static gchar *
-google_backend_get_resource_id (EWebDAVCollectionBackend *webdav_backend,
-                               ESource *source)
-{
-       g_return_val_if_fail (E_IS_SOURCE (source), NULL);
-
-       if (e_source_has_extension (source, E_SOURCE_EXTENSION_ADDRESS_BOOK))
-               return g_strdup (GOOGLE_CONTACTS_RESOURCE_ID);
-
-       /* Chain up to parent's method. */
-       return E_WEBDAV_COLLECTION_BACKEND_CLASS (e_google_backend_parent_class)->get_resource_id 
(webdav_backend, source);
-}
-
 static gboolean
 google_backend_is_custom_source (EWebDAVCollectionBackend *webdav_backend,
                                 ESource *source)
 {
        g_return_val_if_fail (E_IS_SOURCE (source), FALSE);
 
-       if (e_source_has_extension (source, E_SOURCE_EXTENSION_ADDRESS_BOOK) ||
-           e_source_has_extension (source, E_SOURCE_EXTENSION_TASK_LIST))
+       if (e_source_has_extension (source, E_SOURCE_EXTENSION_TASK_LIST))
                return TRUE;
 
        /* Chain up to parent's method. */
@@ -697,12 +634,10 @@ google_backend_is_custom_source (EWebDAVCollectionBackend *webdav_backend,
 static void
 google_backend_populate (ECollectionBackend *backend)
 {
-       ESourceCollection *collection_extension;
        ESourceAuthentication *authentication_extension;
        ESource *source;
 
        source = e_backend_get_source (E_BACKEND (backend));
-       collection_extension = e_source_get_extension (source, E_SOURCE_EXTENSION_COLLECTION);
        authentication_extension = e_source_get_extension (source, E_SOURCE_EXTENSION_AUTHENTICATION);
 
        /* When the WebDAV extension is created, the auth method can be reset, thus ensure
@@ -716,15 +651,6 @@ google_backend_populate (ECollectionBackend *backend)
 
        /* Chain up to parent's method. */
        E_COLLECTION_BACKEND_CLASS (e_google_backend_parent_class)->populate (backend);
-
-       if (e_source_collection_get_contacts_enabled (collection_extension)) {
-               GList *list;
-
-               list = e_collection_backend_list_contacts_sources (backend);
-               if (list == NULL)
-                       google_backend_add_contacts (backend);
-               g_list_free_full (list, (GDestroyNotify) g_object_unref);
-       }
 }
 
 static gchar *
@@ -733,12 +659,10 @@ google_backend_dup_resource_id (ECollectionBackend *backend,
 {
        if (e_source_has_extension (child_source, E_SOURCE_EXTENSION_CALENDAR) ||
            e_source_has_extension (child_source, E_SOURCE_EXTENSION_MEMO_LIST) ||
-           e_source_has_extension (child_source, E_SOURCE_EXTENSION_TASK_LIST))
+           e_source_has_extension (child_source, E_SOURCE_EXTENSION_TASK_LIST) ||
+           e_source_has_extension (child_source, E_SOURCE_EXTENSION_ADDRESS_BOOK))
                return E_COLLECTION_BACKEND_CLASS (e_google_backend_parent_class)->dup_resource_id (backend, 
child_source);
 
-       if (e_source_has_extension (child_source, E_SOURCE_EXTENSION_ADDRESS_BOOK))
-               return g_strdup (GOOGLE_CONTACTS_RESOURCE_ID);
-
        return NULL;
 }
 
@@ -749,7 +673,6 @@ google_backend_child_added (ECollectionBackend *backend,
        ESource *collection_source;
        const gchar *extension_name;
        gboolean is_mail = FALSE;
-       gboolean has_external_auth = FALSE;
 
        /* Chain up to parent's child_added() method. */
        E_COLLECTION_BACKEND_CLASS (e_google_backend_parent_class)->
@@ -785,8 +708,6 @@ google_backend_child_added (ECollectionBackend *backend,
                        child_source, extension_name);
                auth_child_user = e_source_authentication_get_user (
                        auth_child_extension);
-               has_external_auth = e_source_authentication_get_is_external (
-                       auth_child_extension);
 
                /* XXX Do not override an existing user name setting.
                 *     The IMAP or (especially) SMTP configuration may
@@ -846,42 +767,6 @@ google_backend_child_added (ECollectionBackend *backend,
                        child_source, "notify::oauth2-support",
                        G_CALLBACK (google_backend_contacts_update_auth_method_cb),
                        backend);
-
-               if (!has_external_auth) {
-                       /* Even the book is part of the collection it can be removed
-                          separately, if not configured through GOA or UOA. */
-                       e_server_side_source_set_removable (E_SERVER_SIDE_SOURCE (child_source), TRUE);
-               }
-       }
-}
-
-static void
-google_backend_child_removed (ECollectionBackend *backend,
-                             ESource *child_source)
-{
-       ESource *collection_source;
-       gboolean has_external_auth = FALSE;
-
-       /* Chain up to parent's method. */
-       E_COLLECTION_BACKEND_CLASS (e_google_backend_parent_class)->child_removed (backend, child_source);
-
-       collection_source = e_backend_get_source (E_BACKEND (backend));
-
-       if (e_source_has_extension (child_source, E_SOURCE_EXTENSION_AUTHENTICATION)) {
-               ESourceAuthentication *auth_child_extension;
-
-               auth_child_extension = e_source_get_extension (child_source, 
E_SOURCE_EXTENSION_AUTHENTICATION);
-               has_external_auth = e_source_authentication_get_is_external (auth_child_extension);
-       }
-
-       if (e_source_has_extension (child_source, E_SOURCE_EXTENSION_ADDRESS_BOOK) &&
-           e_source_has_extension (collection_source, E_SOURCE_EXTENSION_COLLECTION) &&
-           !has_external_auth) {
-               ESourceCollection *collection_extension;
-
-               collection_extension = e_source_get_extension (collection_source, 
E_SOURCE_EXTENSION_COLLECTION);
-
-               e_source_collection_set_contacts_enabled (collection_extension, FALSE);
        }
 }
 
@@ -914,10 +799,8 @@ e_google_backend_class_init (EGoogleBackendClass *class)
        collection_backend_class->populate = google_backend_populate;
        collection_backend_class->dup_resource_id = google_backend_dup_resource_id;
        collection_backend_class->child_added = google_backend_child_added;
-       collection_backend_class->child_removed = google_backend_child_removed;
 
        webdav_collection_backend_class = E_WEBDAV_COLLECTION_BACKEND_CLASS (class);
-       webdav_collection_backend_class->get_resource_id = google_backend_get_resource_id;
        webdav_collection_backend_class->is_custom_source = google_backend_is_custom_source;
 }
 
diff --git a/src/services/evolution-source-registry/evolution-source-registry-migrate-tweaks.c 
b/src/services/evolution-source-registry/evolution-source-registry-migrate-tweaks.c
index 82d113d98..6c7b221f5 100644
--- a/src/services/evolution-source-registry/evolution-source-registry-migrate-tweaks.c
+++ b/src/services/evolution-source-registry/evolution-source-registry-migrate-tweaks.c
@@ -208,6 +208,56 @@ evolution_source_registry_migrate_webdav_book_to_carddav (ESourceRegistryServer
        return modified;
 }
 
+
+static gboolean
+evolution_source_registry_migrate_google_book_to_carddav (ESourceRegistryServer *server,
+                                                         GKeyFile *key_file,
+                                                         const gchar *uid)
+{
+       gboolean modified = FALSE;
+
+       g_return_val_if_fail (key_file != NULL, FALSE);
+
+       if (g_key_file_has_group (key_file, E_SOURCE_EXTENSION_ADDRESS_BOOK) &&
+           g_key_file_has_key (key_file, E_SOURCE_EXTENSION_ADDRESS_BOOK, "BackendName", NULL)) {
+               gchar *backend_name;
+
+               backend_name = g_key_file_get_string (key_file, E_SOURCE_EXTENSION_ADDRESS_BOOK, 
"BackendName", NULL);
+               if (g_strcmp0 (backend_name, "google") == 0) {
+                       g_key_file_set_string (key_file, E_SOURCE_EXTENSION_ADDRESS_BOOK, "BackendName", 
"carddav");
+                       modified = TRUE;
+               }
+
+               g_free (backend_name);
+       }
+
+       if (modified && g_key_file_has_group (key_file, E_SOURCE_EXTENSION_AUTHENTICATION)) {
+               gchar *user;
+
+               user = g_key_file_get_string (key_file, E_SOURCE_EXTENSION_AUTHENTICATION, "User", NULL);
+
+               if (user && *user) {
+                       gchar *path;
+
+                       /* Unfortunately no mapping with the default book, thus either drop it or hard code 
the URL */
+                       path = g_strdup_printf ("/carddav/v1/principals/%s/lists/default/", user);
+
+                       g_key_file_set_string (key_file, E_SOURCE_EXTENSION_WEBDAV_BACKEND, "ResourcePath", 
path);
+                       g_key_file_set_string (key_file, E_SOURCE_EXTENSION_AUTHENTICATION, "Host", 
"www.googleapis.com");
+                       g_key_file_set_string (key_file, E_SOURCE_EXTENSION_AUTHENTICATION, "Method", 
"Google");
+                       g_key_file_set_integer (key_file, E_SOURCE_EXTENSION_AUTHENTICATION, "Port", 443);
+                       g_key_file_set_string (key_file, E_SOURCE_EXTENSION_AUTHENTICATION, "User", user);
+                       g_key_file_set_string (key_file, E_SOURCE_EXTENSION_SECURITY, "Method", "tls");
+
+                       g_free (path);
+               }
+
+               g_free (user);
+       }
+
+       return modified;
+}
+
 gboolean
 evolution_source_registry_migrate_tweak_key_file (ESourceRegistryServer *server,
                                                  GKeyFile *key_file,
@@ -218,6 +268,7 @@ evolution_source_registry_migrate_tweak_key_file (ESourceRegistryServer *server,
        modified = evolution_source_registry_migrate_imap_to_imapx (server, key_file, uid);
        modified = evolution_source_registry_migrate_owncloud_to_webdav (server, key_file, uid) || modified;
        modified = evolution_source_registry_migrate_webdav_book_to_carddav (server, key_file, uid) || 
modified;
+       modified = evolution_source_registry_migrate_google_book_to_carddav (server, key_file, uid) || 
modified;
 
        return modified;
 }


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