Skip to content

Commit

Permalink
fix(caldav): harden null handling of iMip scheduling method
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
  • Loading branch information
st3iny committed Mar 2, 2023
1 parent 2f64d16 commit a35b960
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
21 changes: 16 additions & 5 deletions apps/dav/lib/CalDAV/Schedule/IMipPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,11 @@ public function schedule(Message $iTipMessage) {
$senderName = $senderName->getValue() ?? null;
}

if ($senderName === null || empty(trim($senderName))) {
// Try to get the sender name from the current user id if available.
if ($this->userId !== null && ($senderName === null || empty(trim($senderName)))) {
$senderName = $this->userManager->getDisplayName($this->userId);
}

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

switch (strtolower($iTipMessage->method)) {
Expand All @@ -229,17 +231,26 @@ public function schedule(Message $iTipMessage) {
break;
}


$data['attendee_name'] = ($recipientName ?: $recipient);
$data['invitee_name'] = ($senderName ?: $sender);

$fromEMail = Util::getDefaultEmailAddress('invitations-noreply');
$fromName = $this->imipService->getFrom($senderName, $this->defaults->getName());

$message = $this->mailer->createMessage()
->setFrom([$fromEMail => $fromName])
->setTo([$recipient => $recipientName])
->setReplyTo([$sender => $senderName]);
->setFrom([$fromEMail => $fromName]);

if ($recipientName !== null) {
$message->setTo([$recipient => $recipientName]);
} else {
$message->setTo([$recipient]);
}

if ($senderName !== null) {
$message->setReplyTo([$sender => $senderName]);
} else {
$message->setReplyTo([$sender]);
}

$template = $this->mailer->createEMailTemplate('dav.calendarInvite.' . $method, $data);
$template->addHeader();
Expand Down
10 changes: 7 additions & 3 deletions apps/dav/lib/CalDAV/Schedule/IMipService.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,15 @@ public function __construct(URLGenerator $urlGenerator,
}

/**
* @param string $senderName
* @param $default
* @param string|null $senderName
* @param string $default
* @return string
*/
public function getFrom(string $senderName, $default): string {
public function getFrom(?string $senderName, string $default): string {
if ($senderName === null) {
return $default;
}

return $this->l10n->t('%1$s via %2$s', [$senderName, $default]);
}

Expand Down

0 comments on commit a35b960

Please sign in to comment.