[evolution-ews/gnome-3-22] Bug 770936 - BAD REQUEST due to empty Categories element



commit 6d87b21cadc58c7d61beb588afec5d21185ad104
Author: Milan Crha <mcrha redhat com>
Date:   Tue Oct 18 12:55:23 2016 +0200

    Bug 770936 - BAD REQUEST due to empty Categories element

 src/calendar/e-cal-backend-ews-utils.c |   58 ++++++++++++++++++++++---------
 src/camel/camel-ews-folder.c           |   34 +++++++++++++-----
 src/camel/camel-ews-utils.c            |   21 +++++++----
 src/camel/camel-ews-utils.h            |    2 +-
 4 files changed, 79 insertions(+), 36 deletions(-)
---
diff --git a/src/calendar/e-cal-backend-ews-utils.c b/src/calendar/e-cal-backend-ews-utils.c
index 8925217..24ebb43 100644
--- a/src/calendar/e-cal-backend-ews-utils.c
+++ b/src/calendar/e-cal-backend-ews-utils.c
@@ -1209,18 +1209,28 @@ convert_categories_calcomp_to_xml (ESoapMessage *msg,
        if (!categ_list)
                return;
 
-       e_soap_message_start_element (msg, "Categories", NULL, NULL);
-
-       for (citer = categ_list; citer;  citer = g_slist_next (citer)) {
+       /* Categories cannot be empty, thus first verify they are not */
+       for (citer = categ_list; citer; citer = g_slist_next (citer)) {
                const gchar *category = citer->data;
 
-               if (!category || !*category)
-                       continue;
-
-               e_ews_message_write_string_parameter (msg, "String", NULL, category);
+               if (category && *category)
+                       break;
        }
 
-       e_soap_message_end_element (msg); /* Categories */
+       if (citer) {
+               e_soap_message_start_element (msg, "Categories", NULL, NULL);
+
+               for (citer = categ_list; citer; citer = g_slist_next (citer)) {
+                       const gchar *category = citer->data;
+
+                       if (!category || !*category)
+                               continue;
+
+                       e_ews_message_write_string_parameter (msg, "String", NULL, category);
+               }
+
+               e_soap_message_end_element (msg); /* Categories */
+       }
 
        e_cal_component_free_categories_list (categ_list);
 }
@@ -1506,20 +1516,34 @@ convert_component_categories_to_updatexml (ECalComponent *comp,
        g_return_if_fail (base_elem_name != NULL);
 
        e_cal_component_get_categories_list (comp, &categ_list);
-       e_ews_message_start_set_item_field (msg, "Categories", "item", base_elem_name);
-       e_soap_message_start_element (msg, "Categories", NULL, NULL);
 
-       for (citer = categ_list; citer;  citer = g_slist_next (citer)) {
-               const gchar *category = citer->data;
+       /* Categories cannot be empty, thus first verify they are not */
 
-               if (!category || !*category)
-                       continue;
+       for (citer = categ_list; citer; citer = g_slist_next (citer)) {
+               const gchar *category = citer->data;
 
-               e_ews_message_write_string_parameter (msg, "String", NULL, category);
+               if (category && *category)
+                       break;
        }
 
-       e_soap_message_end_element (msg); /* Categories */
-       e_ews_message_end_set_item_field (msg);
+       if (citer) {
+               e_ews_message_start_set_item_field (msg, "Categories", "item", base_elem_name);
+               e_soap_message_start_element (msg, "Categories", NULL, NULL);
+
+               for (citer = categ_list; citer; citer = g_slist_next (citer)) {
+                       const gchar *category = citer->data;
+
+                       if (!category || !*category)
+                               continue;
+
+                       e_ews_message_write_string_parameter (msg, "String", NULL, category);
+               }
+
+               e_soap_message_end_element (msg); /* Categories */
+               e_ews_message_end_set_item_field (msg);
+       } else {
+               e_ews_message_add_delete_item_field (msg, "Categories", "item");
+       }
 
        e_cal_component_free_categories_list (categ_list);
 }
diff --git a/src/camel/camel-ews-folder.c b/src/camel/camel-ews-folder.c
index 9900030..fcec38a 100644
--- a/src/camel/camel-ews-folder.c
+++ b/src/camel/camel-ews-folder.c
@@ -923,6 +923,7 @@ msg_update_flags (ESoapMessage *msg,
 
        for (iter = mi_list; iter; iter = g_slist_next (iter)) {
                guint32 flags_changed;
+               GSList *user_flags;
 
                mi = iter->data;
 
@@ -983,20 +984,33 @@ msg_update_flags (ESoapMessage *msg,
                }
 
                /* now update the Categories */
-               e_soap_message_start_element (msg, "SetItemField", NULL, NULL);
+               user_flags = ews_utils_gather_server_user_flags (msg, mi);
+               if (user_flags) {
+                       GSList *link;
 
-               e_soap_message_start_element (msg, "FieldURI", NULL, NULL);
-               e_soap_message_add_attribute (msg, "FieldURI", "item:Categories", NULL, NULL);
-               e_soap_message_end_element (msg);
+                       e_soap_message_start_element (msg, "SetItemField", NULL, NULL);
+
+                       e_soap_message_start_element (msg, "FieldURI", NULL, NULL);
+                       e_soap_message_add_attribute (msg, "FieldURI", "item:Categories", NULL, NULL);
+                       e_soap_message_end_element (msg);
+
+                       e_soap_message_start_element (msg, "Message", NULL, NULL);
+                       e_soap_message_start_element (msg, "Categories", NULL, NULL);
 
-               e_soap_message_start_element (msg, "Message", NULL, NULL);
-               e_soap_message_start_element (msg, "Categories", NULL, NULL);
+                       for (link = user_flags; link; link = g_slist_next (link)) {
+                               const gchar *user_flag = link->data;
 
-               ews_utils_replace_server_user_flags (msg, mi);
+                               e_ews_message_write_string_parameter (msg, "String", NULL, user_flag);
+                       }
+
+                       e_soap_message_end_element (msg); /* Categories */
+                       e_soap_message_end_element (msg); /* Message */
+                       e_soap_message_end_element (msg); /* SetItemField */
+               } else {
+                       e_ews_message_add_delete_item_field (msg, "Categories", "item");
+               }
 
-               e_soap_message_end_element (msg); /* Categories */
-               e_soap_message_end_element (msg); /* Message */
-               e_soap_message_end_element (msg); /* SetItemField */
+               g_slist_free_full (user_flags, g_free);
 
                ews_utils_update_followup_flags (msg, (CamelMessageInfo *) mi);
 
diff --git a/src/camel/camel-ews-utils.c b/src/camel/camel-ews-utils.c
index 27b7389..f9a8d42 100644
--- a/src/camel/camel-ews-utils.c
+++ b/src/camel/camel-ews-utils.c
@@ -422,10 +422,13 @@ ews_utils_is_system_user_flag (const gchar *name)
                g_str_equal (name, "$has-cal");
 }
 
-void
-ews_utils_replace_server_user_flags (ESoapMessage *msg,
-                                     CamelEwsMessageInfo *mi)
+/* free with g_slist_free_full (flags, g_free);
+   the lists' members are values for the String xml element. */
+GSList *
+ews_utils_gather_server_user_flags (ESoapMessage *msg,
+                                   CamelEwsMessageInfo *mi)
 {
+       GSList *user_flags = NULL;
        const CamelFlag *flag;
 
        /* transfer camel flags to become the categories as an XML
@@ -441,8 +444,10 @@ ews_utils_replace_server_user_flags (ESoapMessage *msg,
                if (ews_utils_is_system_user_flag (n))
                        continue;
 
-               e_ews_message_write_string_parameter (msg, "String", NULL, n);
+               user_flags = g_slist_prepend (user_flags, g_strdup (n));
        }
+
+       return g_slist_reverse (user_flags);
 }
 
 static void
@@ -995,13 +1000,13 @@ ews_utils_update_followup_flags (ESoapMessage *msg,
        if (dueby && *dueby)
                dueby_tt = camel_header_decode_date (dueby, NULL);
 
-       /* PidTagFlagStatus */
-       e_ews_message_add_set_item_field_extended_tag_int (msg, NULL, "Message", 0x1090,
-               followup ? (completed_tt != (time_t) 0 ? 0x01 /* followupComplete */: 0x02 /* followupFlagged 
*/) : 0x0);
-
        if (followup) {
                time_t now_tt = time (NULL);
 
+               /* PidTagFlagStatus */
+               e_ews_message_add_set_item_field_extended_tag_int (msg, NULL, "Message", 0x1090,
+                       completed_tt != (time_t) 0 ? 0x01 /* followupComplete */: 0x02 /* followupFlagged */);
+
                /* PidLidFlagRequest */
                e_ews_message_add_set_item_field_extended_distinguished_tag_string (msg, NULL, "Message", 
"Common", 0x8530, followup);
 
diff --git a/src/camel/camel-ews-utils.h b/src/camel/camel-ews-utils.h
index 0cf4940..93ec395 100644
--- a/src/camel/camel-ews-utils.h
+++ b/src/camel/camel-ews-utils.h
@@ -74,7 +74,7 @@ void          camel_ews_utils_sync_updated_items
                                                (CamelEwsFolder *ews_folder,
                                                 GSList *items_updated,
                                                 CamelFolderChangeInfo *change_info);
-void           ews_utils_replace_server_user_flags
+GSList *       ews_utils_gather_server_user_flags
                                                (ESoapMessage *msg,
                                                 CamelEwsMessageInfo *mi);
 void           ews_utils_update_followup_flags (ESoapMessage *msg,


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