+/*
+ * Utility function to encapsulate a subcomponent into a full VCALENDAR.
+ *
+ * We also scan for any date/time properties that reference timezones, and attach
+ * those timezones along with the supplied subcomponent. (Increase the size of the array if you need to.)
+ *
+ * Note: if you change anything here, change it in Citadel server's ical_send_out_invitations() too.
+ */
+icalcomponent *ical_encapsulate_subcomponent(icalcomponent *subcomp) {
+ icalcomponent *encaps;
+ icalproperty *p;
+ struct icaltimetype t;
+ const icaltimezone *attached_zones[5] = { NULL, NULL, NULL, NULL, NULL };
+ int i;
+ const icaltimezone *z;
+ int num_zones_attached = 0;
+ int zone_already_attached;
+
+ if (subcomp == NULL) {
+ syslog(LOG_WARNING, "ERROR: ical_encapsulate_subcomponent() called with NULL argument\n");
+ return NULL;
+ }
+
+ /*
+ * If we're already looking at a full VCALENDAR component, this is probably an error.
+ */
+ if (icalcomponent_isa(subcomp) == ICAL_VCALENDAR_COMPONENT) {
+ syslog(LOG_WARNING, "ERROR: component sent to ical_encapsulate_subcomponent() already top level\n");
+ return subcomp;
+ }
+
+ /* search for... */
+ for (p = icalcomponent_get_first_property(subcomp, ICAL_ANY_PROPERTY);
+ p != NULL;
+ p = icalcomponent_get_next_property(subcomp, 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 */
+ if ((icaltime_is_valid_time(t)) && (z=icaltime_get_timezone(t), z)) {
+
+ zone_already_attached = 0;
+ for (i=0; i<5; ++i) {
+ if (z == attached_zones[i]) {
+ ++zone_already_attached;
+ syslog(LOG_DEBUG, "zone already attached!!\n");
+ }
+ }
+ if ((!zone_already_attached) && (num_zones_attached < 5)) {
+ syslog(LOG_DEBUG, "attaching zone %d!\n", num_zones_attached);
+ attached_zones[num_zones_attached++] = z;
+ }