[evolution-data-server] [IMAPx] Message moved to real Trash/Junk multiple times



commit 8ba72793929dc5e20d9a7b20aca75fceff4e4a58
Author: Milan Crha <mcrha redhat com>
Date:   Wed May 27 09:53:07 2015 +0200

    [IMAPx] Message moved to real Trash/Junk multiple times
    
    When a real Trash/Junk is set for the account, then the deleted/junk
    messages are moved to the respective folder according to the internal
    folder's hash table of the message UIDs to be moved. The hash table is
    populated on various places, but emptied only on one. There happened
    that the move to the Trash/Junk folder emptied the hash table, but
    then the moved UID was re-added back during the move operation, thus
    the next folder visit and the change save there was re-tried to move
    already moved, thus nonexistent, message into the real Trash/Junk
    folder, which could fail with error.
    
    This change makes sure that the hash tables of UIDs to be moved to
    the Trash/Junk folders contain only existing UIDs.

 camel/providers/imapx/camel-imapx-folder.c |   42 +++++++++++++++++++++++++--
 1 files changed, 38 insertions(+), 4 deletions(-)
---
diff --git a/camel/providers/imapx/camel-imapx-folder.c b/camel/providers/imapx/camel-imapx-folder.c
index 7644dea..a6a52f0 100644
--- a/camel/providers/imapx/camel-imapx-folder.c
+++ b/camel/providers/imapx/camel-imapx-folder.c
@@ -1331,6 +1331,37 @@ exit:
 }
 
 static void
+imapx_folder_changed (CamelFolder *folder,
+                     CamelFolderChangeInfo *info)
+{
+       g_return_if_fail (CAMEL_IS_IMAPX_FOLDER (folder));
+
+       if (info && info->uid_removed && info->uid_removed->len) {
+               CamelIMAPXFolder *imapx_folder;
+               guint ii;
+
+               imapx_folder = CAMEL_IMAPX_FOLDER (folder);
+
+               g_mutex_lock (&imapx_folder->priv->move_to_hash_table_lock);
+
+               for (ii = 0; ii < info->uid_removed->len; ii++) {
+                       const gchar *message_uid = info->uid_removed->pdata[ii];
+
+                       if (!message_uid)
+                               continue;
+
+                       g_hash_table_remove (imapx_folder->priv->move_to_real_trash_uids, message_uid);
+                       g_hash_table_remove (imapx_folder->priv->move_to_real_junk_uids, message_uid);
+               }
+
+               g_mutex_unlock (&imapx_folder->priv->move_to_hash_table_lock);
+       }
+
+       /* Chain up to parent's method. */
+       CAMEL_FOLDER_CLASS (camel_imapx_folder_parent_class)->changed (folder, info);
+}
+
+static void
 imapx_rename (CamelFolder *folder,
               const gchar *new_name)
 {
@@ -1385,6 +1416,7 @@ camel_imapx_folder_class_init (CamelIMAPXFolderClass *class)
        folder_class->synchronize_sync = imapx_synchronize_sync;
        folder_class->synchronize_message_sync = imapx_synchronize_message_sync;
        folder_class->transfer_messages_to_sync = imapx_transfer_messages_to_sync;
+       folder_class->changed = imapx_folder_changed;
 
        g_object_class_install_property (
                object_class,
@@ -1428,14 +1460,14 @@ camel_imapx_folder_init (CamelIMAPXFolder *imapx_folder)
        GHashTable *move_to_real_trash_uids;
 
        move_to_real_junk_uids = g_hash_table_new_full (
-               (GHashFunc) g_direct_hash,
-               (GEqualFunc) g_direct_equal,
+               (GHashFunc) g_str_hash,
+               (GEqualFunc) g_str_equal,
                (GDestroyNotify) camel_pstring_free,
                (GDestroyNotify) NULL);
 
        move_to_real_trash_uids = g_hash_table_new_full (
-               (GHashFunc) g_direct_hash,
-               (GEqualFunc) g_direct_equal,
+               (GHashFunc) g_str_hash,
+               (GEqualFunc) g_str_equal,
                (GDestroyNotify) camel_pstring_free,
                (GDestroyNotify) NULL);
 
@@ -1810,6 +1842,7 @@ camel_imapx_folder_add_move_to_real_junk (CamelIMAPXFolder *folder,
 {
        g_return_if_fail (CAMEL_IS_IMAPX_FOLDER (folder));
        g_return_if_fail (message_uid != NULL);
+       g_return_if_fail (camel_folder_summary_check_uid (CAMEL_FOLDER (folder)->summary, message_uid));
 
        g_mutex_lock (&folder->priv->move_to_hash_table_lock);
 
@@ -1840,6 +1873,7 @@ camel_imapx_folder_add_move_to_real_trash (CamelIMAPXFolder *folder,
 {
        g_return_if_fail (CAMEL_IS_IMAPX_FOLDER (folder));
        g_return_if_fail (message_uid != NULL);
+       g_return_if_fail (camel_folder_summary_check_uid (CAMEL_FOLDER (folder)->summary, message_uid));
 
        g_mutex_lock (&folder->priv->move_to_hash_table_lock);
 


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