|
19 | 19 | use OCP\AppFramework\Db\DoesNotExistException; |
20 | 20 | use OCP\Calendar\IManager; |
21 | 21 | use Psr\Log\LoggerInterface; |
| 22 | +use Throwable; |
| 23 | + |
22 | 24 | use function array_filter; |
23 | 25 |
|
24 | 26 | class IMipService { |
@@ -121,31 +123,44 @@ public function process(): void { |
121 | 123 | $imapMessage = current(array_filter($imapMessages, static fn (IMAPMessage $imapMessage) => $message->getUid() === $imapMessage->getUid())); |
122 | 124 | if (empty($imapMessage->scheduling)) { |
123 | 125 | // No scheduling info, maybe the DB is wrong |
| 126 | + $message->setImipProcessed(true); |
124 | 127 | $message->setImipError(true); |
125 | 128 | continue; |
126 | 129 | } |
127 | 130 |
|
128 | 131 | $sender = $imapMessage->getFrom()->first()?->getEmail(); |
129 | 132 | if ($sender === null) { |
| 133 | + $message->setImipProcessed(true); |
130 | 134 | $message->setImipError(true); |
131 | 135 | continue; |
132 | 136 | } |
133 | 137 |
|
134 | | - foreach ($imapMessage->scheduling as $schedulingInfo) { // an IMAP message could contain more than one iMIP object |
135 | | - if ($schedulingInfo['method'] === 'REQUEST') { |
136 | | - $processed = $this->calendarManager->handleIMipRequest($principalUri, $sender, $recipient, $schedulingInfo['contents']); |
137 | | - $message->setImipProcessed($processed); |
138 | | - $message->setImipError(!$processed); |
139 | | - } elseif ($schedulingInfo['method'] === 'REPLY') { |
140 | | - $processed = $this->calendarManager->handleIMipReply($principalUri, $sender, $recipient, $schedulingInfo['contents']); |
141 | | - $message->setImipProcessed($processed); |
142 | | - $message->setImipError(!$processed); |
143 | | - } elseif ($schedulingInfo['method'] === 'CANCEL') { |
144 | | - $replyTo = $imapMessage->getReplyTo()->first()?->getEmail(); |
145 | | - $processed = $this->calendarManager->handleIMipCancel($principalUri, $sender, $replyTo, $recipient, $schedulingInfo['contents']); |
146 | | - $message->setImipProcessed($processed); |
147 | | - $message->setImipError(!$processed); |
| 138 | + try { |
| 139 | + // an IMAP message could contain more than one iMIP object |
| 140 | + foreach ($imapMessage->scheduling as $schedulingInfo) { |
| 141 | + if ($schedulingInfo['method'] === 'REQUEST') { |
| 142 | + $processed = $this->calendarManager->handleIMipRequest($principalUri, $sender, $recipient, $schedulingInfo['contents']); |
| 143 | + $message->setImipProcessed($processed); |
| 144 | + $message->setImipError(!$processed); |
| 145 | + } elseif ($schedulingInfo['method'] === 'REPLY') { |
| 146 | + $processed = $this->calendarManager->handleIMipReply($principalUri, $sender, $recipient, $schedulingInfo['contents']); |
| 147 | + $message->setImipProcessed($processed); |
| 148 | + $message->setImipError(!$processed); |
| 149 | + } elseif ($schedulingInfo['method'] === 'CANCEL') { |
| 150 | + $replyTo = $imapMessage->getReplyTo()->first()?->getEmail(); |
| 151 | + $processed = $this->calendarManager->handleIMipCancel($principalUri, $sender, $replyTo, $recipient, $schedulingInfo['contents']); |
| 152 | + $message->setImipProcessed($processed); |
| 153 | + $message->setImipError(!$processed); |
| 154 | + } |
148 | 155 | } |
| 156 | + } catch (Throwable $e) { |
| 157 | + $this->logger->error('iMIP message processing failed', [ |
| 158 | + 'exception' => $e, |
| 159 | + 'messageId' => $message->getId(), |
| 160 | + 'mailboxId' => $mailbox->getId(), |
| 161 | + ]); |
| 162 | + $message->setImipProcessed(true); |
| 163 | + $message->setImipError(true); |
149 | 164 | } |
150 | 165 | } |
151 | 166 | $this->messageMapper->updateImipData(...$filteredMessages); |
|
0 commit comments