Blame SOURCES/evolution-ews-3.28.5-import-event-timezone.patch

c9b2f7
diff -up evolution-ews-3.28.5/src/calendar/e-cal-backend-ews.c.import-event-timezone evolution-ews-3.28.5/src/calendar/e-cal-backend-ews.c
c9b2f7
--- evolution-ews-3.28.5/src/calendar/e-cal-backend-ews.c.import-event-timezone	2018-07-30 16:01:00.000000000 +0200
c9b2f7
+++ evolution-ews-3.28.5/src/calendar/e-cal-backend-ews.c	2018-09-04 11:14:27.815647542 +0200
c9b2f7
@@ -579,7 +579,7 @@ ecb_ews_item_to_component_sync (ECalBack
c9b2f7
 			if (start_zone != NULL) {
c9b2f7
 				icalcomp = icalcomponent_get_first_component (vcomp, kind);
c9b2f7
 
c9b2f7
-				dt = e_cal_backend_ews_get_datetime_with_zone (timezone_cache, icalcomp, ICAL_DTSTART_PROPERTY, icalproperty_get_dtstart);
c9b2f7
+				dt = e_cal_backend_ews_get_datetime_with_zone (timezone_cache, vcomp, icalcomp, ICAL_DTSTART_PROPERTY, icalproperty_get_dtstart);
c9b2f7
 				dt = icaltime_convert_to_zone (dt, start_zone);
c9b2f7
 				icalcomponent_set_dtstart (icalcomp, dt);
c9b2f7
 
c9b2f7
@@ -587,7 +587,7 @@ ecb_ews_item_to_component_sync (ECalBack
c9b2f7
 				e_timezone_cache_add_timezone (timezone_cache, start_zone);
c9b2f7
 
c9b2f7
 				if (end_zone != NULL) {
c9b2f7
-					dt = e_cal_backend_ews_get_datetime_with_zone (timezone_cache, icalcomp, ICAL_DTEND_PROPERTY, icalproperty_get_dtend);
c9b2f7
+					dt = e_cal_backend_ews_get_datetime_with_zone (timezone_cache, vcomp, icalcomp, ICAL_DTEND_PROPERTY, icalproperty_get_dtend);
c9b2f7
 					dt = icaltime_convert_to_zone (dt, end_zone);
c9b2f7
 					icalcomponent_set_dtend (icalcomp, dt);
c9b2f7
 
c9b2f7
@@ -655,11 +655,11 @@ ecb_ews_item_to_component_sync (ECalBack
c9b2f7
 				zone = icaltimezone_get_builtin_timezone (tzid);
c9b2f7
 
c9b2f7
 			if (zone != NULL) {
c9b2f7
-				dt = e_cal_backend_ews_get_datetime_with_zone (timezone_cache, icalcomp, ICAL_DTSTART_PROPERTY, icalproperty_get_dtstart);
c9b2f7
+				dt = e_cal_backend_ews_get_datetime_with_zone (timezone_cache, vcomp, icalcomp, ICAL_DTSTART_PROPERTY, icalproperty_get_dtstart);
c9b2f7
 				dt = icaltime_convert_to_zone (dt, zone);
c9b2f7
 				icalcomponent_set_dtstart (icalcomp, dt);
c9b2f7
 
c9b2f7
-				dt = e_cal_backend_ews_get_datetime_with_zone (timezone_cache, icalcomp, ICAL_DTEND_PROPERTY, icalproperty_get_dtend);
c9b2f7
+				dt = e_cal_backend_ews_get_datetime_with_zone (timezone_cache, vcomp, icalcomp, ICAL_DTEND_PROPERTY, icalproperty_get_dtend);
c9b2f7
 				dt = icaltime_convert_to_zone (dt, zone);
c9b2f7
 				icalcomponent_set_dtend (icalcomp, dt);
c9b2f7
 			}
c9b2f7
@@ -2930,7 +2930,7 @@ ecb_ews_send_cancellation_email_sync (EC
c9b2f7
 	icalcomponent_add_property (vevent, icalproperty_new_status (ICAL_STATUS_CANCELLED));
c9b2f7
 	prop = icalcomponent_get_first_property (vevent, ICAL_METHOD_PROPERTY);
c9b2f7
 	if (prop != NULL) icalcomponent_remove_property (vevent, prop);
c9b2f7
-	dt = e_cal_backend_ews_get_datetime_with_zone (E_TIMEZONE_CACHE (cbews), vevent, ICAL_DTSTART_PROPERTY, icalproperty_get_dtstart);
c9b2f7
+	dt = e_cal_backend_ews_get_datetime_with_zone (E_TIMEZONE_CACHE (cbews), NULL, vevent, ICAL_DTSTART_PROPERTY, icalproperty_get_dtstart);
c9b2f7
 	icaltz = (icaltimezone *)
c9b2f7
 		(dt.zone ? dt.zone : ecb_ews_get_timezone_from_ical_component (cbews, vevent));
c9b2f7
 	vtz = icaltimezone_get_component (icaltz);
c9b2f7
@@ -2973,6 +2973,7 @@ ecb_ews_send_cancellation_email_sync (EC
c9b2f7
 
c9b2f7
 static void
c9b2f7
 ecb_ews_receive_objects_no_exchange_mail (ECalBackendEws *cbews,
c9b2f7
+					  icalcomponent *vcalendar,
c9b2f7
 					  icalcomponent *subcomp,
c9b2f7
 					  GSList **ids,
c9b2f7
 					  GCancellable *cancellable,
c9b2f7
@@ -2984,6 +2985,7 @@ ecb_ews_receive_objects_no_exchange_mail
c9b2f7
 	convert_data.connection = cbews->priv->cnc;
c9b2f7
 	convert_data.timezone_cache = E_TIMEZONE_CACHE (cbews);
c9b2f7
 	convert_data.icalcomp = subcomp;
c9b2f7
+	convert_data.vcalendar = vcalendar;
c9b2f7
 	convert_data.default_zone = icaltimezone_get_utc_timezone ();
c9b2f7
 
c9b2f7
 	fid = e_ews_folder_id_new (cbews->priv->folder_id, NULL, FALSE);
c9b2f7
@@ -3228,6 +3230,7 @@ ecb_ews_get_item_accept_id (ECalComponen
c9b2f7
 
c9b2f7
 static gboolean
c9b2f7
 ecb_ews_do_method_request_publish_reply (ECalBackendEws *cbews,
c9b2f7
+					 icalcomponent *vcalendar,
c9b2f7
 					 ECalComponent *comp,
c9b2f7
 					 icalcomponent *subcomp,
c9b2f7
 					 const gchar *response_type,
c9b2f7
@@ -3258,7 +3261,7 @@ ecb_ews_do_method_request_publish_reply
c9b2f7
 	while (pass < 2) {
c9b2f7
 		/*in case we do not have item id we will create item with mime content only*/
c9b2f7
 		if (!item_id || (response_type && g_ascii_strcasecmp (response_type, "NEEDS-ACTION") == 0)) {
c9b2f7
-			ecb_ews_receive_objects_no_exchange_mail (cbews, subcomp, &ids, cancellable, &local_error);
c9b2f7
+			ecb_ews_receive_objects_no_exchange_mail (cbews, vcalendar, subcomp, &ids, cancellable, &local_error);
c9b2f7
 		} else {
c9b2f7
 			EwsCalendarConvertData convert_data = { 0 };
c9b2f7
 
c9b2f7
@@ -3367,6 +3370,7 @@ ecb_ews_do_method_request_publish_reply
c9b2f7
 			}
c9b2f7
 
c9b2f7
 			convert_data.timezone_cache = E_TIMEZONE_CACHE (cbews);
c9b2f7
+			convert_data.vcalendar = vcalendar;
c9b2f7
 
c9b2f7
 			e_ews_connection_update_items_sync (
c9b2f7
 				cbews->priv->cnc,
c9b2f7
@@ -3452,7 +3456,7 @@ ecb_ews_receive_objects_sync (ECalBacken
c9b2f7
 
c9b2f7
 			comp = e_cal_component_new_from_icalcomponent (icalcomponent_new_clone (subcomp));
c9b2f7
 
c9b2f7
-			success = ecb_ews_do_method_request_publish_reply (cbews, comp, subcomp, response_type, user_email, rsvp_requested, cancellable, error);
c9b2f7
+			success = ecb_ews_do_method_request_publish_reply (cbews, icalcomp, comp, subcomp, response_type, user_email, rsvp_requested, cancellable, error);
c9b2f7
 
c9b2f7
 			do_refresh = TRUE;
c9b2f7
 
c9b2f7
diff -up evolution-ews-3.28.5/src/calendar/e-cal-backend-ews-utils.c.import-event-timezone evolution-ews-3.28.5/src/calendar/e-cal-backend-ews-utils.c
c9b2f7
--- evolution-ews-3.28.5/src/calendar/e-cal-backend-ews-utils.c.import-event-timezone	2018-07-30 16:01:00.000000000 +0200
c9b2f7
+++ evolution-ews-3.28.5/src/calendar/e-cal-backend-ews-utils.c	2018-09-04 11:16:58.892645453 +0200
c9b2f7
@@ -178,7 +178,8 @@ e_cal_backend_ews_tz_util_get_msdn_equiv
c9b2f7
 {
c9b2f7
 	const gchar *msdn_tz_location = NULL;
c9b2f7
 
c9b2f7
-	g_return_val_if_fail (ical_tz_location != NULL, NULL);
c9b2f7
+	if (!ical_tz_location || !*ical_tz_location)
c9b2f7
+		return NULL;
c9b2f7
 
c9b2f7
 	g_rec_mutex_lock (&tz_mutex);
c9b2f7
 	if (ical_to_msdn == NULL) {
c9b2f7
@@ -199,7 +200,8 @@ e_cal_backend_ews_tz_util_get_ical_equiv
c9b2f7
 {
c9b2f7
 	const gchar *ical_tz_location = NULL;
c9b2f7
 
c9b2f7
-	g_return_val_if_fail (msdn_tz_location != NULL, NULL);
c9b2f7
+	if (!msdn_tz_location || !*msdn_tz_location)
c9b2f7
+		return NULL;
c9b2f7
 
c9b2f7
 	g_rec_mutex_lock (&tz_mutex);
c9b2f7
 	if (msdn_to_ical == NULL) {
c9b2f7
@@ -1113,11 +1115,11 @@ convert_vevent_calcomp_to_xml (ESoapMess
c9b2f7
 		e_ews_message_write_string_parameter (msg, "ReminderIsSet", NULL, "false");
c9b2f7
 
c9b2f7
 	/* start time, end time and meeting time zone */
c9b2f7
-	dtstart = e_cal_backend_ews_get_datetime_with_zone (convert_data->timezone_cache, icalcomp, ICAL_DTSTART_PROPERTY, icalproperty_get_dtstart);
c9b2f7
+	dtstart = e_cal_backend_ews_get_datetime_with_zone (convert_data->timezone_cache, convert_data->vcalendar, icalcomp, ICAL_DTSTART_PROPERTY, icalproperty_get_dtstart);
c9b2f7
 	tzid_start = (icaltimezone *) (dtstart.zone ? dtstart.zone : convert_data->default_zone);
c9b2f7
 	ical_location_start = icaltimezone_get_location (tzid_start);
c9b2f7
 
c9b2f7
-	dtend = e_cal_backend_ews_get_datetime_with_zone (convert_data->timezone_cache, icalcomp, ICAL_DTEND_PROPERTY, icalproperty_get_dtend);
c9b2f7
+	dtend = e_cal_backend_ews_get_datetime_with_zone (convert_data->timezone_cache, convert_data->vcalendar, icalcomp, ICAL_DTEND_PROPERTY, icalproperty_get_dtend);
c9b2f7
 	tzid_end = (icaltimezone *) (dtend.zone ? dtend.zone : convert_data->default_zone);
c9b2f7
 	ical_location_end = icaltimezone_get_location (tzid_end);
c9b2f7
 
c9b2f7
@@ -1272,7 +1274,7 @@ convert_vtodo_calcomp_to_xml (ESoapMessa
c9b2f7
 
c9b2f7
 	prop = icalcomponent_get_first_property (icalcomp, ICAL_DUE_PROPERTY);
c9b2f7
 	if (prop) {
c9b2f7
-		dt = e_cal_backend_ews_get_datetime_with_zone (convert_data->timezone_cache, icalcomp, ICAL_DUE_PROPERTY, icalproperty_get_due);
c9b2f7
+		dt = e_cal_backend_ews_get_datetime_with_zone (convert_data->timezone_cache, convert_data->vcalendar, icalcomp, ICAL_DUE_PROPERTY, icalproperty_get_due);
c9b2f7
 		e_ews_cal_utils_set_time (msg, "DueDate", &dt, TRUE);
c9b2f7
 	}
c9b2f7
 
c9b2f7
@@ -1285,7 +1287,7 @@ convert_vtodo_calcomp_to_xml (ESoapMessa
c9b2f7
 
c9b2f7
 	prop = icalcomponent_get_first_property (icalcomp, ICAL_DTSTART_PROPERTY);
c9b2f7
 	if (prop) {
c9b2f7
-		dt = e_cal_backend_ews_get_datetime_with_zone (convert_data->timezone_cache, icalcomp, ICAL_DTSTART_PROPERTY, icalproperty_get_dtstart);
c9b2f7
+		dt = e_cal_backend_ews_get_datetime_with_zone (convert_data->timezone_cache, convert_data->vcalendar, icalcomp, ICAL_DTSTART_PROPERTY, icalproperty_get_dtstart);
c9b2f7
 		e_ews_cal_utils_set_time (msg, "StartDate", &dt, TRUE);
c9b2f7
 	}
c9b2f7
 
c9b2f7
@@ -1536,8 +1538,8 @@ convert_vevent_component_to_updatexml (E
c9b2f7
 	}
c9b2f7
 	/* Update other properties allowed only for meeting organizers*/
c9b2f7
 	/*meeting dates*/
c9b2f7
-	dtstart = e_cal_backend_ews_get_datetime_with_zone (convert_data->timezone_cache, icalcomp, ICAL_DTSTART_PROPERTY, icalproperty_get_dtstart);
c9b2f7
-	dtstart_old = e_cal_backend_ews_get_datetime_with_zone (convert_data->timezone_cache, icalcomp_old, ICAL_DTSTART_PROPERTY, icalproperty_get_dtstart);
c9b2f7
+	dtstart = e_cal_backend_ews_get_datetime_with_zone (convert_data->timezone_cache, convert_data->vcalendar, icalcomp, ICAL_DTSTART_PROPERTY, icalproperty_get_dtstart);
c9b2f7
+	dtstart_old = e_cal_backend_ews_get_datetime_with_zone (convert_data->timezone_cache, convert_data->vcalendar, icalcomp_old, ICAL_DTSTART_PROPERTY, icalproperty_get_dtstart);
c9b2f7
 	dt_start_changed = icaltime_compare (dtstart, dtstart_old) != 0;
c9b2f7
 	if (dtstart.zone != NULL) {
c9b2f7
 		tzid_start = (icaltimezone *) dtstart.zone;
c9b2f7
@@ -1548,8 +1550,8 @@ convert_vevent_component_to_updatexml (E
c9b2f7
 			dt_start_changed_timezone_name = TRUE;
c9b2f7
 	}
c9b2f7
 
c9b2f7
-	dtend = e_cal_backend_ews_get_datetime_with_zone (convert_data->timezone_cache, icalcomp, ICAL_DTEND_PROPERTY, icalproperty_get_dtend);
c9b2f7
-	dtend_old = e_cal_backend_ews_get_datetime_with_zone (convert_data->timezone_cache, icalcomp_old, ICAL_DTEND_PROPERTY, icalproperty_get_dtend);
c9b2f7
+	dtend = e_cal_backend_ews_get_datetime_with_zone (convert_data->timezone_cache, convert_data->vcalendar, icalcomp, ICAL_DTEND_PROPERTY, icalproperty_get_dtend);
c9b2f7
+	dtend_old = e_cal_backend_ews_get_datetime_with_zone (convert_data->timezone_cache, convert_data->vcalendar, icalcomp_old, ICAL_DTEND_PROPERTY, icalproperty_get_dtend);
c9b2f7
 	dt_end_changed = icaltime_compare (dtend, dtend_old) != 0;
c9b2f7
 	if (dtend.zone != NULL) {
c9b2f7
 		tzid_end = (icaltimezone *) dtend.zone;
c9b2f7
@@ -1768,7 +1770,7 @@ convert_vtodo_component_to_updatexml (ES
c9b2f7
 
c9b2f7
 	prop = icalcomponent_get_first_property (icalcomp, ICAL_DUE_PROPERTY);
c9b2f7
 	if (prop) {
c9b2f7
-		dt = e_cal_backend_ews_get_datetime_with_zone (convert_data->timezone_cache, icalcomp, ICAL_DUE_PROPERTY, icalproperty_get_due);
c9b2f7
+		dt = e_cal_backend_ews_get_datetime_with_zone (convert_data->timezone_cache, convert_data->vcalendar, icalcomp, ICAL_DUE_PROPERTY, icalproperty_get_due);
c9b2f7
 		e_ews_message_start_set_item_field (msg, "DueDate", "task", "Task");
c9b2f7
 		e_ews_cal_utils_set_time (msg, "DueDate", &dt, TRUE);
c9b2f7
 		e_ews_message_end_set_item_field (msg);
c9b2f7
@@ -1787,7 +1789,7 @@ convert_vtodo_component_to_updatexml (ES
c9b2f7
 
c9b2f7
 	prop = icalcomponent_get_first_property (icalcomp, ICAL_DTSTART_PROPERTY);
c9b2f7
 	if (prop) {
c9b2f7
-		dt = e_cal_backend_ews_get_datetime_with_zone (convert_data->timezone_cache, icalcomp, ICAL_DTSTART_PROPERTY, icalproperty_get_dtstart);
c9b2f7
+		dt = e_cal_backend_ews_get_datetime_with_zone (convert_data->timezone_cache, convert_data->vcalendar, icalcomp, ICAL_DTSTART_PROPERTY, icalproperty_get_dtstart);
c9b2f7
 		e_ews_message_start_set_item_field (msg, "StartDate", "task", "Task");
c9b2f7
 		e_ews_cal_utils_set_time (msg, "StartDate", &dt, TRUE);
c9b2f7
 		e_ews_message_end_set_item_field (msg);
c9b2f7
@@ -2011,6 +2013,7 @@ e_cal_backend_ews_prepare_accept_item_re
c9b2f7
 
c9b2f7
 struct icaltimetype
c9b2f7
 e_cal_backend_ews_get_datetime_with_zone (ETimezoneCache *timezone_cache,
c9b2f7
+					  icalcomponent *vcalendar,
c9b2f7
 					  icalcomponent *comp,
c9b2f7
 					  icalproperty_kind prop_kind,
c9b2f7
 					  struct icaltimetype (* get_func) (const icalproperty *prop))
c9b2f7
@@ -2018,7 +2021,7 @@ e_cal_backend_ews_get_datetime_with_zone
c9b2f7
 	struct icaltimetype dt = icaltime_null_time ();
c9b2f7
 	icalproperty *prop;
c9b2f7
 	icalparameter *param;
c9b2f7
-	const gchar *tzid;
c9b2f7
+	const gchar *tzid, *eqv_tzid;
c9b2f7
 
c9b2f7
 	g_return_val_if_fail (E_IS_TIMEZONE_CACHE (timezone_cache), dt);
c9b2f7
 	g_return_val_if_fail (comp != NULL, dt);
c9b2f7
@@ -2034,6 +2037,8 @@ e_cal_backend_ews_get_datetime_with_zone
c9b2f7
 	    icaltime_is_null_time (dt))
c9b2f7
 		return dt;
c9b2f7
 
c9b2f7
+	dt.zone = NULL;
c9b2f7
+
c9b2f7
 	param = icalproperty_get_first_parameter (prop, ICAL_TZID_PARAMETER);
c9b2f7
 	if (!param)
c9b2f7
 		return dt;
c9b2f7
@@ -2042,7 +2047,23 @@ e_cal_backend_ews_get_datetime_with_zone
c9b2f7
 	if (!tzid || !*tzid)
c9b2f7
 		return dt;
c9b2f7
 
c9b2f7
-	dt.zone = e_timezone_cache_get_timezone (timezone_cache, tzid);
c9b2f7
+	eqv_tzid = e_cal_backend_ews_tz_util_get_ical_equivalent (tzid);
c9b2f7
+
c9b2f7
+	if (!eqv_tzid) {
c9b2f7
+		/* Unlikely to work, but just in case */
c9b2f7
+		eqv_tzid = e_cal_backend_ews_tz_util_get_msdn_equivalent (tzid);
c9b2f7
+		if (eqv_tzid)
c9b2f7
+			eqv_tzid = e_cal_backend_ews_tz_util_get_ical_equivalent (eqv_tzid);
c9b2f7
+	}
c9b2f7
+
c9b2f7
+	if (eqv_tzid)
c9b2f7
+		dt.zone = e_timezone_cache_get_timezone (timezone_cache, eqv_tzid);
c9b2f7
+
c9b2f7
+	if (!dt.zone)
c9b2f7
+		dt.zone = e_timezone_cache_get_timezone (timezone_cache, tzid);
c9b2f7
+
c9b2f7
+	if (!dt.zone)
c9b2f7
+		dt.zone = vcalendar ? icalcomponent_get_timezone (vcalendar, tzid) : NULL;
c9b2f7
 
c9b2f7
 	return dt;
c9b2f7
 }
c9b2f7
diff -up evolution-ews-3.28.5/src/calendar/e-cal-backend-ews-utils.h.import-event-timezone evolution-ews-3.28.5/src/calendar/e-cal-backend-ews-utils.h
c9b2f7
--- evolution-ews-3.28.5/src/calendar/e-cal-backend-ews-utils.h.import-event-timezone	2018-07-30 16:01:00.000000000 +0200
c9b2f7
+++ evolution-ews-3.28.5/src/calendar/e-cal-backend-ews-utils.h	2018-09-04 11:14:27.814647542 +0200
c9b2f7
@@ -47,6 +47,7 @@ typedef struct {
c9b2f7
 	ECalComponent *comp;
c9b2f7
 	ECalComponent *old_comp;
c9b2f7
 	icalcomponent *icalcomp;
c9b2f7
+	icalcomponent *vcalendar; /* can be NULL, parent of icalcomp, where timezones can be eventually found */
c9b2f7
 	gchar *item_id;
c9b2f7
 	gchar *change_key;
c9b2f7
 	EEwsItemChangeType change_type;
c9b2f7
@@ -82,6 +83,7 @@ guint e_cal_backend_ews_rid_to_index (ic
c9b2f7
 
c9b2f7
 struct icaltimetype
c9b2f7
 		e_cal_backend_ews_get_datetime_with_zone	(ETimezoneCache *timezone_cache,
c9b2f7
+								 icalcomponent *vcalendar,
c9b2f7
 								 icalcomponent *comp,
c9b2f7
 								 icalproperty_kind prop_kind,
c9b2f7
 								 struct icaltimetype (* get_func) (const icalproperty *prop));