summaryrefslogtreecommitdiffstats
path: root/apps/dav
diff options
context:
space:
mode:
authorAnna Larch <anna@nextcloud.com>2023-10-11 18:13:39 +0200
committerAnna <anna@nextcloud.com>2023-11-27 09:24:22 +0100
commitbecf192b6b3ad64a6c85ca78b444cb8381e29e2b (patch)
treeea04ca783c4c77047237b06f1ccc4e0889e3c291 /apps/dav
parent9f196a5d81bf039ae734a614db3955a776e829bf (diff)
downloadnextcloud-server-becf192b6b3ad64a6c85ca78b444cb8381e29e2b.tar.gz
nextcloud-server-becf192b6b3ad64a6c85ca78b444cb8381e29e2b.zip
fix(scheduling): don't send iMIP emails to rooms / resources
Signed-off-by: Anna Larch <anna@nextcloud.com>
Diffstat (limited to 'apps/dav')
-rw-r--r--apps/dav/lib/CalDAV/Schedule/IMipPlugin.php24
-rw-r--r--apps/dav/lib/CalDAV/Schedule/IMipService.php13
-rw-r--r--apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php163
3 files changed, 188 insertions, 12 deletions
diff --git a/apps/dav/lib/CalDAV/Schedule/IMipPlugin.php b/apps/dav/lib/CalDAV/Schedule/IMipPlugin.php
index e164e420ae3..561e2a573b9 100644
--- a/apps/dav/lib/CalDAV/Schedule/IMipPlugin.php
+++ b/apps/dav/lib/CalDAV/Schedule/IMipPlugin.php
@@ -41,14 +41,8 @@ use OCA\DAV\CalDAV\EventComparisonService;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Defaults;
use OCP\IConfig;
-use OCP\IDBConnection;
-use OCP\IL10N;
-use OCP\IURLGenerator;
use OCP\IUserManager;
-use OCP\L10N\IFactory as L10NFactory;
-use OCP\Mail\IEMailTemplate;
use OCP\Mail\IMailer;
-use OCP\Security\ISecureRandom;
use OCP\Util;
use Psr\Log\LoggerInterface;
use Sabre\CalDAV\Schedule\IMipPlugin as SabreIMipPlugin;
@@ -56,13 +50,9 @@ use Sabre\DAV;
use Sabre\DAV\INode;
use Sabre\VObject\Component\VCalendar;
use Sabre\VObject\Component\VEvent;
-use Sabre\VObject\Component\VTimeZone;
-use Sabre\VObject\DateTimeParser;
use Sabre\VObject\ITip\Message;
use Sabre\VObject\Parameter;
-use Sabre\VObject\Property;
use Sabre\VObject\Reader;
-use Sabre\VObject\Recur\EventIterator;
/**
* iMIP handler.
@@ -199,6 +189,20 @@ class IMipPlugin extends SabreIMipPlugin {
// we also might not have an old event as this could be a new
// invitation, or a new recurrence exception
$attendee = $this->imipService->getCurrentAttendee($iTipMessage);
+ if($attendee === null) {
+ $uid = $vEvent->UID ?? 'no UID found';
+ $this->logger->debug('Could not find recipient ' . $recipient . ' as attendee for event with UID ' . $uid);
+ $iTipMessage->scheduleStatus = '5.0;EMail delivery failed';
+ return;
+ }
+ // Don't send emails to things
+ if($this->imipService->isRoomOrResource($attendee)) {
+ $this->logger->debug('No invitation sent as recipient is room or resource', [
+ 'attendee' => $recipient,
+ ]);
+ $iTipMessage->scheduleStatus = '1.0;We got the message, but it\'s not significant enough to warrant an email';
+ return;
+ }
$this->imipService->setL10n($attendee);
// Build the sender name.
diff --git a/apps/dav/lib/CalDAV/Schedule/IMipService.php b/apps/dav/lib/CalDAV/Schedule/IMipService.php
index e6d1bbcd875..1e7b0bc3b02 100644
--- a/apps/dav/lib/CalDAV/Schedule/IMipService.php
+++ b/apps/dav/lib/CalDAV/Schedule/IMipService.php
@@ -673,4 +673,17 @@ class IMipService {
}
return null;
}
+
+ public function isRoomOrResource(Property $attendee): bool {
+ $cuType = $attendee->offsetGet('CUTYPE');
+ if(!$cuType instanceof Parameter) {
+ return false;
+ }
+ $type = $cuType->getValue() ?? 'INDIVIDUAL';
+ if (\in_array(strtoupper($type), ['RESOURCE', 'ROOM', 'UNKNOWN'], true)) {
+ // Don't send emails to things
+ return true;
+ }
+ return false;
+ }
}
diff --git a/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php b/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php
index bf28fb472a8..c5092e5f483 100644
--- a/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php
+++ b/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php
@@ -45,6 +45,7 @@ use Psr\Log\LoggerInterface;
use Sabre\VObject\Component\VCalendar;
use Sabre\VObject\Component\VEvent;
use Sabre\VObject\ITip\Message;
+use Sabre\VObject\Property;
use Test\TestCase;
use function array_merge;
@@ -183,6 +184,13 @@ class IMipPluginTest extends TestCase {
'meeting_title' => 'Fellowship meeting without (!) Boromir',
'attendee_name' => 'frodo@hobb.it'
];
+ $attendees = $newVevent->select('ATTENDEE');
+ $atnd = '';
+ foreach ($attendees as $attendee) {
+ if (strcasecmp($attendee->getValue(), $message->recipient) === 0) {
+ $atnd = $attendee;
+ }
+ }
$this->plugin->setVCalendar($oldVCalendar);
$this->service->expects(self::once())
->method('getLastOccurrence')
@@ -195,6 +203,14 @@ class IMipPluginTest extends TestCase {
->method('findModified')
->willReturn(['new' => [$newVevent], 'old' => [$oldVEvent]]);
$this->service->expects(self::once())
+ ->method('getCurrentAttendee')
+ ->with($message)
+ ->willReturn($atnd);
+ $this->service->expects(self::once())
+ ->method('isRoomOrResource')
+ ->with($atnd)
+ ->willReturn(false);
+ $this->service->expects(self::once())
->method('buildBodyData')
->with($newVevent, $oldVEvent)
->willReturn($data);
@@ -232,6 +248,91 @@ class IMipPluginTest extends TestCase {
$this->assertEquals('1.1', $message->getScheduleStatus());
}
+ public function testAttendeeIsResource(): void {
+ $message = new Message();
+ $message->method = 'REQUEST';
+ $newVCalendar = new VCalendar();
+ $newVevent = new VEvent($newVCalendar, 'one', array_merge([
+ 'UID' => 'uid-1234',
+ 'SEQUENCE' => 1,
+ 'SUMMARY' => 'Fellowship meeting without (!) Boromir',
+ 'DTSTART' => new \DateTime('2016-01-01 00:00:00')
+ ], []));
+ $newVevent->add('ORGANIZER', 'mailto:gandalf@wiz.ard');
+ $newVevent->add('ATTENDEE', 'mailto:' . 'the-shire@hobb.it', ['RSVP' => 'TRUE', 'CN' => 'The Shire', 'CUTYPE' => 'ROOM']);
+ $message->message = $newVCalendar;
+ $message->sender = 'mailto:gandalf@wiz.ard';
+ $message->senderName = 'Mr. Wizard';
+ $message->recipient = 'mailto:' . 'the-shire@hobb.it';
+ // save the old copy in the plugin
+ $oldVCalendar = new VCalendar();
+ $oldVEvent = new VEvent($oldVCalendar, 'one', [
+ 'UID' => 'uid-1234',
+ 'SEQUENCE' => 0,
+ 'SUMMARY' => 'Fellowship meeting',
+ 'DTSTART' => new \DateTime('2016-01-01 00:00:00')
+ ]);
+ $oldVEvent->add('ORGANIZER', 'mailto:gandalf@wiz.ard');
+ $oldVEvent->add('ATTENDEE', 'mailto:' . 'the-shire@hobb.it', ['RSVP' => 'TRUE', 'CN' => 'The Shire', 'CUTYPE' => 'ROOM']);
+ $oldVEvent->add('ATTENDEE', 'mailto:' . 'boromir@tra.it.or', ['RSVP' => 'TRUE']);
+ $oldVCalendar->add($oldVEvent);
+ $data = ['invitee_name' => 'Mr. Wizard',
+ 'meeting_title' => 'Fellowship meeting without (!) Boromir',
+ 'attendee_name' => 'frodo@hobb.it'
+ ];
+ $attendees = $newVevent->select('ATTENDEE');
+ $room = '';
+ foreach ($attendees as $attendee) {
+ if (strcasecmp($attendee->getValue(), $message->recipient) === 0) {
+ $room = $attendee;
+ }
+ }
+ $this->plugin->setVCalendar($oldVCalendar);
+ $this->service->expects(self::once())
+ ->method('getLastOccurrence')
+ ->willReturn('1496912700');
+ $this->mailer->expects(self::once())
+ ->method('validateMailAddress')
+ ->with('the-shire@hobb.it')
+ ->willReturn(true);
+ $this->eventComparisonService->expects(self::once())
+ ->method('findModified')
+ ->willReturn(['new' => [$newVevent], 'old' => [$oldVEvent]]);
+ $this->service->expects(self::once())
+ ->method('getCurrentAttendee')
+ ->with($message)
+ ->willReturn($room);
+ $this->service->expects(self::once())
+ ->method('isRoomOrResource')
+ ->with($room)
+ ->willReturn(true);
+ $this->service->expects(self::never())
+ ->method('buildBodyData');
+ $this->userManager->expects(self::never())
+ ->method('getDisplayName');
+ $this->service->expects(self::never())
+ ->method('getFrom');
+ $this->service->expects(self::never())
+ ->method('addSubjectAndHeading');
+ $this->service->expects(self::never())
+ ->method('addBulletList');
+ $this->service->expects(self::never())
+ ->method('getAttendeeRsvpOrReqForParticipant');
+ $this->config->expects(self::never())
+ ->method('getAppValue');
+ $this->service->expects(self::never())
+ ->method('createInvitationToken');
+ $this->service->expects(self::never())
+ ->method('addResponseButtons');
+ $this->service->expects(self::never())
+ ->method('addMoreOptionsButton');
+ $this->mailer->expects(self::never())
+ ->method('send');
+ $this->plugin->schedule($message);
+ $this->assertEquals('1.0', $message->getScheduleStatus());
+ }
+
+
public function testParsingRecurrence(): void {
$message = new Message();
$message->method = 'REQUEST';
@@ -274,6 +375,13 @@ class IMipPluginTest extends TestCase {
'meeting_title' => 'Elevenses',
'attendee_name' => 'frodo@hobb.it'
];
+ $attendees = $newVevent->select('ATTENDEE');
+ $atnd = '';
+ foreach ($attendees as $attendee) {
+ if (strcasecmp($attendee->getValue(), $message->recipient) === 0) {
+ $atnd = $attendee;
+ }
+ }
$this->plugin->setVCalendar($oldVCalendar);
$this->service->expects(self::once())
->method('getLastOccurrence')
@@ -286,6 +394,14 @@ class IMipPluginTest extends TestCase {
->method('findModified')
->willReturn(['old' => [] ,'new' => [$newVevent]]);
$this->service->expects(self::once())
+ ->method('getCurrentAttendee')
+ ->with($message)
+ ->willReturn($atnd);
+ $this->service->expects(self::once())
+ ->method('isRoomOrResource')
+ ->with($atnd)
+ ->willReturn(false);
+ $this->service->expects(self::once())
->method('buildBodyData')
->with($newVevent, null)
->willReturn($data);
@@ -384,6 +500,13 @@ class IMipPluginTest extends TestCase {
'meeting_title' => 'Fellowship meeting without (!) Boromir',
'attendee_name' => 'frodo@hobb.it'
];
+ $attendees = $newVevent->select('ATTENDEE');
+ $atnd = '';
+ foreach ($attendees as $attendee) {
+ if (strcasecmp($attendee->getValue(), $message->recipient) === 0) {
+ $atnd = $attendee;
+ }
+ }
$this->plugin->setVCalendar($oldVcalendar);
$this->service->expects(self::once())
->method('getLastOccurrence')
@@ -396,6 +519,14 @@ class IMipPluginTest extends TestCase {
->method('findModified')
->willReturn(['old' => [] ,'new' => [$newVevent]]);
$this->service->expects(self::once())
+ ->method('getCurrentAttendee')
+ ->with($message)
+ ->willReturn($atnd);
+ $this->service->expects(self::once())
+ ->method('isRoomOrResource')
+ ->with($atnd)
+ ->willReturn(false);
+ $this->service->expects(self::once())
->method('buildBodyData')
->with($newVevent, null)
->willReturn($data);
@@ -458,7 +589,13 @@ class IMipPluginTest extends TestCase {
'meeting_title' => 'Fellowship meeting',
'attendee_name' => 'frodo@hobb.it'
];
-
+ $attendees = $newVevent->select('ATTENDEE');
+ $atnd = '';
+ foreach ($attendees as $attendee) {
+ if (strcasecmp($attendee->getValue(), $message->recipient) === 0) {
+ $atnd = $attendee;
+ }
+ }
$this->service->expects(self::once())
->method('getLastOccurrence')
->willReturn('1496912700');
@@ -471,6 +608,14 @@ class IMipPluginTest extends TestCase {
->with($newVCalendar, null)
->willReturn(['old' => [] ,'new' => [$newVevent]]);
$this->service->expects(self::once())
+ ->method('getCurrentAttendee')
+ ->with($message)
+ ->willReturn($atnd);
+ $this->service->expects(self::once())
+ ->method('isRoomOrResource')
+ ->with($atnd)
+ ->willReturn(false);
+ $this->service->expects(self::once())
->method('buildBodyData')
->with($newVevent, null)
->willReturn($data);
@@ -530,7 +675,13 @@ class IMipPluginTest extends TestCase {
'meeting_title' => 'Fellowship meeting',
'attendee_name' => 'frodo@hobb.it'
];
-
+ $attendees = $newVevent->select('ATTENDEE');
+ $atnd = '';
+ foreach ($attendees as $attendee) {
+ if (strcasecmp($attendee->getValue(), $message->recipient) === 0) {
+ $atnd = $attendee;
+ }
+ }
$this->service->expects(self::once())
->method('getLastOccurrence')
->willReturn('1496912700');
@@ -543,6 +694,14 @@ class IMipPluginTest extends TestCase {
->with($newVCalendar, null)
->willReturn(['old' => [] ,'new' => [$newVevent]]);
$this->service->expects(self::once())
+ ->method('getCurrentAttendee')
+ ->with($message)
+ ->willReturn($atnd);
+ $this->service->expects(self::once())
+ ->method('isRoomOrResource')
+ ->with($atnd)
+ ->willReturn(false);
+ $this->service->expects(self::once())
->method('buildBodyData')
->with($newVevent, null)
->willReturn($data);