2015-12-18 13:56:25 +03:00
|
|
|
<?php
|
2016-01-12 17:02:16 +03:00
|
|
|
/**
|
2016-07-21 17:49:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
2017-06-08 12:50:17 +03:00
|
|
|
* @copyright Copyright (c) 2017, Georg Ehrke
|
2016-07-21 17:49:16 +03:00
|
|
|
*
|
2017-11-06 22:15:27 +03:00
|
|
|
* @author Georg Ehrke <oc.list@georgehrke.com>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
|
|
|
* @author Leon Klingele <leon@struktur.de>
|
2016-01-12 17:02:16 +03:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
|
|
|
*/
|
2015-12-18 13:56:25 +03:00
|
|
|
namespace OCA\DAV\CalDAV\Schedule;
|
|
|
|
|
2017-06-08 12:50:17 +03:00
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
2017-11-14 17:01:53 +03:00
|
|
|
use OCP\Defaults;
|
2017-09-07 17:33:45 +03:00
|
|
|
use OCP\IConfig;
|
2018-06-19 22:01:14 +03:00
|
|
|
use OCP\IDBConnection;
|
2017-11-02 18:38:16 +03:00
|
|
|
use OCP\IL10N;
|
2015-12-18 13:56:25 +03:00
|
|
|
use OCP\ILogger;
|
2017-11-02 18:38:16 +03:00
|
|
|
use OCP\IURLGenerator;
|
2017-09-07 17:33:45 +03:00
|
|
|
use OCP\L10N\IFactory as L10NFactory;
|
2017-11-02 18:38:16 +03:00
|
|
|
use OCP\Mail\IEMailTemplate;
|
2015-12-18 13:56:25 +03:00
|
|
|
use OCP\Mail\IMailer;
|
2018-06-19 22:01:14 +03:00
|
|
|
use OCP\Security\ISecureRandom;
|
2017-09-07 17:33:45 +03:00
|
|
|
use Sabre\CalDAV\Schedule\IMipPlugin as SabreIMipPlugin;
|
2017-06-08 12:50:17 +03:00
|
|
|
use Sabre\VObject\Component\VCalendar;
|
2017-10-31 17:05:26 +03:00
|
|
|
use Sabre\VObject\Component\VEvent;
|
2017-06-08 12:50:17 +03:00
|
|
|
use Sabre\VObject\DateTimeParser;
|
2017-10-31 17:05:26 +03:00
|
|
|
use Sabre\VObject\ITip\Message;
|
2017-09-07 17:33:45 +03:00
|
|
|
use Sabre\VObject\Parameter;
|
2017-10-31 17:05:26 +03:00
|
|
|
use Sabre\VObject\Property;
|
2017-06-08 12:50:17 +03:00
|
|
|
use Sabre\VObject\Recur\EventIterator;
|
2015-12-18 13:56:25 +03:00
|
|
|
/**
|
|
|
|
* iMIP handler.
|
|
|
|
*
|
|
|
|
* This class is responsible for sending out iMIP messages. iMIP is the
|
|
|
|
* email-based transport for iTIP. iTIP deals with scheduling operations for
|
|
|
|
* iCalendar objects.
|
|
|
|
*
|
|
|
|
* If you want to customize the email that gets sent out, you can do so by
|
|
|
|
* extending this class and overriding the sendMessage method.
|
|
|
|
*
|
|
|
|
* @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/).
|
|
|
|
* @author Evert Pot (http://evertpot.com/)
|
|
|
|
* @license http://sabre.io/license/ Modified BSD License
|
|
|
|
*/
|
|
|
|
class IMipPlugin extends SabreIMipPlugin {
|
|
|
|
|
2017-09-07 17:33:45 +03:00
|
|
|
/** @var string */
|
|
|
|
private $userId;
|
|
|
|
|
|
|
|
/** @var IConfig */
|
|
|
|
private $config;
|
|
|
|
|
2015-12-18 13:56:25 +03:00
|
|
|
/** @var IMailer */
|
|
|
|
private $mailer;
|
|
|
|
|
|
|
|
/** @var ILogger */
|
|
|
|
private $logger;
|
|
|
|
|
2017-06-08 12:50:17 +03:00
|
|
|
/** @var ITimeFactory */
|
|
|
|
private $timeFactory;
|
|
|
|
|
2017-09-07 17:33:45 +03:00
|
|
|
/** @var L10NFactory */
|
|
|
|
private $l10nFactory;
|
|
|
|
|
2017-11-02 18:38:16 +03:00
|
|
|
/** @var IURLGenerator */
|
|
|
|
private $urlGenerator;
|
|
|
|
|
2018-06-19 22:01:14 +03:00
|
|
|
/** @var ISecureRandom */
|
|
|
|
private $random;
|
|
|
|
|
|
|
|
/** @var IDBConnection */
|
|
|
|
private $db;
|
|
|
|
|
2017-11-14 17:01:53 +03:00
|
|
|
/** @var Defaults */
|
|
|
|
private $defaults;
|
|
|
|
|
2017-06-08 12:50:17 +03:00
|
|
|
const MAX_DATE = '2038-01-01';
|
|
|
|
|
2017-09-07 17:33:45 +03:00
|
|
|
const METHOD_REQUEST = 'request';
|
|
|
|
const METHOD_REPLY = 'reply';
|
|
|
|
const METHOD_CANCEL = 'cancel';
|
|
|
|
|
2015-12-18 13:56:25 +03:00
|
|
|
/**
|
2017-09-07 17:33:45 +03:00
|
|
|
* @param IConfig $config
|
2015-12-18 13:56:25 +03:00
|
|
|
* @param IMailer $mailer
|
2017-06-08 12:50:17 +03:00
|
|
|
* @param ILogger $logger
|
|
|
|
* @param ITimeFactory $timeFactory
|
2017-09-07 17:33:45 +03:00
|
|
|
* @param L10NFactory $l10nFactory
|
2017-11-02 18:38:16 +03:00
|
|
|
* @param IUrlGenerator $urlGenerator
|
2017-11-14 17:01:53 +03:00
|
|
|
* @param Defaults $defaults
|
2018-06-19 22:01:14 +03:00
|
|
|
* @param ISecureRandom $random
|
|
|
|
* @param IDBConnection $db
|
2017-10-31 17:05:26 +03:00
|
|
|
* @param string $userId
|
2015-12-18 13:56:25 +03:00
|
|
|
*/
|
2018-06-19 22:01:14 +03:00
|
|
|
public function __construct(IConfig $config, IMailer $mailer, ILogger $logger,
|
|
|
|
ITimeFactory $timeFactory, L10NFactory $l10nFactory,
|
|
|
|
IURLGenerator $urlGenerator, Defaults $defaults,
|
|
|
|
ISecureRandom $random, IDBConnection $db, $userId) {
|
2015-12-18 13:56:25 +03:00
|
|
|
parent::__construct('');
|
2017-09-07 17:33:45 +03:00
|
|
|
$this->userId = $userId;
|
|
|
|
$this->config = $config;
|
2015-12-18 13:56:25 +03:00
|
|
|
$this->mailer = $mailer;
|
|
|
|
$this->logger = $logger;
|
2017-06-08 12:50:17 +03:00
|
|
|
$this->timeFactory = $timeFactory;
|
2017-09-07 17:33:45 +03:00
|
|
|
$this->l10nFactory = $l10nFactory;
|
2017-11-02 18:38:16 +03:00
|
|
|
$this->urlGenerator = $urlGenerator;
|
2018-06-19 22:01:14 +03:00
|
|
|
$this->random = $random;
|
|
|
|
$this->db = $db;
|
2017-11-14 17:01:53 +03:00
|
|
|
$this->defaults = $defaults;
|
2015-12-18 13:56:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event handler for the 'schedule' event.
|
|
|
|
*
|
2017-10-31 17:05:26 +03:00
|
|
|
* @param Message $iTipMessage
|
2015-12-18 13:56:25 +03:00
|
|
|
* @return void
|
|
|
|
*/
|
2017-10-31 17:05:26 +03:00
|
|
|
public function schedule(Message $iTipMessage) {
|
2015-12-18 13:56:25 +03:00
|
|
|
|
|
|
|
// Not sending any emails if the system considers the update
|
|
|
|
// insignificant.
|
|
|
|
if (!$iTipMessage->significantChange) {
|
|
|
|
if (!$iTipMessage->scheduleStatus) {
|
|
|
|
$iTipMessage->scheduleStatus = '1.0;We got the message, but it\'s not significant enough to warrant an email';
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$summary = $iTipMessage->message->VEVENT->SUMMARY;
|
|
|
|
|
|
|
|
if (parse_url($iTipMessage->sender, PHP_URL_SCHEME) !== 'mailto') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parse_url($iTipMessage->recipient, PHP_URL_SCHEME) !== 'mailto') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-08 12:50:17 +03:00
|
|
|
// don't send out mails for events that already took place
|
2018-06-19 22:01:14 +03:00
|
|
|
$lastOccurrence = $this->getLastOccurrence($iTipMessage->message);
|
|
|
|
$currentTime = $this->timeFactory->getTime();
|
|
|
|
if ($lastOccurrence < $currentTime) {
|
2017-06-08 12:50:17 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-31 17:05:26 +03:00
|
|
|
// Strip off mailto:
|
2015-12-18 13:56:25 +03:00
|
|
|
$sender = substr($iTipMessage->sender, 7);
|
|
|
|
$recipient = substr($iTipMessage->recipient, 7);
|
|
|
|
|
2017-10-31 17:05:26 +03:00
|
|
|
$senderName = $iTipMessage->senderName ?: null;
|
|
|
|
$recipientName = $iTipMessage->recipientName ?: null;
|
2015-12-18 13:56:25 +03:00
|
|
|
|
2017-10-31 17:05:26 +03:00
|
|
|
/** @var VEvent $vevent */
|
2017-09-07 17:33:45 +03:00
|
|
|
$vevent = $iTipMessage->message->VEVENT;
|
|
|
|
|
|
|
|
$attendee = $this->getCurrentAttendee($iTipMessage);
|
2018-10-24 19:39:30 +03:00
|
|
|
$defaultLang = $this->l10nFactory->findLanguage();
|
2017-10-31 17:05:26 +03:00
|
|
|
$lang = $this->getAttendeeLangOrDefault($defaultLang, $attendee);
|
|
|
|
$l10n = $this->l10nFactory->get('dav', $lang);
|
2017-09-07 17:33:45 +03:00
|
|
|
|
2017-10-31 17:05:26 +03:00
|
|
|
$meetingAttendeeName = $recipientName ?: $recipient;
|
|
|
|
$meetingInviteeName = $senderName ?: $sender;
|
2015-12-18 13:56:25 +03:00
|
|
|
|
2017-09-07 17:33:45 +03:00
|
|
|
$meetingTitle = $vevent->SUMMARY;
|
|
|
|
$meetingDescription = $vevent->DESCRIPTION;
|
2015-12-18 13:56:25 +03:00
|
|
|
|
2017-11-02 18:38:16 +03:00
|
|
|
$start = $vevent->DTSTART;
|
|
|
|
if (isset($vevent->DTEND)) {
|
|
|
|
$end = $vevent->DTEND;
|
|
|
|
} elseif (isset($vevent->DURATION)) {
|
|
|
|
$isFloating = $vevent->DTSTART->isFloating();
|
|
|
|
$end = clone $vevent->DTSTART;
|
|
|
|
$endDateTime = $end->getDateTime();
|
|
|
|
$endDateTime = $endDateTime->add(DateTimeParser::parse($vevent->DURATION->getValue()));
|
|
|
|
$end->setDateTime($endDateTime, $isFloating);
|
|
|
|
} elseif (!$vevent->DTSTART->hasTime()) {
|
|
|
|
$isFloating = $vevent->DTSTART->isFloating();
|
|
|
|
$end = clone $vevent->DTSTART;
|
|
|
|
$endDateTime = $end->getDateTime();
|
|
|
|
$endDateTime = $endDateTime->modify('+1 day');
|
|
|
|
$end->setDateTime($endDateTime, $isFloating);
|
|
|
|
} else {
|
|
|
|
$end = clone $vevent->DTSTART;
|
|
|
|
}
|
|
|
|
|
|
|
|
$meetingWhen = $this->generateWhenString($l10n, $start, $end);
|
2017-09-07 17:33:45 +03:00
|
|
|
|
|
|
|
$meetingUrl = $vevent->URL;
|
2017-11-02 18:38:16 +03:00
|
|
|
$meetingLocation = $vevent->LOCATION;
|
2017-09-07 17:33:45 +03:00
|
|
|
|
|
|
|
$defaultVal = '--';
|
2017-10-31 17:47:51 +03:00
|
|
|
|
|
|
|
$method = self::METHOD_REQUEST;
|
|
|
|
switch (strtolower($iTipMessage->method)) {
|
|
|
|
case self::METHOD_REPLY:
|
|
|
|
$method = self::METHOD_REPLY;
|
|
|
|
break;
|
|
|
|
case self::METHOD_CANCEL:
|
|
|
|
$method = self::METHOD_CANCEL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$data = array(
|
2017-09-07 17:33:45 +03:00
|
|
|
'attendee_name' => (string)$meetingAttendeeName ?: $defaultVal,
|
|
|
|
'invitee_name' => (string)$meetingInviteeName ?: $defaultVal,
|
|
|
|
'meeting_title' => (string)$meetingTitle ?: $defaultVal,
|
|
|
|
'meeting_description' => (string)$meetingDescription ?: $defaultVal,
|
|
|
|
'meeting_url' => (string)$meetingUrl ?: $defaultVal,
|
|
|
|
);
|
|
|
|
|
2017-11-14 17:01:53 +03:00
|
|
|
$fromEMail = \OCP\Util::getDefaultEmailAddress('invitations-noreply');
|
2018-10-09 15:32:14 +03:00
|
|
|
$fromName = $l10n->t('%1$s via %2$s', [$senderName, $this->defaults->getName()]);
|
2017-11-14 17:01:53 +03:00
|
|
|
|
2017-09-07 17:33:45 +03:00
|
|
|
$message = $this->mailer->createMessage()
|
2017-11-14 17:01:53 +03:00
|
|
|
->setFrom([$fromEMail => $fromName])
|
2017-09-07 17:33:45 +03:00
|
|
|
->setReplyTo([$sender => $senderName])
|
2017-11-02 18:38:16 +03:00
|
|
|
->setTo([$recipient => $recipientName]);
|
2017-10-31 17:47:51 +03:00
|
|
|
|
|
|
|
$template = $this->mailer->createEMailTemplate('dav.calendarInvite.' . $method, $data);
|
|
|
|
$template->addHeader();
|
|
|
|
|
2017-11-02 18:38:16 +03:00
|
|
|
$this->addSubjectAndHeading($template, $l10n, $method, $summary,
|
|
|
|
$meetingAttendeeName, $meetingInviteeName);
|
|
|
|
$this->addBulletList($template, $l10n, $meetingWhen, $meetingLocation,
|
|
|
|
$meetingDescription, $meetingUrl);
|
2018-06-19 22:01:14 +03:00
|
|
|
$this->addResponseButtons($template, $l10n, $iTipMessage, $lastOccurrence);
|
2017-10-31 17:47:51 +03:00
|
|
|
|
|
|
|
$template->addFooter();
|
|
|
|
$message->useTemplate($template);
|
|
|
|
|
|
|
|
$attachment = $this->mailer->createAttachment(
|
|
|
|
$iTipMessage->message->serialize(),
|
|
|
|
'event.ics',// TODO(leon): Make file name unique, e.g. add event id
|
|
|
|
'text/calendar; method=' . $iTipMessage->method
|
|
|
|
);
|
|
|
|
$message->attach($attachment);
|
2017-09-07 17:33:45 +03:00
|
|
|
|
2015-12-18 13:56:25 +03:00
|
|
|
try {
|
|
|
|
$failed = $this->mailer->send($message);
|
2017-10-31 17:05:26 +03:00
|
|
|
$iTipMessage->scheduleStatus = '1.1; Scheduling message is sent via iMip';
|
2015-12-18 13:56:25 +03:00
|
|
|
if ($failed) {
|
|
|
|
$this->logger->error('Unable to deliver message to {failed}', ['app' => 'dav', 'failed' => implode(', ', $failed)]);
|
|
|
|
$iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
|
|
|
|
}
|
|
|
|
} catch(\Exception $ex) {
|
|
|
|
$this->logger->logException($ex, ['app' => 'dav']);
|
|
|
|
$iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-08 12:50:17 +03:00
|
|
|
/**
|
|
|
|
* check if event took place in the past already
|
|
|
|
* @param VCalendar $vObject
|
2018-06-19 22:01:14 +03:00
|
|
|
* @return int
|
2017-06-08 12:50:17 +03:00
|
|
|
*/
|
2018-06-19 22:01:14 +03:00
|
|
|
private function getLastOccurrence(VCalendar $vObject) {
|
2017-10-31 17:05:26 +03:00
|
|
|
/** @var VEvent $component */
|
2017-06-08 12:50:17 +03:00
|
|
|
$component = $vObject->VEVENT;
|
|
|
|
|
|
|
|
$firstOccurrence = $component->DTSTART->getDateTime()->getTimeStamp();
|
|
|
|
// Finding the last occurrence is a bit harder
|
|
|
|
if (!isset($component->RRULE)) {
|
|
|
|
if (isset($component->DTEND)) {
|
|
|
|
$lastOccurrence = $component->DTEND->getDateTime()->getTimeStamp();
|
|
|
|
} elseif (isset($component->DURATION)) {
|
2017-10-31 17:05:26 +03:00
|
|
|
/** @var \DateTime $endDate */
|
2017-06-08 12:50:17 +03:00
|
|
|
$endDate = clone $component->DTSTART->getDateTime();
|
2017-06-09 13:13:02 +03:00
|
|
|
// $component->DTEND->getDateTime() returns DateTimeImmutable
|
|
|
|
$endDate = $endDate->add(DateTimeParser::parse($component->DURATION->getValue()));
|
2017-10-31 17:05:26 +03:00
|
|
|
$lastOccurrence = $endDate->getTimestamp();
|
2017-06-08 12:50:17 +03:00
|
|
|
} elseif (!$component->DTSTART->hasTime()) {
|
2017-10-31 17:05:26 +03:00
|
|
|
/** @var \DateTime $endDate */
|
2017-06-08 12:50:17 +03:00
|
|
|
$endDate = clone $component->DTSTART->getDateTime();
|
2017-06-09 13:13:02 +03:00
|
|
|
// $component->DTSTART->getDateTime() returns DateTimeImmutable
|
|
|
|
$endDate = $endDate->modify('+1 day');
|
2017-10-31 17:05:26 +03:00
|
|
|
$lastOccurrence = $endDate->getTimestamp();
|
2017-06-08 12:50:17 +03:00
|
|
|
} else {
|
|
|
|
$lastOccurrence = $firstOccurrence;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$it = new EventIterator($vObject, (string)$component->UID);
|
|
|
|
$maxDate = new \DateTime(self::MAX_DATE);
|
|
|
|
if ($it->isInfinite()) {
|
|
|
|
$lastOccurrence = $maxDate->getTimestamp();
|
|
|
|
} else {
|
|
|
|
$end = $it->getDtEnd();
|
|
|
|
while($it->valid() && $end < $maxDate) {
|
|
|
|
$end = $it->getDtEnd();
|
|
|
|
$it->next();
|
|
|
|
|
|
|
|
}
|
|
|
|
$lastOccurrence = $end->getTimestamp();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-19 22:01:14 +03:00
|
|
|
return $lastOccurrence;
|
2017-06-08 12:50:17 +03:00
|
|
|
}
|
2017-09-07 17:33:45 +03:00
|
|
|
|
|
|
|
|
2017-10-31 17:05:26 +03:00
|
|
|
/**
|
|
|
|
* @param Message $iTipMessage
|
|
|
|
* @return null|Property
|
|
|
|
*/
|
|
|
|
private function getCurrentAttendee(Message $iTipMessage) {
|
|
|
|
/** @var VEvent $vevent */
|
2017-09-07 17:33:45 +03:00
|
|
|
$vevent = $iTipMessage->message->VEVENT;
|
|
|
|
$attendees = $vevent->select('ATTENDEE');
|
|
|
|
foreach ($attendees as $attendee) {
|
2017-10-31 17:05:26 +03:00
|
|
|
/** @var Property $attendee */
|
2017-09-07 17:33:45 +03:00
|
|
|
if (strcasecmp($attendee->getValue(), $iTipMessage->recipient) === 0) {
|
|
|
|
return $attendee;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-10-31 17:05:26 +03:00
|
|
|
/**
|
|
|
|
* @param string $default
|
|
|
|
* @param Property|null $attendee
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function getAttendeeLangOrDefault($default, Property $attendee = null) {
|
|
|
|
if ($attendee !== null) {
|
2017-09-07 17:33:45 +03:00
|
|
|
$lang = $attendee->offsetGet('LANGUAGE');
|
|
|
|
if ($lang instanceof Parameter) {
|
|
|
|
return $lang->getValue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $default;
|
|
|
|
}
|
|
|
|
|
2017-11-02 18:38:16 +03:00
|
|
|
/**
|
|
|
|
* @param IL10N $l10n
|
|
|
|
* @param Property $dtstart
|
|
|
|
* @param Property $dtend
|
|
|
|
*/
|
|
|
|
private function generateWhenString(IL10N $l10n, Property $dtstart, Property $dtend) {
|
|
|
|
$isAllDay = $dtstart instanceof Property\ICalendar\Date;
|
|
|
|
|
|
|
|
/** @var Property\ICalendar\Date | Property\ICalendar\DateTime $dtstart */
|
|
|
|
/** @var Property\ICalendar\Date | Property\ICalendar\DateTime $dtend */
|
|
|
|
/** @var \DateTimeImmutable $dtstartDt */
|
|
|
|
$dtstartDt = $dtstart->getDateTime();
|
|
|
|
/** @var \DateTimeImmutable $dtendDt */
|
|
|
|
$dtendDt = $dtend->getDateTime();
|
|
|
|
|
|
|
|
$diff = $dtstartDt->diff($dtendDt);
|
|
|
|
|
|
|
|
$dtstartDt = new \DateTime($dtstartDt->format(\DateTime::ATOM));
|
|
|
|
$dtendDt = new \DateTime($dtendDt->format(\DateTime::ATOM));
|
|
|
|
|
|
|
|
if ($isAllDay) {
|
|
|
|
// One day event
|
|
|
|
if ($diff->days === 1) {
|
|
|
|
return $l10n->l('date', $dtstartDt, ['width' => 'medium']);
|
|
|
|
}
|
|
|
|
|
|
|
|
//event that spans over multiple days
|
|
|
|
$localeStart = $l10n->l('date', $dtstartDt, ['width' => 'medium']);
|
|
|
|
$localeEnd = $l10n->l('date', $dtendDt, ['width' => 'medium']);
|
|
|
|
|
|
|
|
return $localeStart . ' - ' . $localeEnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @var Property\ICalendar\DateTime $dtstart */
|
|
|
|
/** @var Property\ICalendar\DateTime $dtend */
|
|
|
|
$isFloating = $dtstart->isFloating();
|
|
|
|
$startTimezone = $endTimezone = null;
|
|
|
|
if (!$isFloating) {
|
|
|
|
$prop = $dtstart->offsetGet('TZID');
|
|
|
|
if ($prop instanceof Parameter) {
|
|
|
|
$startTimezone = $prop->getValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
$prop = $dtend->offsetGet('TZID');
|
|
|
|
if ($prop instanceof Parameter) {
|
|
|
|
$endTimezone = $prop->getValue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-16 12:09:25 +03:00
|
|
|
$localeStart = $l10n->l('weekdayName', $dtstartDt, ['width' => 'abbreviated']) . ', ' .
|
|
|
|
$l10n->l('datetime', $dtstartDt, ['width' => 'medium|short']);
|
2017-11-02 18:38:16 +03:00
|
|
|
|
|
|
|
// always show full date with timezone if timezones are different
|
|
|
|
if ($startTimezone !== $endTimezone) {
|
2017-11-16 12:09:25 +03:00
|
|
|
$localeEnd = $l10n->l('datetime', $dtendDt, ['width' => 'medium|short']);
|
2017-11-02 18:38:16 +03:00
|
|
|
|
|
|
|
return $localeStart . ' (' . $startTimezone . ') - ' .
|
|
|
|
$localeEnd . ' (' . $endTimezone . ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
// show only end time if date is the same
|
|
|
|
if ($this->isDayEqual($dtstartDt, $dtendDt)) {
|
2017-11-16 12:09:25 +03:00
|
|
|
$localeEnd = $l10n->l('time', $dtendDt, ['width' => 'short']);
|
2017-11-02 18:38:16 +03:00
|
|
|
} else {
|
2017-11-16 12:09:25 +03:00
|
|
|
$localeEnd = $l10n->l('weekdayName', $dtendDt, ['width' => 'abbreviated']) . ', ' .
|
|
|
|
$l10n->l('datetime', $dtendDt, ['width' => 'medium|short']);
|
2017-11-02 18:38:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return $localeStart . ' - ' . $localeEnd . ' (' . $startTimezone . ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param \DateTime $dtStart
|
|
|
|
* @param \DateTime $dtEnd
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
private function isDayEqual(\DateTime $dtStart, \DateTime $dtEnd) {
|
|
|
|
return $dtStart->format('Y-m-d') === $dtEnd->format('Y-m-d');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param IEMailTemplate $template
|
|
|
|
* @param IL10N $l10n
|
|
|
|
* @param string $method
|
|
|
|
* @param string $summary
|
|
|
|
* @param string $attendeeName
|
|
|
|
* @param string $inviteeName
|
|
|
|
*/
|
|
|
|
private function addSubjectAndHeading(IEMailTemplate $template, IL10N $l10n,
|
|
|
|
$method, $summary, $attendeeName, $inviteeName) {
|
|
|
|
if ($method === self::METHOD_CANCEL) {
|
|
|
|
$template->setSubject('Cancelled: ' . $summary);
|
|
|
|
$template->addHeading($l10n->t('Invitation canceled'), $l10n->t('Hello %s,', [$attendeeName]));
|
2018-10-09 15:32:14 +03:00
|
|
|
$template->addBodyText($l10n->t('The meeting »%1$s« with %2$s was canceled.', [$summary, $inviteeName]));
|
2017-11-02 18:38:16 +03:00
|
|
|
} else if ($method === self::METHOD_REPLY) {
|
|
|
|
$template->setSubject('Re: ' . $summary);
|
|
|
|
$template->addHeading($l10n->t('Invitation updated'), $l10n->t('Hello %s,', [$attendeeName]));
|
2018-10-09 15:32:14 +03:00
|
|
|
$template->addBodyText($l10n->t('The meeting »%1$s« with %2$s was updated.', [$summary, $inviteeName]));
|
2017-11-02 18:38:16 +03:00
|
|
|
} else {
|
|
|
|
$template->setSubject('Invitation: ' . $summary);
|
2018-10-09 15:32:14 +03:00
|
|
|
$template->addHeading($l10n->t('%1$s invited you to »%2$s«', [$inviteeName, $summary]), $l10n->t('Hello %s,', [$attendeeName]));
|
2017-11-02 18:38:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param IEMailTemplate $template
|
|
|
|
* @param IL10N $l10n
|
|
|
|
* @param string $time
|
|
|
|
* @param string $location
|
|
|
|
* @param string $description
|
|
|
|
* @param string $url
|
|
|
|
*/
|
|
|
|
private function addBulletList(IEMailTemplate $template, IL10N $l10n, $time, $location, $description, $url) {
|
|
|
|
$template->addBodyListItem($time, $l10n->t('When:'),
|
|
|
|
$this->getAbsoluteImagePath('filetypes/text-calendar.svg'));
|
|
|
|
|
|
|
|
if ($location) {
|
|
|
|
$template->addBodyListItem($location, $l10n->t('Where:'),
|
|
|
|
$this->getAbsoluteImagePath('filetypes/location.svg'));
|
|
|
|
}
|
|
|
|
if ($description) {
|
|
|
|
$template->addBodyListItem((string)$description, $l10n->t('Description:'),
|
|
|
|
$this->getAbsoluteImagePath('filetypes/text.svg'));
|
|
|
|
}
|
|
|
|
if ($url) {
|
|
|
|
$template->addBodyListItem((string)$url, $l10n->t('Link:'),
|
|
|
|
$this->getAbsoluteImagePath('filetypes/link.svg'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-19 22:01:14 +03:00
|
|
|
/**
|
|
|
|
* @param IEMailTemplate $template
|
|
|
|
* @param IL10N $l10n
|
|
|
|
* @param Message $iTipMessage
|
|
|
|
* @param int $lastOccurrence
|
|
|
|
*/
|
|
|
|
private function addResponseButtons(IEMailTemplate $template, IL10N $l10n,
|
|
|
|
Message $iTipMessage, $lastOccurrence) {
|
|
|
|
$token = $this->createInvitationToken($iTipMessage, $lastOccurrence);
|
|
|
|
|
|
|
|
$template->addBodyButtonGroup(
|
|
|
|
$l10n->t('Accept'),
|
|
|
|
$this->urlGenerator->linkToRouteAbsolute('dav.invitation_response.accept', [
|
|
|
|
'token' => $token,
|
|
|
|
]),
|
|
|
|
$l10n->t('Decline'),
|
|
|
|
$this->urlGenerator->linkToRouteAbsolute('dav.invitation_response.decline', [
|
|
|
|
'token' => $token,
|
|
|
|
])
|
|
|
|
);
|
|
|
|
|
|
|
|
$moreOptionsURL = $this->urlGenerator->linkToRouteAbsolute('dav.invitation_response.options', [
|
|
|
|
'token' => $token,
|
|
|
|
]);
|
|
|
|
$html = vsprintf('<small><a href="%s">%s</a></small>', [
|
2018-07-30 16:05:55 +03:00
|
|
|
$moreOptionsURL, $l10n->t('More options …')
|
2018-06-19 22:01:14 +03:00
|
|
|
]);
|
|
|
|
$text = $l10n->t('More options at %s', [$moreOptionsURL]);
|
|
|
|
|
|
|
|
$template->addBodyText($html, $text);
|
|
|
|
}
|
|
|
|
|
2017-11-02 18:38:16 +03:00
|
|
|
/**
|
|
|
|
* @param string $path
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function getAbsoluteImagePath($path) {
|
|
|
|
return $this->urlGenerator->getAbsoluteURL(
|
|
|
|
$this->urlGenerator->imagePath('core', $path)
|
|
|
|
);
|
|
|
|
}
|
2018-06-19 22:01:14 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Message $iTipMessage
|
|
|
|
* @param int $lastOccurrence
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function createInvitationToken(Message $iTipMessage, $lastOccurrence):string {
|
|
|
|
$token = $this->random->generate(60, ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS);
|
|
|
|
|
|
|
|
/** @var VEvent $vevent */
|
|
|
|
$vevent = $iTipMessage->message->VEVENT;
|
|
|
|
$attendee = $iTipMessage->recipient;
|
|
|
|
$organizer = $iTipMessage->sender;
|
|
|
|
$sequence = $iTipMessage->sequence;
|
|
|
|
$recurrenceId = isset($vevent->{'RECURRENCE-ID'}) ?
|
|
|
|
$vevent->{'RECURRENCE-ID'}->serialize() : null;
|
|
|
|
$uid = $vevent->{'UID'};
|
|
|
|
|
|
|
|
$query = $this->db->getQueryBuilder();
|
2018-07-12 13:11:11 +03:00
|
|
|
$query->insert('calendar_invitations')
|
2018-06-19 22:01:14 +03:00
|
|
|
->values([
|
|
|
|
'token' => $query->createNamedParameter($token),
|
|
|
|
'attendee' => $query->createNamedParameter($attendee),
|
|
|
|
'organizer' => $query->createNamedParameter($organizer),
|
|
|
|
'sequence' => $query->createNamedParameter($sequence),
|
|
|
|
'recurrenceid' => $query->createNamedParameter($recurrenceId),
|
|
|
|
'expiration' => $query->createNamedParameter($lastOccurrence),
|
|
|
|
'uid' => $query->createNamedParameter($uid)
|
|
|
|
])
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
return $token;
|
|
|
|
}
|
2015-12-18 13:56:25 +03:00
|
|
|
}
|