Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 40 additions & 7 deletions apps/dav/lib/CalDAV/Schedule/IMipPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@

use OCA\DAV\CalDAV\CalendarObject;
use OCA\DAV\CalDAV\EventComparisonService;
use OCP\Accounts\IAccountManager;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Defaults;
use OCP\IAppConfig;
use OCP\IUser;
use OCP\IUserSession;
use OCP\Mail\IEmailValidator;
use OCP\Mail\IMailer;
Expand Down Expand Up @@ -66,6 +68,7 @@ public function __construct(
private EventComparisonService $eventComparisonService,
private IMailManager $mailManager,
private IEmailValidator $emailValidator,
private IAccountManager $accountManager,
) {
parent::__construct('');
}
Expand Down Expand Up @@ -184,21 +187,17 @@ public function schedule(Message $iTipMessage) {
}
$this->imipService->setL10nFromAttendee($attendee);

// Build the sender name.
$sender = substr($iTipMessage->sender, 7);

// Due to a bug in sabre, the senderName property for an iTIP message can actually also be a VObject Property
// If the iTIP message senderName is null or empty use the user session name as the senderName
if (($iTipMessage->senderName instanceof Parameter) && !empty(trim($iTipMessage->senderName->getValue()))) {
$senderName = trim($iTipMessage->senderName->getValue());
} elseif (is_string($iTipMessage->senderName) && !empty(trim($iTipMessage->senderName))) {
$senderName = trim($iTipMessage->senderName);
} elseif ($this->userSession->getUser() !== null) {
$senderName = trim($this->userSession->getUser()->getDisplayName());
} else {
$senderName = '';
$senderName = $this->getSenderNameFor($sender);
}

$sender = substr($iTipMessage->sender, 7);

$replyingAttendee = null;
switch (strtolower($iTipMessage->method)) {
case self::METHOD_REPLY:
Expand Down Expand Up @@ -338,6 +337,40 @@ public function schedule(Message $iTipMessage) {
}
}

/**
* Messages are regularly brokered on behalf of somebody else, so the
* session user's name is only used when the sender address is one of
* theirs.
*/
private function getSenderNameFor(string $sender): ?string {
$user = $this->userSession->getUser();
if ($user !== null && $this->isAddressOfUser($sender, $user)) {
return trim($user->getDisplayName()) ?: null;
}

return null;
}

/**
* Profile email addresses are part of the user's calendar-user-address-set
* and therefore valid sender addresses next to the system email address.
*/
private function isAddressOfUser(string $address, IUser $user): bool {
if (strcasecmp((string)$user->getEMailAddress(), $address) === 0) {
return true;
}

$emailCollection = $this->accountManager->getAccount($user)
->getPropertyCollection(IAccountManager::COLLECTION_EMAIL);
foreach ($emailCollection->getProperties() as $property) {
if (strcasecmp($property->getValue(), $address) === 0) {
return true;
}
}

return false;
}

/**
* @return ?VCalendar
*/
Expand Down
1 change: 1 addition & 0 deletions apps/dav/lib/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ public function __construct(
\OCP\Server::get(EventComparisonService::class),
\OCP\Server::get(\OCP\Mail\Provider\IManager::class),
\OCP\Server::get(IEmailValidator::class),
\OCP\Server::get(IAccountManager::class),
));
}
$this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use OCA\DAV\CalDAV\EventComparisonService;
use OCA\DAV\CalDAV\Schedule\IMipPlugin;
use OCA\DAV\CalDAV\Schedule\IMipService;
use OCP\Accounts\IAccountManager;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Config\IUserConfig;
use OCP\Defaults;
Expand Down Expand Up @@ -132,6 +133,7 @@ protected function setUp(): void {
$this->eventComparisonService,
$this->mailManager,
$this->getEmailValidatorWithStrictEmailCheck(),
$this->createMock(IAccountManager::class),
);

// ITipMessage
Expand Down
Loading
Loading