From 721a0bd1561c74a67db5512906d69821d7146126 Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Mon, 27 Jul 2026 12:27:01 +0200 Subject: [PATCH] fix(imip): add context to imip log messages Assisted-by: ClaudeCode:claude-sonnet-5 Signed-off-by: Daniel Kesselberg --- lib/private/Calendar/Manager.php | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/lib/private/Calendar/Manager.php b/lib/private/Calendar/Manager.php index dff931d4ddc59..63aa4e9b691ef 100644 --- a/lib/private/Calendar/Manager.php +++ b/lib/private/Calendar/Manager.php @@ -243,11 +243,16 @@ public function handleIMip( array $options = [], ): bool { + $logContext = [ + 'userId' => $userId, + 'options' => $options, + ]; + $userUri = 'principals/users/' . $userId; $userCalendars = $this->getCalendarsForPrincipal($userUri); 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; } @@ -255,34 +260,37 @@ public function handleIMip( /** @var VCalendar $vObject|null */ $vObject = Reader::read($message); } 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($vObject->VEVENT)) { - $this->logger->warning('iMip message does not contain any event(s)'); + $this->logger->warning('iMip message does not contain any event(s)', $logContext); return false; } /** @var VEvent $vEvent */ $vEvent = $vObject->VEVENT; if (!isset($vEvent->UID)) { - $this->logger->warning('iMip message event dose not contains a UID'); + $this->logger->warning('iMip message event dose not contains a UID', $logContext); return false; } + $logContext['eventUid'] = $vEvent->UID->getValue(); + if (!isset($vEvent->ORGANIZER)) { // 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'); + $this->logger->warning('iMip message event does not contain an organizer and no recipient was provided', $logContext); return false; } } if (!isset($vEvent->ATTENDEE)) { - $this->logger->warning('iMip message event dose not contains any attendees'); + $this->logger->warning('iMip message event dose not contains any attendees', $logContext); return false; } @@ -300,7 +308,8 @@ public function handleIMip( } return true; } catch (CalendarException $e) { - $this->logger->error('iMip message could not be processed because an error occurred', ['exception' => $e]); + $logContext['exception'] = $e; + $this->logger->error('iMip message could not be processed because an error occurred', $logContext); return false; } } @@ -324,14 +333,14 @@ public function handleIMip( } } if ($calendar === null) { - $this->logger->warning('iMip message could not be processed because no writable calendar was found'); + $this->logger->warning('iMip message could not be processed because no writable calendar was found', $logContext); return false; } if (!empty($options['absentCreateStatus'])) { $status = strtoupper($options['absentCreateStatus']); if (in_array($status, ['TENTATIVE', 'CONFIRMED', 'CANCELLED'], true) === false) { - $this->logger->warning('iMip message could not be processed because an invalid status was provided for the event'); + $this->logger->warning('iMip message could not be processed because an invalid status was provided for the event', $logContext); return false; } @@ -345,14 +354,15 @@ public function handleIMip( try { $calendar->handleIMipMessage($userId, $vObject->serialize()); } catch (CalendarException $e) { - $this->logger->error('iMip message could not be processed because an error occurred', ['exception' => $e]); + $logContext['exception'] = $e; + $this->logger->error('iMip message could not be processed because an error occurred', $logContext); return false; } return true; } - $this->logger->warning('iMip message could not be processed because no corresponding event was found in any calendar'); + $this->logger->warning('iMip message could not be processed because no corresponding event was found in any calendar', $logContext); return false; }