Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Freebusy floating timezone #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 3 additions & 26 deletions imap/caldav_alarm.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,29 +453,6 @@ static int update_alarmdb(const char *mboxname,
return -1;
}

static icaltimezone *get_floatingtz(const char *mailbox, const char *userid)
{
icaltimezone *floatingtz = NULL;

struct buf buf = BUF_INITIALIZER;
const char *annotname = DAV_ANNOT_NS "<" XML_NS_CALDAV ">calendar-timezone";
if (!annotatemore_lookupmask(mailbox, annotname, userid, &buf)) {
icalcomponent *comp = NULL;
comp = icalparser_parse_string(buf_cstring(&buf));
icalcomponent *subcomp =
icalcomponent_get_first_component(comp, ICAL_VTIMEZONE_COMPONENT);
if (subcomp) {
floatingtz = icaltimezone_new();
icalcomponent_remove_component(comp, subcomp);
icaltimezone_set_component(floatingtz, subcomp);
}
icalcomponent_free(comp);
}
buf_free(&buf);

return floatingtz;
}

static icalcomponent *vpatch_from_peruserdata(const struct buf *userdata)
{
struct dlist *dl;
Expand Down Expand Up @@ -784,7 +761,7 @@ static int process_peruser_alarms_cb(const char *mailbox, uint32_t uid,
icalcomponent_free(vpatch);

/* Fetch per-user timezone for floating events */
floatingtz = get_floatingtz(mailbox, userid);
floatingtz = caldav_mailbox_floatingtz(mailbox, userid);

/* Process any VALARMs in the patched iCalendar resource */
check = process_alarms(mailbox, uid, userid, floatingtz, myical,
Expand Down Expand Up @@ -914,7 +891,7 @@ static void process_records(ptrarray_t *list, time_t runtime)
/* transient open error, don't delete this alarm */
continue;
}
floatingtz = get_floatingtz(mailbox->name, "");
floatingtz = caldav_mailbox_floatingtz(mailbox->name, "");
}
process_one_record(mailbox, data->imap_uid, floatingtz, runtime);
}
Expand Down Expand Up @@ -1009,7 +986,7 @@ EXPORTED int caldav_alarm_upgrade()
caldav_alarm_close(alarmdb);
if (rc) continue;

icaltimezone *floatingtz = get_floatingtz(mailbox->name, "");
icaltimezone *floatingtz = caldav_mailbox_floatingtz(mailbox->name, "");

/* add alarms for all records */
struct mailbox_iter *iter =
Expand Down
24 changes: 24 additions & 0 deletions imap/caldav_db.c
Original file line number Diff line number Diff line change
Expand Up @@ -783,3 +783,27 @@ EXPORTED int caldav_get_events(struct caldav_db *caldavdb,

return r;
}

EXPORTED icaltimezone *caldav_mailbox_floatingtz(const char *mailbox,
const char *userid)
{
icaltimezone *floatingtz = NULL;

struct buf buf = BUF_INITIALIZER;
const char *annotname = DAV_ANNOT_NS "<" XML_NS_CALDAV ">calendar-timezone";
if (!annotatemore_lookupmask(mailbox, annotname, userid, &buf)) {
icalcomponent *comp = NULL;
comp = icalparser_parse_string(buf_cstring(&buf));
icalcomponent *subcomp =
icalcomponent_get_first_component(comp, ICAL_VTIMEZONE_COMPONENT);
if (subcomp) {
floatingtz = icaltimezone_new();
icalcomponent_remove_component(comp, subcomp);
icaltimezone_set_component(floatingtz, subcomp);
}
icalcomponent_free(comp);
}
buf_free(&buf);

return floatingtz;
}
5 changes: 5 additions & 0 deletions imap/caldav_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,9 @@ int caldav_get_updates(struct caldav_db *caldavdb,
modseq_t oldmodseq, const char *mailbox, int kind,
int max_records, caldav_cb_t *cb, void *rock);


/* Find the floating timezone on a calendar */
icaltimezone *caldav_mailbox_floatingtz(const char *mailbox,
const char *userid);

#endif /* CALDAV_DB_H */
24 changes: 18 additions & 6 deletions imap/http_caldav.c
Original file line number Diff line number Diff line change
Expand Up @@ -5346,7 +5346,8 @@ static int expand_cb(icalcomponent *comp,
/* Expand recurrences of ical in range.
NOTE: expand_cb() is destructive of ical as it builds expanded_ical */
static icalcomponent *expand_caldata(icalcomponent **ical,
struct icalperiodtype range)
struct icalperiodtype range,
icaltimezone *floatingtz)
{
icalcomponent *expanded_ical =
icalcomponent_vanew(ICAL_VCALENDAR_COMPONENT,
Expand All @@ -5360,10 +5361,10 @@ static icalcomponent *expand_caldata(icalcomponent **ical,
if (prop)
icalcomponent_add_property(expanded_ical, icalproperty_new_clone(prop));

icalcomponent_myforeach(*ical, range, NULL, expand_cb, expanded_ical);
icalcomponent_myforeach(*ical, range, floatingtz, expand_cb, expanded_ical);
icalcomponent_free(*ical);
*ical = expanded_ical;

return *ical;
}

Expand Down Expand Up @@ -5525,7 +5526,7 @@ static int propfind_caldata(const xmlChar *name, xmlNsPtr ns,
ical = fctx->obj;

if (partial->expand) {
fctx->obj = expand_caldata(&ical, partial->range);
fctx->obj = expand_caldata(&ical, partial->range, NULL);
}
else limit_caldata(ical, &partial->range);
}
Expand Down Expand Up @@ -6886,7 +6887,8 @@ static void expand_occurrences(icalcomponent *ical,
struct icalperiodtype rangespan =
{ fbfilter->start, fbfilter->end, icaldurationtype_null_duration() };

icalcomponent_myforeach(ical, rangespan, NULL, add_freebusy_comp, fbfilter);
icalcomponent_myforeach(ical, rangespan, fbfilter->floatingtz,
add_freebusy_comp, fbfilter);
}


Expand Down Expand Up @@ -7043,7 +7045,16 @@ static int busytime_by_collection(const mbentry_t *mbentry, void *rock)
}
}

return propfind_by_collection(mbentry, rock);
fbfilter->floatingtz = caldav_mailbox_floatingtz(mboxname, fctx->userid);

int r = propfind_by_collection(mbentry, rock);

if (fbfilter->floatingtz) {
icaltimezone_free(fbfilter->floatingtz, 1);
fbfilter->floatingtz = NULL;
}
return r;

}


Expand Down Expand Up @@ -7104,6 +7115,7 @@ static void combine_vavailability(struct freebusy_filter *fbfilter)
unsigned i, j;

memset(&availfilter, 0, sizeof(struct freebusy_filter));
availfilter.floatingtz = fbfilter->floatingtz;

/* Sort VAVAILABILITY periods by priority and start time */
qsort(vavail->vav, vavail->len,
Expand Down
2 changes: 1 addition & 1 deletion imap/http_caldav_sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ struct freebusy_filter {
unsigned flags;
struct icaltimetype start;
struct icaltimetype end;
icaltimezone *tz;
icaltimezone *floatingtz;
struct freebusy_array freebusy; /* array of found freebusy periods */
struct vavailability_array vavail; /* array of found vavail components */
};
Expand Down