|
11 | 11 |
|
12 | 12 | use OCA\DAV\CalDAV\CalendarObject; |
13 | 13 | use OCA\DAV\CalDAV\EventComparisonService; |
| 14 | +use OCP\Accounts\IAccountManager; |
14 | 15 | use OCP\AppFramework\Utility\ITimeFactory; |
15 | 16 | use OCP\Defaults; |
16 | 17 | use OCP\IAppConfig; |
| 18 | +use OCP\IUser; |
17 | 19 | use OCP\IUserSession; |
18 | 20 | use OCP\Mail\IEmailValidator; |
19 | 21 | use OCP\Mail\IMailer; |
@@ -66,6 +68,7 @@ public function __construct( |
66 | 68 | private EventComparisonService $eventComparisonService, |
67 | 69 | private IMailManager $mailManager, |
68 | 70 | private IEmailValidator $emailValidator, |
| 71 | + private IAccountManager $accountManager, |
69 | 72 | ) { |
70 | 73 | parent::__construct(''); |
71 | 74 | } |
@@ -184,21 +187,17 @@ public function schedule(Message $iTipMessage) { |
184 | 187 | } |
185 | 188 | $this->imipService->setL10nFromAttendee($attendee); |
186 | 189 |
|
187 | | - // Build the sender name. |
| 190 | + $sender = substr($iTipMessage->sender, 7); |
| 191 | + |
188 | 192 | // Due to a bug in sabre, the senderName property for an iTIP message can actually also be a VObject Property |
189 | | - // If the iTIP message senderName is null or empty use the user session name as the senderName |
190 | 193 | if (($iTipMessage->senderName instanceof Parameter) && !empty(trim($iTipMessage->senderName->getValue()))) { |
191 | 194 | $senderName = trim($iTipMessage->senderName->getValue()); |
192 | 195 | } elseif (is_string($iTipMessage->senderName) && !empty(trim($iTipMessage->senderName))) { |
193 | 196 | $senderName = trim($iTipMessage->senderName); |
194 | | - } elseif ($this->userSession->getUser() !== null) { |
195 | | - $senderName = trim($this->userSession->getUser()->getDisplayName()); |
196 | 197 | } else { |
197 | | - $senderName = ''; |
| 198 | + $senderName = $this->getSenderNameFor($sender); |
198 | 199 | } |
199 | 200 |
|
200 | | - $sender = substr($iTipMessage->sender, 7); |
201 | | - |
202 | 201 | $replyingAttendee = null; |
203 | 202 | switch (strtolower($iTipMessage->method)) { |
204 | 203 | case self::METHOD_REPLY: |
@@ -338,6 +337,40 @@ public function schedule(Message $iTipMessage) { |
338 | 337 | } |
339 | 338 | } |
340 | 339 |
|
| 340 | + /** |
| 341 | + * Messages are regularly brokered on behalf of somebody else, so the |
| 342 | + * session user's name is only used when the sender address is one of |
| 343 | + * theirs. |
| 344 | + */ |
| 345 | + private function getSenderNameFor(string $sender): ?string { |
| 346 | + $user = $this->userSession->getUser(); |
| 347 | + if ($user !== null && $this->isAddressOfUser($sender, $user)) { |
| 348 | + return trim($user->getDisplayName()) ?: null; |
| 349 | + } |
| 350 | + |
| 351 | + return null; |
| 352 | + } |
| 353 | + |
| 354 | + /** |
| 355 | + * Profile email addresses are part of the user's calendar-user-address-set |
| 356 | + * and therefore valid sender addresses next to the system email address. |
| 357 | + */ |
| 358 | + private function isAddressOfUser(string $address, IUser $user): bool { |
| 359 | + if (strcasecmp((string)$user->getEMailAddress(), $address) === 0) { |
| 360 | + return true; |
| 361 | + } |
| 362 | + |
| 363 | + $emailCollection = $this->accountManager->getAccount($user) |
| 364 | + ->getPropertyCollection(IAccountManager::COLLECTION_EMAIL); |
| 365 | + foreach ($emailCollection->getProperties() as $property) { |
| 366 | + if (strcasecmp($property->getValue(), $address) === 0) { |
| 367 | + return true; |
| 368 | + } |
| 369 | + } |
| 370 | + |
| 371 | + return false; |
| 372 | + } |
| 373 | + |
341 | 374 | /** |
342 | 375 | * @return ?VCalendar |
343 | 376 | */ |
|
0 commit comments