8fddca2
From 1966c22fc4249a1157a4d4c1224138ce78653514 Mon Sep 17 00:00:00 2001
8fddca2
From: Ken Murchison <murch@andrew.cmu.edu>
8fddca2
Date: Sat, 21 Oct 2017 19:04:08 -0400
8fddca2
Subject: [PATCH] Account for the removal of icaltimetype.is_utc field in
8fddca2
 upcoming libical
8fddca2
8fddca2
---
8fddca2
 configure.ac             |  5 +++++
8fddca2
 imap/http_caldav.c       |  2 +-
8fddca2
 imap/http_caldav_sched.c |  4 ++--
8fddca2
 imap/http_tzdist.c       | 22 +++++++++++-----------
8fddca2
 imap/ical_support.c      |  9 +++++++++
8fddca2
 imap/ical_support.h      |  2 ++
8fddca2
 imap/jmap_ical.c         |  4 ++--
8fddca2
 imap/xcal.c              |  4 ++--
8fddca2
 8 files changed, 34 insertions(+), 18 deletions(-)
8fddca2
8fddca2
diff --git a/configure.ac b/configure.ac
8fddca2
index b7f2d0da9..8eb11966d 100644
8fddca2
--- a/configure.ac
8fddca2
+++ b/configure.ac
8fddca2
@@ -1492,6 +1492,11 @@ dnl
8fddca2
                         icalrecur_freq_to_string, icalrecur_weekday_to_string],
8fddca2
                 [], [], [[#include <libical/ical.h>]])
8fddca2
 
8fddca2
+        AC_CHECK_MEMBER(icaltimetype.is_utc,
8fddca2
+                AC_DEFINE(ICALTIME_HAS_IS_UTC,[],
8fddca2
+                        [Does icaltimetype have is_utc field?]),
8fddca2
+                        [], [#include <libical/ical.h>])
8fddca2
+
8fddca2
         AC_CHECK_LIB(ical, icalproperty_new_acknowledged,
8fddca2
                 AC_DEFINE(HAVE_VALARM_EXT_PROPS,[],
8fddca2
                         [Do we have built-in support for VALARM extensions props?]))
8fddca2
diff --git a/imap/http_caldav.c b/imap/http_caldav.c
8fddca2
index eb9d4add1..4cb11d228 100644
8fddca2
--- a/imap/http_caldav.c
8fddca2
+++ b/imap/http_caldav.c
8fddca2
@@ -2391,7 +2391,7 @@ static struct icaltimetype icaltime_from_rfc3339_string(const char *str)
8fddca2
         goto fail;
8fddca2
     }
8fddca2
 
8fddca2
-    tt.is_utc = 1;
8fddca2
+    icaltime_set_utc(&tt, 1);
8fddca2
     return tt;
8fddca2
 
8fddca2
   fail:
8fddca2
diff --git a/imap/http_caldav_sched.c b/imap/http_caldav_sched.c
8fddca2
index 1dc97a501..b896d871a 100644
8fddca2
--- a/imap/http_caldav_sched.c
8fddca2
+++ b/imap/http_caldav_sched.c
8fddca2
@@ -355,7 +355,7 @@ static int imip_send_sendmail(icalcomponent *ical,
8fddca2
     cp += sprintf(cp, "%s, %02u %s %04u",
8fddca2
                   day_of_week[icaltime_day_of_week(start)-1],
8fddca2
                   start.day, month_of_year[start.month-1], start.year);
8fddca2
-    if (!start.is_date) {
8fddca2
+    if (!icaltime_is_date(start)) {
8fddca2
         cp += sprintf(cp, " %02u:%02u", start.hour, start.minute);
8fddca2
         if (start.second) cp += sprintf(cp, ":%02u", start.second);
8fddca2
         strcpy(cp, " UTC");
8fddca2
@@ -370,7 +370,7 @@ static int imip_send_sendmail(icalcomponent *ical,
8fddca2
                           day_of_week[icaltime_day_of_week(end)-1],
8fddca2
                           end.day, month_of_year[end.month-1], end.year);
8fddca2
         }
8fddca2
-        if (!end.is_date) {
8fddca2
+        if (!icaltime_is_date(end)) {
8fddca2
             cp += sprintf(cp, " %02u:%02u", end.hour, end.minute);
8fddca2
             if (end.second) cp += sprintf(cp, ":%02u", end.second);
8fddca2
             strcpy(cp, " UTC");
8fddca2
diff --git a/imap/http_tzdist.c b/imap/http_tzdist.c
8fddca2
index 258440ce9..a88e8bf68 100644
8fddca2
--- a/imap/http_tzdist.c
8fddca2
+++ b/imap/http_tzdist.c
8fddca2
@@ -1376,7 +1376,7 @@ static void truncate_vtimezone(icalcomponent *vtz,
8fddca2
 
8fddca2
         /* Adjust DTSTART observance to UTC */
8fddca2
         icaltime_adjust(&obs.onset, 0, 0, 0, -obs.offset_from);
8fddca2
-        obs.onset.is_utc = 1;
8fddca2
+        icaltime_set_utc(&obs.onset, 1);
8fddca2
 
8fddca2
         /* Check DTSTART vs window close */
8fddca2
         if (!icaltime_is_null_time(end) &&
8fddca2
@@ -1451,7 +1451,7 @@ static void truncate_vtimezone(icalcomponent *vtz,
8fddca2
                 if (!eternal) {
8fddca2
                     /* Adjust UNTIL to local time (for iterator) */
8fddca2
                     icaltime_adjust(&rrule.until, 0, 0, 0, obs.offset_from);
8fddca2
-                    rrule.until.is_utc = 0;
8fddca2
+                    icaltime_set_utc(&rrule.until, 0);
8fddca2
                 }
8fddca2
 
8fddca2
                 if (trunc_dtstart) {
8fddca2
@@ -1475,7 +1475,7 @@ static void truncate_vtimezone(icalcomponent *vtz,
8fddca2
 
8fddca2
                     /* Adjust observance to UTC */
8fddca2
                     icaltime_adjust(&obs.onset, 0, 0, 0, -obs.offset_from);
8fddca2
-                    obs.onset.is_utc = 1;
8fddca2
+                    icaltime_set_utc(&obs.onset, 1);
8fddca2
 
8fddca2
                     if (trunc_until && icaltime_compare(obs.onset, end) >= 0) {
8fddca2
                         /* Observance is on/after window close */
8fddca2
@@ -1580,7 +1580,7 @@ static void truncate_vtimezone(icalcomponent *vtz,
8fddca2
 
8fddca2
             /* Adjust observance to UTC */
8fddca2
             icaltime_adjust(&obs.onset, 0, 0, 0, -obs.offset_from);
8fddca2
-            obs.onset.is_utc = 1;
8fddca2
+            icaltime_set_utc(&obs.onset, 1);
8fddca2
 
8fddca2
             if (!icaltime_is_null_time(end) &&
8fddca2
                 icaltime_compare(obs.onset, end) >= 0) {
8fddca2
@@ -1691,7 +1691,7 @@ static void truncate_vtimezone(icalcomponent *vtz,
8fddca2
             case ICAL_DTSTART_PROPERTY:
8fddca2
                 /* Adjust window open to local time */
8fddca2
                 icaltime_adjust(&start, 0, 0, 0, tombstone.offset_from);
8fddca2
-                start.is_utc = 0;
8fddca2
+                icaltime_set_utc(&start, 0);
8fddca2
 
8fddca2
                 icalproperty_set_dtstart(prop, start);
8fddca2
                 break;
8fddca2
@@ -1775,14 +1775,14 @@ static int action_get(struct transaction_t *txn)
8fddca2
     /* Sanity check the parameters */
8fddca2
     if ((param = hash_lookup("start", &txn->req_qparams))) {
8fddca2
         start = icaltime_from_string(param->s);
8fddca2
-        if (param->next || !start.is_utc) {  /* once only, UTC */
8fddca2
+        if (param->next || !icaltime_is_utc(start)) {  /* once only, UTC */
8fddca2
             return json_error_response(txn, TZ_INVALID_START, param, &start;;
8fddca2
         }
8fddca2
     }
8fddca2
 
8fddca2
     if ((param = hash_lookup("end", &txn->req_qparams))) {
8fddca2
         end = icaltime_from_string(param->s);
8fddca2
-        if (param->next || !end.is_utc  /* once only, UTC */
8fddca2
+        if (param->next || !icaltime_is_utc(end)  /* once only, UTC */
8fddca2
             || icaltime_compare(end, start) <= 0) {  /* end MUST be > start */
8fddca2
             return json_error_response(txn, TZ_INVALID_END, param, &end;;
8fddca2
         }
8fddca2
@@ -1956,7 +1956,7 @@ static int action_expand(struct transaction_t *txn)
8fddca2
         return json_error_response(txn, TZ_INVALID_START, param, NULL);
8fddca2
 
8fddca2
     start = icaltime_from_string(param->s);
8fddca2
-    if (!start.is_utc)  /* MUST be UTC */
8fddca2
+    if (!icaltime_is_utc(start))  /* MUST be UTC */
8fddca2
         return json_error_response(txn, TZ_INVALID_START, param, &start;;
8fddca2
 
8fddca2
     param = hash_lookup("end", &txn->req_qparams);
8fddca2
@@ -1964,7 +1964,7 @@ static int action_expand(struct transaction_t *txn)
8fddca2
         return json_error_response(txn, TZ_INVALID_END, param, NULL);
8fddca2
 
8fddca2
     end = icaltime_from_string(param->s);
8fddca2
-    if (!end.is_utc  /* MUST be UTC */
8fddca2
+    if (!icaltime_is_utc(end)  /* MUST be UTC */
8fddca2
         || icaltime_compare(end, start) <= 0) {  /* end MUST be > start */
8fddca2
         return json_error_response(txn, TZ_INVALID_END, param, &end;;
8fddca2
     }
8fddca2
@@ -2237,7 +2237,7 @@ static int json_error_response(struct transaction_t *txn, long tz_code,
8fddca2
     else if (param->next) fmt = "Multiple %s parameters";
8fddca2
     else if (!param->s || !param->s[0]) fmt = "Missing %s value";
8fddca2
     else if (!time) fmt = "Invalid %s value";
8fddca2
-    else if (!time->is_utc) fmt = "Invalid %s UTC value";
8fddca2
+    else if (!icaltime_is_utc(*time)) fmt = "Invalid %s UTC value";
8fddca2
     else fmt = "End date-time <= start date-time";
8fddca2
 
8fddca2
     assert(!buf_len(&txn->buf));
8fddca2
@@ -2500,7 +2500,7 @@ static struct buf *_icaltimezone_as_tzfile(icalcomponent* ical,
8fddca2
         for (n = 0; n < obsarray->num_elements; n++) {
8fddca2
             long long int t;
8fddca2
             unsigned typeidx;
8fddca2
-            icaltimetype tt_1601 = { 1601, 1, 1, 0, 0, 0, 1, 0, 0, NULL };
8fddca2
+            icaltimetype tt_1601 = icaltime_from_string("1601-01-01T00:00:00Z");
8fddca2
 
8fddca2
             obs = icalarray_element_at(obsarray, n);
8fddca2
             t = icaltime_to_gmtime64(obs->onset);
8fddca2
diff --git a/imap/ical_support.c b/imap/ical_support.c
8fddca2
index 3deb649b1..13861b25a 100644
8fddca2
--- a/imap/ical_support.c
8fddca2
+++ b/imap/ical_support.c
8fddca2
@@ -833,6 +833,15 @@ icalrecurrenceset_get_utc_timespan(icalcomponent *ical,
8fddca2
     return span;
8fddca2
 }
8fddca2
 
8fddca2
+EXPORTED void icaltime_set_utc(struct icaltimetype *t, int set)
8fddca2
+{
8fddca2
+#ifdef ICALTIME_HAS_IS_UTC
8fddca2
+    t->is_utc = set;
8fddca2
+#else
8fddca2
+    icaltime_set_timezone(t, set ? icaltimezone_get_utc_timezone() : NULL);
8fddca2
+#endif
8fddca2
+}
8fddca2
+
8fddca2
 
8fddca2
 #ifndef HAVE_TZDIST_PROPS
8fddca2
 
8fddca2
diff --git a/imap/ical_support.h b/imap/ical_support.h
8fddca2
index 8db35ed1f..0336d59e1 100644
8fddca2
--- a/imap/ical_support.h
8fddca2
+++ b/imap/ical_support.h
8fddca2
@@ -100,6 +100,8 @@ extern struct icalperiodtype icalrecurrenceset_get_utc_timespan(icalcomponent *i
8fddca2
                                                                                 void*),
8fddca2
                                                                 void *cb_rock);
8fddca2
 
8fddca2
+extern void icaltime_set_utc(struct icaltimetype *t, int set);
8fddca2
+
8fddca2
 
8fddca2
 /* Functions not declared in in libical < v2.0 */
8fddca2
 
8fddca2
diff --git a/imap/jmap_ical.c b/imap/jmap_ical.c
8fddca2
index c0d4910f5..dd8460f36 100644
8fddca2
--- a/imap/jmap_ical.c
8fddca2
+++ b/imap/jmap_ical.c
8fddca2
@@ -737,7 +737,7 @@ static const char *tzid_from_icalprop(icalproperty *prop, int guess) {
8fddca2
     } else {
8fddca2
         icalvalue *val = icalproperty_get_value(prop);
8fddca2
         icaltimetype dt = icalvalue_get_datetime(val);
8fddca2
-        if (icaltime_is_valid_time(dt) && dt.is_utc) {
8fddca2
+        if (icaltime_is_valid_time(dt) && icaltime_is_utc(dt)) {
8fddca2
             tzid = "Etc/UTC";
8fddca2
         }
8fddca2
     }
8fddca2
@@ -2615,7 +2615,7 @@ static icalproperty *dtprop_to_ical(icalcomponent *comp,
8fddca2
     /* Set the new property. */
8fddca2
     prop = icalproperty_new(kind);
8fddca2
     icalproperty_set_value(prop, val);
8fddca2
-    if (tz && !dt.is_utc) {
8fddca2
+    if (tz && !icaltime_is_utc(dt)) {
8fddca2
         icalparameter *param = icalproperty_get_first_parameter(prop, ICAL_TZID_PARAMETER);
8fddca2
         const char *tzid = icaltimezone_get_location(tz);
8fddca2
         if (param) {
8fddca2
diff --git a/imap/xcal.c b/imap/xcal.c
8fddca2
index 27a32d96b..36129fdcc 100644
8fddca2
--- a/imap/xcal.c
8fddca2
+++ b/imap/xcal.c
8fddca2
@@ -115,8 +115,8 @@ const char *icaltime_as_iso_string(const struct icaltimetype tt)
8fddca2
     static char str[21];
8fddca2
     const char *fmt;
8fddca2
 
8fddca2
-    if (tt.is_date) fmt = "%04d-%02d-%02d";
8fddca2
-    else if (tt.is_utc) fmt = "%04d-%02d-%02dT%02d:%02d:%02dZ";
8fddca2
+    if (icaltime_is_date(tt)) fmt = "%04d-%02d-%02d";
8fddca2
+    else if (icaltime_is_utc(tt)) fmt = "%04d-%02d-%02dT%02d:%02d:%02dZ";
8fddca2
     else fmt = "%04d-%02d-%02dT%02d:%02d:%02d";
8fddca2
 
8fddca2
     snprintf(str, sizeof(str), fmt, tt.year, tt.month, tt.day,