Skip to content

Commit

Permalink
Merge pull request #5065 from rsto/http_caldav_proppatch_timezone_id
Browse files Browse the repository at this point in the history
http_caldav.c: do not require tzdist module for calendar-timezone-id
  • Loading branch information
rsto authored Oct 22, 2024
2 parents 45290f9 + 0612d1e commit cca5510
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 6 deletions.
149 changes: 149 additions & 0 deletions cassandane/tiny-tests/Caldav/rfc7898_calendar_timezone_id
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
#!perl
use Cassandane::Tiny;
use XML::Spice;

sub test_rfc7898_calendar_timezone_id {
my ($self) = @_;
my $caldav = $self->{caldav};

my $vtimezone = <<EOF;
BEGIN:VCALENDAR
PRODID:-//citadel.org//NONSGML Citadel calendar//EN
VERSION:2.0
BEGIN:VTIMEZONE
TZID:Etc/GMT+2
LAST-MODIFIED:20240909T122233Z
BEGIN:STANDARD
TZNAME:Etc/GMT+2
TZOFFSETFROM:-0200
TZOFFSETTO:-0200
DTSTART:16010101T000000
END:STANDARD
END:VTIMEZONE
END:VCALENDAR
EOF

xlog $self, "Verify no timezone or timezone-id is set";
$self->assert_timezone_id(undef);

xlog $self, "Set timezone";
my $res = $caldav->Request(
'PROPPATCH', "/dav/calendars/user/cassandane/Default",
x('D:propertyupdate', $caldav->NS(),
x('D:set',
x('D:prop',
x('C:calendar-timezone', $vtimezone),
),
),
),
);

xlog $self, "Verify timezone and timezone-id are set";
$self->assert_timezone_id("Etc/GMT+2");

xlog $self, "Set timezone-id";
$res = $caldav->Request(
'PROPPATCH', "/dav/calendars/user/cassandane/Default",
x('D:propertyupdate', $caldav->NS(),
x('D:set',
x('D:prop',
x('C:calendar-timezone-id', 'Etc/GMT+2'),
),
),
),
);

xlog $self, "Verify timezone and timezone-id are set";
$self->assert_timezone_id("Etc/GMT+2");

xlog $self, "Delete timezone property";
$res = $caldav->Request(
'PROPPATCH', "/dav/calendars/user/cassandane/Default",
x('D:propertyupdate', $caldav->NS(),
x('D:remove',
x('D:prop',
x('C:calendar-timezone'),
),
),
),
);

xlog $self, "Verify no timezone or timezone-id is set";
$self->assert_timezone_id(undef);

xlog $self, "Set differing timezone and timezone-id, timezone as second";
$res = $caldav->Request(
'PROPPATCH', "/dav/calendars/user/cassandane/Default",
x('D:propertyupdate', $caldav->NS(),
x('D:set',
x('D:prop',
x('C:calendar-timezone-id', 'Etc/GMT+4'),
x('C:calendar-timezone', $vtimezone),
),
),
),
);

xlog $self, "Verify timezone-id matches timezone value";
$self->assert_timezone_id("Etc/GMT+2");

xlog $self, "Set differing timezone and timezone-id, timezone-id as second";
$res = $caldav->Request(
'PROPPATCH', "/dav/calendars/user/cassandane/Default",
x('D:propertyupdate', $caldav->NS(),
x('D:set',
x('D:prop',
x('C:calendar-timezone', $vtimezone),
x('C:calendar-timezone-id', 'Etc/GMT+4'),
),
),
),
);

xlog $self, "Verify timezone-id matches timezone value";
$self->assert_timezone_id("Etc/GMT+4");

xlog $self, "Delete timezone-id property";
$res = $caldav->Request(
'PROPPATCH', "/dav/calendars/user/cassandane/Default",
x('D:propertyupdate', $caldav->NS(),
x('D:remove',
x('D:prop',
x('C:calendar-timezone-id'),
),
),
),
);

xlog $self, "Verify no timezone or timezone-id is set";
$self->assert_timezone_id(undef);
}

sub assert_timezone_id {
my ($self, $tzid) = @_;
my $caldav = $self->{caldav};

my $res = $caldav->Request(
'PROPFIND', "/dav/calendars/user/cassandane/Default",
x('D:propfind', $caldav->NS(),
x('D:prop',
x('C:calendar-timezone-id'),
x('C:calendar-timezone'),
),
),
);

my $propstat = $res->{'{DAV:}response'}[0]{'{DAV:}propstat'}[0];
if (not $tzid) {
$self->assert_str_equals(
'HTTP/1.1 404 Not Found',
$propstat->{'{DAV:}status'}{content}
);
$self->assert(
exists $propstat->{'{DAV:}prop'}
{'{urn:ietf:params:xml:ns:caldav}calendar-timezone-id'});
$self->assert(
exists $propstat->{'{DAV:}prop'}
{'{urn:ietf:params:xml:ns:caldav}calendar-timezone'});
}
}
16 changes: 16 additions & 0 deletions changes/next/http_caldav_proppatch_timezone_id
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Description:

Enable the calendar-timezone-id (RFC 7809) DAV property even if tzdist http module is disabled.


Config changes:

None

Upgrade instructions:

None

GitHub issue:

None
9 changes: 3 additions & 6 deletions imap/http_caldav.c
Original file line number Diff line number Diff line change
Expand Up @@ -6396,7 +6396,7 @@ static int propfind_timezone(const xmlChar *name, xmlNsPtr ns,
data = buf_cstring(&attrib);
datalen = attrib.len;
}
else if ((namespace_calendar.allow & ALLOW_CAL_NOTZ)) {
else {
/* Check for CALDAV:calendar-timezone-id */
prop_annot = DAV_ANNOT_NS "<" XML_NS_CALDAV ">calendar-timezone-id";

Expand Down Expand Up @@ -6429,7 +6429,6 @@ static int propfind_timezone(const xmlChar *name, xmlNsPtr ns,
else r = HTTP_SERVER_ERROR;
}
}
else r = HTTP_NOT_FOUND;
}

if (!r) r = propfind_getdata(name, ns, fctx, prop, propstat,
Expand Down Expand Up @@ -6742,8 +6741,7 @@ static int propfind_tzid(const xmlChar *name, xmlNsPtr ns,
const char *value = NULL;
int r = 0;

if (!(namespace_calendar.allow & ALLOW_CAL_NOTZ) ||
!fctx->req_tgt->userid || fctx->req_tgt->resource) {
if (!fctx->req_tgt->userid || fctx->req_tgt->resource) {
return HTTP_NOT_FOUND;
}

Expand Down Expand Up @@ -6793,8 +6791,7 @@ static int proppatch_tzid(xmlNodePtr prop, unsigned set,
struct propstat propstat[],
void *rock __attribute__((unused)))
{
if ((namespace_calendar.allow & ALLOW_CAL_NOTZ) &&
pctx->txn->req_tgt.collection && !pctx->txn->req_tgt.resource) {
if (pctx->txn->req_tgt.collection && !pctx->txn->req_tgt.resource) {
xmlChar *freeme = NULL;
const char *tzid = NULL;
const icaltimezone *tz = NULL;
Expand Down

0 comments on commit cca5510

Please sign in to comment.