Skip to content

Commit

Permalink
fixup! fixup! feat: add iMip Request Handling
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianKrupinski committed Oct 20, 2024
1 parent 2fb439f commit 53365ee
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions lib/private/Calendar/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,38 +214,38 @@ public function handleIMipRequest(
string $recipient,
string $calendarData,
): bool {
// determine if user has any calendars

$userCalendars = $this->getCalendarsForPrincipal($principalUri);
if (empty($userCalendars)) {
$this->logger->warning('iMip message could not be processed because user has on calendars');
return false;
}
// convert calendar string data to calendar object

/** @var VCalendar $vObject|null */
$calendarObject = Reader::read($calendarData);
// determine if event has the correct method

if (!isset($calendarObject->METHOD) || $calendarObject->METHOD->getValue() !== 'REQUEST') {
$this->logger->warning('iMip message contains an incorrect or invalid method');
return false;
}
// determine if calendar object contains any events

if (!isset($calendarObject->VEVENT)) {
$this->logger->warning('iMip message contains an no event');
return false;
}
// extract event(s)

$eventObject = $calendarObject->VEVENT;
// determine if event contains a uid

if (!isset($eventObject->UID)) {
$this->logger->warning('iMip message event dose not contains a UID');
return false;
}
// determine if event contains any attendees

if (!isset($eventObject->ATTENDEE)) {
$this->logger->warning('iMip message event dose not contains any attendees');
return false;
}
// determine if any of the attendees are the recipient

foreach ($eventObject->ATTENDEE as $entry) {
$address = trim(str_replace('mailto:', '', $entry->getValue()));
if ($address === $recipient) {
Expand All @@ -257,17 +257,17 @@ public function handleIMipRequest(
$this->logger->warning('iMip message event does not contain a attendee that matches the recipient');
return false;
}
// find event in calendar and update it

foreach ($userCalendars as $calendar) {
// determine if calendar is deleted, shared, or read only and ignore

if ($calendar->isDeleted() || !$calendar->isWritable() || $calendar->isShared()) {
continue;
}
// find event and update it

if (!empty($calendar->search($recipient, ['ATTENDEE'], ['uid' => $eventObject->UID->getValue()]))) {
try {
if ($calendar instanceof IHandleImipMessage) {
$calendar->handleIMipMessage('', $calendarData); // sabre will handle the scheduling behind the scenes
$calendar->handleIMipMessage('', $calendarData);
}
return true;
} catch (CalendarException $e) {
Expand All @@ -276,7 +276,7 @@ public function handleIMipRequest(
}
}
}
// if we got this far, log the attempt and exit

$this->logger->warning('iMip message event could not be processed because the no corresponding event was found in any calendar');
return false;
}
Expand Down

0 comments on commit 53365ee

Please sign in to comment.