diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index 2874d35caa5e4..ffd7c605032bf 100644 --- a/apps/files_sharing/lib/Controller/ShareAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -659,7 +659,16 @@ public function createShare( $this->checkInheritedAttributes($share); // Handle mail send - if ($sendMail === 'true' || $sendMail === 'false') { + if (is_null($sendMail)) { + // Define a default behavior when sendMail is not provided + if ($shareType === IShare::TYPE_EMAIL && strlen($shareWith) !== 0) { + // For email shares, the default is to send the mail + $share->setMailSend(true); + } else { + // For all other share types, the default is to not send the mail + $share->setMailSend(false); + } + } else { $share->setMailSend($sendMail === 'true'); } @@ -719,7 +728,7 @@ public function createShare( } // Only share by mail have a recipient - if (is_string($shareWith) && $shareType === IShare::TYPE_EMAIL) { + if (!empty($shareWith) && $shareType === IShare::TYPE_EMAIL) { // If sending a mail have been requested, validate the mail address if ($share->getMailSend() && !$this->mailer->validateMailAddress($shareWith)) { throw new OCSNotFoundException($this->l->t('Please specify a valid email address')); @@ -1219,11 +1228,6 @@ public function updateShare( } $this->checkInheritedAttributes($share); - // Handle mail send - if ($sendMail === 'true' || $sendMail === 'false') { - $share->setMailSend($sendMail === 'true'); - } - /** * expirationdate, password and publicUpload only make sense for link shares */