[evolution-data-server] Bug #274316 - [IMAP] Follow-up flag lost on message move/copy



commit 469359ec4f2233eb2206db19a12bb7ed4409d44b
Author: Milan Crha <mcrha redhat com>
Date:   Wed Feb 19 12:57:49 2014 +0100

    Bug #274316 - [IMAP] Follow-up flag lost on message move/copy
    
    This applies to any only-locally-stored flags (user tags) on a message.

 camel/providers/imapx/camel-imapx-server.c |  105 ++++++++++++++++++++++------
 camel/providers/imapx/camel-imapx-utils.c  |    9 ++-
 camel/providers/imapx/camel-imapx-utils.h  |    2 +
 3 files changed, 93 insertions(+), 23 deletions(-)
---
diff --git a/camel/providers/imapx/camel-imapx-server.c b/camel/providers/imapx/camel-imapx-server.c
index b5d04fa..8a867ec 100644
--- a/camel/providers/imapx/camel-imapx-server.c
+++ b/camel/providers/imapx/camel-imapx-server.c
@@ -2459,7 +2459,7 @@ imapx_untagged_fetch (CamelIMAPXServer *is,
                                        data = camel_imapx_job_get_data (job);
                                        g_return_val_if_fail (data != NULL, FALSE);
 
-                                       imapx_set_message_info_flags_for_new_message (mi, server_flags, 
server_user_flags, folder);
+                                       imapx_set_message_info_flags_for_new_message (mi, server_flags, 
server_user_flags, FALSE, NULL, folder);
                                        camel_folder_summary_add (folder->summary, mi);
                                        camel_folder_change_info_add_uid (data->changes, mi->uid);
 
@@ -5130,6 +5130,69 @@ imapx_command_copy_messages_step_done (CamelIMAPXServer *is,
                goto exit;
        }
 
+       if (ic->status && ic->status->u.copyuid.uids && ic->status->u.copyuid.copied_uids &&
+           ic->status->u.copyuid.uids->len == ic->status->u.copyuid.copied_uids->len) {
+               CamelFolder *destination;
+
+               destination = imapx_server_ref_folder (is, data->destination);
+               if (destination) {
+                       CamelMessageInfo *source_info, *destination_info;
+                       CamelFolderChangeInfo *changes;
+                       gint ii;
+
+                       changes = camel_folder_change_info_new ();
+
+                       for (ii = 0; ii < ic->status->u.copyuid.uids->len; ii++) {
+                               gchar *uid;
+                               gboolean is_new = FALSE;
+
+                               uid = g_strdup_printf ("%d", g_array_index (ic->status->u.copyuid.uids, 
guint32, ii));
+                               source_info = camel_folder_summary_get (folder->summary, uid);
+                               g_free (uid);
+
+                               if (!source_info)
+                                       continue;
+
+                               uid = g_strdup_printf ("%d", g_array_index 
(ic->status->u.copyuid.copied_uids, guint32, ii));
+                               destination_info = camel_folder_summary_get (folder->summary, uid);
+
+                               if (!destination_info) {
+                                       is_new = TRUE;
+                                       destination_info = camel_message_info_clone (source_info);
+                                       destination_info->summary = destination->summary;
+                                       camel_pstring_free (destination_info->uid);
+                                       destination_info->uid = camel_pstring_strdup (uid);
+                               }
+
+                               g_free (uid);
+
+                               imapx_set_message_info_flags_for_new_message (
+                                       destination_info,
+                                       ((CamelMessageInfoBase *) source_info)->flags,
+                                       ((CamelMessageInfoBase *) source_info)->user_flags,
+                                       TRUE,
+                                       ((CamelMessageInfoBase *) source_info)->user_tags,
+                                       destination);
+                               if (is_new)
+                                       camel_folder_summary_add (destination->summary, destination_info);
+                               camel_folder_change_info_add_uid (changes, destination_info->uid);
+
+                               camel_message_info_unref (source_info);
+                               if (!is_new)
+                                       camel_message_info_unref (destination_info);
+                       }
+
+                       if (camel_folder_change_info_changed (changes)) {
+                               camel_folder_summary_touch (destination->summary);
+                               camel_folder_summary_save_to_db (destination->summary, NULL);
+                               camel_folder_changed (destination, changes);
+                       }
+
+                       camel_folder_change_info_free (changes);
+                       g_object_unref (destination);
+               }
+       }
+
        if (data->delete_originals) {
                gint j;
 
@@ -5300,11 +5363,12 @@ imapx_command_append_message_done (CamelIMAPXServer *is,
                                g_warning ("%s: Failed to rename '%s' to '%s': %s", G_STRFUNC, data->path, 
cur, g_strerror (errno));
                        }
 
-                       /* should we update the message count ? */
                        imapx_set_message_info_flags_for_new_message (
                                mi,
                                ((CamelMessageInfoBase *) data->info)->flags,
                                ((CamelMessageInfoBase *) data->info)->user_flags,
+                               TRUE,
+                               ((CamelMessageInfoBase *) data->info)->user_tags,
                                folder);
                        camel_folder_summary_add (folder->summary, mi);
                        changes = camel_folder_change_info_new ();
@@ -8466,31 +8530,28 @@ camel_imapx_server_append_message (CamelIMAPXServer *is,
        info->uid = camel_pstring_strdup (uid);
        if (mi != NULL) {
                CamelMessageInfoBase *base_info = (CamelMessageInfoBase *) info;
+               const CamelFlag *flag;
+               const CamelTag *tag;
 
                base_info->flags = camel_message_info_flags (mi);
                base_info->size = camel_message_info_size (mi);
 
-               if ((is->priv->permanentflags & CAMEL_MESSAGE_USER) != 0) {
-                       const CamelFlag *flag;
-                       const CamelTag *tag;
-
-                       flag = camel_message_info_user_flags (mi);
-                       while (flag != NULL) {
-                               if (*flag->name != '\0')
-                                       camel_flag_set (
-                                               &base_info->user_flags,
-                                               flag->name, TRUE);
-                               flag = flag->next;
-                       }
+               flag = camel_message_info_user_flags (mi);
+               while (flag != NULL) {
+                       if (*flag->name != '\0')
+                               camel_flag_set (
+                                       &base_info->user_flags,
+                                       flag->name, TRUE);
+                       flag = flag->next;
+               }
 
-                       tag = camel_message_info_user_tags (mi);
-                       while (tag != NULL) {
-                               if (*tag->name != '\0')
-                                       camel_tag_set (
-                                               &base_info->user_tags,
-                                               tag->name, tag->value);
-                               tag = tag->next;
-                       }
+               tag = camel_message_info_user_tags (mi);
+               while (tag != NULL) {
+                       if (*tag->name != '\0')
+                               camel_tag_set (
+                                       &base_info->user_tags,
+                                       tag->name, tag->value);
+                       tag = tag->next;
                }
 
                if (date_time <= 0)
diff --git a/camel/providers/imapx/camel-imapx-utils.c b/camel/providers/imapx/camel-imapx-utils.c
index 83a98c3..1807c34 100644
--- a/camel/providers/imapx/camel-imapx-utils.c
+++ b/camel/providers/imapx/camel-imapx-utils.c
@@ -328,6 +328,8 @@ void
 imapx_set_message_info_flags_for_new_message (CamelMessageInfo *info,
                                               guint32 server_flags,
                                               CamelFlag *server_user_flags,
+                                             gboolean force_user_flags,
+                                             CamelTag *user_tags,
                                               CamelFolder *folder)
 {
        CamelMessageInfoBase *binfo = (CamelMessageInfoBase *) info;
@@ -338,9 +340,14 @@ imapx_set_message_info_flags_for_new_message (CamelMessageInfo *info,
 
        xinfo->server_flags = server_flags;
 
-       if (folder->permanent_flags & CAMEL_MESSAGE_USER)
+       if (force_user_flags || (folder->permanent_flags & CAMEL_MESSAGE_USER) != 0)
                imapx_update_user_flags (info, server_user_flags);
 
+       while (user_tags) {
+               camel_message_info_set_user_tag (info, user_tags->name, user_tags->value);
+               user_tags = user_tags->next;
+       }
+
        binfo->flags &= ~CAMEL_MESSAGE_FOLDER_FLAGGED;
        binfo->dirty = TRUE;
 }
diff --git a/camel/providers/imapx/camel-imapx-utils.h b/camel/providers/imapx/camel-imapx-utils.h
index 00835a8..92032ad 100644
--- a/camel/providers/imapx/camel-imapx-utils.h
+++ b/camel/providers/imapx/camel-imapx-utils.h
@@ -151,6 +151,8 @@ void                imapx_set_message_info_flags_for_new_message
                                                (CamelMessageInfo *info,
                                                 guint32 server_flags,
                                                 CamelFlag *server_user_flags,
+                                                gboolean force_user_flags,
+                                                CamelTag *user_tags,
                                                 CamelFolder *folder);
 void           imapx_update_store_summary      (CamelFolder *folder);
 


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