diff options
author | skjnldsv <skjnldsv@protonmail.com> | 2024-07-05 14:02:53 +0200 |
---|---|---|
committer | John Molakvoæ <skjnldsv@users.noreply.github.com> | 2024-07-12 20:14:30 +0200 |
commit | c253112cf77411ee374ea29a9566cdd28d3e544d (patch) | |
tree | e78bde64bbe1746105bb244141036d745ac31971 /lib | |
parent | d388370c3b4bd50d1ad7668aef9000bd54a8c442 (diff) | |
download | nextcloud-server-c253112cf77411ee374ea29a9566cdd28d3e544d.tar.gz nextcloud-server-c253112cf77411ee374ea29a9566cdd28d3e544d.zip |
chore(files_sharing): refactor mail handling
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Share20/DefaultShareProvider.php | 46 |
1 files changed, 22 insertions, 24 deletions
diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php index 1d529a65626..875c2a85188 100644 --- a/lib/private/Share20/DefaultShareProvider.php +++ b/lib/private/Share20/DefaultShareProvider.php @@ -1384,36 +1384,34 @@ class DefaultShareProvider implements IShareProviderWithNotification { public function sendMailNotification(IShare $share): true { try { + // Check user + $user = $this->userManager->get($share->getSharedWith()); + if ($user === null) { + $this->logger->debug('Share notification not sent to ' . $share->getSharedWith() . ' because user could not be found.', ['app' => 'share']); + return false; + } + // Handle user shares if ($share->getShareType() === IShare::TYPE_USER) { - $user = $this->userManager->get($share->getSharedWith()); - if ($user !== null) { - $emailAddress = $user->getEMailAddress(); - if ($emailAddress !== null && $emailAddress !== '') { - $userLang = $this->l10nFactory->getUserLanguage($user); - $l = $this->l10nFactory->get('lib', $userLang); - $this->sendUserShareMail( - $l, - $share->getNode()->getName(), - $this->urlGenerator->linkToRouteAbsolute('files_sharing.Accept.accept', ['shareId' => $share->getFullId()]), - $share->getSharedBy(), - $emailAddress, - $share->getExpirationDate(), - $share->getNote() - ); - $this->logger->debug('Sent share notification to ' . $emailAddress . ' for share with ID ' . $share->getId() . '.', ['app' => 'share']); - return true; - - } + // Check email address + $emailAddress = $user->getEMailAddress(); + if ($emailAddress === null || $emailAddress === '') { $this->logger->debug('Share notification not sent to ' . $share->getSharedWith() . ' because email address is not set.', ['app' => 'share']); return false; } - $this->logger->debug('Share notification not sent to ' . $share->getSharedWith() . ' because user could not be found.', ['app' => 'share']); - return false; - } - // Handle link shares - if ($share->getShareType() === IShare::TYPE_LINK) { + $userLang = $this->l10nFactory->getUserLanguage($user); + $l = $this->l10nFactory->get('lib', $userLang); + $this->sendUserShareMail( + $l, + $share->getNode()->getName(), + $this->urlGenerator->linkToRouteAbsolute('files_sharing.Accept.accept', ['shareId' => $share->getFullId()]), + $share->getSharedBy(), + $emailAddress, + $share->getExpirationDate(), + $share->getNote() + ); + $this->logger->debug('Sent share notification to ' . $emailAddress . ' for share with ID ' . $share->getId() . '.', ['app' => 'share']); return true; } } catch (\Exception $e) { |