Skip to content

Commit

Permalink
Merge pull request #46145 from nextcloud/backport/44893/stable28
Browse files Browse the repository at this point in the history
[stable28] fix(caldav): When message is a reply compare the message sender not the recipient
  • Loading branch information
kesselb authored Jun 27, 2024
2 parents 427f3c9 + 77291ce commit 7c60d70
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 2 deletions.
7 changes: 5 additions & 2 deletions apps/dav/lib/CalDAV/Schedule/IMipService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
71 changes: 71 additions & 0 deletions apps/dav/tests/unit/CalDAV/Schedule/IMipServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}

0 comments on commit 7c60d70

Please sign in to comment.