+ /* Look for properties containing timezone parameters, to see if we need to attach VTIMEZONEs */
+ for (p = icalcomponent_get_first_property(the_request, ICAL_ANY_PROPERTY);
+ p != NULL;
+ p = icalcomponent_get_next_property(the_request, ICAL_ANY_PROPERTY))
+ {
+ if ( (icalproperty_isa(p) == ICAL_COMPLETED_PROPERTY)
+ || (icalproperty_isa(p) == ICAL_CREATED_PROPERTY)
+ || (icalproperty_isa(p) == ICAL_DATEMAX_PROPERTY)
+ || (icalproperty_isa(p) == ICAL_DATEMIN_PROPERTY)
+ || (icalproperty_isa(p) == ICAL_DTEND_PROPERTY)
+ || (icalproperty_isa(p) == ICAL_DTSTAMP_PROPERTY)
+ || (icalproperty_isa(p) == ICAL_DTSTART_PROPERTY)
+ || (icalproperty_isa(p) == ICAL_DUE_PROPERTY)
+ || (icalproperty_isa(p) == ICAL_EXDATE_PROPERTY)
+ || (icalproperty_isa(p) == ICAL_LASTMODIFIED_PROPERTY)
+ || (icalproperty_isa(p) == ICAL_MAXDATE_PROPERTY)
+ || (icalproperty_isa(p) == ICAL_MINDATE_PROPERTY)
+ || (icalproperty_isa(p) == ICAL_RECURRENCEID_PROPERTY)
+ ) {
+ t = icalproperty_get_dtstart(p); // it's safe to use dtstart for all of them
+
+ /* Determine the tzid in order for some of the conditions below to work */
+ tzidp = icalproperty_get_first_parameter(p, ICAL_TZID_PARAMETER);
+ if (tzidp) {
+ tzidc = icalparameter_get_tzid(tzidp);
+ }
+ else {
+ tzidc = NULL;
+ }
+
+ /* First see if there's a timezone attached to the data structure itself */
+ if (icaltime_is_utc(t)) {
+ z = icaltimezone_get_utc_timezone();
+ }
+ else {
+ z = icaltime_get_timezone(t);
+ }
+
+ /* If not, try to determine the tzid from the parameter using attached zones */
+ if ((!z) && (tzidc)) {
+ z = icalcomponent_get_timezone(top_level_cal, tzidc);
+ }
+
+ /* Still no good? Try our internal database */
+ if ((!z) && (tzidc)) {
+ z = icaltimezone_get_builtin_timezone_from_tzid(tzidc);
+ }
+
+ if (z) {
+ /* We have a valid timezone. Good. Now we need to attach it. */
+
+ zone_already_attached = 0;
+ for (i=0; i<5; ++i) {
+ if (z == attached_zones[i]) {
+ /* We've already got this one, no need to attach another. */
+ ++zone_already_attached;
+ }
+ }
+ if ((!zone_already_attached) && (num_zones_attached < 5)) {
+ /* This is a new one, so attach it. */
+ attached_zones[num_zones_attached++] = z;
+ }
+
+ icalproperty_set_parameter(p,
+ icalparameter_new_tzid(icaltimezone_get_tzid(z))
+ );
+ }
+ }
+ }
+
+ /* Encapsulate any timezones we need */
+ if (num_zones_attached > 0) for (i=0; i<num_zones_attached; ++i) {
+ icalcomponent *zc;
+ zc = icalcomponent_new_clone(icaltimezone_get_component(attached_zones[i]));
+ icalcomponent_add_component(encaps, zc);
+ }
+
+ /* Here we go: encapsulate the VEVENT into the VCALENDAR. We now no longer