diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index cf83587467724..5050d7bb63642 100644 --- a/apps/files_sharing/lib/Controller/ShareAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -658,8 +658,24 @@ public function createShare( $this->checkInheritedAttributes($share); // Handle mail send - if ($sendMail === 'true' || $sendMail === 'false') { - $share->setMailSend($sendMail === 'true'); + if (is_null($sendMail)) { + // Define a default behavior when sendMail is not provided + if($shareType === IShare::TYPE_EMAIL) { + // 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 { + // Convert common "truthy" and "falsy" values to proper booleans + $sendMailBool = filter_var($sendMail, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); + + if ($sendMailBool !== null) { + $share->setMailSend($sendMailBool); + } else { + throw new OCSNotFoundException($this->l->t('Invalid value for sendMail')); + } } if ($shareType === IShare::TYPE_USER) {