Skip to content
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
19 changes: 14 additions & 5 deletions lib/private/Calendar/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ public function newQuery(string $principalUri): ICalendarQuery {
protected function handleIMip(
string $userId,
string $message,
array $options = [],
): bool {

$userUri = 'principals/users/' . $userId;
Expand Down Expand Up @@ -258,8 +259,13 @@ protected function handleIMip(
}

if (!isset($vEvent->ORGANIZER)) {
$this->logger->warning('iMip message event dose not contains an organizer');
return false;
// quirks mode: for Microsoft Exchange Servers use recipient as organizer if no organizer is set
if (isset($options['recipient']) && $options['recipient'] !== '') {
$vEvent->add('ORGANIZER', 'mailto:' . $options['recipient']);
} else {
$this->logger->warning('iMip message event does not contain an organizer and no recipient was provided');
return false;
}
}

if (!isset($vEvent->ATTENDEE)) {
Expand Down Expand Up @@ -308,7 +314,8 @@ public function handleIMipRequest(
return false;
}
$userId = substr($principalUri, 17);
return $this->handleIMip($userId, $calendarData);
$options = ['recipient' => $recipient];
return $this->handleIMip($userId, $calendarData, $options);
}

/**
Expand All @@ -327,7 +334,8 @@ public function handleIMipReply(
return false;
}
$userId = substr($principalUri, 17);
return $this->handleIMip($userId, $calendarData);
$options = ['recipient' => $recipient];
return $this->handleIMip($userId, $calendarData, $options);
}

/**
Expand All @@ -347,7 +355,8 @@ public function handleIMipCancel(
return false;
}
$userId = substr($principalUri, 17);
return $this->handleIMip($userId, $calendarData);
$options = ['recipient' => $recipient];
return $this->handleIMip($userId, $calendarData, $options);
}

public function createEventBuilder(): ICalendarEventBuilder {
Expand Down
74 changes: 74 additions & 0 deletions tests/lib/Calendar/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,80 @@ public function testHandleImipWithNoEvent(): void {
$this->assertFalse($result);
}

public function testHandleImipMissingOrganizerWithRecipient(): void {
// construct mock user calendar
$userCalendar = $this->createMock(ITestCalendar::class);
$userCalendar->expects(self::once())
->method('isDeleted')
->willReturn(false);
$userCalendar->expects(self::once())
->method('isWritable')
->willReturn(true);
$userCalendar->expects(self::once())
->method('search')
->willReturn([['uri' => 'principals/user/attendee1/personal']]);
// construct mock calendar manager and returns
/** @var Manager&MockObject $manager */
$manager = $this->getMockBuilder(Manager::class)
->setConstructorArgs([
$this->coordinator,
$this->container,
$this->logger,
$this->time,
$this->secureRandom,
$this->userManager,
$this->serverFactory,
])
->onlyMethods(['getCalendarsForPrincipal'])
->getMock();
$manager->expects(self::once())
->method('getCalendarsForPrincipal')
->willReturn([$userCalendar]);
// construct parameters
$userId = 'attendee1';
$calendar = $this->vCalendar1a;
$calendar->add('METHOD', 'REQUEST');
$calendar->VEVENT->remove('ORGANIZER');
// construct user calendar returns
$userCalendar->expects(self::once())
->method('handleIMipMessage');
// test method
$result = $this->invokePrivate($manager, 'handleIMip', [$userId, $calendar->serialize(), ['recipient' => 'organizer@testing.com']]);
}

public function testHandleImipMissingOrganizerNoRecipient(): void {
// construct mock user calendar
$userCalendar = $this->createMock(ITestCalendar::class);
// construct mock calendar manager and returns
/** @var Manager&MockObject $manager */
$manager = $this->getMockBuilder(Manager::class)
->setConstructorArgs([
$this->coordinator,
$this->container,
$this->logger,
$this->time,
$this->secureRandom,
$this->userManager,
$this->serverFactory,
])
->onlyMethods(['getCalendarsForPrincipal'])
->getMock();
$manager->expects(self::once())
->method('getCalendarsForPrincipal')
->willReturn([$userCalendar]);
// construct parameters
$userId = 'attendee1';
$calendar = $this->vCalendar1a;
$calendar->add('METHOD', 'REQUEST');
$calendar->VEVENT->remove('ORGANIZER');
// Logger expects warning
$this->logger->expects($this->once())
->method('warning')
->with('iMip message event does not contain an organizer and no recipient was provided');

$result = $this->invokePrivate($manager, 'handleIMip', [$userId, $calendar->serialize(), []]);
}

public function testHandleImipWithNoUid(): void {
// construct mock user calendar
$userCalendar = $this->createMock(ITestCalendar::class);
Expand Down
Loading