[evolution-data-server/gnome-3-36] I#240 - IMAPx: Disable move to real junk/trash in server-side virtual folders



commit 0d718177ef1c9a49bd612f7d716ae5ef56ef6729
Author: Milan Crha <mcrha redhat com>
Date:   Thu Aug 6 09:22:55 2020 +0200

    I#240 - IMAPx: Disable move to real junk/trash in server-side virtual folders
    
    Closes https://gitlab.gnome.org/GNOME/evolution-data-server/-/issues/240

 .../providers/imapx/camel-imapx-conn-manager.c     | 16 ++++++++++++---
 src/camel/providers/imapx/camel-imapx-folder.c     | 24 ++++++++++++++++++++++
 src/camel/providers/imapx/camel-imapx-folder.h     |  4 ++++
 3 files changed, 41 insertions(+), 3 deletions(-)
---
diff --git a/src/camel/providers/imapx/camel-imapx-conn-manager.c 
b/src/camel/providers/imapx/camel-imapx-conn-manager.c
index 74b025fb3..2bee99d6e 100644
--- a/src/camel/providers/imapx/camel-imapx-conn-manager.c
+++ b/src/camel/providers/imapx/camel-imapx-conn-manager.c
@@ -1882,7 +1882,7 @@ camel_imapx_conn_manager_sync_changes_sync (CamelIMAPXConnManager *conn_man,
        CamelIMAPXJob *job;
        CamelFolder *folder = NULL;
        gboolean need_to_expunge = FALSE, expunge = FALSE;
-       gboolean success;
+       gboolean success, is_virtual_mailbox;
 
        g_return_val_if_fail (CAMEL_IS_IMAPX_CONN_MANAGER (conn_man), FALSE);
 
@@ -1905,14 +1905,24 @@ camel_imapx_conn_manager_sync_changes_sync (CamelIMAPXConnManager *conn_man,
                        success = FALSE;
        }
 
-       if (success) {
+       is_virtual_mailbox = camel_imapx_mailbox_has_attribute (mailbox, CAMEL_IMAPX_LIST_ATTR_ALL) ||
+                            camel_imapx_mailbox_has_attribute (mailbox, CAMEL_IMAPX_LIST_ATTR_FLAGGED);
+
+       if (success && is_virtual_mailbox) {
+               CamelIMAPXFolder *imapx_folder = CAMEL_IMAPX_FOLDER (folder);
+
+               camel_imapx_folder_clear_move_to_real_trash_uids (imapx_folder);
+               camel_imapx_folder_clear_move_to_real_junk_uids (imapx_folder);
+       }
+
+       if (success && !is_virtual_mailbox) {
                success = imapx_conn_manager_move_to_real_junk_sync (
                        conn_man, folder, cancellable,
                        &need_to_expunge, error);
                expunge |= need_to_expunge;
        }
 
-       if (success) {
+       if (success && !is_virtual_mailbox) {
                success = imapx_conn_manager_move_to_real_trash_sync (
                        conn_man, folder, cancellable,
                        &need_to_expunge, error);
diff --git a/src/camel/providers/imapx/camel-imapx-folder.c b/src/camel/providers/imapx/camel-imapx-folder.c
index 1ef5750fc..926f15904 100644
--- a/src/camel/providers/imapx/camel-imapx-folder.c
+++ b/src/camel/providers/imapx/camel-imapx-folder.c
@@ -1617,6 +1617,30 @@ camel_imapx_folder_add_move_to_inbox (CamelIMAPXFolder *folder,
        g_mutex_unlock (&folder->priv->move_to_hash_table_lock);
 }
 
+void
+camel_imapx_folder_clear_move_to_real_trash_uids (CamelIMAPXFolder *folder)
+{
+       g_return_if_fail (CAMEL_IS_IMAPX_FOLDER (folder));
+
+       g_mutex_lock (&folder->priv->move_to_hash_table_lock);
+
+       g_hash_table_remove_all (folder->priv->move_to_real_trash_uids);
+
+       g_mutex_unlock (&folder->priv->move_to_hash_table_lock);
+}
+
+void
+camel_imapx_folder_clear_move_to_real_junk_uids (CamelIMAPXFolder *folder)
+{
+       g_return_if_fail (CAMEL_IS_IMAPX_FOLDER (folder));
+
+       g_mutex_lock (&folder->priv->move_to_hash_table_lock);
+
+       g_hash_table_remove_all (folder->priv->move_to_real_junk_uids);
+
+       g_mutex_unlock (&folder->priv->move_to_hash_table_lock);
+}
+
 /**
  * camel_imapx_folder_invalidate_local_cache:
  * @folder: a #CamelIMAPXFolder
diff --git a/src/camel/providers/imapx/camel-imapx-folder.h b/src/camel/providers/imapx/camel-imapx-folder.h
index 9a9431569..1d42f7f7a 100644
--- a/src/camel/providers/imapx/camel-imapx-folder.h
+++ b/src/camel/providers/imapx/camel-imapx-folder.h
@@ -111,6 +111,10 @@ void               camel_imapx_folder_claim_move_to_real_trash_uids
 void           camel_imapx_folder_claim_move_to_inbox_uids
                                                (CamelIMAPXFolder *folder,
                                                 GPtrArray *out_uids_to_copy);
+void           camel_imapx_folder_clear_move_to_real_trash_uids
+                                               (CamelIMAPXFolder *folder);
+void           camel_imapx_folder_clear_move_to_real_junk_uids
+                                               (CamelIMAPXFolder *folder);
 void           camel_imapx_folder_update_cache_expire
                                                (CamelFolder *folder,
                                                 time_t expire_when);


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