From 77291ce2aec53b77fe067aed6c44242b9b18b8de Mon Sep 17 00:00:00 2001 From: SebastianKrupinski Date: Wed, 17 Apr 2024 10:40:31 -0400 Subject: [PATCH] fix(caldav): when message is a reply compare the message sender not the recipient Signed-off-by: SebastianKrupinski Signed-off-by: Daniel Kesselberg --- apps/dav/lib/CalDAV/Schedule/IMipService.php | 7 +- .../unit/CalDAV/Schedule/IMipServiceTest.php | 71 +++++++++++++++++++ 2 files changed, 76 insertions(+), 2 deletions(-) diff --git a/apps/dav/lib/CalDAV/Schedule/IMipService.php b/apps/dav/lib/CalDAV/Schedule/IMipService.php index 95c6b5739af28..1a99a859279c9 100644 --- a/apps/dav/lib/CalDAV/Schedule/IMipService.php +++ b/apps/dav/lib/CalDAV/Schedule/IMipService.php @@ -569,8 +569,11 @@ public function getCurrentAttendee(Message $iTipMessage): ?Property { $vevent = $iTipMessage->message->VEVENT; $attendees = $vevent->select('ATTENDEE'); foreach ($attendees as $attendee) { - /** @var Property $attendee */ - if (strcasecmp($attendee->getValue(), $iTipMessage->recipient) === 0) { + if ($iTipMessage->method === 'REPLY' && strcasecmp($attendee->getValue(), $iTipMessage->sender) === 0) { + /** @var Property $attendee */ + return $attendee; + } elseif (strcasecmp($attendee->getValue(), $iTipMessage->recipient) === 0) { + /** @var Property $attendee */ return $attendee; } } diff --git a/apps/dav/tests/unit/CalDAV/Schedule/IMipServiceTest.php b/apps/dav/tests/unit/CalDAV/Schedule/IMipServiceTest.php index 142731098266a..fd48d04dc8e08 100644 --- a/apps/dav/tests/unit/CalDAV/Schedule/IMipServiceTest.php +++ b/apps/dav/tests/unit/CalDAV/Schedule/IMipServiceTest.php @@ -41,6 +41,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Sabre\VObject\Component\VCalendar; use Sabre\VObject\Component\VEvent; +use Sabre\VObject\ITip\Message; use Sabre\VObject\Property\ICalendar\DateTime; use Test\TestCase; @@ -271,4 +272,74 @@ public function testGetLastOccurrenceFallback(): void { $occurrence = $this->service->getLastOccurrence($vCalendar); $this->assertEquals(1451606400, $occurrence); } + + public function testGetCurrentAttendeeRequest(): void { + // Construct ITip Message + $message = new Message(); + $message->method = 'REQUEST'; + $message->sequence = 1; + $message->sender = 'mailto:organizer@example.com'; + $message->senderName = 'The Organizer'; + $message->recipient = 'mailto:attendee@example.com'; + $message->recipientName = 'The Attendee'; + $message->significantChange = true; + $message->message = new VCalendar(); + $message->message->add('VEVENT', ['UID' => '82496785-1915-4604-a5ce-4e2091639c9a', 'SEQUENCE' => 1]); + $message->message->VEVENT->add('SUMMARY', 'Fellowship meeting'); + $message->message->VEVENT->add('DTSTART', (new \DateTime('NOW'))->modify('+1 hour')); + $message->message->VEVENT->add('DTEND', (new \DateTime('NOW'))->modify('+2 hour')); + $message->message->VEVENT->add('ORGANIZER', 'mailto:organizer@example.com', ['CN' => 'The Organizer']); + $message->message->VEVENT->add('ATTENDEE', 'mailto:attendee@example.com', ['CN' => 'The Attendee']); + // Test getCurrentAttendee + $result = $this->service->getCurrentAttendee($message); + // Evaluate Result + $this->assertEquals($message->message->VEVENT->ATTENDEE, $result); + } + + public function testGetCurrentAttendeeReply(): void { + // Construct ITip Message + $message = new Message(); + $message->method = 'REPLY'; + $message->sequence = 2; + $message->sender = 'mailto:attendee@example.com'; + $message->senderName = 'The Attendee'; + $message->recipient = 'mailto:organizer@example.com'; + $message->recipientName = 'The Organizer'; + $message->significantChange = true; + $message->message = new VCalendar(); + $message->message->add('METHOD', 'REPLY'); + $message->message->add('VEVENT', ['UID' => '82496785-1915-4604-a5ce-4e2091639c9a', 'SEQUENCE' => 2]); + $message->message->VEVENT->add('SUMMARY', 'Fellowship meeting'); + $message->message->VEVENT->add('DTSTART', (new \DateTime('NOW'))->modify('+1 hour')); + $message->message->VEVENT->add('DTEND', (new \DateTime('NOW'))->modify('+2 hour')); + $message->message->VEVENT->add('ORGANIZER', 'mailto:organizer@example.com', ['CN' => 'The Organizer']); + $message->message->VEVENT->add('ATTENDEE', 'mailto:attendee@example.com', ['CN' => 'The Attendee']); + // Test getCurrentAttendee + $result = $this->service->getCurrentAttendee($message); + // Evaluate Result + $this->assertEquals($message->message->VEVENT->ATTENDEE, $result); + } + + public function testGetCurrentAttendeeMismatch(): void { + // Construct ITip Message + $message = new Message(); + $message->method = 'REQUEST'; + $message->sequence = 1; + $message->sender = 'mailto:organizer@example.com'; + $message->senderName = 'The Organizer'; + $message->recipient = 'mailto:mismatch@example.com'; + $message->recipientName = 'The Mismatch'; + $message->significantChange = true; + $message->message = new VCalendar(); + $message->message->add('VEVENT', ['UID' => '82496785-1915-4604-a5ce-4e2091639c9a', 'SEQUENCE' => 1]); + $message->message->VEVENT->add('SUMMARY', 'Fellowship meeting'); + $message->message->VEVENT->add('DTSTART', (new \DateTime('NOW'))->modify('+1 hour')); + $message->message->VEVENT->add('DTEND', (new \DateTime('NOW'))->modify('+2 hour')); + $message->message->VEVENT->add('ORGANIZER', 'mailto:organizer@example.com', ['CN' => 'The Organizer']); + $message->message->VEVENT->add('ATTENDEE', 'mailto:attendee@example.com', ['CN' => 'The Attendee']); + // Test getCurrentAttendee + $result = $this->service->getCurrentAttendee($message); + // Evaluate Result + $this->assertEquals(null, $result); + } }