diff --git a/lib/private/Calendar/Manager.php b/lib/private/Calendar/Manager.php index 78bf7a7d82861..c210b13381091 100644 --- a/lib/private/Calendar/Manager.php +++ b/lib/private/Calendar/Manager.php @@ -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) { @@ -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) { @@ -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; }