]> www.infradead.org Git - users/dwmw2/ews-sync.git/commitdiff
Add TZID to recurrenceid property, return correct component on recursion
authorDavid Woodhouse <dwmw2@infradead.org>
Thu, 22 Jul 2010 13:21:32 +0000 (14:21 +0100)
committerDavid Woodhouse <dwmw2@infradead.org>
Thu, 22 Jul 2010 13:21:32 +0000 (14:21 +0100)
calitem_to_ical.c

index f64f6cea809876e5c1f9fcc5def9709911549923..34c44075c354a4e9765fb5b8f68bf92823dbbcac 100644 (file)
@@ -74,23 +74,25 @@ icalcomponent *ews_calitem_to_ical(xmlNode *xml_node, const gchar *parent_id,
 
        dtstart = dtend = icaltime_null_time();
        
-       calcomp = icalcomponent_new_vcalendar();
-       icalcomponent_set_method(calcomp, ICAL_METHOD_PUBLISH);
-       prop = icalproperty_new_version("2.0");
-       icalcomponent_add_property(calcomp, prop);
 
-       if (parent_zone)
+       if (parent_zone) {
+               calcomp = NULL;
                icaltz = parent_zone;
-       else {
+       } else {
+               calcomp = icalcomponent_new_vcalendar();
+               icalcomponent_set_method(calcomp, ICAL_METHOD_PUBLISH);
+               prop = icalproperty_new_version("2.0");
+               icalcomponent_add_property(calcomp, prop);
+
                icaltz = get_meeting_timezone(xml_node, error);
                if (icaltz)
                        freetz = TRUE;
-               else {
+               else
                        icaltz = get_timezone(xml_node, error);
-                       if (icaltz) {
-                               icalcomponent *comp = icaltimezone_get_component(icaltz);
-                               icalcomponent_add_component(calcomp, comp);
-                       }
+
+               if (icaltz) {
+                       icalcomponent *comp = icaltimezone_get_component(icaltz);
+                       icalcomponent_add_component(calcomp, comp);
                }
        }
 
@@ -229,30 +231,39 @@ icalcomponent *ews_calitem_to_ical(xmlNode *xml_node, const gchar *parent_id,
                }
                free(deletia);
        }
-       icalcomponent_add_component(calcomp, comp);
+       if (calcomp) {
+               icalcomponent_add_component(calcomp, comp);
 
-       if (modifia) {
-               const char *uid = icalcomponent_get_uid(comp);
-
-               for (i = 0; i < modifia_count; i++) {
-                       printf("Modified: %s\n", modifia[i]);
-                       if (fetch_subitem) {
-                               comp = fetch_subitem(fetch_subitem_priv, modifia[i], uid, icaltz, error);
-                               if (!comp)
-                                       goto err;
+               if (modifia) {
+                       const char *uid = icalcomponent_get_uid(comp);
+                       
+                       for (i = 0; i < modifia_count; i++) {
+                               if (fetch_subitem) {
+                                       comp = fetch_subitem(fetch_subitem_priv, modifia[i], uid, icaltz, error);
+                                       if (!comp)
+                                               goto err;
+                                       icalcomponent_add_component(calcomp, comp);
+                               }
                        }
+                       free(modifia);
                }
-               free(modifia);
        }
 
        if (freetz)
                icaltimezone_free(icaltz, 1);
-       return calcomp;
+
+       return calcomp?:comp;
 
  err:
-       icalcomponent_free(calcomp);
+       if (comp)
+               icalcomponent_free(comp);
+       if (calcomp)
+               icalcomponent_free(calcomp);
        if (deletia)
                free(deletia);
+       if (modifia)
+               free(modifia);
+
        return NULL;
                        
 }
@@ -395,14 +406,23 @@ gboolean process_time(icalcomponent *comp, xmlNode *xml_node, icaltimetype *ical
 
 gboolean process_orig_start(icalcomponent *comp, xmlNode *xml_node, icaltimezone *icaltz, GError **error)
 {
+       icalproperty *prop;
+       const char *tzid = NULL;
        icaltimetype t;
 
        if (!process_time(comp, xml_node, &t, error))
                return FALSE;
 
-       if (icaltz)
+       if (icaltz) {
                t = icaltime_convert_to_zone(t, icaltz);
-       icalcomponent_set_recurrenceid(comp, t);
+       }
+
+       /* Grr, icalproperty_add_recurrenceid() doesn't include TZID */
+       prop = icalproperty_new_recurrenceid(t);
+       tzid = icaltime_get_tzid(t);
+       if (tzid)
+               icalproperty_add_parameter(prop, icalparameter_new_tzid(tzid));
+       icalcomponent_add_property(comp, prop);
        return TRUE;
 }