[evolution-data-server] I#369 - IMAPx: Add an option to send client 'ID' during login phase



commit a2e7045a155fa11655c8232fcdeac02bc8c1bc5a
Author: z-z-zoey <highwayPegg 163 com>
Date:   Mon Jan 10 15:17:54 2022 +0100

    I#369 - IMAPx: Add an option to send client 'ID' during login phase
    
    Closes https://gitlab.gnome.org/GNOME/evolution-data-server/-/issues/369

 src/camel/providers/imapx/camel-imapx-job.c      |  2 +
 src/camel/providers/imapx/camel-imapx-job.h      |  1 +
 src/camel/providers/imapx/camel-imapx-provider.c |  2 +
 src/camel/providers/imapx/camel-imapx-server.c   | 11 ++++
 src/camel/providers/imapx/camel-imapx-settings.c | 71 +++++++++++++++++++++++-
 src/camel/providers/imapx/camel-imapx-settings.h |  5 ++
 6 files changed, 91 insertions(+), 1 deletion(-)
---
diff --git a/src/camel/providers/imapx/camel-imapx-job.c b/src/camel/providers/imapx/camel-imapx-job.c
index 99bb616b4..22e0fb623 100644
--- a/src/camel/providers/imapx/camel-imapx-job.c
+++ b/src/camel/providers/imapx/camel-imapx-job.c
@@ -40,6 +40,8 @@ camel_imapx_job_get_kind_name (guint32 job_kind)
                return "AUTHENTICATE";
        case CAMEL_IMAPX_JOB_LOGIN:
                return "LOGIN";
+       case CAMEL_IMAPX_JOB_ID:
+               return "ID";
        case CAMEL_IMAPX_JOB_NAMESPACE:
                return "NAMESPACE";
        case CAMEL_IMAPX_JOB_SELECT:
diff --git a/src/camel/providers/imapx/camel-imapx-job.h b/src/camel/providers/imapx/camel-imapx-job.h
index b27de5f83..e0f811816 100644
--- a/src/camel/providers/imapx/camel-imapx-job.h
+++ b/src/camel/providers/imapx/camel-imapx-job.h
@@ -32,6 +32,7 @@ typedef enum {
        CAMEL_IMAPX_JOB_STARTTLS,
        CAMEL_IMAPX_JOB_AUTHENTICATE,
        CAMEL_IMAPX_JOB_LOGIN,
+       CAMEL_IMAPX_JOB_ID,
        CAMEL_IMAPX_JOB_NAMESPACE,
        CAMEL_IMAPX_JOB_SELECT,
        CAMEL_IMAPX_JOB_STATUS,
diff --git a/src/camel/providers/imapx/camel-imapx-provider.c 
b/src/camel/providers/imapx/camel-imapx-provider.c
index fab7cbcc9..2988784a5 100644
--- a/src/camel/providers/imapx/camel-imapx-provider.c
+++ b/src/camel/providers/imapx/camel-imapx-provider.c
@@ -49,6 +49,8 @@ CamelProviderConfEntry imapx_conf_entries[] = {
          N_("Numbe_r of concurrent connections to use"), "y:1:3:7" },
        { CAMEL_PROVIDER_CONF_CHECKBOX, "full-update-on-metered-network", NULL,
          N_("Enable full folder update on _metered network"), "1" },
+       { CAMEL_PROVIDER_CONF_CHECKBOX, "send-client-id", NULL,
+         N_("Send client I_D to the server"), "0" },
        { CAMEL_PROVIDER_CONF_SECTION_END },
        { CAMEL_PROVIDER_CONF_SECTION_START, "folders", NULL,
          N_("Folders") },
diff --git a/src/camel/providers/imapx/camel-imapx-server.c b/src/camel/providers/imapx/camel-imapx-server.c
index 6fedcfa0a..2d0193657 100644
--- a/src/camel/providers/imapx/camel-imapx-server.c
+++ b/src/camel/providers/imapx/camel-imapx-server.c
@@ -3203,6 +3203,7 @@ camel_imapx_server_authenticate_sync (CamelIMAPXServer *is,
        gchar *host;
        gchar *user;
        gboolean can_retry_login = FALSE;
+       gboolean send_client_id;
        gboolean success;
 
        g_return_val_if_fail (
@@ -3218,6 +3219,8 @@ camel_imapx_server_authenticate_sync (CamelIMAPXServer *is,
        host = camel_network_settings_dup_host (network_settings);
        user = camel_network_settings_dup_user (network_settings);
 
+       send_client_id = camel_imapx_settings_get_send_client_id (CAMEL_IMAPX_SETTINGS (settings));
+
        g_object_unref (settings);
 
        if (mechanism != NULL) {
@@ -3370,6 +3373,14 @@ camel_imapx_server_authenticate_sync (CamelIMAPXServer *is,
                }
 
                g_mutex_unlock (&is->priv->stream_lock);
+
+               if (send_client_id) {
+                       camel_imapx_command_unref (ic);
+
+                       ic = camel_imapx_command_new (is, CAMEL_IMAPX_JOB_ID, "ID (\"name\" \"" PACKAGE "\" 
\"version\" \"" VERSION "\")");
+                       if (!camel_imapx_server_process_command_sync (is, ic, _("Failed to issue ID"), 
cancellable, error))
+                               result = CAMEL_AUTHENTICATION_ERROR;
+               }
        }
 
        camel_imapx_command_unref (ic);
diff --git a/src/camel/providers/imapx/camel-imapx-settings.c 
b/src/camel/providers/imapx/camel-imapx-settings.c
index a09ea28c6..632e351c0 100644
--- a/src/camel/providers/imapx/camel-imapx-settings.c
+++ b/src/camel/providers/imapx/camel-imapx-settings.c
@@ -47,6 +47,7 @@ struct _CamelIMAPXSettingsPrivate {
        gboolean ignore_other_users_namespace;
        gboolean ignore_shared_folders_namespace;
        gboolean full_update_on_metered_network;
+       gboolean send_client_id;
 
        CamelSortType fetch_order;
 };
@@ -79,7 +80,8 @@ enum {
        PROP_USE_SUBSCRIPTIONS,
        PROP_IGNORE_OTHER_USERS_NAMESPACE,
        PROP_IGNORE_SHARED_FOLDERS_NAMESPACE,
-       PROP_FULL_UPDATE_ON_METERED_NETWORK
+       PROP_FULL_UPDATE_ON_METERED_NETWORK,
+       PROP_SEND_CLIENT_ID
 };
 
 G_DEFINE_TYPE_WITH_CODE (
@@ -258,6 +260,12 @@ imapx_settings_set_property (GObject *object,
                                CAMEL_IMAPX_SETTINGS (object),
                                g_value_get_boolean (value));
                        return;
+
+               case PROP_SEND_CLIENT_ID:
+                       camel_imapx_settings_set_send_client_id (
+                               CAMEL_IMAPX_SETTINGS (object),
+                               g_value_get_boolean (value));
+                       return;
        }
 
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -458,6 +466,13 @@ imapx_settings_get_property (GObject *object,
                                camel_imapx_settings_get_full_update_on_metered_network (
                                CAMEL_IMAPX_SETTINGS (object)));
                        return;
+
+               case PROP_SEND_CLIENT_ID:
+                       g_value_set_boolean (
+                               value,
+                               camel_imapx_settings_get_send_client_id (
+                               CAMEL_IMAPX_SETTINGS (object)));
+                       return;
        }
 
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -810,6 +825,19 @@ camel_imapx_settings_class_init (CamelIMAPXSettingsClass *class)
                        G_PARAM_CONSTRUCT |
                        G_PARAM_EXPLICIT_NOTIFY |
                        G_PARAM_STATIC_STRINGS));
+
+       g_object_class_install_property (
+               object_class,
+               PROP_SEND_CLIENT_ID,
+               g_param_spec_boolean (
+                       "send-client-id",
+                       "Send Client ID",
+                       "Whether to send client ID to the server",
+                       FALSE,
+                       G_PARAM_READWRITE |
+                       G_PARAM_CONSTRUCT |
+                       G_PARAM_EXPLICIT_NOTIFY |
+                       G_PARAM_STATIC_STRINGS));
 }
 
 static void
@@ -1953,3 +1981,44 @@ camel_imapx_settings_set_full_update_on_metered_network (CamelIMAPXSettings *set
 
        g_object_notify (G_OBJECT (settings), "full-update-on-metered-network");
 }
+
+/**
+ * camel_imapx_settings_get_send_client_id:
+ * @settings: a #CamelIMAPXSettings
+ *
+ * Returns whether to send client ID to the server, using the 'ID' extension (RFC 2971).
+ *
+ * Returns: whether to send client ID to the server
+ *
+ * Since: 3.44
+ **/
+gboolean
+camel_imapx_settings_get_send_client_id (CamelIMAPXSettings *settings)
+{
+       g_return_val_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings), FALSE);
+
+       return settings->priv->send_client_id;
+}
+
+/**
+ * camel_imapx_settings_set_send_client_id:
+ * @settings: a #CamelIMAPXSettings
+ * @send_client_id: whether to send client ID to the server
+ *
+ * Sets whether to send client ID to the server, using the 'ID' extension (RFC 2971).
+ *
+ * Since: 3.44
+ **/
+void
+camel_imapx_settings_set_send_client_id (CamelIMAPXSettings *settings,
+                                        gboolean send_client_id)
+{
+       g_return_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings));
+
+       if ((settings->priv->send_client_id ? 1 : 0) == (send_client_id ? 1 : 0))
+               return;
+
+       settings->priv->send_client_id = send_client_id;
+
+       g_object_notify (G_OBJECT (settings), "send-client-id");
+}
diff --git a/src/camel/providers/imapx/camel-imapx-settings.h 
b/src/camel/providers/imapx/camel-imapx-settings.h
index 3e32c617e..1f1232388 100644
--- a/src/camel/providers/imapx/camel-imapx-settings.h
+++ b/src/camel/providers/imapx/camel-imapx-settings.h
@@ -176,6 +176,11 @@ gboolean   camel_imapx_settings_get_full_update_on_metered_network
 void           camel_imapx_settings_set_full_update_on_metered_network
                                                (CamelIMAPXSettings *settings,
                                                 gboolean full_update_on_metered_network);
+gboolean       camel_imapx_settings_get_send_client_id
+                                               (CamelIMAPXSettings *settings);
+void           camel_imapx_settings_set_send_client_id
+                                               (CamelIMAPXSettings *settings,
+                                                gboolean send_client_id);
 
 G_END_DECLS
 


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