You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IMipPlugin.php 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. * @copyright Copyright (c) 2017, Georg Ehrke
  5. *
  6. * @author brad2014 <brad2014@users.noreply.github.com>
  7. * @author Brad Rubenstein <brad@wbr.tech>
  8. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  9. * @author Georg Ehrke <oc.list@georgehrke.com>
  10. * @author Joas Schilling <coding@schilljs.com>
  11. * @author Leon Klingele <leon@struktur.de>
  12. * @author rakekniven <mark.ziegler@rakekniven.de>
  13. * @author Roeland Jago Douma <roeland@famdouma.nl>
  14. * @author Thomas Müller <thomas.mueller@tmit.eu>
  15. *
  16. * @license AGPL-3.0
  17. *
  18. * This code is free software: you can redistribute it and/or modify
  19. * it under the terms of the GNU Affero General Public License, version 3,
  20. * as published by the Free Software Foundation.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU Affero General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU Affero General Public License, version 3,
  28. * along with this program. If not, see <http://www.gnu.org/licenses/>
  29. *
  30. */
  31. namespace OCA\DAV\CalDAV\Schedule;
  32. use OCP\AppFramework\Utility\ITimeFactory;
  33. use OCP\Defaults;
  34. use OCP\IConfig;
  35. use OCP\IDBConnection;
  36. use OCP\IL10N;
  37. use OCP\ILogger;
  38. use OCP\IURLGenerator;
  39. use OCP\IUserManager;
  40. use OCP\L10N\IFactory as L10NFactory;
  41. use OCP\Mail\IEMailTemplate;
  42. use OCP\Mail\IMailer;
  43. use OCP\Security\ISecureRandom;
  44. use Sabre\CalDAV\Schedule\IMipPlugin as SabreIMipPlugin;
  45. use Sabre\VObject\Component\VCalendar;
  46. use Sabre\VObject\Component\VEvent;
  47. use Sabre\VObject\DateTimeParser;
  48. use Sabre\VObject\ITip\Message;
  49. use Sabre\VObject\Parameter;
  50. use Sabre\VObject\Property;
  51. use Sabre\VObject\Recur\EventIterator;
  52. /**
  53. * iMIP handler.
  54. *
  55. * This class is responsible for sending out iMIP messages. iMIP is the
  56. * email-based transport for iTIP. iTIP deals with scheduling operations for
  57. * iCalendar objects.
  58. *
  59. * If you want to customize the email that gets sent out, you can do so by
  60. * extending this class and overriding the sendMessage method.
  61. *
  62. * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/).
  63. * @author Evert Pot (http://evertpot.com/)
  64. * @license http://sabre.io/license/ Modified BSD License
  65. */
  66. class IMipPlugin extends SabreIMipPlugin {
  67. /** @var string */
  68. private $userId;
  69. /** @var IConfig */
  70. private $config;
  71. /** @var IMailer */
  72. private $mailer;
  73. /** @var ILogger */
  74. private $logger;
  75. /** @var ITimeFactory */
  76. private $timeFactory;
  77. /** @var L10NFactory */
  78. private $l10nFactory;
  79. /** @var IURLGenerator */
  80. private $urlGenerator;
  81. /** @var ISecureRandom */
  82. private $random;
  83. /** @var IDBConnection */
  84. private $db;
  85. /** @var Defaults */
  86. private $defaults;
  87. /** @var IUserManager */
  88. private $userManager;
  89. const MAX_DATE = '2038-01-01';
  90. const METHOD_REQUEST = 'request';
  91. const METHOD_REPLY = 'reply';
  92. const METHOD_CANCEL = 'cancel';
  93. /**
  94. * @param IConfig $config
  95. * @param IMailer $mailer
  96. * @param ILogger $logger
  97. * @param ITimeFactory $timeFactory
  98. * @param L10NFactory $l10nFactory
  99. * @param IUrlGenerator $urlGenerator
  100. * @param Defaults $defaults
  101. * @param ISecureRandom $random
  102. * @param IDBConnection $db
  103. * @param string $userId
  104. */
  105. public function __construct(IConfig $config, IMailer $mailer, ILogger $logger,
  106. ITimeFactory $timeFactory, L10NFactory $l10nFactory,
  107. IURLGenerator $urlGenerator, Defaults $defaults,
  108. ISecureRandom $random, IDBConnection $db, IUserManager $userManager,
  109. $userId) {
  110. parent::__construct('');
  111. $this->userId = $userId;
  112. $this->config = $config;
  113. $this->mailer = $mailer;
  114. $this->logger = $logger;
  115. $this->timeFactory = $timeFactory;
  116. $this->l10nFactory = $l10nFactory;
  117. $this->urlGenerator = $urlGenerator;
  118. $this->random = $random;
  119. $this->db = $db;
  120. $this->defaults = $defaults;
  121. $this->userManager = $userManager;
  122. }
  123. /**
  124. * Event handler for the 'schedule' event.
  125. *
  126. * @param Message $iTipMessage
  127. * @return void
  128. */
  129. public function schedule(Message $iTipMessage) {
  130. // Not sending any emails if the system considers the update
  131. // insignificant.
  132. if (!$iTipMessage->significantChange) {
  133. if (!$iTipMessage->scheduleStatus) {
  134. $iTipMessage->scheduleStatus = '1.0;We got the message, but it\'s not significant enough to warrant an email';
  135. }
  136. return;
  137. }
  138. $summary = $iTipMessage->message->VEVENT->SUMMARY;
  139. if (parse_url($iTipMessage->sender, PHP_URL_SCHEME) !== 'mailto') {
  140. return;
  141. }
  142. if (parse_url($iTipMessage->recipient, PHP_URL_SCHEME) !== 'mailto') {
  143. return;
  144. }
  145. // don't send out mails for events that already took place
  146. $lastOccurrence = $this->getLastOccurrence($iTipMessage->message);
  147. $currentTime = $this->timeFactory->getTime();
  148. if ($lastOccurrence < $currentTime) {
  149. return;
  150. }
  151. // Strip off mailto:
  152. $sender = substr($iTipMessage->sender, 7);
  153. $recipient = substr($iTipMessage->recipient, 7);
  154. $senderName = $iTipMessage->senderName ?: null;
  155. $recipientName = $iTipMessage->recipientName ?: null;
  156. if ($senderName === null || empty(trim($senderName))) {
  157. $user = $this->userManager->get($this->userId);
  158. if ($user) {
  159. // getDisplayName automatically uses the uid
  160. // if no display-name is set
  161. $senderName = $user->getDisplayName();
  162. }
  163. }
  164. /** @var VEvent $vevent */
  165. $vevent = $iTipMessage->message->VEVENT;
  166. $attendee = $this->getCurrentAttendee($iTipMessage);
  167. $defaultLang = $this->l10nFactory->findLanguage();
  168. $lang = $this->getAttendeeLangOrDefault($defaultLang, $attendee);
  169. $l10n = $this->l10nFactory->get('dav', $lang);
  170. $meetingAttendeeName = $recipientName ?: $recipient;
  171. $meetingInviteeName = $senderName ?: $sender;
  172. $meetingTitle = $vevent->SUMMARY;
  173. $meetingDescription = $vevent->DESCRIPTION;
  174. $start = $vevent->DTSTART;
  175. if (isset($vevent->DTEND)) {
  176. $end = $vevent->DTEND;
  177. } elseif (isset($vevent->DURATION)) {
  178. $isFloating = $vevent->DTSTART->isFloating();
  179. $end = clone $vevent->DTSTART;
  180. $endDateTime = $end->getDateTime();
  181. $endDateTime = $endDateTime->add(DateTimeParser::parse($vevent->DURATION->getValue()));
  182. $end->setDateTime($endDateTime, $isFloating);
  183. } elseif (!$vevent->DTSTART->hasTime()) {
  184. $isFloating = $vevent->DTSTART->isFloating();
  185. $end = clone $vevent->DTSTART;
  186. $endDateTime = $end->getDateTime();
  187. $endDateTime = $endDateTime->modify('+1 day');
  188. $end->setDateTime($endDateTime, $isFloating);
  189. } else {
  190. $end = clone $vevent->DTSTART;
  191. }
  192. $meetingWhen = $this->generateWhenString($l10n, $start, $end);
  193. $meetingUrl = $vevent->URL;
  194. $meetingLocation = $vevent->LOCATION;
  195. $defaultVal = '--';
  196. $method = self::METHOD_REQUEST;
  197. switch (strtolower($iTipMessage->method)) {
  198. case self::METHOD_REPLY:
  199. $method = self::METHOD_REPLY;
  200. break;
  201. case self::METHOD_CANCEL:
  202. $method = self::METHOD_CANCEL;
  203. break;
  204. }
  205. $data = [
  206. 'attendee_name' => (string)$meetingAttendeeName ?: $defaultVal,
  207. 'invitee_name' => (string)$meetingInviteeName ?: $defaultVal,
  208. 'meeting_title' => (string)$meetingTitle ?: $defaultVal,
  209. 'meeting_description' => (string)$meetingDescription ?: $defaultVal,
  210. 'meeting_url' => (string)$meetingUrl ?: $defaultVal,
  211. ];
  212. $fromEMail = \OCP\Util::getDefaultEmailAddress('invitations-noreply');
  213. $fromName = $l10n->t('%1$s via %2$s', [$senderName, $this->defaults->getName()]);
  214. $message = $this->mailer->createMessage()
  215. ->setFrom([$fromEMail => $fromName])
  216. ->setReplyTo([$sender => $senderName])
  217. ->setTo([$recipient => $recipientName]);
  218. $template = $this->mailer->createEMailTemplate('dav.calendarInvite.' . $method, $data);
  219. $template->addHeader();
  220. $this->addSubjectAndHeading($template, $l10n, $method, $summary,
  221. $meetingAttendeeName, $meetingInviteeName);
  222. $this->addBulletList($template, $l10n, $meetingWhen, $meetingLocation,
  223. $meetingDescription, $meetingUrl);
  224. // Only add response buttons to invitation requests: Fix Issue #11230
  225. if (($method == self::METHOD_REQUEST) && $this->getAttendeeRSVP($attendee)) {
  226. /*
  227. ** Only offer invitation accept/reject buttons, which link back to the
  228. ** nextcloud server, to recipients who can access the nextcloud server via
  229. ** their internet/intranet. Issue #12156
  230. **
  231. ** The app setting is stored in the appconfig database table.
  232. **
  233. ** For nextcloud servers accessible to the public internet, the default
  234. ** "invitation_link_recipients" value "yes" (all recipients) is appropriate.
  235. **
  236. ** When the nextcloud server is restricted behind a firewall, accessible
  237. ** only via an internal network or via vpn, you can set "dav.invitation_link_recipients"
  238. ** to the email address or email domain, or comma separated list of addresses or domains,
  239. ** of recipients who can access the server.
  240. **
  241. ** To always deliver URLs, set invitation_link_recipients to "yes".
  242. ** To suppress URLs entirely, set invitation_link_recipients to boolean "no".
  243. */
  244. $recipientDomain = substr(strrchr($recipient, "@"), 1);
  245. $invitationLinkRecipients = explode(',', preg_replace('/\s+/', '', strtolower($this->config->getAppValue('dav', 'invitation_link_recipients', 'yes'))));
  246. if (strcmp('yes', $invitationLinkRecipients[0]) === 0
  247. || in_array(strtolower($recipient), $invitationLinkRecipients)
  248. || in_array(strtolower($recipientDomain), $invitationLinkRecipients)) {
  249. $this->addResponseButtons($template, $l10n, $iTipMessage, $lastOccurrence);
  250. }
  251. }
  252. $template->addFooter();
  253. $message->useTemplate($template);
  254. $attachment = $this->mailer->createAttachment(
  255. $iTipMessage->message->serialize(),
  256. 'event.ics',// TODO(leon): Make file name unique, e.g. add event id
  257. 'text/calendar; method=' . $iTipMessage->method
  258. );
  259. $message->attach($attachment);
  260. try {
  261. $failed = $this->mailer->send($message);
  262. $iTipMessage->scheduleStatus = '1.1; Scheduling message is sent via iMip';
  263. if ($failed) {
  264. $this->logger->error('Unable to deliver message to {failed}', ['app' => 'dav', 'failed' => implode(', ', $failed)]);
  265. $iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
  266. }
  267. } catch(\Exception $ex) {
  268. $this->logger->logException($ex, ['app' => 'dav']);
  269. $iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
  270. }
  271. }
  272. /**
  273. * check if event took place in the past already
  274. * @param VCalendar $vObject
  275. * @return int
  276. */
  277. private function getLastOccurrence(VCalendar $vObject) {
  278. /** @var VEvent $component */
  279. $component = $vObject->VEVENT;
  280. $firstOccurrence = $component->DTSTART->getDateTime()->getTimeStamp();
  281. // Finding the last occurrence is a bit harder
  282. if (!isset($component->RRULE)) {
  283. if (isset($component->DTEND)) {
  284. $lastOccurrence = $component->DTEND->getDateTime()->getTimeStamp();
  285. } elseif (isset($component->DURATION)) {
  286. /** @var \DateTime $endDate */
  287. $endDate = clone $component->DTSTART->getDateTime();
  288. // $component->DTEND->getDateTime() returns DateTimeImmutable
  289. $endDate = $endDate->add(DateTimeParser::parse($component->DURATION->getValue()));
  290. $lastOccurrence = $endDate->getTimestamp();
  291. } elseif (!$component->DTSTART->hasTime()) {
  292. /** @var \DateTime $endDate */
  293. $endDate = clone $component->DTSTART->getDateTime();
  294. // $component->DTSTART->getDateTime() returns DateTimeImmutable
  295. $endDate = $endDate->modify('+1 day');
  296. $lastOccurrence = $endDate->getTimestamp();
  297. } else {
  298. $lastOccurrence = $firstOccurrence;
  299. }
  300. } else {
  301. $it = new EventIterator($vObject, (string)$component->UID);
  302. $maxDate = new \DateTime(self::MAX_DATE);
  303. if ($it->isInfinite()) {
  304. $lastOccurrence = $maxDate->getTimestamp();
  305. } else {
  306. $end = $it->getDtEnd();
  307. while($it->valid() && $end < $maxDate) {
  308. $end = $it->getDtEnd();
  309. $it->next();
  310. }
  311. $lastOccurrence = $end->getTimestamp();
  312. }
  313. }
  314. return $lastOccurrence;
  315. }
  316. /**
  317. * @param Message $iTipMessage
  318. * @return null|Property
  319. */
  320. private function getCurrentAttendee(Message $iTipMessage) {
  321. /** @var VEvent $vevent */
  322. $vevent = $iTipMessage->message->VEVENT;
  323. $attendees = $vevent->select('ATTENDEE');
  324. foreach ($attendees as $attendee) {
  325. /** @var Property $attendee */
  326. if (strcasecmp($attendee->getValue(), $iTipMessage->recipient) === 0) {
  327. return $attendee;
  328. }
  329. }
  330. return null;
  331. }
  332. /**
  333. * @param string $default
  334. * @param Property|null $attendee
  335. * @return string
  336. */
  337. private function getAttendeeLangOrDefault($default, Property $attendee = null) {
  338. if ($attendee !== null) {
  339. $lang = $attendee->offsetGet('LANGUAGE');
  340. if ($lang instanceof Parameter) {
  341. return $lang->getValue();
  342. }
  343. }
  344. return $default;
  345. }
  346. /**
  347. * @param Property|null $attendee
  348. * @return bool
  349. */
  350. private function getAttendeeRSVP(Property $attendee = null) {
  351. if ($attendee !== null) {
  352. $rsvp = $attendee->offsetGet('RSVP');
  353. if (($rsvp instanceof Parameter) && (strcasecmp($rsvp->getValue(), 'TRUE') === 0)) {
  354. return true;
  355. }
  356. }
  357. // RFC 5545 3.2.17: default RSVP is false
  358. return false;
  359. }
  360. /**
  361. * @param IL10N $l10n
  362. * @param Property $dtstart
  363. * @param Property $dtend
  364. */
  365. private function generateWhenString(IL10N $l10n, Property $dtstart, Property $dtend) {
  366. $isAllDay = $dtstart instanceof Property\ICalendar\Date;
  367. /** @var Property\ICalendar\Date | Property\ICalendar\DateTime $dtstart */
  368. /** @var Property\ICalendar\Date | Property\ICalendar\DateTime $dtend */
  369. /** @var \DateTimeImmutable $dtstartDt */
  370. $dtstartDt = $dtstart->getDateTime();
  371. /** @var \DateTimeImmutable $dtendDt */
  372. $dtendDt = $dtend->getDateTime();
  373. $diff = $dtstartDt->diff($dtendDt);
  374. $dtstartDt = new \DateTime($dtstartDt->format(\DateTime::ATOM));
  375. $dtendDt = new \DateTime($dtendDt->format(\DateTime::ATOM));
  376. if ($isAllDay) {
  377. // One day event
  378. if ($diff->days === 1) {
  379. return $l10n->l('date', $dtstartDt, ['width' => 'medium']);
  380. }
  381. // DTEND is exclusive, so if the ics data says 2020-01-01 to 2020-01-05,
  382. // the email should show 2020-01-01 to 2020-01-04.
  383. $dtendDt->modify('-1 day');
  384. //event that spans over multiple days
  385. $localeStart = $l10n->l('date', $dtstartDt, ['width' => 'medium']);
  386. $localeEnd = $l10n->l('date', $dtendDt, ['width' => 'medium']);
  387. return $localeStart . ' - ' . $localeEnd;
  388. }
  389. /** @var Property\ICalendar\DateTime $dtstart */
  390. /** @var Property\ICalendar\DateTime $dtend */
  391. $isFloating = $dtstart->isFloating();
  392. $startTimezone = $endTimezone = null;
  393. if (!$isFloating) {
  394. $prop = $dtstart->offsetGet('TZID');
  395. if ($prop instanceof Parameter) {
  396. $startTimezone = $prop->getValue();
  397. }
  398. $prop = $dtend->offsetGet('TZID');
  399. if ($prop instanceof Parameter) {
  400. $endTimezone = $prop->getValue();
  401. }
  402. }
  403. $localeStart = $l10n->l('weekdayName', $dtstartDt, ['width' => 'abbreviated']) . ', ' .
  404. $l10n->l('datetime', $dtstartDt, ['width' => 'medium|short']);
  405. // always show full date with timezone if timezones are different
  406. if ($startTimezone !== $endTimezone) {
  407. $localeEnd = $l10n->l('datetime', $dtendDt, ['width' => 'medium|short']);
  408. return $localeStart . ' (' . $startTimezone . ') - ' .
  409. $localeEnd . ' (' . $endTimezone . ')';
  410. }
  411. // show only end time if date is the same
  412. if ($this->isDayEqual($dtstartDt, $dtendDt)) {
  413. $localeEnd = $l10n->l('time', $dtendDt, ['width' => 'short']);
  414. } else {
  415. $localeEnd = $l10n->l('weekdayName', $dtendDt, ['width' => 'abbreviated']) . ', ' .
  416. $l10n->l('datetime', $dtendDt, ['width' => 'medium|short']);
  417. }
  418. return $localeStart . ' - ' . $localeEnd . ' (' . $startTimezone . ')';
  419. }
  420. /**
  421. * @param \DateTime $dtStart
  422. * @param \DateTime $dtEnd
  423. * @return bool
  424. */
  425. private function isDayEqual(\DateTime $dtStart, \DateTime $dtEnd) {
  426. return $dtStart->format('Y-m-d') === $dtEnd->format('Y-m-d');
  427. }
  428. /**
  429. * @param IEMailTemplate $template
  430. * @param IL10N $l10n
  431. * @param string $method
  432. * @param string $summary
  433. * @param string $attendeeName
  434. * @param string $inviteeName
  435. */
  436. private function addSubjectAndHeading(IEMailTemplate $template, IL10N $l10n,
  437. $method, $summary, $attendeeName, $inviteeName) {
  438. if ($method === self::METHOD_CANCEL) {
  439. $template->setSubject('Cancelled: ' . $summary);
  440. $template->addHeading($l10n->t('Invitation canceled'), $l10n->t('Hello %s,', [$attendeeName]));
  441. $template->addBodyText($l10n->t('The meeting »%1$s« with %2$s was canceled.', [$summary, $inviteeName]));
  442. } else if ($method === self::METHOD_REPLY) {
  443. $template->setSubject('Re: ' . $summary);
  444. $template->addHeading($l10n->t('Invitation updated'), $l10n->t('Hello %s,', [$attendeeName]));
  445. $template->addBodyText($l10n->t('The meeting »%1$s« with %2$s was updated.', [$summary, $inviteeName]));
  446. } else {
  447. $template->setSubject('Invitation: ' . $summary);
  448. $template->addHeading($l10n->t('%1$s invited you to »%2$s«', [$inviteeName, $summary]), $l10n->t('Hello %s,', [$attendeeName]));
  449. }
  450. }
  451. /**
  452. * @param IEMailTemplate $template
  453. * @param IL10N $l10n
  454. * @param string $time
  455. * @param string $location
  456. * @param string $description
  457. * @param string $url
  458. */
  459. private function addBulletList(IEMailTemplate $template, IL10N $l10n, $time, $location, $description, $url) {
  460. $template->addBodyListItem($time, $l10n->t('When:'),
  461. $this->getAbsoluteImagePath('filetypes/text-calendar.svg'));
  462. if ($location) {
  463. $template->addBodyListItem($location, $l10n->t('Where:'),
  464. $this->getAbsoluteImagePath('filetypes/location.svg'));
  465. }
  466. if ($description) {
  467. $template->addBodyListItem((string)$description, $l10n->t('Description:'),
  468. $this->getAbsoluteImagePath('filetypes/text.svg'));
  469. }
  470. if ($url) {
  471. $template->addBodyListItem((string)$url, $l10n->t('Link:'),
  472. $this->getAbsoluteImagePath('filetypes/link.svg'));
  473. }
  474. }
  475. /**
  476. * @param IEMailTemplate $template
  477. * @param IL10N $l10n
  478. * @param Message $iTipMessage
  479. * @param int $lastOccurrence
  480. */
  481. private function addResponseButtons(IEMailTemplate $template, IL10N $l10n,
  482. Message $iTipMessage, $lastOccurrence) {
  483. $token = $this->createInvitationToken($iTipMessage, $lastOccurrence);
  484. $template->addBodyButtonGroup(
  485. $l10n->t('Accept'),
  486. $this->urlGenerator->linkToRouteAbsolute('dav.invitation_response.accept', [
  487. 'token' => $token,
  488. ]),
  489. $l10n->t('Decline'),
  490. $this->urlGenerator->linkToRouteAbsolute('dav.invitation_response.decline', [
  491. 'token' => $token,
  492. ])
  493. );
  494. $moreOptionsURL = $this->urlGenerator->linkToRouteAbsolute('dav.invitation_response.options', [
  495. 'token' => $token,
  496. ]);
  497. $html = vsprintf('<small><a href="%s">%s</a></small>', [
  498. $moreOptionsURL, $l10n->t('More options …')
  499. ]);
  500. $text = $l10n->t('More options at %s', [$moreOptionsURL]);
  501. $template->addBodyText($html, $text);
  502. }
  503. /**
  504. * @param string $path
  505. * @return string
  506. */
  507. private function getAbsoluteImagePath($path) {
  508. return $this->urlGenerator->getAbsoluteURL(
  509. $this->urlGenerator->imagePath('core', $path)
  510. );
  511. }
  512. /**
  513. * @param Message $iTipMessage
  514. * @param int $lastOccurrence
  515. * @return string
  516. */
  517. private function createInvitationToken(Message $iTipMessage, $lastOccurrence):string {
  518. $token = $this->random->generate(60, ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS);
  519. /** @var VEvent $vevent */
  520. $vevent = $iTipMessage->message->VEVENT;
  521. $attendee = $iTipMessage->recipient;
  522. $organizer = $iTipMessage->sender;
  523. $sequence = $iTipMessage->sequence;
  524. $recurrenceId = isset($vevent->{'RECURRENCE-ID'}) ?
  525. $vevent->{'RECURRENCE-ID'}->serialize() : null;
  526. $uid = $vevent->{'UID'};
  527. $query = $this->db->getQueryBuilder();
  528. $query->insert('calendar_invitations')
  529. ->values([
  530. 'token' => $query->createNamedParameter($token),
  531. 'attendee' => $query->createNamedParameter($attendee),
  532. 'organizer' => $query->createNamedParameter($organizer),
  533. 'sequence' => $query->createNamedParameter($sequence),
  534. 'recurrenceid' => $query->createNamedParameter($recurrenceId),
  535. 'expiration' => $query->createNamedParameter($lastOccurrence),
  536. 'uid' => $query->createNamedParameter($uid)
  537. ])
  538. ->execute();
  539. return $token;
  540. }
  541. }