[evolution-data-server] [IMAPx] Enhance and make work namespace override options



commit 694816e744e1e8d635eb0843364b7ea5550383f1
Author: Milan Crha <mcrha redhat com>
Date:   Tue Dec 2 16:04:41 2014 +0100

    [IMAPx] Enhance and make work namespace override options
    
    The namespace override didn't work at all, thus made it work first,
    then added two new options to ignore other users namespace and
    shared folders namespace. All these options modify server-supplied
    list of namespaces.

 .../imapx/camel-imapx-namespace-response.c         |   51 +++++++
 .../imapx/camel-imapx-namespace-response.h         |    6 +
 camel/providers/imapx/camel-imapx-settings.c       |  138 +++++++++++++++++++-
 camel/providers/imapx/camel-imapx-settings.h       |   10 ++
 camel/providers/imapx/camel-imapx-store.c          |   70 ++++++++++
 5 files changed, 274 insertions(+), 1 deletions(-)
---
diff --git a/camel/providers/imapx/camel-imapx-namespace-response.c 
b/camel/providers/imapx/camel-imapx-namespace-response.c
index 057946d..579ba50 100644
--- a/camel/providers/imapx/camel-imapx-namespace-response.c
+++ b/camel/providers/imapx/camel-imapx-namespace-response.c
@@ -324,6 +324,57 @@ camel_imapx_namespace_response_list (CamelIMAPXNamespaceResponse *response)
 }
 
 /**
+ * camel_imapx_namespace_response_remove:
+ * @response: a #CamelIMAPXNamespaceResponse
+ * @namespace: a #CamelIMAPXNamespace to add
+ *
+ * Adds a @namespace into the list of namespaces. It adds its own
+ * reference on the @namespace.
+ *
+ * Since: 3.14
+ **/
+void
+camel_imapx_namespace_response_add (CamelIMAPXNamespaceResponse *response,
+                                   CamelIMAPXNamespace *namespace)
+{
+       g_return_if_fail (CAMEL_IS_IMAPX_NAMESPACE_RESPONSE (response));
+       g_return_if_fail (CAMEL_IS_IMAPX_NAMESPACE (namespace));
+
+       g_queue_push_tail (&response->priv->namespaces, g_object_ref (namespace));
+}
+
+/**
+ * camel_imapx_namespace_response_remove:
+ * @response: a #CamelIMAPXNamespaceResponse
+ * @namespace: a #CamelIMAPXNamespace to remove
+ *
+ * Removes @namespace from the list of namespaces in the @response.
+ * If no such namespace exists then does nothing.
+ *
+ * Since: 3.14
+ **/
+void
+camel_imapx_namespace_response_remove (CamelIMAPXNamespaceResponse *response,
+                                      CamelIMAPXNamespace *namespace)
+{
+       GList *link;
+
+       g_return_if_fail (CAMEL_IS_IMAPX_NAMESPACE_RESPONSE (response));
+       g_return_if_fail (CAMEL_IS_IMAPX_NAMESPACE (namespace));
+
+       for (link = g_queue_peek_head_link (&response->priv->namespaces);
+            link; link = g_list_next (link)) {
+               CamelIMAPXNamespace *ns = link->data;
+
+               if (camel_imapx_namespace_equal (namespace, ns)) {
+                       g_queue_remove (&response->priv->namespaces, ns);
+                       g_object_unref (ns);
+                       break;
+               }
+       }
+}
+
+/**
  * camel_imapx_namespace_response_lookup:
  * @response: a #CamelIMAPXNamespaceResponse
  * @mailbox_name: a mailbox name
diff --git a/camel/providers/imapx/camel-imapx-namespace-response.h 
b/camel/providers/imapx/camel-imapx-namespace-response.h
index ee68149..0321dd3 100644
--- a/camel/providers/imapx/camel-imapx-namespace-response.h
+++ b/camel/providers/imapx/camel-imapx-namespace-response.h
@@ -75,6 +75,12 @@ CamelIMAPXNamespaceResponse *
                                        (CamelIMAPXListResponse *list_response);
 GList *                camel_imapx_namespace_response_list
                                        (CamelIMAPXNamespaceResponse *response);
+void           camel_imapx_namespace_response_add
+                                       (CamelIMAPXNamespaceResponse *response,
+                                        CamelIMAPXNamespace *namespace);
+void           camel_imapx_namespace_response_remove
+                                       (CamelIMAPXNamespaceResponse *response,
+                                        CamelIMAPXNamespace *namespace);
 CamelIMAPXNamespace *
                camel_imapx_namespace_response_lookup
                                        (CamelIMAPXNamespaceResponse *response,
diff --git a/camel/providers/imapx/camel-imapx-settings.c b/camel/providers/imapx/camel-imapx-settings.c
index 50a430b..a781141 100644
--- a/camel/providers/imapx/camel-imapx-settings.c
+++ b/camel/providers/imapx/camel-imapx-settings.c
@@ -46,6 +46,8 @@ struct _CamelIMAPXSettingsPrivate {
        gboolean use_real_trash_path;
        gboolean use_shell_command;
        gboolean use_subscriptions;
+       gboolean ignore_other_users_namespace;
+       gboolean ignore_shared_folders_namespace;
 
        CamelSortType fetch_order;
 };
@@ -75,7 +77,9 @@ enum {
        PROP_USE_REAL_JUNK_PATH,
        PROP_USE_REAL_TRASH_PATH,
        PROP_USE_SHELL_COMMAND,
-       PROP_USE_SUBSCRIPTIONS
+       PROP_USE_SUBSCRIPTIONS,
+       PROP_IGNORE_OTHER_USERS_NAMESPACE,
+       PROP_IGNORE_SHARED_FOLDERS_NAMESPACE
 };
 
 G_DEFINE_TYPE_WITH_CODE (
@@ -235,6 +239,18 @@ imapx_settings_set_property (GObject *object,
                                CAMEL_IMAPX_SETTINGS (object),
                                g_value_get_boolean (value));
                        return;
+
+               case PROP_IGNORE_OTHER_USERS_NAMESPACE:
+                       camel_imapx_settings_set_ignore_other_users_namespace (
+                               CAMEL_IMAPX_SETTINGS (object),
+                               g_value_get_boolean (value));
+                       return;
+
+               case PROP_IGNORE_SHARED_FOLDERS_NAMESPACE:
+                       camel_imapx_settings_set_ignore_shared_folders_namespace (
+                               CAMEL_IMAPX_SETTINGS (object),
+                               g_value_get_boolean (value));
+                       return;
        }
 
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -414,6 +430,20 @@ imapx_settings_get_property (GObject *object,
                                camel_imapx_settings_get_use_subscriptions (
                                CAMEL_IMAPX_SETTINGS (object)));
                        return;
+
+               case PROP_IGNORE_OTHER_USERS_NAMESPACE:
+                       g_value_set_boolean (
+                               value,
+                               camel_imapx_settings_get_ignore_other_users_namespace (
+                               CAMEL_IMAPX_SETTINGS (object)));
+                       return;
+
+               case PROP_IGNORE_SHARED_FOLDERS_NAMESPACE:
+                       g_value_set_boolean (
+                               value,
+                               camel_imapx_settings_get_ignore_shared_folders_namespace (
+                               CAMEL_IMAPX_SETTINGS (object)));
+                       return;
        }
 
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -712,6 +742,30 @@ camel_imapx_settings_class_init (CamelIMAPXSettingsClass *class)
                        G_PARAM_READWRITE |
                        G_PARAM_CONSTRUCT |
                        G_PARAM_STATIC_STRINGS));
+
+       g_object_class_install_property (
+               object_class,
+               PROP_IGNORE_OTHER_USERS_NAMESPACE,
+               g_param_spec_boolean (
+                       "ignore-other-users-namespace",
+                       "Ignore Other Users Namespace",
+                       "Whether to ignore other users namespace",
+                       FALSE,
+                       G_PARAM_READWRITE |
+                       G_PARAM_CONSTRUCT |
+                       G_PARAM_STATIC_STRINGS));
+
+       g_object_class_install_property (
+               object_class,
+               PROP_IGNORE_SHARED_FOLDERS_NAMESPACE,
+               g_param_spec_boolean (
+                       "ignore-shared-folders-namespace",
+                       "Ignore Shared Folders Namespace",
+                       "Whether to ignore shared folders namespace",
+                       FALSE,
+                       G_PARAM_READWRITE |
+                       G_PARAM_CONSTRUCT |
+                       G_PARAM_STATIC_STRINGS));
 }
 
 static void
@@ -1502,6 +1556,88 @@ camel_imapx_settings_set_use_namespace (CamelIMAPXSettings *settings,
 }
 
 /**
+ * camel_imapx_settings_get_ignore_other_users_namespace:
+ * @settings: a #CamelIMAPXSettings
+ *
+ * Returns whether to ignore namespace for other users.
+ *
+ * Returns: whether to ignore namespace for other users
+ *
+ * Since: 3.14
+ **/
+gboolean
+camel_imapx_settings_get_ignore_other_users_namespace (CamelIMAPXSettings *settings)
+{
+       g_return_val_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings), FALSE);
+
+       return settings->priv->ignore_other_users_namespace;
+}
+
+/**
+ * camel_imapx_settings_set_ignore_other_users_namespace:
+ * @settings: a #CamelIMAPXSettings
+ * @ignore: whether to ignore the namespace
+ *
+ * Sets whether to ignore other users namespace.
+ *
+ * Since: 3.14
+ **/
+void
+camel_imapx_settings_set_ignore_other_users_namespace (CamelIMAPXSettings *settings,
+                                                      gboolean ignore)
+{
+       g_return_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings));
+
+       if (settings->priv->ignore_other_users_namespace == ignore)
+               return;
+
+       settings->priv->ignore_other_users_namespace = ignore;
+
+       g_object_notify (G_OBJECT (settings), "ignore-other-users-namespace");
+}
+
+/**
+ * camel_imapx_settings_get_ignore_shared_folders_namespace:
+ * @settings: a #CamelIMAPXSettings
+ *
+ * Returns whether to ignore namespace for shared folders.
+ *
+ * Returns: whether to ignore namespace for shared folders
+ *
+ * Since: 3.14
+ **/
+gboolean
+camel_imapx_settings_get_ignore_shared_folders_namespace (CamelIMAPXSettings *settings)
+{
+       g_return_val_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings), FALSE);
+
+       return settings->priv->ignore_shared_folders_namespace;
+}
+
+/**
+ * camel_imapx_settings_set_ignore_shared_folders_namespace:
+ * @settings: a #CamelIMAPXSettings
+ * @ignore: whether to ignore the namespace
+ *
+ * Sets whether to ignore shared folders namespace.
+ *
+ * Since: 3.14
+ **/
+void
+camel_imapx_settings_set_ignore_shared_folders_namespace (CamelIMAPXSettings *settings,
+                                                         gboolean ignore)
+{
+       g_return_if_fail (CAMEL_IS_IMAPX_SETTINGS (settings));
+
+       if (settings->priv->ignore_shared_folders_namespace == ignore)
+               return;
+
+       settings->priv->ignore_shared_folders_namespace = ignore;
+
+       g_object_notify (G_OBJECT (settings), "ignore-shared-folders-namespace");
+}
+
+/**
  * camel_imapx_settings_get_use_qresync:
  * @settings: a #CamelIMAPXSettings
  *
diff --git a/camel/providers/imapx/camel-imapx-settings.h b/camel/providers/imapx/camel-imapx-settings.h
index 526c67b..c2626c9 100644
--- a/camel/providers/imapx/camel-imapx-settings.h
+++ b/camel/providers/imapx/camel-imapx-settings.h
@@ -133,6 +133,16 @@ gboolean   camel_imapx_settings_get_use_namespace
 void           camel_imapx_settings_set_use_namespace
                                                (CamelIMAPXSettings *settings,
                                                 gboolean use_namespace);
+gboolean       camel_imapx_settings_get_ignore_other_users_namespace
+                                               (CamelIMAPXSettings *settings);
+void           camel_imapx_settings_set_ignore_other_users_namespace
+                                               (CamelIMAPXSettings *settings,
+                                                gboolean ignore);
+gboolean       camel_imapx_settings_get_ignore_shared_folders_namespace
+                                               (CamelIMAPXSettings *settings);
+void           camel_imapx_settings_set_ignore_shared_folders_namespace
+                                               (CamelIMAPXSettings *settings,
+                                                gboolean ignore);
 gboolean       camel_imapx_settings_get_use_qresync
                                                (CamelIMAPXSettings *settings);
 void           camel_imapx_settings_set_use_qresync
diff --git a/camel/providers/imapx/camel-imapx-store.c b/camel/providers/imapx/camel-imapx-store.c
index d400b93..86ee2d4 100644
--- a/camel/providers/imapx/camel-imapx-store.c
+++ b/camel/providers/imapx/camel-imapx-store.c
@@ -2882,6 +2882,9 @@ void
 camel_imapx_store_set_namespaces (CamelIMAPXStore *imapx_store,
                                  CamelIMAPXNamespaceResponse *namespaces)
 {
+       CamelIMAPXSettings *imapx_settings;
+       gboolean ignore_other_users_namespace, ignore_shared_folders_namespace;
+
        g_return_if_fail (CAMEL_IS_IMAPX_STORE (imapx_store));
        if (namespaces)
                g_return_if_fail (CAMEL_IS_IMAPX_NAMESPACE_RESPONSE (namespaces));
@@ -2889,12 +2892,79 @@ camel_imapx_store_set_namespaces (CamelIMAPXStore *imapx_store,
        if (namespaces)
                g_object_ref (namespaces);
 
+       imapx_settings = CAMEL_IMAPX_SETTINGS (camel_service_ref_settings (CAMEL_SERVICE (imapx_store)));
+
        g_mutex_lock (&imapx_store->priv->namespaces_lock);
 
        g_clear_object (&imapx_store->priv->namespaces);
        imapx_store->priv->namespaces = namespaces;
 
+       if (camel_imapx_settings_get_use_namespace (imapx_settings)) {
+               gchar *use_namespace = camel_imapx_settings_dup_namespace (imapx_settings);
+
+               if (use_namespace && *use_namespace) {
+                       /* Overwrite personal namespaces to the given */
+                       GList *nslist, *link;
+                       gchar folder_sep = 0;
+                       CamelIMAPXNamespace *override_ns = NULL;
+
+                       nslist = camel_imapx_namespace_response_list (namespaces);
+                       for (link = nslist; link; link = g_list_next (link)) {
+                               CamelIMAPXNamespace *ns = link->data;
+
+                               if (!folder_sep)
+                                       folder_sep = camel_imapx_namespace_get_separator (ns);
+
+                               if (camel_imapx_namespace_get_category (ns) == 
CAMEL_IMAPX_NAMESPACE_PERSONAL) {
+                                       if (!override_ns) {
+                                               override_ns = camel_imapx_namespace_new (
+                                                       CAMEL_IMAPX_NAMESPACE_PERSONAL,
+                                                       use_namespace,
+                                                       camel_imapx_namespace_get_separator (ns));
+                                       }
+
+                                       camel_imapx_namespace_response_remove (namespaces, ns);
+                               }
+                       }
+
+                       if (!override_ns) {
+                               override_ns = camel_imapx_namespace_new (
+                                       CAMEL_IMAPX_NAMESPACE_PERSONAL,
+                                       use_namespace,
+                                       folder_sep);
+                       }
+
+                       camel_imapx_namespace_response_add (namespaces, override_ns);
+
+                       g_list_free_full (nslist, g_object_unref);
+                       g_clear_object (&override_ns);
+               }
+
+               g_free (use_namespace);
+       }
+
+       ignore_other_users_namespace = camel_imapx_settings_get_ignore_other_users_namespace (imapx_settings);
+       ignore_shared_folders_namespace = camel_imapx_settings_get_ignore_shared_folders_namespace 
(imapx_settings);
+
+       if (ignore_other_users_namespace || ignore_shared_folders_namespace) {
+               GList *nslist, *link;
+
+               nslist = camel_imapx_namespace_response_list (namespaces);
+               for (link = nslist; link; link = g_list_next (link)) {
+                       CamelIMAPXNamespace *ns = link->data;
+
+                       if ((ignore_other_users_namespace && camel_imapx_namespace_get_category (ns) == 
CAMEL_IMAPX_NAMESPACE_OTHER_USERS) ||
+                           (ignore_shared_folders_namespace && camel_imapx_namespace_get_category (ns) == 
CAMEL_IMAPX_NAMESPACE_SHARED)) {
+                               camel_imapx_namespace_response_remove (namespaces, ns);
+                       }
+               }
+
+               g_list_free_full (nslist, g_object_unref);
+       }
+
        g_mutex_unlock (&imapx_store->priv->namespaces_lock);
+
+       g_clear_object (&imapx_settings);
 }
 
 static void


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