diff options
-rw-r--r-- | lib/private/Calendar/Manager.php | 73 | ||||
-rw-r--r-- | tests/lib/Calendar/ManagerTest.php | 2 |
2 files changed, 48 insertions, 27 deletions
diff --git a/lib/private/Calendar/Manager.php b/lib/private/Calendar/Manager.php index a326e25df85..bb6e7fba8d7 100644 --- a/lib/private/Calendar/Manager.php +++ b/lib/private/Calendar/Manager.php @@ -230,10 +230,15 @@ class Manager implements IManager { string $recipient, string $calendarData, ): bool { + $logContext = [ + 'principalUri' => $principalUri, + 'sender' => $sender, + 'recipient' => $recipient, + ]; $userCalendars = $this->getCalendarsForPrincipal($principalUri); if (empty($userCalendars)) { - $this->logger->warning('iMip message could not be processed because user has no calendars'); + $this->logger->warning('iMip message could not be processed because user has no calendars', $logContext); return false; } @@ -241,17 +246,18 @@ class Manager implements IManager { /** @var VCalendar $vObject|null */ $calendarObject = Reader::read($calendarData); } catch (ParseException $e) { - $this->logger->error('iMip message could not be processed because an error occurred while parsing the iMip message', ['exception' => $e]); + $logContext['exception'] = $e; + $this->logger->error('iMip message could not be processed because an error occurred while parsing the iMip message', $logContext); return false; } if (!isset($calendarObject->METHOD) || $calendarObject->METHOD->getValue() !== 'REQUEST') { - $this->logger->warning('iMip message contains an incorrect or invalid method'); + $this->logger->warning('iMip message contains an incorrect or invalid method', $logContext); return false; } if (!isset($calendarObject->VEVENT)) { - $this->logger->warning('iMip message contains no event'); + $this->logger->warning('iMip message contains no event', $logContext); return false; } @@ -259,17 +265,20 @@ class Manager implements IManager { $eventObject = $calendarObject->VEVENT; if (!isset($eventObject->UID)) { - $this->logger->warning('iMip message event does not contains a UID'); + $this->logger->warning('iMip message event does not contains a UID', $logContext); return false; } + $vEventUid = $vEvent->UID->getValue(); + $logContext['vEventUid'] = $vEventUid; + if (!isset($eventObject->ORGANIZER)) { - $this->logger->warning('iMip message event does not contains an organizer'); + $this->logger->warning('iMip message event does not contains an organizer', $logContext); return false; } if (!isset($eventObject->ATTENDEE)) { - $this->logger->warning('iMip message event does not contains any attendees'); + $this->logger->warning('iMip message event does not contains any attendees', $logContext); return false; } @@ -281,7 +290,7 @@ class Manager implements IManager { } } if (!isset($attendee)) { - $this->logger->warning('iMip message event does not contain a attendee that matches the recipient'); + $this->logger->warning('iMip message event does not contain a attendee that matches the recipient', $logContext); return false; } @@ -295,20 +304,21 @@ class Manager implements IManager { continue; } - if (!empty($calendar->search($recipient, ['ATTENDEE'], ['uid' => $eventObject->UID->getValue()]))) { + if (!empty($calendar->search($recipient, ['ATTENDEE'], ['uid' => $vEventUid]))) { try { if ($calendar instanceof IHandleImipMessage) { $calendar->handleIMipMessage('', $calendarData); } return true; } catch (CalendarException $e) { - $this->logger->error('An error occurred while processing the iMip message event', ['exception' => $e]); + $logContext['exception'] = $e; + $this->logger->error('An error occurred while processing the iMip message event', $logContext); return false; } } } - $this->logger->warning('iMip message event could not be processed because no corresponding event was found in any calendar'); + $this->logger->warning('iMip message event could not be processed because no corresponding event was found in any calendar', $logContext); return false; } @@ -419,7 +429,8 @@ class Manager implements IManager { try { $found->handleIMipMessage($name, $calendarData); // sabre will handle the scheduling behind the scenes } catch (CalendarException $e) { - $this->logger->error('An error occurred while processing the iMip message event', ['exception' => $e]); + $logContext['exception'] = $e; + $this->logger->error('An error occurred while processing the iMip message event', $logContext); return false; } return true; @@ -436,10 +447,15 @@ class Manager implements IManager { string $recipient, string $calendarData, ): bool { + $logContext = [ + 'principalUri' => $principalUri, + 'sender' => $sender, + 'recipient' => $recipient, + ]; $calendars = $this->getCalendarsForPrincipal($principalUri); if (empty($calendars)) { - $this->logger->warning('iMip message could not be processed because user has no calendars'); + $this->logger->warning('iMip message could not be processed because user has no calendars', $logContext); return false; } @@ -447,22 +463,23 @@ class Manager implements IManager { /** @var VCalendar $vObject|null */ $vObject = Reader::read($calendarData); } catch (ParseException $e) { - $this->logger->error('iMip message could not be processed because an error occurred while parsing the iMip message', ['exception' => $e]); + $logContext['exception'] = $e; + $this->logger->error('iMip message could not be processed because an error occurred while parsing the iMip message', $logContext); return false; } if ($vObject === null) { - $this->logger->warning('iMip message contains an invalid calendar object'); + $this->logger->warning('iMip message contains an invalid calendar object', $logContext); return false; } if (!isset($vObject->METHOD) || $vObject->METHOD->getValue() !== 'CANCEL') { - $this->logger->warning('iMip message contains an incorrect or invalid method'); + $this->logger->warning('iMip message contains an incorrect or invalid method', $logContext); return false; } if (!isset($vObject->VEVENT)) { - $this->logger->warning('iMip message contains no event'); + $this->logger->warning('iMip message contains no event', $logContext); return false; } @@ -470,23 +487,26 @@ class Manager implements IManager { $vEvent = $vObject->{'VEVENT'}; if (!isset($vEvent->UID)) { - $this->logger->warning('iMip message event does not contains a UID'); + $this->logger->warning('iMip message event does not contains a UID', $logContext); return false; } + $vEventUid = $vEvent->UID->getValue(); + $logContext['vEventUid'] = $vEventUid; + if (!isset($vEvent->ORGANIZER)) { - $this->logger->warning('iMip message event does not contains an organizer'); + $this->logger->warning('iMip message event does not contains an organizer', $logContext); return false; } if (!isset($vEvent->ATTENDEE)) { - $this->logger->warning('iMip message event does not contains any attendees'); + $this->logger->warning('iMip message event does not contains any attendees', $logContext); return false; } $attendee = substr($vEvent->{'ATTENDEE'}->getValue(), 7); if (strcasecmp($recipient, $attendee) !== 0) { - $this->logger->warning('iMip message event could not be processed because recipient must be an ATTENDEE of this event'); + $this->logger->warning('iMip message event could not be processed because recipient must be an ATTENDEE of this event', $logContext); return false; } @@ -497,7 +517,7 @@ class Manager implements IManager { $organizer = substr($vEvent->{'ORGANIZER'}->getValue(), 7); $isNotOrganizer = ($replyTo !== null) ? (strcasecmp($sender, $organizer) !== 0 && strcasecmp($replyTo, $organizer) !== 0) : (strcasecmp($sender, $organizer) !== 0); if ($isNotOrganizer) { - $this->logger->warning('iMip message event could not be processed because sender must be the ORGANIZER of this event'); + $this->logger->warning('iMip message event could not be processed because sender must be the ORGANIZER of this event', $logContext); return false; } @@ -505,7 +525,7 @@ class Manager implements IManager { /** @var DateTime $eventTime */ $eventTime = $vEvent->{'DTSTART'}; if ($eventTime->getDateTime()->getTimeStamp() < $this->timeFactory->getTime()) { // this might cause issues with recurrences - $this->logger->warning('iMip message event could not be processed because the event is in the past'); + $this->logger->warning('iMip message event could not be processed because the event is in the past', $logContext); return false; } @@ -517,7 +537,7 @@ class Manager implements IManager { foreach ($calendars as $calendar) { // We should not search in writable calendars if ($calendar instanceof IHandleImipMessage) { - $o = $calendar->search($recipient, ['ATTENDEE'], ['uid' => $vEvent->{'UID'}->getValue()]); + $o = $calendar->search($recipient, ['ATTENDEE'], ['uid' => $vEventUid]); if (!empty($o)) { $found = $calendar; $name = $o[0]['uri']; @@ -527,7 +547,7 @@ class Manager implements IManager { } if (empty($found)) { - $this->logger->warning('iMip message event could not be processed because no corresponding event was found in any calendar ' . $principalUri . 'and UID' . $vEvent->{'UID'}->getValue()); + $this->logger->warning('iMip message event could not be processed because no corresponding event was found in any calendar', $logContext); return false; } @@ -535,7 +555,8 @@ class Manager implements IManager { $found->handleIMipMessage($name, $calendarData); // sabre will handle the scheduling behind the scenes return true; } catch (CalendarException $e) { - $this->logger->error('An error occurred while processing the iMip message event', ['exception' => $e]); + $logContext['exception'] = $e; + $this->logger->error('An error occurred while processing the iMip message event', $logContext); return false; } } diff --git a/tests/lib/Calendar/ManagerTest.php b/tests/lib/Calendar/ManagerTest.php index 10f46687ba9..36156d9d8e4 100644 --- a/tests/lib/Calendar/ManagerTest.php +++ b/tests/lib/Calendar/ManagerTest.php @@ -1078,7 +1078,7 @@ class ManagerTest extends TestCase { $calendarData->add('METHOD', 'REPLY'); // construct logger return $this->logger->expects(self::once())->method('warning') - ->with('iMip message event could not be processed because no corresponding event was found in any calendar ' . $principalUri . 'and UID' . $calendarData->VEVENT->UID->getValue()); + ->with('iMip message event could not be processed because no corresponding event was found in any calendar'); // Act $result = $manager->handleIMipReply($principalUri, $sender, $recipient, $calendarData->serialize()); // Assert |