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