Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable28] fix(caldav): When message is a reply compare the message sender not the recipient #46145

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading