CalDAVTalk.pm

filter: Statementstmt 20.2% 99 / 488 Branchbran 2.7% 7 / 252 Conditioncond 3.3% 4 / 120 MC/DCmcdc 0.0% 0 / 68 Subroutinesub 43.1% 22 / 51 Podpod 92.3% 24 / 26 totaltotal 15.5% 156 / 1005 CC 197 SCAR 63.7
CC
197
Cov
13%
GetCalendars
2352.0
_updateEvent
552.0
GetFreeBusy
272.0
CRAP 586.7
↑ Summary CalDAVTalk/TimeZones.pm »
1 package Net::CalDAVTalk;
2  
3 4 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 ▶use Net::DAVTalk;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use base qw(Net::DAVTalk);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use DateTime::Format::ICal;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use DateTime::TimeZone;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use JSON::XS qw(encode_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use Text::JSCalendar;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use Text::VCardFast qw(vcard2hash);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use XML::Spice;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶use Digest::SHA qw(sha1_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 4 ▶use URI::Escape qw(uri_unescape);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 4 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 4 our $BATCHSIZE = 100;
22  
23  
24  
25  
26 our (
27 4 $DefaultCalendarColour,
28 $DefaultDisplayName,
29 );
30  
31 4 our $UTC = DateTime::TimeZone::UTC->new();
32 4 our $FLOATING = DateTime::TimeZone::Floating->new();
33 4 our $LOCALE = DateTime::Locale->load('en_US');
34  
35 # Beginning and End of time as used for "all event" date ranges
36 # Reducing this range may result in events disappearing from FastMail
37 # calendars, as we think they have been deleted from the other end,
38 # so best to avoid this.
39 # However, from my tests, the events should be resurrected once this date
40 # window includes them again.
41  
42 4 my $BoT = '1970-01-01T00:00:00';
43 4 my $EoT = '2038-01-19T00:00:00';
44  
45 my (
46 4 %ColourNames,
47 %UTCLinks,
48 %EventKeys,
49 );
50  
51 4 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
52 4 $DefaultCalendarColour = '#0252D4';
53 4 $DefaultDisplayName = 'Untitled Calendar';
54  
55 4 %EventKeys = (
56 '' => {
57 uid => [0, 'string', 1, undef],
58 relatedTo => [0, 'string', 0, undef],
59 prodId => [0, 'string', 0, undef],
60 created => [0, 'utcdate', 0, undef],
61 updated => [0, 'utcdate', 1, undef],
62 sequence => [0, 'number', 0, undef],
63 title => [0, 'string', 0, ''],
64 description => [0, 'string', 0, ''],
65 links => [0, 'object', 0, undef],
66 locale => [0, 'string', 0, undef],
67 localizations => [0, 'patch', 0, undef],
68 locations => [0, 'object', 0, undef],
69 showWithoutTime => [0, 'bool', 0, $JSON::false],
70 start => [0, 'localdate', 1, undef],
71 timeZone => [0, 'timezone', 0, undef],
72 duration => [0, 'duration', 0, undef],
73 recurrenceRule => [0, 'object', 0, undef],
74 recurrenceOverrides => [0, 'patch', 0, undef],
75 status => [0, 'string', 0, undef],
76 freeBusyStatus => [0, 'string', 0, undef],
77 organizerCalendarAddress => [0, 'string', 0, undef],
78 participants => [0, 'object', 0, undef],
79 alerts => [0, 'object', 0, undef],
80 },
81 links => {
82 href => [0, 'string', 1, undef],
83 type => [0, 'string', 0, undef],
84 size => [0, 'number', 0, undef],
85 rel => [0, 'string', 1, undef],
86 title => [0, 'string', 1, undef],
87 properties => [0, 'string', 1, undef],
88 },
89 locations => {
90 name => [0, 'string', 0, undef],
91 accessInstructions => [0, 'string', 0, undef],
92 rel => [0, 'string', 0, 'unknown'],
93 timeZone => [0, 'timezone', 0, undef],
94 address => [0, 'object', 0, undef],
95 coordinates => [0, 'string', 0, undef],
96 uri => [0, 'string', 0, undef],
97 },
98 recurrenceRule => {
99 frequency => [0, 'string', 1, undef],
100 interval => [0, 'number', 0, undef],
101 rscale => [0, 'string', 0, 'gregorian'],
102 skip => [0, 'string', 0, 'omit'],
103 firstDayOfWeek => [0, 'string', 0, 'mo'],
104 byDay => [1, 'object', 0, undef],
105 byMonthDay => [1, 'number', 0, undef],
106 byMonth => [1, 'string', 0, undef],
107 byYearDay => [1, 'number', 0, undef],
108 byWeekNo => [1, 'number', 0, undef],
109 byHour => [1, 'number', 0, undef],
110 byMinute => [1, 'number', 0, undef],
111 bySecond => [1, 'number', 0, undef],
112 bySetPosition => [1, 'number', 0, undef],
113 count => [0, 'number', 0, undef],
114 until => [0, 'localdate', 0, undef],
115 },
116 byDay => {
117 day => [0, 'string', 1, undef],
118 nthOfPeriod => [0, 'number', 0, undef],
119 },
120 participants => {
121 name => [0, 'string', 1, undef],
122 email => [0, 'string', 1, undef],
123 kind => [0, 'string', 0, 'individual'],
124 roles => [0, 'object', 0, undef],
125 calendarAddress => [0, 'string', 0, undef],
126 participationStatus => [0, 'string', 0, 'needs-action'],
127 expectReply => [0, 'bool', 0, $JSON::false],
128 scheduleAgent => [0, 'string', 0, undef],
129 scheduleUpdated => [0, 'utcdate', 0, undef],
130 memberOf => [0, 'object', 0, undef],
131 },
132 alerts => {
133 action => [0, 'string', 1, undef],
134 trigger => [0, 'object', 1, undef],
135 },
136 );
137  
138 # Colour names defined in CSS Color Module Level 3
139 # http://www.w3.org/TR/css3-color/
140  
141 %ColourNames
142 4 = map { $_ => 1 }
143 qw{
144 aliceblue
145 antiquewhite
146 aqua
147 aquamarine
148 azure
149 beige
150 bisque
151 black
152 blanchedalmond
153 blue
154 blueviolet
155 brown
156 burlywood
157 cadetblue
158 chartreuse
159 chocolate
160 coral
161 cornflowerblue
162 cornsilk
163 crimson
164 cyan
165 darkblue
166 darkcyan
167 darkgoldenrod
168 darkgray
169 darkgreen
170 darkgrey
171 darkkhaki
172 darkmagenta
173 darkolivegreen
174 darkorange
175 darkorchid
176 darkred
177 darksalmon
178 darkseagreen
179 darkslateblue
180 darkslategray
181 darkslategrey
182 darkturquoise
183 darkviolet
184 deeppink
185 deepskyblue
186 dimgray
187 dimgrey
188 dodgerblue
189 firebrick
190 floralwhite
191 forestgreen
192 fuchsia
193 gainsboro
194 ghostwhite
195 gold
196 goldenrod
197 gray
198 green
199 greenyellow
200 grey
201 honeydew
202 hotpink
203 indianred
204 indigo
205 ivory
206 khaki
207 lavender
208 lavenderblush
209 lawngreen
210 lemonchiffon
211 lightblue
212 lightcoral
213 lightcyan
214 lightgoldenrodyellow
215 lightgray
216 lightgreen
217 lightgrey
218 lightpink
219 lightsalmon
220 lightseagreen
221 lightskyblue
222 lightslategray
223 lightslategrey
224 lightsteelblue
225 lightyellow
226 lime
227 limegreen
228 linen
229 magenta
230 maroon
231 mediumaquamarine
232 mediumblue
233 mediumorchid
234 mediumpurple
235 mediumseagreen
236 mediumslateblue
237 mediumspringgreen
238 mediumturquoise
239 mediumvioletred
240 midnightblue
241 mintcream
242 mistyrose
243 moccasin
244 navajowhite
245 navy
246 oldlace
247 olive
248 olivedrab
249 orange
250 orangered
251 orchid
252 palegoldenrod
253 palegreen
254 paleturquoise
255 palevioletred
256 papayawhip
257 peachpuff
258 peru
259 pink
260 plum
261 powderblue
262 purple
263 red
264 rosybrown
265 royalblue
266 saddlebrown
267 salmon
268 sandybrown
269 seagreen
270 seashell
271 sienna
272 silver
273 skyblue
274 slateblue
275 slategray
276 slategrey
277 snow
278 springgreen
279 steelblue
280 tan
281 teal
282 thistle
283 tomato
284 turquoise
285 violet
286 wheat
287 white
288 whitesmoke
289 yellow
290 yellowgreen
291 };
292  
293 4 %UTCLinks = (
294 'Etc/GMT-0' => 1,
295 'Etc/GMT+0' => 1,
296 'Etc/GMT0' => 1,
297 'Etc/GMT' => 1,
298 'Etc/Greenwich' => 1,
299 'Etc/UCT' => 1,
300 'Etc/Universal' => 1,
301 'Etc/UTC' => 1,
302 'Etc/Zulu' => 1,
303 'GMT' => 1,
304 'UCT' => 1,
305 'UTC' => 1,
306 );
307 }
308  
309  
310 =head1 NAME
311  
312 Net::CalDAVTalk - Module to talk CalDAV and give a JSON interface to the data
313  
314 =head1 VERSION
315  
316 Version 0.16
317  
318 =cut
319  
320 4 our $VERSION = '0.19';
321  
322  
323 =head1 SYNOPSIS
324  
325 This module is the initial release of the code used at FastMail for talking
326 to CalDAV servers. It's quite specific to an early version of our API, so
327 while it might be useful to others, it's being pushed to CPAN more because
328 the Cassandane test suite needs it.
329  
330 See Net::DAVTalk for details on how to specify hosts and paths.
331  
332 my $CalDAV = Net::CalDAVTalk->new(
333 user => $service->user(),
334 password => $service->pass(),
335 host => $service->host(),
336 port => $service->port(),
337 scheme => 'http',
338 url => '/',
339 expandurl => 1,
340 );
341  
342 or using DNS:
343  
344 my $domain = $user;
345 $domain =~ s/.*\@//;
346  
347 my $url;
348 my ($reply) = $Resolver->search("_caldavs._tcp.$domain", "srv");
349 if ($reply) {
350 my @d = $reply->answer;
351 if (@d) {
352 my $host = $d[0]->target();
353 my $port = $d[0]->port();
354 $url = "https://$host";
355 $url .= ":$port" unless $port eq 443;
356 }
357 }
358  
359 This will use the '/.well-known/caldav' address to find the actual current user
360 principal, and from there the calendar-home-set for further operations.
361  
362 my $foo = Net::CalDAVTalk->new(
363 user => $user,
364 password => $password,
365 url => $url,
366 expandurl => 1,
367 );
368  
369  
370 =head1 SUBROUTINES/METHODS
371  
372 =head2 new(%args)
373  
374 Takes the same arguments as Net::DAVTalk and adds the caldav namespaces
375 and some Cyrus specific namespaces for all XML requests.
376  
377 A => 'http://apple.com/ns/ical/'
378 C => 'urn:ietf:params:xml:ns:caldav'
379 CY => 'http://cyrusimap.org/ns/'
380 UF => 'http://cyrusimap.org/ns/userflag/'
381 SF => 'http://cyrusimap.org/ns/sysflag/'
382  
383 =cut
384  
385 2 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
386 2 my ($Class, %Params) = @_;
387  
388 2 $Params{homesetns} = 'C';
389 2 $Params{homeset} = 'calendar-home-set';
390 2 $Params{wellknown} = 'caldav';
391  
392 2 my $Self = $Class->SUPER::new(%Params);
393  
394 2 $Self->ns(A => 'http://apple.com/ns/ical/');
395 2 $Self->ns(C => 'urn:ietf:params:xml:ns:caldav');
396 2 $Self->ns(CY => 'http://cyrusimap.org/ns/');
397 2 $Self->ns(UF => 'http://cyrusimap.org/ns/userflag/');
398 2 $Self->ns(SF => 'http://cyrusimap.org/ns/sysflag/');
399  
400 2 return $Self;
401 }
402  
403 15 ▶sub _jscal {
Subroutine _jscal: called CC=2 SCAR=7.0
404 15 my $Self = shift;
405 15 ▶ $Self->{_jscal} ||= Text::JSCalendar->new();
Condition66%2/3
$Self->{"_jscal"} ||= "Text::JSCalendar"->new
l!l&&r!l&&!r
1410
MC/DC0%0/2
$Self->{"_jscal"} ||= "Text::JSCalendar"->new
$Self->{"_jscal"} "Text::JSCalendar"->new
Truth table66%2/3
A ||= B
A= $Self->{"_jscal"}B= "Text::JSCalendar"->new
ABresult
1X1
011
000
406 15 return $Self->{_jscal};
407 }
408  
409 =head2 $self->tz($name)
410  
411 Returns a DateTime::TimeZone object for the given name, but caches
412 the result for speed.
413  
414 =cut
415  
416 0 ▶sub tz {
Subroutine tz: not called CC=4 SCAR=30.0
Pod documented
417 0 my $Self = shift;
418 0 my $tzName = shift;
419 0 ▶ return $FLOATING unless defined $tzName;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tzName 0 0 0
420 0 ▶ return $UTC if $UTCLinks{$tzName};
Branch: 1 branch
BranchTrueFalseTotal
if $UTCLinks{$tzName} 0 0 0
421 0 ▶ unless (exists $Self->{_tz}{$tzName}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Self->{"_tz"}{$tzName}) 0 0 0
422 0 $Self->{_tz}{$tzName} = DateTime::TimeZone->new(name => $tzName);
423 }
424 0 return $Self->{_tz}{$tzName};
425 }
426  
427 =head2 $self->logger(sub { })
428  
429 Sets a function to receive all log messages. Gets called with the first
430 argument being a level name, and then a list of items to log:
431  
432 e.g.
433  
434 $CalDAV->logger(sub {
435 my $level = shift;
436 return if ($level eq 'debug' and not $ENV{DEBUG_CALDAV});
437 warn "LOG $level: $_\n" for @_;
438 });
439  
440 =cut
441  
442 0 ▶sub logger {
Subroutine logger: not called CC=2 SCAR=17.9
Pod documented
443 0 my $Self = shift;
444  
445 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
446 0 $Self->{logger} = shift;
447 }
448  
449 0 return $Self->{logger};
450 }
451  
452 =head2 $self->DeleteCalendar($calendarId)
453  
454 Delete the named calendar from the server (shorturl - see Net::DAVTalk)
455  
456 =cut
457  
458 =head2 $Cal->DeleteCalendar($calendarId)
459  
460 Delete the calendar with collection name $calendarId (full or relative path)
461  
462 e.g.
463  
464 $Cal->DeleteCalendar('Default');
465  
466 =cut
467  
468 0 ▶sub DeleteCalendar {
Subroutine DeleteCalendar: not called CC=2 SCAR=17.9
Pod documented
469 0 my ($Self, $calendarId) = @_;
470  
471 0 ▶ unless ($calendarId) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($calendarId) 0 0 0
472 0 confess 'Calendar not specified';
473 }
474  
475 $Self->Request(
476 0 'DELETE',
477 "$calendarId/",
478 );
479  
480 0 return 1;
481 }
482  
483 0 ▶sub _fixColour {
Subroutine _fixColour: not called CC=7 SCAR=40.3
484 0 ▶ my $color = lc(shift || '');
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
485  
486 0 ▶ return $color if $ColourNames{$color};
Branch: 1 branch
BranchTrueFalseTotal
if $ColourNames{$color} 0 0 0
487 0 ▶ return $DefaultCalendarColour unless $color =~ m/^\s*(\#[a-f0-9]{3,8})\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $color =~ /^\s*(\#[a-f0-9]{3,8})\s*$/ 0 0 0
488 0 $color = $1;
489 0 ▶ return uc($color) if length($color) == 7;
Branch: 1 branch
BranchTrueFalseTotal
if length $color == 7 0 0 0
490  
491 # Optional digit is for transparency (RGBA)
492 0 ▶ if ( $color =~ m/^#(.)(.)(.).?$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($color =~ /^#(.)(.)(.).?$/) 0 0 0
493 0 return uc "#$1$1$2$2$3$3";
494 }
495  
496 # Last two digits are for transparency (RGBA)
497 0 ▶ if ( length($color) == 9 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $color == 9) 0 0 0
498 0 return uc(substr($color,0,7));
499 }
500  
501 0 return $DefaultCalendarColour;
502 }
503  
504  
505 =head2 $self->GetCalendar($calendarId)
506  
507 Get a single calendar from the server by calendarId
508 (currently implemented very inefficiently as a get
509 of all calendars. Returns undef if the calendar
510 doesn't exist.
511  
512 e.g
513 my $Calendar = $CalDAV->GetCalendar('Default');
514  
515 =cut
516  
517 0 ▶sub GetCalendar {
Subroutine GetCalendar: not called CC=3 SCAR=24.8
Pod documented
518 0 my ($Self, $CalendarId) = @_;
519 0 my $Calendars = $Self->GetCalendars();
520 0 ▶ die "No calendars" unless ($Calendars and @$Calendars);
Branch: 1 branch
BranchTrueFalseTotal
unless $Calendars and @$Calendars 0 0 0
Condition0%0/3
$Calendars and @$Calendars
!ll&&!rl&&r
000
MC/DC0%0/2
$Calendars and @$Calendars
$Calendars @$Calendars
Truth table0%0/3
A and B
A= $CalendarsB= @$Calendars
ABresult
0X0
100
111
521 0 my ($Calendar) = grep { $_->{id} eq $CalendarId } @$Calendars;
522 0 return $Calendar;
523 }
524  
525 =head2 $self->GetCalendars(Properties => [])
526  
527 Fetch all the calendars on the server. You can request additional
528 properties, but they aren't parsed well yet.
529  
530 e.g
531  
532 my $Calendars = $CalDAV->GetCalendars();
533 foreach my $Cal (@$Calendars) {
534 # do stuff
535 }
536  
537 =cut
538  
539 0 ▶sub GetCalendars {
Subroutine GetCalendars: not called CC=48 SCAR=77.6
Pod documented
540 0 my ($Self, %Args) = @_;
541  
542 # XXX To generalise for CPAN:
543 # XXX - the PROPFIND should be D:allprop unless $Args{Properties} is set
544 # XXX - return all properties as object attributes without renaming
545 # XXX - translate property names to our own liking within ME::CalDAV
546  
547 0 my %Properties = map { $_ => 1 } (
548 'D:displayname',
549 'D:resourcetype',
550 'A:calendar-color',
551 'D:current-user-privilege-set',
552 'D:acl',
553 'A:calendar-order',
554 'C:calendar-timezone',
555 'D:sync-token',
556 'D:supported-report-set',
557 'C:supported-calendar-data',
558 0 ▶ @{$Args{Properties} || []},
Condition0%0/2
$Args{'Properties'} || []
l!l
00
MC/DC0%0/1
$Args{'Properties'} || []
$Args{'Properties'}
Truth table0%0/2
A
A= $Args{'Properties'}
Aresult
11
00
559 );
560  
561 my $Response = $Self->Request(
562 'PROPFIND',
563 '',
564 x('D:propfind', $Self->NS(),
565 x('D:prop',
566 0 map { x($_) } keys %Properties,
567 ),
568 ),
569 Depth => 1,
570 );
571  
572 0 my @Calendars;
573  
574 0 my $NS_A = $Self->ns('A');
575 0 my $NS_C = $Self->ns('C');
576 0 my $NS_CY = $Self->ns('CY');
577 0 my $NS_D = $Self->ns('D');
578 0 ▶ foreach my $Response (@{$Response->{"{$NS_D}response"} || []}) {
Condition0%0/2
$$Response{"{$NS_D}response"} || []
l!l
00
MC/DC0%0/1
$$Response{"{$NS_D}response"} || []
$$Response{"{$NS_D}response"}
Truth table0%0/2
A
A= $$Response{"{$NS_D}response"}
Aresult
11
00
579 0 ▶ next unless $Response->{"{$NS_D}href"}{content};
Branch: 1 branch
BranchTrueFalseTotal
unless $$Response{"{$NS_D}href"}{"content"} 0 0 0
580 0 my $href = uri_unescape($Response->{"{$NS_D}href"}{content});
581  
582 # grab the short version of the path
583 0 my $calendarId = $Self->shortpath($href);
584 # and remove trailing slash always
585 0 $calendarId =~ s{/$}{};
586  
587 0 ▶ foreach my $Propstat (@{$Response->{"{$NS_D}propstat"} || []}) {
Condition0%0/2
$$Response{"{$NS_D}propstat"} || []
l!l
00
MC/DC0%0/1
$$Response{"{$NS_D}propstat"} || []
$$Response{"{$NS_D}propstat"}
Truth table0%0/2
A
A= $$Response{"{$NS_D}propstat"}
Aresult
11
00
588 0 ▶ next unless $Propstat->{"{$NS_D}prop"}{"{$NS_D}resourcetype"}{"{$NS_C}calendar"};
Branch: 1 branch
BranchTrueFalseTotal
unless $$Propstat{"{$NS_D}prop"}{"{$NS_D}resourcetype"}{"{$NS_C}calendar"} 0 0 0
589  
590 # XXX - this should be moved into ME::CalDAV::GetCalendars()
591 0 my $visData = $Propstat->{"{$NS_D}prop"}{"{$NS_C}X-FM-isVisible"}{content};
592 0 ▶ my $isVisible = (not defined($visData) or $visData) ? $JSON::true : $JSON::false;
Branch: 1 branch
BranchTrueFalseTotal
!defined($visData) || $visData ? : 0 0 0
Condition0%0/3
not defined $visData or $visData
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $visData or $visData
not defined $visData $visData
Truth table0%0/3
not(A) or B
A= not defined $visDataB= $visData
ABresult
1X1
011
000
593  
594 0 my %Privileges = (
595 mayAdmin => $JSON::false,
596 mayWrite => $JSON::false,
597 mayRead => $JSON::false,
598 mayReadFreeBusy => $JSON::false,
599 );
600  
601 0 my $Priv = $Propstat->{"{$NS_D}prop"}{"{$NS_D}current-user-privilege-set"}{"{$NS_D}privilege"};
602 0 ▶ $Priv = [] unless ($Priv and ref($Priv) eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
unless $Priv and ref $Priv eq "ARRAY" 0 0 0
Condition0%0/3
$Priv and ref $Priv eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
$Priv and ref $Priv eq "ARRAY"
$Priv ref $Priv eq "ARRAY"
Truth table0%0/3
A and B
A= $PrivB= ref $Priv eq "ARRAY"
ABresult
0X0
100
111
603 0 foreach my $item (@$Priv) {
604 0 ▶ $Privileges{'mayAdmin'} = $JSON::true if $item->{"{$NS_CY}admin"};
Branch: 1 branch
BranchTrueFalseTotal
if $$item{"{$NS_CY}admin"} 0 0 0
605 0 ▶ $Privileges{'mayWrite'} = $JSON::true if $item->{"{$NS_D}write-content"};
Branch: 1 branch
BranchTrueFalseTotal
if $$item{"{$NS_D}write-content"} 0 0 0
606 0 ▶ $Privileges{'mayRead'} = $JSON::true if $item->{"{$NS_D}read"};
Branch: 1 branch
BranchTrueFalseTotal
if $$item{"{$NS_D}read"} 0 0 0
607 0 ▶ $Privileges{'mayReadFreeBusy'} = $JSON::true if $item->{"{$NS_C}read-free-busy"};
Branch: 1 branch
BranchTrueFalseTotal
if $$item{"{$NS_C}read-free-busy"} 0 0 0
608 }
609  
610 0 my $CanSync;
611 0 my $Report = $Propstat->{"{$NS_D}prop"}{"{$NS_D}supported-report-set"}{"{$NS_D}supported-report"};
612 0 ▶ $Report = [] unless ($Report and ref($Report) eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
unless $Report and ref $Report eq "ARRAY" 0 0 0
Condition0%0/3
$Report and ref $Report eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
$Report and ref $Report eq "ARRAY"
$Report ref $Report eq "ARRAY"
Truth table0%0/3
A and B
A= $ReportB= ref $Report eq "ARRAY"
ABresult
0X0
100
111
613 0 foreach my $item (@$Report) {
614 # XXX - do we want to check the other things too?
615 0 ▶ $CanSync = 1 if $item->{"{$NS_D}report"}{"{$NS_D}sync-collection"};
Branch: 1 branch
BranchTrueFalseTotal
if $$item{"{$NS_D}report"}{"{$NS_D}sync-collection"} 0 0 0
616 }
617  
618 0 my $CanEvent;
619 0 my $Type = $Propstat->{"{$NS_D}prop"}{"{$NS_C}supported-calendar-data"}{"{$NS_C}calendar-data"};
620 0 ▶ $Type = [] unless ($Type and ref($Type) eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
unless $Type and ref $Type eq "ARRAY" 0 0 0
Condition0%0/3
$Type and ref $Type eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
$Type and ref $Type eq "ARRAY"
$Type ref $Type eq "ARRAY"
Truth table0%0/3
A and B
A= $TypeB= ref $Type eq "ARRAY"
ABresult
0X0
100
111
621 0 foreach my $item (@$Type) {
622 0 ▶ next unless $item->{"\@content-type"};
Branch: 1 branch
BranchTrueFalseTotal
unless $item->{"\@content-type"} 0 0 0
623 0 ▶ $CanEvent = 1 if $item->{"\@content-type"}{content} eq "application/event+json";
Branch: 1 branch
BranchTrueFalseTotal
if $item->{"\@content-type"}{"content"} eq "application/event+json" 0 0 0
624 }
625  
626 # XXX - temporary compat
627 0 ▶ $Privileges{isReadOnly} = $Privileges{mayWrite} ? $JSON::false : $JSON::true;
Branch: 1 branch
BranchTrueFalseTotal
$Privileges{'mayWrite'} ? : 0 0 0
628  
629 0 my @ShareWith;
630 0 my $ace = $Propstat->{"{$NS_D}prop"}{"{$NS_D}acl"}{"{$NS_D}ace"};
631 0 ▶ $ace = [] unless ($ace and ref($ace) eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
unless $ace and ref $ace eq "ARRAY" 0 0 0
Condition0%0/3
$ace and ref $ace eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
$ace and ref $ace eq "ARRAY"
$ace ref $ace eq "ARRAY"
Truth table0%0/3
A and B
A= $aceB= ref $ace eq "ARRAY"
ABresult
0X0
100
111
632 0 foreach my $Acl (@$ace) {
633 0 ▶ next if $Acl->{"{$NS_D}protected"}; # ignore admin ACLs
Branch: 1 branch
BranchTrueFalseTotal
if $$Acl{"{$NS_D}protected"} 0 0 0
634 0 ▶ next unless $Acl->{"{$NS_D}grant"};
Branch: 1 branch
BranchTrueFalseTotal
unless $$Acl{"{$NS_D}grant"} 0 0 0
635 0 ▶ next unless $Acl->{"{$NS_D}grant"}{"{$NS_D}privilege"};
Branch: 1 branch
BranchTrueFalseTotal
unless $$Acl{"{$NS_D}grant"}{"{$NS_D}privilege"} 0 0 0
636 0 ▶ next unless ref($Acl->{"{$NS_D}grant"}{"{$NS_D}privilege"}) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $$Acl{"{$NS_D}grant"}{"{$NS_D}privilege"} eq "ARRAY" 0 0 0
637 # XXX - freeBusyPublic here? Or should we do it via the web server?
638 0 ▶ my $user = uri_unescape($Acl->{"{$NS_D}principal"}{"{$NS_D}href"}{content} // '');
Condition0%0/2
$$Acl{"{$NS_D}principal"}{"{$NS_D}href"}{"content"} // ""
l!l
00
MC/DC0%0/1
$$Acl{"{$NS_D}principal"}{"{$NS_D}href"}{"content"} // ""
$$Acl{"{$NS_D}principal"}{"{$NS_D}href"}{"content"}
Truth table0%0/2
A
A= $$Acl{"{$NS_D}principal"}{"{$NS_D}href"}{"content"}
Aresult
11
00
639 0 ▶ next unless $user =~ m{^/dav/principals/user/([^/]+)};
Branch: 1 branch
BranchTrueFalseTotal
unless $user =~ m[^/dav/principals/user/([^/]+)] 0 0 0
640 0 my $email = $1;
641 0 ▶ next if $email eq 'admin';
Branch: 1 branch
BranchTrueFalseTotal
if $email eq "admin" 0 0 0
642 0 my %ShareObject = (
643 email => $email,
644 mayAdmin => $JSON::false,
645 mayWrite => $JSON::false,
646 mayRead => $JSON::false,
647 mayReadFreeBusy => $JSON::false,
648 );
649 0 foreach my $item (@{$Acl->{"{$NS_D}grant"}{"{$NS_D}privilege"}}) {
650 0 ▶ $ShareObject{'mayAdmin'} = $JSON::true if $item->{"{$NS_CY}admin"};
Branch: 1 branch
BranchTrueFalseTotal
if $$item{"{$NS_CY}admin"} 0 0 0
651 0 ▶ $ShareObject{'mayWrite'} = $JSON::true if $item->{"{$NS_D}write-content"};
Branch: 1 branch
BranchTrueFalseTotal
if $$item{"{$NS_D}write-content"} 0 0 0
652 0 ▶ $ShareObject{'mayRead'} = $JSON::true if $item->{"{$NS_D}read"};
Branch: 1 branch
BranchTrueFalseTotal
if $$item{"{$NS_D}read"} 0 0 0
653 0 ▶ $ShareObject{'mayReadFreeBusy'} = $JSON::true if $item->{"{$NS_C}read-free-busy"};
Branch: 1 branch
BranchTrueFalseTotal
if $$item{"{$NS_C}read-free-busy"} 0 0 0
654 }
655  
656 0 push @ShareWith, \%ShareObject;
657 }
658  
659 my %Cal = (
660 id => $calendarId,
661 name => ($Propstat->{"{$NS_D}prop"}{"{$NS_D}displayname"}{content} || $DefaultDisplayName),
662 href => $href,
663 color => _fixColour($Propstat->{"{$NS_D}prop"}{"{$NS_A}calendar-color"}{content}),
664 timeZone => $Propstat->{"{$NS_D}prop"}{"{$NS_C}calendar-timezone"}{content},
665 isVisible => $isVisible,
666 precedence => int($Propstat->{"{$NS_D}prop"}{"{$NS_A}calendar-order"}{content} || 1),
667 0 ▶ syncToken => ($Propstat->{"{$NS_D}prop"}{"{$NS_D}sync-token"}{content} || ''),
Branch: 3 branches
BranchTrueFalseTotal
@ShareWith ? : 0 0 0
$CanSync ? : 0 0 0
$CanEvent ? : 0 0 0
Condition0%0/7
$$Propstat{"{$NS_D}prop"}{"{$NS_D}displayname"}{'content'} || $Net::CalDAVTalk::DefaultDisplayName
l!l&&r!l&&!r
000
$$Propstat{"{$NS_D}prop"}{"{$NS_A}calendar-order"}{'content'} || 1
l!l
00
$$Propstat{"{$NS_D}prop"}{"{$NS_D}sync-token"}{'content'} || ''
l!l
00
MC/DC0%0/2
$$Propstat{"{$NS_D}prop"}{"{$NS_D}displayname"}{'content'} || $Net::CalDAVTalk::DefaultDisplayName
$$Propstat{"{$NS_D}prop"}{"{$NS_D}displayname"}{'content'} $Net::CalDAVTalk::DefaultDisplayName
MC/DC0%0/1
$$Propstat{"{$NS_D}prop"}{"{$NS_A}calendar-order"}{'content'} || 1
$$Propstat{"{$NS_D}prop"}{"{$NS_A}calendar-order"}{'content'}
MC/DC0%0/1
$$Propstat{"{$NS_D}prop"}{"{$NS_D}sync-token"}{'content'} || ''
$$Propstat{"{$NS_D}prop"}{"{$NS_D}sync-token"}{'content'}
Truth table0%0/3
A || B
A= $$Propstat{"{$NS_D}prop"}{"{$NS_D}displayname"}{'content'}B= $Net::CalDAVTalk::DefaultDisplayName
ABresult
1X1
011
000
Truth table0%0/2
A
A= $$Propstat{"{$NS_D}prop"}{"{$NS_A}calendar-order"}{'content'}
Aresult
11
00
Truth table0%0/2
A
A= $$Propstat{"{$NS_D}prop"}{"{$NS_D}sync-token"}{'content'}
Aresult
11
00
668 shareWith => (@ShareWith ? \@ShareWith : $JSON::false),
669 canSync => ($CanSync ? $JSON::true : $JSON::false),
670 _can_event => ($CanEvent ? $JSON::true : $JSON::false),
671 %Privileges,
672 );
673  
674  
675 0 push @Calendars, \%Cal;
676 }
677 }
678  
679 0 return \@Calendars;
680 }
681  
682 =head2 $self->NewCalendar($Args)
683  
684 Create a new calendar. The Args are the as the things returned by GetCalendars,
685 except that if you don't provide 'id' (same as shorturl), then a UUID will be
686 generated for you. It's recommended to not provide 'id' unless you need to
687 create a specific path for compatibility with other things, and to use 'name'
688 to identify the calendar for users. 'name' is stored as DAV:displayname.
689  
690 e.g.
691  
692 my $Id = $CalDAV->NewCalendar({name => 'My Calendar', color => 'aqua'});
693  
694 (Color names will be translated based on the CSS name list)
695  
696 =cut
697  
698 0 ▶sub NewCalendar {
Subroutine NewCalendar: not called CC=11 SCAR=48.8
Pod documented
699 0 my ($Self, $Args) = @_;
700  
701 0 ▶ unless (ref($Args) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $Args eq "HASH") 0 0 0
702 0 confess 'Invalid calendar';
703 }
704  
705 # The URL should be "/$calendarId/" but this isn't true with Zimbra (Yahoo!
706 # Calendar). It will accept a MKCALENDAR at "/$calendarId/" but will rewrite
707 # the calendar's URL to be "/$HTMLEscapedDisplayName/". I'm sure MKCALENDAR
708 # should follow WebDAV's MKCOL method here, but it's not specified in CalDAV.
709  
710 # default values
711 0 ▶ $Args->{id} //= $Self->genuuid();
Condition0%0/3
$Args->{"id"} //= $Self->genuuid
l!l&&r!l&&!r
000
MC/DC0%0/2
$Args->{"id"} //= $Self->genuuid
$Args->{"id"} $Self->genuuid
Truth table0%0/3
A //= B
A= $Args->{"id"}B= $Self->genuuid
ABresult
1X1
011
000
712 0 ▶ $Args->{name} //= $DefaultDisplayName;
Condition0%0/3
$Args->{"name"} //= $Net::CalDAVTalk::DefaultDisplayName
l!l&&r!l&&!r
000
MC/DC0%0/2
$Args->{"name"} //= $Net::CalDAVTalk::DefaultDisplayName
$Args->{"name"} $Net::CalDAVTalk::DefaultDisplayName
Truth table0%0/3
A //= B
A= $Args->{"name"}B= $Net::CalDAVTalk::DefaultDisplayName
ABresult
1X1
011
000
713  
714 0 my $calendarId = $Args->{id};
715  
716 0 my @Properties;
717  
718 0 push @Properties, x('D:displayname', $Args->{name});
719  
720 0 ▶ if (exists $Args->{isVisible}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Args->{"isVisible"}) 0 0 0
721 0 ▶ push @Properties, x('C:X-FM-isVisible', ($Args->{isVisible} ? 1 : 0));
Branch: 1 branch
BranchTrueFalseTotal
$Args->{'isVisible'} ? : 0 0 0
722 }
723  
724 0 ▶ if (exists $Args->{color}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Args->{"color"}) 0 0 0
725 0 push @Properties, x('A:calendar-color', _fixColour($Args->{color}));
726 }
727  
728 0 ▶ if (exists $Args->{timeZone}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Args->{"timeZone"}) 0 0 0
729 0 push @Properties, x('C:calendar-timezone', $Args->{timeZone});
730 }
731  
732 0 ▶ if (exists $Args->{precedence}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Args->{"precedence"}) 0 0 0
733 0 ▶ unless (($Args->{precedence} // '') =~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless (($Args->{"precedence"} // "") =~ /^\d+$/) 0 0 0
Condition0%0/2
$Args->{"precedence"} // ""
l!l
00
MC/DC0%0/1
$Args->{"precedence"} // ""
$Args->{"precedence"}
Truth table0%0/2
A
A= $Args->{"precedence"}
Aresult
11
00
734 0 confess "Invalid precedence ($Args->{precedence}) (expected int >= 0)";
735 }
736  
737 0 push @Properties, x('A:calendar-order', $Args->{precedence});
738 }
739  
740 $Self->Request(
741 0 'MKCALENDAR',
742 "$calendarId/",
743 x('C:mkcalendar', $Self->NS(),
744 x('D:set',
745 x('D:prop', @Properties),
746 ),
747 ),
748 );
749  
750 0 return $calendarId;
751 }
752  
753 =head2 $self->UpdateCalendar($Args)
754  
755 Like 'NewCalendar', but updates an existing calendar, and 'id' is required.
756 Returns the id, just like NewCalendar.
757  
758 =cut
759  
760 0 ▶sub UpdateCalendar {
Subroutine UpdateCalendar: not called CC=12 SCAR=50.5
Pod documented
761 0 my ($Self, $Args, $Prev) = @_;
762  
763 0 ▶ unless (ref($Args) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $Args eq "HASH") 0 0 0
764 0 confess 'Invalid calendar';
765 }
766  
767 0 my %Calendar = %{$Args};
768 0 my $calendarId = $Calendar{id};
769  
770 0 ▶ unless ($calendarId) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($calendarId) 0 0 0
771 0 confess 'Calendar not specified';
772 }
773  
774 0 my @Params;
775  
776 0 ▶ if (defined $Calendar{name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Calendar{"name"}) 0 0 0
777 0 push @Params, x('D:displayname', $Calendar{name});
778 }
779  
780 0 ▶ if (defined $Calendar{color}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Calendar{"color"}) 0 0 0
781 0 push @Params, x('A:calendar-color', _fixColour($Calendar{color}));
782 }
783  
784 0 ▶ if (exists $Args->{timeZone}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Args->{"timeZone"}) 0 0 0
785 0 push @Params, x('C:calendar-timezone', $Args->{timeZone});
786 }
787  
788 0 ▶ if (exists $Calendar{isVisible}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Calendar{"isVisible"}) 0 0 0
789 0 ▶ push @Params, x('C:X-FM-isVisible', $Calendar{isVisible} ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$Calendar{'isVisible'} ? : 0 0 0
790 }
791  
792 0 ▶ if (exists $Calendar{precedence}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Calendar{"precedence"}) 0 0 0
793 0 ▶ unless (($Calendar{precedence} ||'') =~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless (($Calendar{"precedence"} || "") =~ /^\d+$/) 0 0 0
Condition0%0/2
$Calendar{'precedence'} || ''
l!l
00
MC/DC0%0/1
$Calendar{'precedence'} || ''
$Calendar{'precedence'}
Truth table0%0/2
A
A= $Calendar{'precedence'}
Aresult
11
00
794 0 confess "Invalid precedence ($Calendar{precedence})";
795 }
796  
797 0 push @Params, x('A:calendar-order', $Calendar{precedence});
798 }
799  
800 0 ▶ return $calendarId unless @Params;
Branch: 1 branch
BranchTrueFalseTotal
unless @Params 0 0 0
801  
802 0 $Self->Request(
803 'PROPPATCH',
804 "$calendarId/",
805 x('D:propertyupdate', $Self->NS(),
806 x('D:set',
807 x('D:prop',
808 @Params,
809 ),
810 ),
811 ),
812 );
813  
814 0 return $calendarId;
815 }
816  
817 # Event methods
818  
819 =head2 $self->DeleteEvent($Event|$href)
820  
821 Given a single event or the href to the event, delete that event,
822 delete it from the server.
823  
824 Returns true.
825  
826 =cut
827  
828 0 ▶sub DeleteEvent {
Subroutine DeleteEvent: not called CC=3 SCAR=24.8
Pod documented
829 0 my ($Self) = shift;
830 0 my ($Event) = @_;
831  
832 0 ▶ confess "Need an event" unless $Event;
Branch: 1 branch
BranchTrueFalseTotal
unless $Event 0 0 0
833  
834 0 ▶ $Event = { href => $Event, summary => $Event } unless ref($Event) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $Event eq "HASH" 0 0 0
835  
836 $Self->Request(
837 'DELETE',
838 $Event->{href},
839 0 );
840  
841 0 return 1;
842 }
843  
844 =head2 $self->GetEvents($calendarId, %Args)
845  
846 Fetches some or all of the events in a calendar.
847  
848 Supported args:
849  
850 href => [] - perform a multi-get on just these fullpath urls.
851 after+before => ISO8601 - date range to query
852  
853 In scalar context returns an arrayref of events. In list context
854 returns both an arrayref of events and an arrayref of errors:
855  
856 e.g.
857  
858 my ($Events, $Errors) = $CalDAV->GetEvents('Default');
859  
860 =cut
861  
862 0 ▶sub GetEvents {
Subroutine GetEvents: not called CC=2 SCAR=17.9
Pod documented
863 0 my ($Self, $calendarId, %Args) = @_;
864  
865 0 my $urls = $Self->GetEventLinks($calendarId, %Args);
866  
867 0 my @AllUrls = sort keys %$urls;
868  
869 0 my ($Events, $Errors, $Links) = $Self->GetEventsMulti($calendarId, \@AllUrls, %Args);
870  
871 0 ▶ return wantarray ? ($Events, $Errors, $Links) : $Events;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
872 }
873  
874 =head2 $self->GetEventsMulti($calendarId, $Urls, %Args)
875  
876 Fetches the events in Urs from the calendar
877  
878 Supported args:
879  
880 * ContentType
881 * Version
882  
883 For the calendar-data response
884  
885 In scalar context returns an arrayref of events. In list context
886 returns an array of:
887  
888 * arrayref of events
889 * arrayref of errors:
890 * hash of href to getetag
891  
892 =cut
893  
894 1 ▶sub GetEventsMulti {
Subroutine GetEventsMulti: called CC=24 SCAR=54.9
Pod documented
895 1 my ($Self, $calendarId, $Urls, %Args) = @_;
896  
897 1 ▶ confess "Need a calendarId" unless $calendarId;
Branch: 1 branch
BranchTrueFalseTotal
unless $calendarId 0 1 1
898  
899 1 my @Annotations;
900 1 ▶ my $AnnotNames = $Args{Annotations} || [];
Condition50%1/2
$Args{'Annotations'} || []
l!l
01
MC/DC0%0/1
$Args{'Annotations'} || []
$Args{'Annotations'}
Truth table50%1/2
A
A= $Args{'Annotations'}
Aresult
11
00
901 1 foreach my $key (@$AnnotNames) {
902 0 ▶ my $name = ($key =~ m/:/ ? $key : "C:$key");
Branch: 1 branch
BranchTrueFalseTotal
$key =~ /:/ ? : 0 0 0
903 0 push @Annotations, x($name);
904 }
905  
906 1 my %CalProps;
907 1 ▶ if ($Args{ContentType}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args{"ContentType"}) 0 1 1
908 0 $CalProps{'content-type'} = $Args{ContentType};
909 }
910 1 ▶ if ($Args{Version}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args{"Version"}) 0 1 1
911 0 $CalProps{'version'} = $Args{Version};
912 }
913  
914 1 my (@Events, @Errors, %Links);
915  
916 1 ▶ while (my @urls = splice(@$Urls, 0, $BATCHSIZE)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@urls) = splice(@$Urls, 0, $Net::CalDAVTalk::BATCHSIZE)) 1 1 2
917 my $Response = $Self->Request(
918 'REPORT',
919 "$calendarId/",
920 x('C:calendar-multiget', $Self->NS(),
921 x('D:prop',
922 x('C:calendar-data', \%CalProps),
923 x('D:getetag'),
924 @Annotations,
925 ),
926 1 map { x('D:href', $Self->request_href($_)) } @urls,
927  
928 ),
929 Depth => 1,
930 );
931  
932 1 my $NS_A = $Self->ns('A');
933 1 my $NS_C = $Self->ns('C');
934 1 my $NS_D = $Self->ns('D');
935 1 ▶ foreach my $Response (@{$Response->{"{$NS_D}response"} || []}) {
Condition50%1/2
$$Response{"{$NS_D}response"} || []
l!l
01
MC/DC0%0/1
$$Response{"{$NS_D}response"} || []
$$Response{"{$NS_D}response"}
Truth table50%1/2
A
A= $$Response{"{$NS_D}response"}
Aresult
11
00
936 0 ▶ my $href = uri_unescape($Response->{"{$NS_D}href"}{content} // '');
Condition0%0/2
$$Response{"{$NS_D}href"}{"content"} // ""
l!l
00
MC/DC0%0/1
$$Response{"{$NS_D}href"}{"content"} // ""
$$Response{"{$NS_D}href"}{"content"}
Truth table0%0/2
A
A= $$Response{"{$NS_D}href"}{"content"}
Aresult
11
00
937 0 ▶ next unless $href;
Branch: 1 branch
BranchTrueFalseTotal
unless $href 0 0 0
938 0 ▶ foreach my $Propstat (@{$Response->{"{$NS_D}propstat"} || []}) {
Condition0%0/2
$$Response{"{$NS_D}propstat"} || []
l!l
00
MC/DC0%0/1
$$Response{"{$NS_D}propstat"} || []
$$Response{"{$NS_D}propstat"}
Truth table0%0/2
A
A= $$Response{"{$NS_D}propstat"}
Aresult
11
00
939 0 my $etag = $Propstat->{"{$NS_D}prop"}{"{$NS_D}getetag"}{content};
940 0 $Links{$href} = $etag;
941 0 my $Prop = $Propstat->{"{$NS_D}prop"}{"{$NS_C}calendar-data"};
942 0 my $Data = $Prop->{content};
943 0 ▶ next unless $Data;
Branch: 1 branch
BranchTrueFalseTotal
unless $Data 0 0 0
944  
945 0 my $Event;
946  
947 0 ▶ if ($Prop->{'-content-type'} and $Prop->{'-content-type'} =~ m{application/event\+json}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Prop->{'-content-type'} and $Prop->{'-content-type'} =~ m[application/event\+json]) { } 0 0 0
Condition0%0/3
$Prop->{"-content-type"} and $Prop->{"-content-type"} =~ m[application/event\+json]
!ll&&!rl&&r
000
MC/DC0%0/2
$Prop->{"-content-type"} and $Prop->{"-content-type"} =~ m[application/event\+json]
$Prop->{"-content-type"} $Prop->{"-content-type"} =~ m[application/event\+json]
Truth table0%0/3
A and B
A= $Prop->{"-content-type"}B= $Prop->{"-content-type"} =~ m[application/event\+json]
ABresult
0X0
100
111
948 # JSON event is in API format already
949 0 $Event = eval { decode_json($Data) };
950 }
951 else {
952 # returns an array, but there should only be one UID per file
953 0 ($Event) = eval { $Self->vcalendarToEvents($Data) };
954 }
955  
956 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
957 0 push @Errors, $@;
958 0 next;
959 }
960 0 ▶ next unless $Event;
Branch: 1 branch
BranchTrueFalseTotal
unless $Event 0 0 0
961  
962 0 ▶ if ($Args{Full}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args{"Full"}) 0 0 0
963 0 $Event->{_raw} = $Data;
964 }
965  
966 0 $Event->{href} = $href;
967 0 $Event->{id} = $Self->shortpath($href);
968  
969 0 foreach my $key (@$AnnotNames) {
970 0 my $propns = $NS_C;
971 0 my $name = $key;
972 0 ▶ if ($key =~ m/(.*):(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /(.*):(.*)/) 0 0 0
973 0 $name = $2;
974 0 $propns = $Self->ns($1);
975 }
976 0 my $AData = $Propstat->{"{$NS_D}prop"}{"{$propns}$name"}{content};
977 0 ▶ next unless $AData;
Branch: 1 branch
BranchTrueFalseTotal
unless $AData 0 0 0
978 0 $Event->{annotation}{$name} = $AData;
979 }
980  
981 0 push @Events, $Event;
982 }
983 }
984 }
985  
986 1 ▶ return wantarray ? (\@Events, \@Errors, \%Links) : \@Events;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 1 1
987 }
988  
989 =head2 $self->GetEventLinks($calendarId, %Args)
990  
991 Fetches the URLs of calendar events in a calendar.
992  
993 Supported args:
994  
995 after+before => ISO8601 - date range to query
996  
997 returns a hash of href to etag
998  
999 =cut
1000  
1001 0 ▶sub GetEventLinks {
Subroutine GetEventLinks: not called CC=13 SCAR=52.0
Pod documented
1002 0 my ($Self, $calendarId, %Args) = @_;
1003 0 ▶ confess "Need a calendarId" unless $calendarId;
Branch: 1 branch
BranchTrueFalseTotal
unless $calendarId 0 0 0
1004  
1005 0 my @Extra;
1006 0 ▶ if ($Args{AlwaysRange} || $Args{after} || $Args{before}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args{"AlwaysRange"} or $Args{"after"} or $Args{"before"}) 0 0 0
Condition0%0/6
$Args{"AlwaysRange"} or $Args{"after"} or $Args{"before"}
l!l&&r!l&&!r
000
$Args{"AlwaysRange"} or $Args{"after"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$Args{"AlwaysRange"} or $Args{"after"} or $Args{"before"}
$Args{"AlwaysRange"} $Args{"after"} $Args{"before"}
Truth table0%0/4
A or B or C
A= $Args{"AlwaysRange"}B= $Args{"after"}C= $Args{"before"}
ABCresult
1XX1
01X1
0011
0000
1007 0 ▶ my $Start = _wireDate($Args{after} || $BoT);
Condition0%0/3
$Args{'after'} || $BoT
l!l&&r!l&&!r
000
MC/DC0%0/2
$Args{'after'} || $BoT
$Args{'after'} $BoT
Truth table0%0/3
A || B
A= $Args{'after'}B= $BoT
ABresult
1X1
011
000
1008 0 ▶ my $End = _wireDate($Args{before} || $EoT);
Condition0%0/3
$Args{'before'} || $EoT
l!l&&r!l&&!r
000
MC/DC0%0/2
$Args{'before'} || $EoT
$Args{'before'} $EoT
Truth table0%0/3
A || B
A= $Args{'before'}B= $EoT
ABresult
1X1
011
000
1009 0 push @Extra, x('C:time-range', {
1010 start => $Start->strftime('%Y%m%dT000000Z'),
1011 end => $End->strftime('%Y%m%dT000000Z'),
1012 });
1013 }
1014  
1015 0 my $Response = $Self->Request(
1016 'REPORT',
1017 "$calendarId/",
1018 x('C:calendar-query', $Self->NS(),
1019 x('D:prop',
1020 x('D:getetag'),
1021 ),
1022 x('C:filter',
1023 x('C:comp-filter', { name => 'VCALENDAR' },
1024 x('C:comp-filter', { name => 'VEVENT' },
1025 @Extra,
1026 ),
1027 ),
1028 ),
1029 ),
1030 Depth => 1,
1031 );
1032  
1033 0 my (%Links, @Errors);
1034  
1035 0 my $NS_A = $Self->ns('A');
1036 0 my $NS_C = $Self->ns('C');
1037 0 my $NS_D = $Self->ns('D');
1038 0 ▶ foreach my $Response (@{$Response->{"{$NS_D}response"} || []}) {
Condition0%0/2
$$Response{"{$NS_D}response"} || []
l!l
00
MC/DC0%0/1
$$Response{"{$NS_D}response"} || []
$$Response{"{$NS_D}response"}
Truth table0%0/2
A
A= $$Response{"{$NS_D}response"}
Aresult
11
00
1039 0 ▶ my $href = uri_unescape($Response->{"{$NS_D}href"}{content} // '');
Condition0%0/2
$$Response{"{$NS_D}href"}{"content"} // ""
l!l
00
MC/DC0%0/1
$$Response{"{$NS_D}href"}{"content"} // ""
$$Response{"{$NS_D}href"}{"content"}
Truth table0%0/2
A
A= $$Response{"{$NS_D}href"}{"content"}
Aresult
11
00
1040 0 ▶ next unless $href;
Branch: 1 branch
BranchTrueFalseTotal
unless $href 0 0 0
1041 0 ▶ foreach my $Propstat (@{$Response->{"{$NS_D}propstat"} || []}) {
Condition0%0/2
$$Response{"{$NS_D}propstat"} || []
l!l
00
MC/DC0%0/1
$$Response{"{$NS_D}propstat"} || []
$$Response{"{$NS_D}propstat"}
Truth table0%0/2
A
A= $$Response{"{$NS_D}propstat"}
Aresult
11
00
1042 0 my $etag = $Propstat->{"{$NS_D}prop"}{"{$NS_D}getetag"}{content};
1043 0 $Links{$href} = $etag;
1044 }
1045 }
1046  
1047 0 return \%Links;
1048 }
1049  
1050 =head2 $self->GetEvent($href)
1051  
1052 Just get a single event (calls GetEvents with that href)
1053  
1054 =cut
1055  
1056 0 ▶sub GetEvent {
Subroutine GetEvent: not called CC=3 SCAR=24.8
Pod documented
1057 0 my ($Self, $href, %Args) = @_;
1058  
1059 # XXX - API
1060 0 my $calendarId = $href;
1061 0 $calendarId =~ s{/[^/]*$}{};
1062  
1063 0 my ($Events, $Errors) = $Self->GetEventsMulti($calendarId, [$Self->fullpath($href)], %Args);
1064  
1065 0 ▶ die "Errors @$Errors" if @$Errors;
Branch: 1 branch
BranchTrueFalseTotal
if @$Errors 0 0 0
1066 0 ▶ die "Multiple items returned for $href" if @$Events > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @$Events > 1 0 0 0
1067  
1068 0 return $Events->[0];
1069 }
1070  
1071 =head2 $self->GetFreeBusy($calendarId, %Args)
1072  
1073 Like 'GetEvents' but uses a free-busy-query and then generates
1074 synthetic events out of the result.
1075  
1076 Doesn't have a 'href' parameter, just the before/after range.
1077  
1078 =cut
1079  
1080 0 ▶sub GetFreeBusy {
Subroutine GetFreeBusy: not called CC=16 SCAR=56.1
Pod documented
1081 0 my ($Self, $calendarId, %Args) = @_;
1082  
1083 # validate parameters {{{
1084  
1085 0 ▶ confess "Need a calendarId" unless $calendarId;
Branch: 1 branch
BranchTrueFalseTotal
unless $calendarId 0 0 0
1086  
1087 0 my @Query;
1088 0 ▶ if ($Args{AlwaysRange} || $Args{after} || $Args{before}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args{"AlwaysRange"} or $Args{"after"} or $Args{"before"}) 0 0 0
Condition0%0/6
$Args{"AlwaysRange"} or $Args{"after"} or $Args{"before"}
l!l&&r!l&&!r
000
$Args{"AlwaysRange"} or $Args{"after"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$Args{"AlwaysRange"} or $Args{"after"} or $Args{"before"}
$Args{"AlwaysRange"} $Args{"after"} $Args{"before"}
Truth table0%0/4
A or B or C
A= $Args{"AlwaysRange"}B= $Args{"after"}C= $Args{"before"}
ABCresult
1XX1
01X1
0011
0000
1089 0 ▶ my $Start = _wireDate($Args{after} || $BoT);
Condition0%0/3
$Args{'after'} || $BoT
l!l&&r!l&&!r
000
MC/DC0%0/2
$Args{'after'} || $BoT
$Args{'after'} $BoT
Truth table0%0/3
A || B
A= $Args{'after'}B= $BoT
ABresult
1X1
011
000
1090 0 ▶ my $End = _wireDate($Args{before} || $EoT);
Condition0%0/3
$Args{'before'} || $EoT
l!l&&r!l&&!r
000
MC/DC0%0/2
$Args{'before'} || $EoT
$Args{'before'} $EoT
Truth table0%0/3
A || B
A= $Args{'before'}B= $EoT
ABresult
1X1
011
000
1091  
1092 0 push @Query,
1093 x('C:time-range', {
1094 start => $Start->strftime('%Y%m%dT000000Z'),
1095 end => $End->strftime('%Y%m%dT000000Z'),
1096 });
1097 }
1098  
1099 # }}}
1100  
1101 0 my $Response = $Self->Request(
1102 'REPORT',
1103 "$calendarId/",
1104 x('C:free-busy-query', $Self->NS(),
1105 @Query,
1106 ),
1107 Depth => 1,
1108 );
1109  
1110 0 ▶ my $Data = eval { vcard2hash($Response->{content}, multival => ['rrule'], only_one => 1) }
Branch: 1 branch
BranchTrueFalseTotal
my $Data = eval { do { vcard2hash($Response->{"content"}, "multival", ["rrule"], "only_one", 1) } } or confess("Error parsing VFreeBusy data: $@") 0 0 0
1111 or confess "Error parsing VFreeBusy data: $@";
1112  
1113 0 my @result;
1114 my @errors;
1115 0 my $now = DateTime->now();
1116 0 foreach my $item (@{$Data->{objects}[0]{objects}}) {
1117 0 ▶ next unless $item->{type} eq 'vfreebusy';
Branch: 1 branch
BranchTrueFalseTotal
unless $item->{"type"} eq "vfreebusy" 0 0 0
1118 0 foreach my $line (@{$item->{properties}{freebusy}}) {
1119 0 my ($Start, $End) = split '/', $line->{value};
1120 0 my ($StartTime, $IsAllDay) = $Self->_makeDateObj($Start, 'UTC', 'UTC');
1121 0 my $EndTime;
1122 0 ▶ if ($End =~ m/^[+-]?P/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($End =~ /^[+-]?P/i) { } 0 0 0
1123 0 ▶ my $Duration = eval { DateTime::Format::ICal->parse_duration(uc $End) }
Condition0%0/2
eval { do { 'DateTime::Format::ICal'->parse_duration(uc $End) } } || (next)
l!l
00
MC/DC0%0/1
eval { do { 'DateTime::Format::ICal'->parse_duration(uc $End) } } || (next)
eval { do { 'DateTime::Format::ICal'->parse_duration(uc $End) } }
Truth table0%0/2
A
A= eval { do { 'DateTime::Format::ICal'->parse_duration(uc $End) } }
Aresult
11
00
1124 || next;
1125 0 $EndTime = $StartTime->clone()->add($Duration);
1126 } else {
1127 0 ($EndTime) = $Self->_makeDateObj($End, 'UTC', 'UTC');
1128 }
1129 0 my $duration = $Self->_make_duration($EndTime->subtract_datetime($StartTime));
1130 my $NewEvent = {
1131 timeZone => 'Etc/UTC',
1132 start => $StartTime->iso8601(),
1133 duration => $duration,
1134 0 ▶ title => ($Args{name} // ''),
Branch: 1 branch
BranchTrueFalseTotal
$IsAllDay ? : 0 0 0
Condition0%0/2
$Args{"name"} // ""
l!l
00
MC/DC0%0/1
$Args{"name"} // ""
$Args{"name"}
Truth table0%0/2
A
A= $Args{"name"}
Aresult
11
00
1135 isAllDay => ($IsAllDay ? $JSON::true : $JSON::false),
1136 updated => $now->iso8601(),
1137 };
1138  
1139 # Generate a uid that should remain the same for this freebusy entry
1140 0 $NewEvent->{uid} = _hexkey($NewEvent) . '-freebusyauto';
1141 $NewEvent->{isAllDay} =
1142 0 ▶ $NewEvent->{isAllDay} ? $JSON::true : $JSON::false;
Branch: 1 branch
BranchTrueFalseTotal
$NewEvent->{'isAllDay'} ? : 0 0 0
1143 0 push @result, $NewEvent;
1144 }
1145 }
1146  
1147 0 return (\@result, \@errors);
1148 }
1149  
1150 =head2 $self->SyncEvents($calendarId, %Args)
1151  
1152 Like GetEvents, but if you pass a syncToken argument, then it will
1153 fetch changes since that token (obtained from an earlier GetCalendars
1154 call).
1155  
1156 In scalar context still just returns new events, in list context returns
1157 Events, Removed and Errors.
1158  
1159 e.g.
1160  
1161 my ($Events, $Removed, $Errors) = $CalDAV->SyncEvents('Default', syncToken => '...');
1162  
1163 =cut
1164  
1165 0 ▶sub SyncEvents {
Subroutine SyncEvents: not called CC=2 SCAR=17.9
Pod documented
1166 0 my ($Self, $calendarId, %Args) = @_;
1167  
1168 0 my ($Added, $Removed, $Errors, $SyncToken) = $Self->SyncEventLinks($calendarId, %Args);
1169  
1170 0 my @AllUrls = sort keys %$Added;
1171  
1172 0 my ($Events, $ThisErrors, $Links) = $Self->GetEventsMulti($calendarId, \@AllUrls, %Args);
1173 0 push @$Errors, @$ThisErrors;
1174  
1175 0 ▶ return wantarray ? ($Events, $Removed, $Errors, $SyncToken, $Links) : $Events;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1176 }
1177  
1178 =head2 $self->SyncEventLinks($calendarId, %Args)
1179  
1180 Like GetEventLinks, but if you pass a syncToken argument, then it will
1181 fetch changes since that token (obtained from an earlier GetCalendars
1182 or SyncEvent* call).
1183  
1184 In scalar context still just returns Added, in list context returns
1185 Added, Removed, Errors and new token (see Net::DAVTalk's SyncCollection,
1186 which follows a server's truncated responses, RFC 6578 section 3.6, so
1187 one call gets every change):
1188  
1189 * Added: hash of href to etag - added or changed
1190 * Removed: array of href
1191 * Errors: array of descriptive strings
1192 * NewToken: scalar opaque DAV:sync-token
1193  
1194 e.g.
1195  
1196 my ($Added, $Removed, $Errors, $NewToken)
1197 = $CalDAV->SyncEventLinks('Default', syncToken => '...');
1198  
1199 =cut
1200  
1201 1 ▶sub SyncEventLinks {
Subroutine SyncEventLinks: called CC=2 SCAR=7.1
Pod documented
1202 1 my ($Self, $calendarId, %Args) = @_;
1203  
1204 1 ▶ confess "Need a calendarId" unless $calendarId;
Branch: 1 branch
BranchTrueFalseTotal
unless $calendarId 0 1 1
1205  
1206 1 return $Self->SyncCollection($calendarId, %Args);
1207 }
1208  
1209 =head2 $self->NewEvent($calendarId, $Args)
1210  
1211 Create a new event in the named calendar. If you don't specify 'uid' then
1212 a UUID will be created. You should only specify the UID if you need to for
1213 syncing purposes - it's better to auto-generate otherwise.
1214  
1215 Returns the href, but also updates 'uid' in $Args.
1216  
1217 Also updates 'sequence'.
1218  
1219 Special keys consumed from $Args (not stored in the event):
1220  
1221 =over 4
1222  
1223 =item _no_schedule
1224  
1225 If true, sends C<Schedule-Reply: false> on the PUT request, suppressing
1226 iTIP scheduling replies from the server (RFC 6638 section 8.1).
1227  
1228 =back
1229  
1230 e.g.
1231  
1232 my $href = $CalDAV->NewEvent('Default', $Args);
1233 my $newuid = $Args->{uid};
1234  
1235 =cut
1236  
1237 0 ▶sub NewEvent {
Subroutine NewEvent: not called CC=11 SCAR=48.8
Pod documented
1238 0 my ($Self, $calendarId, $Args) = @_;
1239  
1240 0 ▶ confess "Need a calendarId" unless $calendarId;
Branch: 1 branch
BranchTrueFalseTotal
unless $calendarId 0 0 0
1241  
1242 0 ▶ confess "invalid event" unless ref($Args) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $Args eq "HASH" 0 0 0
1243  
1244 0 my $UseEvent = delete $Args->{_put_event_json};
1245 0 my $no_schedule = delete $Args->{_no_schedule};
1246 0 ▶ my @sched_header = $no_schedule ? ('Schedule-Reply' => 'false') : ();
Branch: 1 branch
BranchTrueFalseTotal
$no_schedule ? : 0 0 0
1247  
1248 # calculate updated sequence numbers
1249 0 ▶ unless (exists $Args->{sequence}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Args->{"sequence"}) 0 0 0
1250 0 $Args->{sequence} = 1;
1251 }
1252  
1253 0 ▶ if ($Args->{exceptions}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"exceptions"}) 0 0 0
1254 0 foreach my $recurrenceId (sort keys %{$Args->{exceptions}}) {
1255 0 my $val = $Args->{exceptions}{$recurrenceId};
1256 0 ▶ next unless $val;
Branch: 1 branch
BranchTrueFalseTotal
unless $val 0 0 0
1257 0 ▶ next if exists $val->{sequence};
Branch: 1 branch
BranchTrueFalseTotal
if exists $val->{"sequence"} 0 0 0
1258  
1259 0 $val->{sequence} = $Args->{sequence};
1260 }
1261 }
1262  
1263 0 ▶ $Args->{uid} //= $Self->genuuid();
Condition0%0/3
$Args->{"uid"} //= $Self->genuuid
l!l&&r!l&&!r
000
MC/DC0%0/2
$Args->{"uid"} //= $Self->genuuid
$Args->{"uid"} $Self->genuuid
Truth table0%0/3
A //= B
A= $Args->{"uid"}B= $Self->genuuid
ABresult
1X1
011
000
1264 0 my $uid = $Args->{uid};
1265 0 my $path = $uid;
1266 0 $path =~ tr/[a-zA-Z0-9\@\.\_\-]//cd;
1267 0 my $href = "$calendarId/$path.ics";
1268  
1269 0 ▶ if ($UseEvent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($UseEvent) { } 0 0 0
1270 0 $Self->Request(
1271 'PUT',
1272 $href,
1273 encode_json($Args),
1274 'Content-Type' => 'application/event+json',
1275 @sched_header,
1276 );
1277 }
1278 else {
1279 0 my $VCalendar = $Self->_argsToVCalendar($Args);
1280 0 $Self->Request(
1281 'PUT',
1282 $href,
1283 $VCalendar->as_string(),
1284 'Content-Type' => 'text/calendar',
1285 @sched_header,
1286 );
1287 }
1288  
1289 0 return $href;
1290 }
1291  
1292 =head2 $self->UpdateEvent($href, $Args)
1293  
1294 Like NewEvent, but you only need to specify keys that you want to change,
1295 and it takes the full href to the card instead of the containing calendar.
1296  
1297 Accepts the same special keys as NewEvent (e.g. C<_no_schedule>).
1298  
1299 =cut
1300  
1301 0 ▶sub UpdateEvent {
Subroutine UpdateEvent: not called CC=3 SCAR=24.8
Pod documented
1302 0 my ($Self, $href, $Args) = @_;
1303  
1304 0 my $UseEvent = delete $Args->{_put_event_json};
1305 0 my $no_schedule = delete $Args->{_no_schedule};
1306 0 ▶ my @sched_header = $no_schedule ? ('Schedule-Reply' => 'false') : ();
Branch: 1 branch
BranchTrueFalseTotal
$no_schedule ? : 0 0 0
1307  
1308 0 my ($OldEvent, $NewEvent) = $Self->_updateEvent($href, $Args);
1309  
1310 0 ▶ if ($UseEvent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($UseEvent) { } 0 0 0
1311 0 $Self->Request(
1312 'PUT',
1313 $href,
1314 encode_json($NewEvent),
1315 'Content-Type' => 'application/event+json',
1316 @sched_header,
1317 );
1318 }
1319 else {
1320 0 my $VCalendar = $Self->_argsToVCalendar($NewEvent);
1321 0 $Self->Request(
1322 'PUT',
1323 $href,
1324 $VCalendar->as_string(),
1325 'Content-Type' => 'text/calendar',
1326 @sched_header,
1327 );
1328 }
1329  
1330 0 return 1;
1331 }
1332  
1333 0 ▶sub _updateEvent {
Subroutine _updateEvent: not called CC=23 SCAR=63.1
1334 0 my ($Self, $href, $Args) = @_;
1335  
1336 0 my $OldEvent = $Self->GetEvent($href);
1337  
1338 0 ▶ confess "Error getting old event for $href"
Branch: 1 branch
BranchTrueFalseTotal
unless $OldEvent 0 0 0
1339 unless $OldEvent;
1340  
1341 # Merge patch onto old event (both are flat JSCalendar hashes)
1342 0 my %NewEvent = %$OldEvent;
1343 0 for my $key (keys %$Args) {
1344 0 ▶ if (defined $Args->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Args->{$key}) { } 0 0 0
1345 0 $NewEvent{$key} = $Args->{$key};
1346 } else {
1347 0 delete $NewEvent{$key};
1348 }
1349 }
1350  
1351 # calculate updated sequence numbers
1352 0 ▶ unless (exists $Args->{sequence}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Args->{"sequence"}) 0 0 0
1353 0 ▶ $NewEvent{sequence} = ($OldEvent->{sequence} || 0) + 1;
Condition0%0/2
$OldEvent->{'sequence'} || 0
l!l
00
MC/DC0%0/1
$OldEvent->{'sequence'} || 0
$OldEvent->{'sequence'}
Truth table0%0/2
A
A= $OldEvent->{'sequence'}
Aresult
11
00
1354 }
1355  
1356 0 ▶ if ($NewEvent{exceptions}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($NewEvent{"exceptions"}) 0 0 0
1357 0 foreach my $recurrenceId (sort keys %{$NewEvent{exceptions}}) {
1358 0 my $val = $NewEvent{exceptions}{$recurrenceId};
1359 0 ▶ next unless $val;
Branch: 1 branch
BranchTrueFalseTotal
unless $val 0 0 0
1360 0 ▶ next if exists $val->{sequence};
Branch: 1 branch
BranchTrueFalseTotal
if exists $val->{"sequence"} 0 0 0
1361  
1362 0 my $old = $OldEvent->{exceptions}{$recurrenceId};
1363 0 my $sequence = $NewEvent{sequence};
1364 0 ▶ if ($old && exists $old->{sequence}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($old and exists $old->{"sequence"}) 0 0 0
Condition0%0/3
$old and exists $old->{"sequence"}
!ll&&!rl&&r
000
MC/DC0%0/2
$old and exists $old->{"sequence"}
$old exists $old->{"sequence"}
Truth table0%0/3
A and B
A= $oldB= exists $old->{"sequence"}
ABresult
0X0
100
111
1365 0 ▶ $sequence = $old->{sequence} + 1 unless $sequence > $old->{sequence};
Branch: 1 branch
BranchTrueFalseTotal
unless $sequence > $old->{"sequence"} 0 0 0
1366 }
1367 0 ▶ $val->{sequence} = $sequence if $sequence > $NewEvent{sequence};
Branch: 1 branch
BranchTrueFalseTotal
if $sequence > $NewEvent{"sequence"} 0 0 0
1368 }
1369 }
1370  
1371 0 ▶ if ($NewEvent{recurrenceOverrides}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($NewEvent{"recurrenceOverrides"}) 0 0 0
1372 0 foreach my $recurrenceId (sort keys %{$NewEvent{recurrenceOverrides}}) {
1373 0 my $val = $NewEvent{recurrenceOverrides}{$recurrenceId};
1374 0 ▶ next unless $val;
Branch: 1 branch
BranchTrueFalseTotal
unless $val 0 0 0
1375 0 ▶ next if exists $val->{sequence};
Branch: 1 branch
BranchTrueFalseTotal
if exists $val->{"sequence"} 0 0 0
1376  
1377 0 ▶ my $old = ($OldEvent->{recurrenceOverrides} || {})->{$recurrenceId};
Condition0%0/2
$OldEvent->{'recurrenceOverrides'} || {}
l!l
00
MC/DC0%0/1
$OldEvent->{'recurrenceOverrides'} || {}
$OldEvent->{'recurrenceOverrides'}
Truth table0%0/2
A
A= $OldEvent->{'recurrenceOverrides'}
Aresult
11
00
1378 0 my $sequence = $NewEvent{sequence};
1379 0 ▶ if ($old && exists $old->{sequence}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($old and exists $old->{"sequence"}) 0 0 0
Condition0%0/3
$old and exists $old->{"sequence"}
!ll&&!rl&&r
000
MC/DC0%0/2
$old and exists $old->{"sequence"}
$old exists $old->{"sequence"}
Truth table0%0/3
A and B
A= $oldB= exists $old->{"sequence"}
ABresult
0X0
100
111
1380 0 ▶ $sequence = $old->{sequence} + 1 unless $sequence > $old->{sequence};
Branch: 1 branch
BranchTrueFalseTotal
unless $sequence > $old->{"sequence"} 0 0 0
1381 }
1382 0 ▶ $val->{sequence} = $sequence if $sequence > $NewEvent{sequence};
Branch: 1 branch
BranchTrueFalseTotal
if $sequence > $NewEvent{"sequence"} 0 0 0
1383 }
1384 }
1385  
1386 0 $NewEvent{href} = $href;
1387  
1388 0 return ($OldEvent, \%NewEvent);
1389 }
1390  
1391 =head2 $self->AnnotateEvent($href, $Args)
1392  
1393 Instead of actually changing an event itself, use proppatch to
1394 add or remove properties on the event.
1395  
1396 =cut
1397  
1398 0 ▶sub AnnotateEvent {
Subroutine AnnotateEvent: not called CC=8 SCAR=42.8
Pod documented
1399 0 my ($Self, $href, $Args) = @_;
1400  
1401 0 my $OldEvent = $Self->GetEvent($href);
1402  
1403 0 ▶ confess "Error getting old event for $href"
Branch: 1 branch
BranchTrueFalseTotal
unless $OldEvent 0 0 0
1404 unless $OldEvent;
1405  
1406 0 my @Set;
1407 my @Remove;
1408 0 foreach my $key (sort keys %$Args) {
1409 0 ▶ my $name = ($key =~ m/:/ ? $key : "C:$key");
Branch: 1 branch
BranchTrueFalseTotal
$key =~ /:/ ? : 0 0 0
1410 0 ▶ if (defined $Args->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Args->{$key}) { } 0 0 0
1411 0 push @Set, x($name, $Args->{$key});
1412 }
1413 else {
1414 0 push @Remove, x($name);
1415 }
1416 }
1417  
1418 0 my @Params;
1419 0 ▶ push @Params, x('D:set', x('D:prop', @Set)) if @Set;
Branch: 1 branch
BranchTrueFalseTotal
if @Set 0 0 0
1420 0 ▶ push @Params, x('D:remove', x('D:prop', @Remove)) if @Remove;
Branch: 1 branch
BranchTrueFalseTotal
if @Remove 0 0 0
1421 0 ▶ return undef unless @Params;
Branch: 1 branch
BranchTrueFalseTotal
unless @Params 0 0 0
1422  
1423 0 $Self->Request(
1424 'PROPPATCH',
1425 $href,
1426 x('D:propertyupdate', $Self->NS(), @Params),
1427 );
1428  
1429 0 return 1;
1430 }
1431  
1432 =head2 $self->MoveEvent($href, $newCalendarId)
1433  
1434 Move an event into a new calendar. Returns the new href.
1435  
1436 =cut
1437  
1438 0 ▶sub MoveEvent {
Subroutine MoveEvent: not called CC=3 SCAR=24.8
Pod documented
1439 0 my ($Self, $href, $newCalendarId) = @_;
1440  
1441 0 my $OldEvent = $Self->GetEvent($href);
1442  
1443 0 ▶ return unless $OldEvent;
Branch: 1 branch
BranchTrueFalseTotal
unless $OldEvent 0 0 0
1444  
1445 0 my $dest = $href;
1446 0 $dest =~ s{.*/}{$newCalendarId/};
1447 0 ▶ return if $href eq $dest;
Branch: 1 branch
BranchTrueFalseTotal
if $href eq $dest 0 0 0
1448  
1449 0 $Self->Request(
1450 'MOVE',
1451 $href,
1452 undef,
1453 'Destination' => $Self->fullpath($dest),
1454 );
1455  
1456 0 warn "CAL: MoveEvent $Self->{user} ($href => $dest)\n";
1457  
1458 0 return $dest;
1459 }
1460  
1461 # ============================================================
1462 # Conversion functions - delegated to Text::JSCalendar
1463 # ============================================================
1464  
1465 =head2 $NewEvent = Net::CalDAVTalk->NormaliseEvent($Event);
1466  
1467 Doesn't change the original event, but removes any keys which are the same as their default value
1468  
1469 =cut
1470  
1471 0 ▶sub NormaliseEvent {
Subroutine NormaliseEvent: not called CC=1 SCAR=6.9
Pod documented
1472 0 my ($class, $Event, $Root) = @_;
1473 0 return Text::JSCalendar->NormaliseEvent($Event, $Root);
1474 }
1475  
1476 =head2 Net::CalDAVTalk->CompareEvents($Event1, $Event2);
1477  
1478 Returns true if the events are identical
1479  
1480 =cut
1481  
1482 0 ▶sub CompareEvents {
Subroutine CompareEvents: not called CC=1 SCAR=6.9
Pod documented
1483 0 my ($class, $Event1, $Event2) = @_;
1484 0 return Text::JSCalendar->CompareEvents($Event1, $Event2);
1485 }
1486  
1487 10 ▶sub vcalendarToEvents {
Subroutine vcalendarToEvents: called CC=1 SCAR=0.0
Pod undocumented
1488 10 my $Self = shift;
1489 10 return $Self->_jscal->vcalendarToEvents(@_);
1490 }
1491  
1492 5 ▶sub _argsToVCalendar {
Subroutine _argsToVCalendar: called CC=1 SCAR=0.0
1493 5 my $Self = shift;
1494 5 return $Self->_jscal->_argsToVCalendar(@_);
1495 }
1496  
1497 0 ▶sub eventsToVCalendar {
Subroutine eventsToVCalendar: not called CC=1 SCAR=6.9
Pod undocumented
1498 0 my $Self = shift;
1499 0 return $Self->_jscal->eventsToVCalendar(@_);
1500 }
1501  
1502 # ============================================================
1503 # Minimal helpers still used by GetFreeBusy/GetEventLinks
1504 # ============================================================
1505  
1506 0 ▶sub _wireDate {
Subroutine _wireDate: not called CC=1 SCAR=6.9
1507 0 return Text::JSCalendar::_wireDate(@_);
1508 }
1509  
1510 0 ▶sub _makeDateObj {
Subroutine _makeDateObj: not called CC=1 SCAR=6.9
1511 0 my $Self = shift;
1512 0 return $Self->_jscal->_makeDateObj(@_);
1513 }
1514  
1515 0 ▶sub _make_duration {
Subroutine _make_duration: not called CC=1 SCAR=6.9
1516 0 my $Self = shift;
1517 0 return $Self->_jscal->_make_duration(@_);
1518 }
1519  
1520 0 ▶sub _hexkey {
Subroutine _hexkey: not called CC=1 SCAR=6.9
1521 0 return Text::JSCalendar::_hexkey(@_);
1522 }
1523  
1524 0 ▶sub _stripNonICal {
Subroutine _stripNonICal: not called CC=5 SCAR=34.0
1525 0 my $Self = shift;
1526 0 my $Event = shift;
1527  
1528 0 delete $Event->{alerts};
1529 0 delete $Event->{attendees};
1530 0 delete $Event->{organizer};
1531 0 delete $Event->{participants};
1532 0 delete $Event->{organizerCalendarAddress};
1533  
1534 0 ▶ foreach my $exception (values %{$Event->{exceptions} || $Event->{recurrenceOverrides} || {}}) {
Condition0%0/5
$Event->{'exceptions'} || $Event->{'recurrenceOverrides'} || {}
l!l
00
$Event->{"exceptions"} or $Event->{"recurrenceOverrides"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$Event->{'exceptions'} || $Event->{'recurrenceOverrides'} || {}
$Event->{"exceptions"} $Event->{"recurrenceOverrides"}
Truth table0%0/3
A or B
A= $Event->{"exceptions"}B= $Event->{"recurrenceOverrides"}
ABresult
1X1
011
000
1535 0 ▶ next unless $exception;
Branch: 1 branch
BranchTrueFalseTotal
unless $exception 0 0 0
1536 0 $Self->_stripNonICal($exception);
1537 }
1538 }
1539  
1540 =head2 $self->UpdateAddressSet($DisplayName, $EmailAddress)
1541  
1542 Set the address set and display name for the calendar user (if supported)
1543  
1544 =cut
1545  
1546 0 ▶sub UpdateAddressSet {
Subroutine UpdateAddressSet: not called CC=5 SCAR=34.0
Pod documented
1547 0 my ($Self, $NewDisplayName, $NewAddressSet) = @_;
1548  
1549 0 my ($DisplayName, $AddressSet) = $Self->GetProps(\$Self->{principal}, 'D:displayname', [ 'C:calendar-user-address-set', 'D:href' ]);
1550  
1551 0 ▶ if (!$AddressSet || $AddressSet ne "mailto:" . $NewAddressSet ||
Branch: 1 branch
BranchTrueFalseTotal
if (not $AddressSet or $AddressSet ne 'mailto:' . $NewAddressSet or not $DisplayName or $DisplayName ne $NewDisplayName) 0 0 0
Condition0%0/9
not $AddressSet or $AddressSet ne 'mailto:' . $NewAddressSet or not $DisplayName or $DisplayName ne $NewDisplayName
l!l&&r!l&&!r
000
not $AddressSet or $AddressSet ne 'mailto:' . $NewAddressSet or not $DisplayName
l!l&&r!l&&!r
000
not $AddressSet or $AddressSet ne 'mailto:' . $NewAddressSet
l!l&&r!l&&!r
000
MC/DC0%0/4
not $AddressSet or $AddressSet ne 'mailto:' . $NewAddressSet or not $DisplayName or $DisplayName ne $NewDisplayName
not $AddressSet $AddressSet ne 'mailto:' . $NewAddressSet not $DisplayName $DisplayName ne $NewDisplayName
Truth table0%0/5
not(A) or B or not(C) or D
A= not $AddressSetB= $AddressSet ne 'mailto:' . $NewAddressSetC= not $DisplayNameD= $DisplayName ne $NewDisplayName
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1552 !$DisplayName || $DisplayName ne $NewDisplayName) {
1553 0 $Self->Request(
1554 'PROPPATCH',
1555 "",
1556 x('D:propertyupdate', $Self->NS(),
1557 x('D:set',
1558 x('D:prop',
1559 x('D:displayname', $NewDisplayName),
1560 x('C:calendar-user-address-set', "mailto:" . $NewAddressSet),
1561 )
1562 )
1563 )
1564 );
1565 0 return 1;
1566 }
1567  
1568 0 return 0;
1569 }
1570  
1571 =head2 $self->GetICal($calendarId, $isFreeBusy)
1572  
1573 Given a calender, fetch all the events and generate an ical format file
1574 suitable for import into a client.
1575  
1576 =cut
1577  
1578 0 ▶sub GetICal {
Subroutine GetICal: not called CC=7 SCAR=40.3
Pod documented
1579 0 my $Self = shift;
1580 0 my $calendarId = shift;
1581 0 my $isFreeBusy = shift;
1582  
1583 0 ▶ confess "Need a calendarId" unless $calendarId;
Branch: 1 branch
BranchTrueFalseTotal
unless $calendarId 0 0 0
1584  
1585 0 my $Calendars = $Self->GetCalendars();
1586 0 foreach my $Cal (@$Calendars) {
1587 0 ▶ next unless $calendarId eq $Cal->{id};
Branch: 1 branch
BranchTrueFalseTotal
unless $calendarId eq $Cal->{"id"} 0 0 0
1588 0 ▶ my ($Events, $Errors) = $isFreeBusy ?
Branch: 1 branch
BranchTrueFalseTotal
$isFreeBusy ? : 0 0 0
1589 $Self->GetFreeBusy($calendarId) :
1590 $Self->GetEvents($calendarId);
1591 0 ▶ return undef if @$Errors;
Branch: 1 branch
BranchTrueFalseTotal
if @$Errors 0 0 0
1592 0 $Self->_stripNonICal($_) for @$Events;
1593 my $VCalendar = $Self->_argsToVCalendar($Events,
1594 method => 'PUBLISH',
1595 'x-wr-calname' => $Cal->{name},
1596 'x-wr-timezone' => $Cal->{timeZone},
1597 'x-apple-calendar-color' => $Cal->{color},
1598 # XXX - do we want to add our sync-token here or something?
1599 0 );
1600 0 return ($VCalendar->as_string(), $Cal);
1601 }
1602 0 return undef; # 404
1603 }
1604  
1605 =head1 AUTHOR
1606  
1607 Bron Gondwana, C<< <brong at cpan.org> >>
1608  
1609 =head1 BUGS
1610  
1611 Please report any bugs or feature requests to C<bug-net-caldavtalk at rt.cpan.org>, or through
1612 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-CalDAVTalk>. I will be notified, and then you'll
1613 automatically be notified of progress on your bug as I make changes.
1614  
1615  
1616  
1617  
1618 =head1 SUPPORT
1619  
1620 You can find documentation for this module with the perldoc command.
1621  
1622 perldoc Net::CalDAVTalk
1623  
1624  
1625 You can also look for information at:
1626  
1627 =over 4
1628  
1629 =item * RT: CPAN's request tracker (report bugs here)
1630  
1631 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-CalDAVTalk>
1632  
1633 =item * AnnoCPAN: Annotated CPAN documentation
1634  
1635 L<http://annocpan.org/dist/Net-CalDAVTalk>
1636  
1637 =item * CPAN Ratings
1638  
1639 L<http://cpanratings.perl.org/d/Net-CalDAVTalk>
1640  
1641 =item * Search CPAN
1642  
1643 L<http://search.cpan.org/dist/Net-CalDAVTalk/>
1644  
1645 =back
1646  
1647  
1648 =head1 ACKNOWLEDGEMENTS
1649  
1650  
1651 =head1 LICENSE AND COPYRIGHT
1652  
1653 Copyright 2015-2026 Fastmail Pty Ltd.
1654  
1655 This program is free software; you can redistribute it and/or modify it
1656 under the same terms as Perl itself; that is, either the GNU General
1657 Public License as published by the Free Software Foundation (version 1,
1658 or at your option any later version), or the Artistic License.
1659  
1660 See L<http://dev.perl.org/licenses/> and the LICENSE file included with
1661 this distribution for more information.
1662  
1663 =cut
1664  
1665 4 1; # End of Net::CalDAVTalk
↑ Summary CalDAVTalk/TimeZones.pm »