summaryrefslogtreecommitdiffstats
path: root/apps/dav/lib
diff options
context:
space:
mode:
authorGeorg Ehrke <developer@georgehrke.com>2017-06-08 11:50:17 +0200
committerGeorg Ehrke <developer@georgehrke.com>2017-09-05 13:13:37 +0200
commit86f28669fce3360a75513f06beb945ab54d20a6a (patch)
treed52f22e767f0c0a85fb29d136de82fec52196d50 /apps/dav/lib
parent6be5dc91cb345886c14661f4ce7dd54a2e500f61 (diff)
downloadnextcloud-server-86f28669fce3360a75513f06beb945ab54d20a6a.tar.gz
nextcloud-server-86f28669fce3360a75513f06beb945ab54d20a6a.zip
don't send invitation emails for past events
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
Diffstat (limited to 'apps/dav/lib')
-rw-r--r--apps/dav/lib/CalDAV/Schedule/IMipPlugin.php65
-rw-r--r--apps/dav/lib/Server.php4
2 files changed, 67 insertions, 2 deletions
diff --git a/apps/dav/lib/CalDAV/Schedule/IMipPlugin.php b/apps/dav/lib/CalDAV/Schedule/IMipPlugin.php
index c21edb45848..711d54d7f8e 100644
--- a/apps/dav/lib/CalDAV/Schedule/IMipPlugin.php
+++ b/apps/dav/lib/CalDAV/Schedule/IMipPlugin.php
@@ -1,8 +1,10 @@
<?php
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @copyright Copyright (c) 2017, Georg Ehrke
*
* @author Thomas Müller <thomas.mueller@tmit.eu>
+ * @author Georg Ehrke <oc.list@georgehrke.com>
*
* @license AGPL-3.0
*
@@ -21,10 +23,15 @@
*/
namespace OCA\DAV\CalDAV\Schedule;
+use OCP\AppFramework\Utility\ITimeFactory;
use OCP\ILogger;
use OCP\Mail\IMailer;
+use Sabre\VObject\Component\VCalendar;
+use Sabre\VObject\DateTimeParser;
use Sabre\VObject\ITip;
use Sabre\CalDAV\Schedule\IMipPlugin as SabreIMipPlugin;
+use Sabre\VObject\Recur\EventIterator;
+
/**
* iMIP handler.
*
@@ -47,15 +54,23 @@ class IMipPlugin extends SabreIMipPlugin {
/** @var ILogger */
private $logger;
+ /** @var ITimeFactory */
+ private $timeFactory;
+
+ const MAX_DATE = '2038-01-01';
+
/**
* Creates the email handler.
*
* @param IMailer $mailer
+ * @param ILogger $logger
+ * @param ITimeFactory $timeFactory
*/
- function __construct(IMailer $mailer, ILogger $logger) {
+ function __construct(IMailer $mailer, ILogger $logger, ITimeFactory $timeFactory) {
parent::__construct('');
$this->mailer = $mailer;
$this->logger = $logger;
+ $this->timeFactory = $timeFactory;
}
/**
@@ -85,6 +100,11 @@ class IMipPlugin extends SabreIMipPlugin {
return;
}
+ // don't send out mails for events that already took place
+ if ($this->isEventInThePast($iTipMessage->message)) {
+ return;
+ }
+
$sender = substr($iTipMessage->sender, 7);
$recipient = substr($iTipMessage->recipient, 7);
@@ -125,4 +145,47 @@ class IMipPlugin extends SabreIMipPlugin {
}
}
+ /**
+ * check if event took place in the past already
+ * @param VCalendar $vObject
+ * @return bool
+ */
+ private function isEventInThePast(VCalendar $vObject) {
+ $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)) {
+ $endDate = clone $component->DTSTART->getDateTime();
+ $endDate->add(DateTimeParser::parse($component->DURATION->getValue()));
+ $lastOccurrence = $endDate->getTimeStamp();
+ } elseif (!$component->DTSTART->hasTime()) {
+ $endDate = clone $component->DTSTART->getDateTime();
+ $endDate->modify('+1 day');
+ $lastOccurrence = $endDate->getTimeStamp();
+ } 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();
+ }
+ }
+
+ $currentTime = $this->timeFactory->getTime();
+ return $lastOccurrence < $currentTime;
+ }
}
diff --git a/apps/dav/lib/Server.php b/apps/dav/lib/Server.php
index 896af09f1c0..30c0a4afbd7 100644
--- a/apps/dav/lib/Server.php
+++ b/apps/dav/lib/Server.php
@@ -28,6 +28,7 @@
*/
namespace OCA\DAV;
+use OC\AppFramework\Utility\TimeFactory;
use OCA\DAV\CalDAV\Schedule\IMipPlugin;
use OCA\DAV\CardDAV\ImageExportPlugin;
use OCA\DAV\CardDAV\PhotoCache;
@@ -73,6 +74,7 @@ class Server {
$logger = \OC::$server->getLogger();
$mailer = \OC::$server->getMailer();
$dispatcher = \OC::$server->getEventDispatcher();
+ $timezone = new TimeFactory();
$root = new RootCollection();
$this->server = new \OCA\DAV\Connector\Sabre\Server($root);
@@ -134,7 +136,7 @@ class Server {
$this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin());
$this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
$this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin());
- $this->server->addPlugin(new IMipPlugin($mailer, $logger));
+ $this->server->addPlugin(new IMipPlugin($mailer, $logger, $timezone));
$this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin());
$this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin());
$this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest()));