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

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