]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix(caldav): harden null handling of iMip scheduling method 36935/head
authorRichard Steinmetz <richard@steinmetz.cloud>
Wed, 1 Mar 2023 11:24:28 +0000 (12:24 +0100)
committerRichard Steinmetz (Rebase PR Action) <st3iny@users.noreply.github.com>
Thu, 2 Mar 2023 09:42:10 +0000 (09:42 +0000)
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
apps/dav/lib/CalDAV/Schedule/IMipPlugin.php
apps/dav/lib/CalDAV/Schedule/IMipService.php

index 646cf0f831ace65c111f38a300ed86d472659b4d..ca79205c09f6a19c58cac85f6185b10161c4b031 100644 (file)
@@ -209,9 +209,11 @@ class IMipPlugin extends SabreIMipPlugin {
                        $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)) {
@@ -229,7 +231,6 @@ class IMipPlugin extends SabreIMipPlugin {
                                break;
                }
 
-
                $data['attendee_name'] = ($recipientName ?: $recipient);
                $data['invitee_name'] = ($senderName ?: $sender);
 
@@ -237,9 +238,19 @@ class IMipPlugin extends SabreIMipPlugin {
                $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();
index 3e8e72bd2e4884fdd72a59ff7a1e73ddeb8ff059..50e770e6b4054110a1a7d026e861127f91a324d2 100644 (file)
@@ -70,11 +70,15 @@ class IMipService {
        }
 
        /**
-        * @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]);
        }