[evolution-data-server] Bug 735191 - [IMAPx] Avoid storing server-disallowed message flags



commit bf3aed49e32006df19fa70b31d99ce549b33801d
Author: Milan Crha <mcrha redhat com>
Date:   Fri Aug 29 16:23:02 2014 +0200

    Bug 735191 - [IMAPx] Avoid storing server-disallowed message flags

 camel/providers/imapx/camel-imapx-server.c |  113 +++++++++++++++-------------
 camel/providers/imapx/camel-imapx-utils.c  |    6 +-
 camel/providers/imapx/camel-imapx-utils.h  |    2 +-
 3 files changed, 66 insertions(+), 55 deletions(-)
---
diff --git a/camel/providers/imapx/camel-imapx-server.c b/camel/providers/imapx/camel-imapx-server.c
index 04fafea..39eaf4d 100644
--- a/camel/providers/imapx/camel-imapx-server.c
+++ b/camel/providers/imapx/camel-imapx-server.c
@@ -2423,7 +2423,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, FALSE, NULL, folder);
+                                       imapx_set_message_info_flags_for_new_message (mi, server_flags, 
server_user_flags, FALSE, NULL, is->priv->permanentflags);
                                        camel_folder_summary_add (folder->summary, mi);
                                        camel_folder_change_info_add_uid (data->changes, mi->uid);
 
@@ -5239,7 +5239,7 @@ imapx_command_copy_messages_step_done (CamelIMAPXServer *is,
                                        ((CamelMessageInfoBase *) source_info)->user_flags,
                                        TRUE,
                                        ((CamelMessageInfoBase *) source_info)->user_tags,
-                                       destination);
+                                       is->priv->permanentflags);
                                if (is_new)
                                        camel_folder_summary_add (destination->summary, destination_info);
                                camel_folder_change_info_add_uid (changes, destination_info->uid);
@@ -5436,7 +5436,7 @@ imapx_command_append_message_done (CamelIMAPXServer *is,
                                ((CamelMessageInfoBase *) data->info)->user_flags,
                                TRUE,
                                ((CamelMessageInfoBase *) data->info)->user_tags,
-                               folder);
+                               is->priv->permanentflags);
                        camel_folder_summary_add (folder->summary, mi);
                        changes = camel_folder_change_info_new ();
                        camel_folder_change_info_add_uid (changes, mi->uid);
@@ -7276,7 +7276,9 @@ imapx_command_sync_changes_done (CamelIMAPXServer *is,
                                xinfo->info.flags |= CAMEL_MESSAGE_FOLDER_FLAGGED;
                        }
                        xinfo->info.dirty = TRUE;
-                       camel_flag_list_copy (&xinfo->server_user_flags, &xinfo->info.user_flags);
+                       if ((is->priv->permanentflags & CAMEL_MESSAGE_USER) != 0 ||
+                           camel_flag_list_size (&xinfo->server_user_flags) == 0)
+                               camel_flag_list_copy (&xinfo->server_user_flags, &xinfo->info.user_flags);
 
                        camel_folder_summary_touch (folder->summary);
                        camel_message_info_unref (xinfo);
@@ -8771,66 +8773,75 @@ imapx_server_sync_changes (CamelIMAPXServer *is,
                        camel_imapx_folder_add_move_to_real_trash (
                                CAMEL_IMAPX_FOLDER (folder), uid);
 
+               flags &= is->priv->permanentflags;
+               sflags &= is->priv->permanentflags;
+
                if (flags != sflags) {
                        off_orset |= (flags ^ sflags) & ~flags;
                        on_orset |= (flags ^ sflags) & flags;
                }
 
-               uflags = info->info.user_flags;
-               suflags = info->server_user_flags;
-               while (uflags || suflags) {
-                       gint res;
-
-                       if (uflags) {
-                               if (suflags)
-                                       res = strcmp (uflags->name, suflags->name);
-                               else if (*uflags->name)
-                                       res = -1;
-                               else {
-                                       uflags = uflags->next;
-                                       continue;
+               if ((is->priv->permanentflags & CAMEL_MESSAGE_USER) != 0) {
+                       uflags = info->info.user_flags;
+                       suflags = info->server_user_flags;
+                       while (uflags || suflags) {
+                               gint res;
+
+                               if (uflags) {
+                                       if (suflags)
+                                               res = strcmp (uflags->name, suflags->name);
+                                       else if (*uflags->name)
+                                               res = -1;
+                                       else {
+                                               uflags = uflags->next;
+                                               continue;
+                                       }
+                               } else {
+                                       res = 1;
                                }
-                       } else {
-                               res = 1;
-                       }
 
-                       if (res == 0) {
-                               uflags = uflags->next;
-                               suflags = suflags->next;
-                       } else {
-                               GArray *user_set;
-                               CamelFlag *user_flag;
-                               struct _imapx_flag_change *change = NULL, add = { 0 };
-
-                               if (res < 0) {
-                                       if (on_user == NULL)
-                                               on_user = g_array_new (FALSE, FALSE, sizeof (struct 
_imapx_flag_change));
-                                       user_set = on_user;
-                                       user_flag = uflags;
+                               if (res == 0) {
                                        uflags = uflags->next;
-                               } else {
-                                       if (off_user == NULL)
-                                               off_user = g_array_new (FALSE, FALSE, sizeof (struct 
_imapx_flag_change));
-                                       user_set = off_user;
-                                       user_flag = suflags;
                                        suflags = suflags->next;
-                               }
+                               } else {
+                                       GArray *user_set;
+                                       CamelFlag *user_flag;
+                                       struct _imapx_flag_change *change = NULL, add = { 0 };
+
+                                       if (res < 0) {
+                                               if (on_user == NULL)
+                                                       on_user = g_array_new (FALSE, FALSE, sizeof (struct 
_imapx_flag_change));
+                                               user_set = on_user;
+                                               user_flag = uflags;
+                                               uflags = uflags->next;
+                                       } else {
+                                               if (off_user == NULL)
+                                                       off_user = g_array_new (FALSE, FALSE, sizeof (struct 
_imapx_flag_change));
+                                               user_set = off_user;
+                                               user_flag = suflags;
+                                               suflags = suflags->next;
+                                       }
 
-                               /* Could sort this and binary search */
-                               for (j = 0; j < user_set->len; j++) {
-                                       change = &g_array_index (user_set, struct _imapx_flag_change, j);
-                                       if (strcmp (change->name, user_flag->name) == 0)
-                                               goto found;
+                                       /* Could sort this and binary search */
+                                       for (j = 0; j < user_set->len; j++) {
+                                               change = &g_array_index (user_set, struct _imapx_flag_change, 
j);
+                                               if (strcmp (change->name, user_flag->name) == 0)
+                                                       goto found;
+                                       }
+                                       add.name = g_strdup (user_flag->name);
+                                       add.infos = g_ptr_array_new ();
+                                       g_array_append_val (user_set, add);
+                                       change = &add;
+                               found:
+                                       camel_message_info_ref (info);
+                                       g_ptr_array_add (change->infos, info);
                                }
-                               add.name = g_strdup (user_flag->name);
-                               add.infos = g_ptr_array_new ();
-                               g_array_append_val (user_set, add);
-                               change = &add;
-                       found:
-                               camel_message_info_ref (info);
-                               g_ptr_array_add (change->infos, info);
                        }
+               } else {
+                       /* Cannot save user flags to the server => store them locally only */
+                       camel_flag_list_copy (&info->server_user_flags, &info->info.user_flags);
                }
+
                camel_message_info_unref (info);
        }
 
diff --git a/camel/providers/imapx/camel-imapx-utils.c b/camel/providers/imapx/camel-imapx-utils.c
index 0276d75..f5d18f6 100644
--- a/camel/providers/imapx/camel-imapx-utils.c
+++ b/camel/providers/imapx/camel-imapx-utils.c
@@ -325,7 +325,7 @@ imapx_update_message_info_flags (CamelMessageInfo *info,
                changed = TRUE;
        }
 
-       if ((folder->permanent_flags & CAMEL_MESSAGE_USER) != 0 && imapx_update_user_flags (info, 
server_user_flags))
+       if ((permanent_flags & CAMEL_MESSAGE_USER) != 0 && imapx_update_user_flags (info, server_user_flags))
                changed = TRUE;
 
        return changed;
@@ -337,7 +337,7 @@ imapx_set_message_info_flags_for_new_message (CamelMessageInfo *info,
                                               CamelFlag *server_user_flags,
                                              gboolean force_user_flags,
                                              CamelTag *user_tags,
-                                              CamelFolder *folder)
+                                             guint32 permanent_flags)
 {
        CamelMessageInfoBase *binfo = (CamelMessageInfoBase *) info;
        CamelIMAPXMessageInfo *xinfo = (CamelIMAPXMessageInfo *) info;
@@ -347,7 +347,7 @@ imapx_set_message_info_flags_for_new_message (CamelMessageInfo *info,
 
        xinfo->server_flags = server_flags;
 
-       if (force_user_flags || (folder->permanent_flags & CAMEL_MESSAGE_USER) != 0)
+       if (force_user_flags || (permanent_flags & CAMEL_MESSAGE_USER) != 0)
                imapx_update_user_flags (info, server_user_flags);
 
        while (user_tags) {
diff --git a/camel/providers/imapx/camel-imapx-utils.h b/camel/providers/imapx/camel-imapx-utils.h
index 445ec6a..dc2d5a5 100644
--- a/camel/providers/imapx/camel-imapx-utils.h
+++ b/camel/providers/imapx/camel-imapx-utils.h
@@ -154,7 +154,7 @@ void                imapx_set_message_info_flags_for_new_message
                                                 CamelFlag *server_user_flags,
                                                 gboolean force_user_flags,
                                                 CamelTag *user_tags,
-                                                CamelFolder *folder);
+                                                guint32 permanent_flags);
 void           imapx_update_store_summary      (CamelFolder *folder);
 
 gchar *                camel_imapx_dup_uid_from_summary_index


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