Plugin.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, Roeland Jago Douma <roeland@famdouma.nl>
  4. * @copyright Copyright (c) 2016, Joas Schilling <coding@schilljs.com>
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Daniel Kesselberg <mail@danielkesselberg.de>
  8. * @author Georg Ehrke <oc.list@georgehrke.com>
  9. * @author Joas Schilling <coding@schilljs.com>
  10. * @author Roeland Jago Douma <roeland@famdouma.nl>
  11. * @author Thomas Citharel <nextcloud@tcit.fr>
  12. * @author Richard Steinmetz <richard@steinmetz.cloud>
  13. *
  14. * @license GNU AGPL version 3 or any later version
  15. *
  16. * This program is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License as
  18. * published by the Free Software Foundation, either version 3 of the
  19. * License, or (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Affero General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Affero General Public License
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. *
  29. */
  30. namespace OCA\DAV\CalDAV\Schedule;
  31. use DateTimeZone;
  32. use OCA\DAV\CalDAV\CalDavBackend;
  33. use OCA\DAV\CalDAV\Calendar;
  34. use OCA\DAV\CalDAV\CalendarHome;
  35. use OCP\IConfig;
  36. use Psr\Log\LoggerInterface;
  37. use Sabre\CalDAV\ICalendar;
  38. use Sabre\DAV\INode;
  39. use Sabre\DAV\IProperties;
  40. use Sabre\DAV\PropFind;
  41. use Sabre\DAV\Server;
  42. use Sabre\DAV\Xml\Property\LocalHref;
  43. use Sabre\DAVACL\IPrincipal;
  44. use Sabre\HTTP\RequestInterface;
  45. use Sabre\HTTP\ResponseInterface;
  46. use Sabre\VObject\Component;
  47. use Sabre\VObject\Component\VCalendar;
  48. use Sabre\VObject\Component\VEvent;
  49. use Sabre\VObject\DateTimeParser;
  50. use Sabre\VObject\FreeBusyGenerator;
  51. use Sabre\VObject\ITip;
  52. use Sabre\VObject\Parameter;
  53. use Sabre\VObject\Property;
  54. use Sabre\VObject\Reader;
  55. use function \Sabre\Uri\split;
  56. class Plugin extends \Sabre\CalDAV\Schedule\Plugin {
  57. /**
  58. * @var IConfig
  59. */
  60. private $config;
  61. /** @var ITip\Message[] */
  62. private $schedulingResponses = [];
  63. /** @var string|null */
  64. private $pathOfCalendarObjectChange = null;
  65. public const CALENDAR_USER_TYPE = '{' . self::NS_CALDAV . '}calendar-user-type';
  66. public const SCHEDULE_DEFAULT_CALENDAR_URL = '{' . Plugin::NS_CALDAV . '}schedule-default-calendar-URL';
  67. private LoggerInterface $logger;
  68. /**
  69. * @param IConfig $config
  70. */
  71. public function __construct(IConfig $config, LoggerInterface $logger) {
  72. $this->config = $config;
  73. $this->logger = $logger;
  74. }
  75. /**
  76. * Initializes the plugin
  77. *
  78. * @param Server $server
  79. * @return void
  80. */
  81. public function initialize(Server $server) {
  82. parent::initialize($server);
  83. $server->on('propFind', [$this, 'propFindDefaultCalendarUrl'], 90);
  84. $server->on('afterWriteContent', [$this, 'dispatchSchedulingResponses']);
  85. $server->on('afterCreateFile', [$this, 'dispatchSchedulingResponses']);
  86. }
  87. /**
  88. * Allow manual setting of the object change URL
  89. * to support public write
  90. *
  91. * @param string $path
  92. */
  93. public function setPathOfCalendarObjectChange(string $path): void {
  94. $this->pathOfCalendarObjectChange = $path;
  95. }
  96. /**
  97. * This method handler is invoked during fetching of properties.
  98. *
  99. * We use this event to add calendar-auto-schedule-specific properties.
  100. *
  101. * @param PropFind $propFind
  102. * @param INode $node
  103. * @return void
  104. */
  105. public function propFind(PropFind $propFind, INode $node) {
  106. if ($node instanceof IPrincipal) {
  107. // overwrite Sabre/Dav's implementation
  108. $propFind->handle(self::CALENDAR_USER_TYPE, function () use ($node) {
  109. if ($node instanceof IProperties) {
  110. $props = $node->getProperties([self::CALENDAR_USER_TYPE]);
  111. if (isset($props[self::CALENDAR_USER_TYPE])) {
  112. return $props[self::CALENDAR_USER_TYPE];
  113. }
  114. }
  115. return 'INDIVIDUAL';
  116. });
  117. }
  118. parent::propFind($propFind, $node);
  119. }
  120. /**
  121. * Returns a list of addresses that are associated with a principal.
  122. *
  123. * @param string $principal
  124. * @return array
  125. */
  126. protected function getAddressesForPrincipal($principal) {
  127. $result = parent::getAddressesForPrincipal($principal);
  128. if ($result === null) {
  129. $result = [];
  130. }
  131. return $result;
  132. }
  133. /**
  134. * @param RequestInterface $request
  135. * @param ResponseInterface $response
  136. * @param VCalendar $vCal
  137. * @param mixed $calendarPath
  138. * @param mixed $modified
  139. * @param mixed $isNew
  140. */
  141. public function calendarObjectChange(RequestInterface $request, ResponseInterface $response, VCalendar $vCal, $calendarPath, &$modified, $isNew) {
  142. // Save the first path we get as a calendar-object-change request
  143. if (!$this->pathOfCalendarObjectChange) {
  144. $this->pathOfCalendarObjectChange = $request->getPath();
  145. }
  146. parent::calendarObjectChange($request, $response, $vCal, $calendarPath, $modified, $isNew);
  147. }
  148. /**
  149. * @inheritDoc
  150. */
  151. public function scheduleLocalDelivery(ITip\Message $iTipMessage):void {
  152. /** @var VEvent|null $vevent */
  153. $vevent = $iTipMessage->message->VEVENT ?? null;
  154. // Strip VALARMs from incoming VEVENT
  155. if ($vevent && isset($vevent->VALARM)) {
  156. $vevent->remove('VALARM');
  157. }
  158. parent::scheduleLocalDelivery($iTipMessage);
  159. // We only care when the message was successfully delivered locally
  160. // Log all possible codes returned from the parent method that mean something went wrong
  161. // 3.7, 3.8, 5.0, 5.2
  162. if ($iTipMessage->scheduleStatus !== '1.2;Message delivered locally') {
  163. $this->logger->debug('Message not delivered locally with status: ' . $iTipMessage->scheduleStatus);
  164. return;
  165. }
  166. // We only care about request. reply and cancel are properly handled
  167. // by parent::scheduleLocalDelivery already
  168. if (strcasecmp($iTipMessage->method, 'REQUEST') !== 0) {
  169. return;
  170. }
  171. // If parent::scheduleLocalDelivery set scheduleStatus to 1.2,
  172. // it means that it was successfully delivered locally.
  173. // Meaning that the ACL plugin is loaded and that a principal
  174. // exists for the given recipient id, no need to double check
  175. /** @var \Sabre\DAVACL\Plugin $aclPlugin */
  176. $aclPlugin = $this->server->getPlugin('acl');
  177. $principalUri = $aclPlugin->getPrincipalByUri($iTipMessage->recipient);
  178. $calendarUserType = $this->getCalendarUserTypeForPrincipal($principalUri);
  179. if (strcasecmp($calendarUserType, 'ROOM') !== 0 && strcasecmp($calendarUserType, 'RESOURCE') !== 0) {
  180. $this->logger->debug('Calendar user type is room or resource, not processing further');
  181. return;
  182. }
  183. $attendee = $this->getCurrentAttendee($iTipMessage);
  184. if (!$attendee) {
  185. $this->logger->debug('No attendee set for scheduling message');
  186. return;
  187. }
  188. // We only respond when a response was actually requested
  189. $rsvp = $this->getAttendeeRSVP($attendee);
  190. if (!$rsvp) {
  191. $this->logger->debug('No RSVP requested for attendee ' . $attendee->getValue());
  192. return;
  193. }
  194. if (!$vevent) {
  195. $this->logger->debug('No VEVENT set to process on scheduling message');
  196. return;
  197. }
  198. // We don't support autoresponses for recurrencing events for now
  199. if (isset($vevent->RRULE) || isset($vevent->RDATE)) {
  200. $this->logger->debug('VEVENT is a recurring event, autoresponding not supported');
  201. return;
  202. }
  203. $dtstart = $vevent->DTSTART;
  204. $dtend = $this->getDTEndFromVEvent($vevent);
  205. $uid = $vevent->UID->getValue();
  206. $sequence = isset($vevent->SEQUENCE) ? $vevent->SEQUENCE->getValue() : 0;
  207. $recurrenceId = isset($vevent->{'RECURRENCE-ID'}) ? $vevent->{'RECURRENCE-ID'}->serialize() : '';
  208. $message = <<<EOF
  209. BEGIN:VCALENDAR
  210. PRODID:-//Nextcloud/Nextcloud CalDAV Server//EN
  211. METHOD:REPLY
  212. VERSION:2.0
  213. BEGIN:VEVENT
  214. ATTENDEE;PARTSTAT=%s:%s
  215. ORGANIZER:%s
  216. UID:%s
  217. SEQUENCE:%s
  218. REQUEST-STATUS:2.0;Success
  219. %sEND:VEVENT
  220. END:VCALENDAR
  221. EOF;
  222. if ($this->isAvailableAtTime($attendee->getValue(), $dtstart->getDateTime(), $dtend->getDateTime(), $uid)) {
  223. $partStat = 'ACCEPTED';
  224. } else {
  225. $partStat = 'DECLINED';
  226. }
  227. $vObject = Reader::read(vsprintf($message, [
  228. $partStat,
  229. $iTipMessage->recipient,
  230. $iTipMessage->sender,
  231. $uid,
  232. $sequence,
  233. $recurrenceId
  234. ]));
  235. $responseITipMessage = new ITip\Message();
  236. $responseITipMessage->uid = $uid;
  237. $responseITipMessage->component = 'VEVENT';
  238. $responseITipMessage->method = 'REPLY';
  239. $responseITipMessage->sequence = $sequence;
  240. $responseITipMessage->sender = $iTipMessage->recipient;
  241. $responseITipMessage->recipient = $iTipMessage->sender;
  242. $responseITipMessage->message = $vObject;
  243. // We can't dispatch them now already, because the organizers calendar-object
  244. // was not yet created. Hence Sabre/DAV won't find a calendar-object, when we
  245. // send our reply.
  246. $this->schedulingResponses[] = $responseITipMessage;
  247. }
  248. /**
  249. * @param string $uri
  250. */
  251. public function dispatchSchedulingResponses(string $uri):void {
  252. if ($uri !== $this->pathOfCalendarObjectChange) {
  253. return;
  254. }
  255. foreach ($this->schedulingResponses as $schedulingResponse) {
  256. $this->scheduleLocalDelivery($schedulingResponse);
  257. }
  258. }
  259. /**
  260. * Always use the personal calendar as target for scheduled events
  261. *
  262. * @param PropFind $propFind
  263. * @param INode $node
  264. * @return void
  265. */
  266. public function propFindDefaultCalendarUrl(PropFind $propFind, INode $node) {
  267. if ($node instanceof IPrincipal) {
  268. $propFind->handle(self::SCHEDULE_DEFAULT_CALENDAR_URL, function () use ($node) {
  269. /** @var \OCA\DAV\CalDAV\Plugin $caldavPlugin */
  270. $caldavPlugin = $this->server->getPlugin('caldav');
  271. $principalUrl = $node->getPrincipalUrl();
  272. $calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
  273. if (!$calendarHomePath) {
  274. return null;
  275. }
  276. $isResourceOrRoom = strpos($principalUrl, 'principals/calendar-resources') === 0 ||
  277. strpos($principalUrl, 'principals/calendar-rooms') === 0;
  278. if (strpos($principalUrl, 'principals/users') === 0) {
  279. [, $userId] = split($principalUrl);
  280. $uri = $this->config->getUserValue($userId, 'dav', 'defaultCalendar', CalDavBackend::PERSONAL_CALENDAR_URI);
  281. $displayName = CalDavBackend::PERSONAL_CALENDAR_NAME;
  282. } elseif ($isResourceOrRoom) {
  283. $uri = CalDavBackend::RESOURCE_BOOKING_CALENDAR_URI;
  284. $displayName = CalDavBackend::RESOURCE_BOOKING_CALENDAR_NAME;
  285. } else {
  286. // How did we end up here?
  287. // TODO - throw exception or just ignore?
  288. return null;
  289. }
  290. /** @var CalendarHome $calendarHome */
  291. $calendarHome = $this->server->tree->getNodeForPath($calendarHomePath);
  292. $currentCalendarDeleted = false;
  293. if (!$calendarHome->childExists($uri) || $currentCalendarDeleted = $this->isCalendarDeleted($calendarHome, $uri)) {
  294. // If the default calendar doesn't exist
  295. if ($isResourceOrRoom) {
  296. // Resources or rooms can't be in the trashbin, so we're fine
  297. $this->createCalendar($calendarHome, $principalUrl, $uri, $displayName);
  298. } else {
  299. // And we're not handling scheduling on resource/room booking
  300. $userCalendars = [];
  301. /**
  302. * If the default calendar of the user isn't set and the
  303. * fallback doesn't match any of the user's calendar
  304. * try to find the first "personal" calendar we can write to
  305. * instead of creating a new one.
  306. * A appropriate personal calendar to receive invites:
  307. * - isn't a calendar subscription
  308. * - user can write to it (no virtual/3rd-party calendars)
  309. * - calendar isn't a share
  310. */
  311. foreach ($calendarHome->getChildren() as $node) {
  312. if ($node instanceof Calendar && !$node->isSubscription() && $node->canWrite() && !$node->isShared() && !$node->isDeleted()) {
  313. $userCalendars[] = $node;
  314. }
  315. }
  316. if (count($userCalendars) > 0) {
  317. // Calendar backend returns calendar by calendarorder property
  318. $uri = $userCalendars[0]->getName();
  319. } else {
  320. // Otherwise if we have really nothing, create a new calendar
  321. if ($currentCalendarDeleted) {
  322. // If the calendar exists but is deleted, we need to purge it first
  323. // This may cause some issues in a non synchronous database setup
  324. $calendar = $this->getCalendar($calendarHome, $uri);
  325. if ($calendar instanceof Calendar) {
  326. $calendar->disableTrashbin();
  327. $calendar->delete();
  328. }
  329. }
  330. $this->createCalendar($calendarHome, $principalUrl, $uri, $displayName);
  331. }
  332. }
  333. }
  334. $result = $this->server->getPropertiesForPath($calendarHomePath . '/' . $uri, [], 1);
  335. if (empty($result)) {
  336. return null;
  337. }
  338. return new LocalHref($result[0]['href']);
  339. });
  340. }
  341. }
  342. /**
  343. * Returns a list of addresses that are associated with a principal.
  344. *
  345. * @param string $principal
  346. * @return string|null
  347. */
  348. protected function getCalendarUserTypeForPrincipal($principal):?string {
  349. $calendarUserType = '{' . self::NS_CALDAV . '}calendar-user-type';
  350. $properties = $this->server->getProperties(
  351. $principal,
  352. [$calendarUserType]
  353. );
  354. // If we can't find this information, we'll stop processing
  355. if (!isset($properties[$calendarUserType])) {
  356. return null;
  357. }
  358. return $properties[$calendarUserType];
  359. }
  360. /**
  361. * @param ITip\Message $iTipMessage
  362. * @return null|Property
  363. */
  364. private function getCurrentAttendee(ITip\Message $iTipMessage):?Property {
  365. /** @var VEvent $vevent */
  366. $vevent = $iTipMessage->message->VEVENT;
  367. $attendees = $vevent->select('ATTENDEE');
  368. foreach ($attendees as $attendee) {
  369. /** @var Property $attendee */
  370. if (strcasecmp($attendee->getValue(), $iTipMessage->recipient) === 0) {
  371. return $attendee;
  372. }
  373. }
  374. return null;
  375. }
  376. /**
  377. * @param Property|null $attendee
  378. * @return bool
  379. */
  380. private function getAttendeeRSVP(Property $attendee = null):bool {
  381. if ($attendee !== null) {
  382. $rsvp = $attendee->offsetGet('RSVP');
  383. if (($rsvp instanceof Parameter) && (strcasecmp($rsvp->getValue(), 'TRUE') === 0)) {
  384. return true;
  385. }
  386. }
  387. // RFC 5545 3.2.17: default RSVP is false
  388. return false;
  389. }
  390. /**
  391. * @param VEvent $vevent
  392. * @return Property\ICalendar\DateTime
  393. */
  394. private function getDTEndFromVEvent(VEvent $vevent):Property\ICalendar\DateTime {
  395. if (isset($vevent->DTEND)) {
  396. return $vevent->DTEND;
  397. }
  398. if (isset($vevent->DURATION)) {
  399. $isFloating = $vevent->DTSTART->isFloating();
  400. /** @var Property\ICalendar\DateTime $end */
  401. $end = clone $vevent->DTSTART;
  402. $endDateTime = $end->getDateTime();
  403. $endDateTime = $endDateTime->add(DateTimeParser::parse($vevent->DURATION->getValue()));
  404. $end->setDateTime($endDateTime, $isFloating);
  405. return $end;
  406. }
  407. if (!$vevent->DTSTART->hasTime()) {
  408. $isFloating = $vevent->DTSTART->isFloating();
  409. /** @var Property\ICalendar\DateTime $end */
  410. $end = clone $vevent->DTSTART;
  411. $endDateTime = $end->getDateTime();
  412. $endDateTime = $endDateTime->modify('+1 day');
  413. $end->setDateTime($endDateTime, $isFloating);
  414. return $end;
  415. }
  416. return clone $vevent->DTSTART;
  417. }
  418. /**
  419. * @param string $email
  420. * @param \DateTimeInterface $start
  421. * @param \DateTimeInterface $end
  422. * @param string $ignoreUID
  423. * @return bool
  424. */
  425. private function isAvailableAtTime(string $email, \DateTimeInterface $start, \DateTimeInterface $end, string $ignoreUID):bool {
  426. // This method is heavily inspired by Sabre\CalDAV\Schedule\Plugin::scheduleLocalDelivery
  427. // and Sabre\CalDAV\Schedule\Plugin::getFreeBusyForEmail
  428. $aclPlugin = $this->server->getPlugin('acl');
  429. $this->server->removeListener('propFind', [$aclPlugin, 'propFind']);
  430. $result = $aclPlugin->principalSearch(
  431. ['{http://sabredav.org/ns}email-address' => $this->stripOffMailTo($email)],
  432. [
  433. '{DAV:}principal-URL',
  434. '{' . self::NS_CALDAV . '}calendar-home-set',
  435. '{' . self::NS_CALDAV . '}schedule-inbox-URL',
  436. '{http://sabredav.org/ns}email-address',
  437. ]
  438. );
  439. $this->server->on('propFind', [$aclPlugin, 'propFind'], 20);
  440. // Grabbing the calendar list
  441. $objects = [];
  442. $calendarTimeZone = new DateTimeZone('UTC');
  443. $homePath = $result[0][200]['{' . self::NS_CALDAV . '}calendar-home-set']->getHref();
  444. foreach ($this->server->tree->getNodeForPath($homePath)->getChildren() as $node) {
  445. if (!$node instanceof ICalendar) {
  446. continue;
  447. }
  448. // Getting the list of object uris within the time-range
  449. $urls = $node->calendarQuery([
  450. 'name' => 'VCALENDAR',
  451. 'comp-filters' => [
  452. [
  453. 'name' => 'VEVENT',
  454. 'is-not-defined' => false,
  455. 'time-range' => [
  456. 'start' => $start,
  457. 'end' => $end,
  458. ],
  459. 'comp-filters' => [],
  460. 'prop-filters' => [],
  461. ],
  462. [
  463. 'name' => 'VEVENT',
  464. 'is-not-defined' => false,
  465. 'time-range' => null,
  466. 'comp-filters' => [],
  467. 'prop-filters' => [
  468. [
  469. 'name' => 'UID',
  470. 'is-not-defined' => false,
  471. 'time-range' => null,
  472. 'text-match' => [
  473. 'value' => $ignoreUID,
  474. 'negate-condition' => true,
  475. 'collation' => 'i;octet',
  476. ],
  477. 'param-filters' => [],
  478. ],
  479. ]
  480. ],
  481. ],
  482. 'prop-filters' => [],
  483. 'is-not-defined' => false,
  484. 'time-range' => null,
  485. ]);
  486. foreach ($urls as $url) {
  487. $objects[] = $node->getChild($url)->get();
  488. }
  489. }
  490. $inboxProps = $this->server->getProperties(
  491. $result[0][200]['{' . self::NS_CALDAV . '}schedule-inbox-URL']->getHref(),
  492. ['{' . self::NS_CALDAV . '}calendar-availability']
  493. );
  494. $vcalendar = new VCalendar();
  495. $vcalendar->METHOD = 'REPLY';
  496. $generator = new FreeBusyGenerator();
  497. $generator->setObjects($objects);
  498. $generator->setTimeRange($start, $end);
  499. $generator->setBaseObject($vcalendar);
  500. $generator->setTimeZone($calendarTimeZone);
  501. if (isset($inboxProps['{' . self::NS_CALDAV . '}calendar-availability'])) {
  502. $generator->setVAvailability(
  503. Reader::read(
  504. $inboxProps['{' . self::NS_CALDAV . '}calendar-availability']
  505. )
  506. );
  507. }
  508. $result = $generator->getResult();
  509. if (!isset($result->VFREEBUSY)) {
  510. return false;
  511. }
  512. /** @var Component $freeBusyComponent */
  513. $freeBusyComponent = $result->VFREEBUSY;
  514. $freeBusyProperties = $freeBusyComponent->select('FREEBUSY');
  515. // If there is no Free-busy property at all, the time-range is empty and available
  516. if (count($freeBusyProperties) === 0) {
  517. return true;
  518. }
  519. // If more than one Free-Busy property was returned, it means that an event
  520. // starts or ends inside this time-range, so it's not available and we return false
  521. if (count($freeBusyProperties) > 1) {
  522. return false;
  523. }
  524. /** @var Property $freeBusyProperty */
  525. $freeBusyProperty = $freeBusyProperties[0];
  526. if (!$freeBusyProperty->offsetExists('FBTYPE')) {
  527. // If there is no FBTYPE, it means it's busy
  528. return false;
  529. }
  530. $fbTypeParameter = $freeBusyProperty->offsetGet('FBTYPE');
  531. if (!($fbTypeParameter instanceof Parameter)) {
  532. return false;
  533. }
  534. return (strcasecmp($fbTypeParameter->getValue(), 'FREE') === 0);
  535. }
  536. /**
  537. * @param string $email
  538. * @return string
  539. */
  540. private function stripOffMailTo(string $email): string {
  541. if (stripos($email, 'mailto:') === 0) {
  542. return substr($email, 7);
  543. }
  544. return $email;
  545. }
  546. private function getCalendar(CalendarHome $calendarHome, string $uri): INode {
  547. return $calendarHome->getChild($uri);
  548. }
  549. private function isCalendarDeleted(CalendarHome $calendarHome, string $uri): bool {
  550. $calendar = $this->getCalendar($calendarHome, $uri);
  551. return $calendar instanceof Calendar && $calendar->isDeleted();
  552. }
  553. private function createCalendar(CalendarHome $calendarHome, string $principalUri, string $uri, string $displayName): void {
  554. $calendarHome->getCalDAVBackend()->createCalendar($principalUri, $uri, [
  555. '{DAV:}displayname' => $displayName,
  556. ]);
  557. }
  558. }