[evolution-ews] I#7 - Event timezone not always properly set on the server



commit fb5b6a95c28b78544e7d8da9afb5913f08ba981c
Author: Milan Crha <mcrha redhat com>
Date:   Wed Jul 11 19:25:47 2018 +0200

    I#7 - Event timezone not always properly set on the server
    
    Closes https://gitlab.gnome.org/GNOME/evolution-ews/issues/7

 src/calendar/e-cal-backend-ews-utils.c | 66 +++++++++++++++++++++++++++-------
 src/calendar/e-cal-backend-ews-utils.h |  9 ++++-
 src/calendar/e-cal-backend-ews.c       | 20 +++++++----
 3 files changed, 75 insertions(+), 20 deletions(-)
---
diff --git a/src/calendar/e-cal-backend-ews-utils.c b/src/calendar/e-cal-backend-ews-utils.c
index 1481ae51..f3800bc8 100644
--- a/src/calendar/e-cal-backend-ews-utils.c
+++ b/src/calendar/e-cal-backend-ews-utils.c
@@ -329,6 +329,7 @@ ews_get_alarm (ECalComponent *comp)
 void
 ews_set_alarm (ESoapMessage *msg,
                ECalComponent *comp,
+              ETimezoneCache *timezone_cache,
               gboolean with_due_by)
 {
        /* We know there would be only a single alarm in EWS calendar item */
@@ -350,7 +351,8 @@ ews_set_alarm (ESoapMessage *msg,
                        if (with_due_by) {
                                struct icaltimetype dtstart;
 
-                               dtstart = icalcomponent_get_dtstart (e_cal_component_get_icalcomponent 
(comp));
+                               dtstart = e_cal_backend_ews_get_datetime_with_zone (timezone_cache, 
e_cal_component_get_icalcomponent (comp),
+                                       ICAL_DTSTART_PROPERTY, icalproperty_get_dtstart);
 
                                if (!icaltime_is_null_time (dtstart)) {
                                        e_ews_message_write_time_parameter (msg, "ReminderDueBy", NULL,
@@ -1119,16 +1121,16 @@ convert_vevent_calcomp_to_xml (ESoapMessage *msg,
        /* set alarms */
        has_alarms = e_cal_component_has_alarms (comp);
        if (has_alarms)
-               ews_set_alarm (msg, comp, FALSE);
+               ews_set_alarm (msg, comp, convert_data->timezone_cache, FALSE);
        else
                e_ews_message_write_string_parameter (msg, "ReminderIsSet", NULL, "false");
 
        /* start time, end time and meeting time zone */
-       dtstart = icalcomponent_get_dtstart (icalcomp);
+       dtstart = e_cal_backend_ews_get_datetime_with_zone (convert_data->timezone_cache, icalcomp, 
ICAL_DTSTART_PROPERTY, icalproperty_get_dtstart);
        tzid_start = (icaltimezone *) (dtstart.zone ? dtstart.zone : convert_data->default_zone);
        ical_location_start = icaltimezone_get_location (tzid_start);
 
-       dtend = icalcomponent_get_dtend (icalcomp);
+       dtend = e_cal_backend_ews_get_datetime_with_zone (convert_data->timezone_cache, icalcomp, 
ICAL_DTEND_PROPERTY, icalproperty_get_dtend);
        tzid_end = (icaltimezone *) (dtend.zone ? dtend.zone : convert_data->default_zone);
        ical_location_end = icaltimezone_get_location (tzid_end);
 
@@ -1286,7 +1288,7 @@ convert_vtodo_calcomp_to_xml (ESoapMessage *msg,
 
        prop = icalcomponent_get_first_property (icalcomp, ICAL_DUE_PROPERTY);
        if (prop) {
-               dt = icalproperty_get_due (prop);
+               dt = e_cal_backend_ews_get_datetime_with_zone (convert_data->timezone_cache, icalcomp, 
ICAL_DUE_PROPERTY, icalproperty_get_due);
                e_ews_cal_utils_set_time (msg, "DueDate", &dt, TRUE);
        }
 
@@ -1301,7 +1303,7 @@ convert_vtodo_calcomp_to_xml (ESoapMessage *msg,
 
        prop = icalcomponent_get_first_property (icalcomp, ICAL_DTSTART_PROPERTY);
        if (prop) {
-               dt = icalproperty_get_dtstart (prop);
+               dt = e_cal_backend_ews_get_datetime_with_zone (convert_data->timezone_cache, icalcomp, 
ICAL_DTSTART_PROPERTY, icalproperty_get_dtstart);
                e_ews_cal_utils_set_time (msg, "StartDate", &dt, TRUE);
        }
 
@@ -1324,7 +1326,7 @@ convert_vtodo_calcomp_to_xml (ESoapMessage *msg,
                ECalComponent *comp = e_cal_component_new_from_icalcomponent (icalcomponent_new_clone 
(icalcomp));
 
                if (comp && e_cal_component_has_alarms (comp)) {
-                       ews_set_alarm (msg, comp, TRUE);
+                       ews_set_alarm (msg, comp, convert_data->timezone_cache, TRUE);
                } else {
                        has_alarms = FALSE;
                }
@@ -1578,8 +1580,8 @@ convert_vevent_component_to_updatexml (ESoapMessage *msg,
 
        /* Update other properties allowed only for meeting organizers*/
        /*meeting dates*/
-       dtstart = icalcomponent_get_dtstart (icalcomp);
-       dtstart_old = icalcomponent_get_dtstart (icalcomp_old);
+       dtstart = e_cal_backend_ews_get_datetime_with_zone (convert_data->timezone_cache, icalcomp, 
ICAL_DTSTART_PROPERTY, icalproperty_get_dtstart);
+       dtstart_old = e_cal_backend_ews_get_datetime_with_zone (convert_data->timezone_cache, icalcomp_old, 
ICAL_DTSTART_PROPERTY, icalproperty_get_dtstart);
        dt_start_changed = icaltime_compare (dtstart, dtstart_old) != 0;
        if (dtstart.zone != NULL) {
                tzid_start = (icaltimezone *) dtstart.zone;
@@ -1590,8 +1592,8 @@ convert_vevent_component_to_updatexml (ESoapMessage *msg,
                        dt_start_changed_timezone_name = TRUE;
        }
 
-       dtend = icalcomponent_get_dtend (icalcomp);
-       dtend_old = icalcomponent_get_dtend (icalcomp_old);
+       dtend = e_cal_backend_ews_get_datetime_with_zone (convert_data->timezone_cache, icalcomp, 
ICAL_DTEND_PROPERTY, icalproperty_get_dtend);
+       dtend_old = e_cal_backend_ews_get_datetime_with_zone (convert_data->timezone_cache, icalcomp_old, 
ICAL_DTEND_PROPERTY, icalproperty_get_dtend);
        dt_end_changed = icaltime_compare (dtend, dtend_old) != 0;
        if (dtend.zone != NULL) {
                tzid_end = (icaltimezone *) dtend.zone;
@@ -1811,7 +1813,7 @@ convert_vtodo_component_to_updatexml (ESoapMessage *msg,
 
        prop = icalcomponent_get_first_property (icalcomp, ICAL_DUE_PROPERTY);
        if (prop) {
-               dt = icalproperty_get_due (prop);
+               dt = e_cal_backend_ews_get_datetime_with_zone (convert_data->timezone_cache, icalcomp, 
ICAL_DUE_PROPERTY, icalproperty_get_due);
                e_ews_message_start_set_item_field (msg, "DueDate", "task", "Task");
                e_ews_cal_utils_set_time (msg, "DueDate", &dt, TRUE);
                e_ews_message_end_set_item_field (msg);
@@ -1841,7 +1843,7 @@ convert_vtodo_component_to_updatexml (ESoapMessage *msg,
 
        prop = icalcomponent_get_first_property (icalcomp, ICAL_DTSTART_PROPERTY);
        if (prop) {
-               dt = icalproperty_get_dtstart (prop);
+               dt = e_cal_backend_ews_get_datetime_with_zone (convert_data->timezone_cache, icalcomp, 
ICAL_DTSTART_PROPERTY, icalproperty_get_dtstart);
                e_ews_message_start_set_item_field (msg, "StartDate", "task", "Task");
                e_ews_cal_utils_set_time (msg, "StartDate", &dt, TRUE);
                e_ews_message_end_set_item_field (msg);
@@ -2080,3 +2082,41 @@ e_cal_backend_ews_prepare_accept_item_request (ESoapMessage *msg,
 
        return TRUE;
 }
+
+struct icaltimetype
+e_cal_backend_ews_get_datetime_with_zone (ETimezoneCache *timezone_cache,
+                                         icalcomponent *comp,
+                                         icalproperty_kind prop_kind,
+                                         struct icaltimetype (* get_func) (const icalproperty *prop))
+{
+       struct icaltimetype dt = icaltime_null_time ();
+       icalproperty *prop;
+       icalparameter *param;
+       const gchar *tzid;
+
+       g_return_val_if_fail (E_IS_TIMEZONE_CACHE (timezone_cache), dt);
+       g_return_val_if_fail (comp != NULL, dt);
+       g_return_val_if_fail (get_func != NULL, dt);
+
+       prop = icalcomponent_get_first_property (comp, prop_kind);
+       if (!prop)
+               return dt;
+
+       dt = get_func (prop);
+
+       if (!icaltime_is_valid_time (dt) ||
+           icaltime_is_null_time (dt))
+               return dt;
+
+       param = icalproperty_get_first_parameter (prop, ICAL_TZID_PARAMETER);
+       if (!param)
+               return dt;
+
+       tzid = icalparameter_get_tzid (param);
+       if (!tzid || !*tzid)
+               return dt;
+
+       dt.zone = e_timezone_cache_get_timezone (timezone_cache, tzid);
+
+       return dt;
+}
diff --git a/src/calendar/e-cal-backend-ews-utils.h b/src/calendar/e-cal-backend-ews-utils.h
index 65e95c54..04f1cba7 100644
--- a/src/calendar/e-cal-backend-ews-utils.h
+++ b/src/calendar/e-cal-backend-ews-utils.h
@@ -39,6 +39,7 @@ G_BEGIN_DECLS
 
 typedef struct {
        EEwsConnection *connection;
+       ETimezoneCache *timezone_cache;
        icaltimezone *default_zone;
        gchar *user_email;
        gchar *response_type; /* Accept */
@@ -62,7 +63,7 @@ void ewscal_set_meeting_timezone (ESoapMessage *msg, icaltimezone *icaltz);
 void ewscal_set_reccurence (ESoapMessage *msg, icalproperty *rrule, icaltimetype *dtstart);
 void ewscal_set_reccurence_exceptions (ESoapMessage *msg, icalcomponent *comp);
 gchar *e_ews_extract_attachment_id_from_uri (const gchar *uri);
-void ews_set_alarm (ESoapMessage *msg, ECalComponent *comp, gboolean with_due_by);
+void ews_set_alarm (ESoapMessage *msg, ECalComponent *comp, ETimezoneCache *timezone_cache, gboolean 
with_due_by);
 gint ews_get_alarm (ECalComponent *comp);
 void e_ews_clean_icalcomponent (icalcomponent *icalcomp);
 
@@ -79,6 +80,12 @@ gboolean e_cal_backend_ews_prepare_accept_item_request (ESoapMessage *msg, gpoin
 
 guint e_cal_backend_ews_rid_to_index (icaltimezone *timezone, const gchar *rid, icalcomponent *comp, GError 
**error);
 
+struct icaltimetype
+               e_cal_backend_ews_get_datetime_with_zone        (ETimezoneCache *timezone_cache,
+                                                                icalcomponent *comp,
+                                                                icalproperty_kind prop_kind,
+                                                                struct icaltimetype (* get_func) (const 
icalproperty *prop));
+
 G_END_DECLS
 
 #endif
diff --git a/src/calendar/e-cal-backend-ews.c b/src/calendar/e-cal-backend-ews.c
index 324eda77..24cf222b 100644
--- a/src/calendar/e-cal-backend-ews.c
+++ b/src/calendar/e-cal-backend-ews.c
@@ -499,7 +499,7 @@ ecb_ews_item_to_component_sync (ECalBackendEws *cbews,
                                        icalcomponent *alarm_icalcomp;
                                        struct icaltimetype dtstart, due_by;
 
-                                       dtstart = icalcomponent_get_dtstart (icalcomp);
+                                       dtstart = e_cal_backend_ews_get_datetime_with_zone (timezone_cache, 
icalcomp, ICAL_DTSTART_PROPERTY, icalproperty_get_dtstart);
                                        due_by = icaltime_from_timet_with_zone (reminder_due_by, 0, utc_zone);
 
                                        if (icaltime_is_null_time (dtstart)) {
@@ -638,7 +638,7 @@ ecb_ews_item_to_component_sync (ECalBackendEws *cbews,
                        if (start_zone != NULL) {
                                icalcomp = icalcomponent_get_first_component (vcomp, kind);
 
-                               dt = icalcomponent_get_dtstart (icalcomp);
+                               dt = e_cal_backend_ews_get_datetime_with_zone (timezone_cache, icalcomp, 
ICAL_DTSTART_PROPERTY, icalproperty_get_dtstart);
                                dt = icaltime_convert_to_zone (dt, start_zone);
                                icalcomponent_set_dtstart (icalcomp, dt);
 
@@ -646,7 +646,7 @@ ecb_ews_item_to_component_sync (ECalBackendEws *cbews,
                                e_timezone_cache_add_timezone (timezone_cache, start_zone);
 
                                if (end_zone != NULL) {
-                                       dt = icalcomponent_get_dtend (icalcomp);
+                                       dt = e_cal_backend_ews_get_datetime_with_zone (timezone_cache, 
icalcomp, ICAL_DTEND_PROPERTY, icalproperty_get_dtend);
                                        dt = icaltime_convert_to_zone (dt, end_zone);
                                        icalcomponent_set_dtend (icalcomp, dt);
 
@@ -714,11 +714,11 @@ ecb_ews_item_to_component_sync (ECalBackendEws *cbews,
                                zone = icaltimezone_get_builtin_timezone (tzid);
 
                        if (zone != NULL) {
-                               dt = icalcomponent_get_dtstart (icalcomp);
+                               dt = e_cal_backend_ews_get_datetime_with_zone (timezone_cache, icalcomp, 
ICAL_DTSTART_PROPERTY, icalproperty_get_dtstart);
                                dt = icaltime_convert_to_zone (dt, zone);
                                icalcomponent_set_dtstart (icalcomp, dt);
 
-                               dt = icalcomponent_get_dtend (icalcomp);
+                               dt = e_cal_backend_ews_get_datetime_with_zone (timezone_cache, icalcomp, 
ICAL_DTEND_PROPERTY, icalproperty_get_dtend);
                                dt = icaltime_convert_to_zone (dt, zone);
                                icalcomponent_set_dtend (icalcomp, dt);
                        }
@@ -2506,6 +2506,7 @@ ecb_ews_modify_item_sync (ECalBackendEws *cbews,
                ews_settings = ecb_ews_get_collection_settings (cbews);
 
                convert_data.connection = cbews->priv->cnc;
+               convert_data.timezone_cache = E_TIMEZONE_CACHE (cbews);
                convert_data.user_email = camel_ews_settings_dup_email (ews_settings);
                convert_data.comp = comp;
                convert_data.old_comp = oldcomp;
@@ -2687,6 +2688,7 @@ ecb_ews_save_component_sync (ECalMetaBackend *meta_backend,
                }
 
                convert_data.connection = cbews->priv->cnc;
+               convert_data.timezone_cache = E_TIMEZONE_CACHE (cbews);
                convert_data.icalcomp = icalcomp;
                convert_data.default_zone = icaltimezone_get_utc_timezone ();
 
@@ -2902,6 +2904,8 @@ ecb_ews_discard_alarm_sync (ECalBackendSync *cal_backend_sync,
                return;
        }
 
+       convert_data.timezone_cache = E_TIMEZONE_CACHE (cbews);
+
        if (e_cal_component_has_recurrences (comp)) {
                gint *index;
 
@@ -2985,7 +2989,7 @@ ecb_ews_send_cancellation_email_sync (ECalBackendEws *cbews,
        icalcomponent_add_property (vevent, icalproperty_new_status (ICAL_STATUS_CANCELLED));
        prop = icalcomponent_get_first_property (vevent, ICAL_METHOD_PROPERTY);
        if (prop != NULL) icalcomponent_remove_property (vevent, prop);
-       dt = icalcomponent_get_dtstart (vevent);
+       dt = e_cal_backend_ews_get_datetime_with_zone (E_TIMEZONE_CACHE (cbews), vevent, 
ICAL_DTSTART_PROPERTY, icalproperty_get_dtstart);
        icaltz = (icaltimezone *)
                (dt.zone ? dt.zone : ecb_ews_get_timezone_from_ical_component (cbews, vevent));
        vtz = icaltimezone_get_component (icaltz);
@@ -3037,6 +3041,7 @@ ecb_ews_receive_objects_no_exchange_mail (ECalBackendEws *cbews,
        EwsFolderId *fid;
 
        convert_data.connection = cbews->priv->cnc;
+       convert_data.timezone_cache = E_TIMEZONE_CACHE (cbews);
        convert_data.icalcomp = subcomp;
        convert_data.default_zone = icaltimezone_get_utc_timezone ();
 
@@ -3316,6 +3321,7 @@ ecb_ews_do_method_request_publish_reply (ECalBackendEws *cbews,
                } else {
                        EwsCalendarConvertData convert_data = { 0 };
 
+                       convert_data.timezone_cache = E_TIMEZONE_CACHE (cbews);
                        convert_data.response_type = (gchar *) response_type;
                        convert_data.item_id = item_id;
                        convert_data.change_key = change_key;
@@ -3419,6 +3425,8 @@ ecb_ews_do_method_request_publish_reply (ECalBackendEws *cbews,
                                }
                        }
 
+                       convert_data.timezone_cache = E_TIMEZONE_CACHE (cbews);
+
                        e_ews_connection_update_items_sync (
                                cbews->priv->cnc,
                                EWS_PRIORITY_MEDIUM,


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