diff --git a/apps/sharebymail/lib/ShareByMailProvider.php b/apps/sharebymail/lib/ShareByMailProvider.php index c9658cd8d1..187a36f183 100644 --- a/apps/sharebymail/lib/ShareByMailProvider.php +++ b/apps/sharebymail/lib/ShareByMailProvider.php @@ -346,7 +346,8 @@ class ShareByMailProvider implements IShareProvider { $share->getNode()->getName(), $link, $share->getSharedBy(), - $share->getSharedWith() + $share->getSharedWith(), + $share->getExpirationDate() ); } catch (HintException $hintException) { $this->logger->error('Failed to send share by mail: ' . $hintException->getMessage()); @@ -368,12 +369,14 @@ class ShareByMailProvider implements IShareProvider { * @param string $link * @param string $initiator * @param string $shareWith + * @param \DateTime|null $expiration * @throws \Exception If mail couldn't be sent */ protected function sendMailNotification($filename, $link, $initiator, - $shareWith) { + $shareWith, + \DateTime $expiration = null) { $initiatorUser = $this->userManager->get($initiator); $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; $subject = (string)$this->l->t('%s shared »%s« with you', array($initiatorDisplayName, $filename)); @@ -381,6 +384,12 @@ class ShareByMailProvider implements IShareProvider { $message = $this->mailer->createMessage(); $emailTemplate = $this->mailer->createEMailTemplate(); + $emailTemplate->setMetaData('sharebymail.RecipientNotification', [ + 'filename' => $filename, + 'link' => $link, + 'initiator' => $initiatorDisplayName, + 'expiration' => $expiration, + ]); $emailTemplate->addHeader(); $emailTemplate->addHeading($this->l->t('%s shared »%s« with you', [$initiatorDisplayName, $filename]), false); diff --git a/apps/sharebymail/tests/ShareByMailProviderTest.php b/apps/sharebymail/tests/ShareByMailProviderTest.php index e649a9dbd0..9ab9dbef4a 100644 --- a/apps/sharebymail/tests/ShareByMailProviderTest.php +++ b/apps/sharebymail/tests/ShareByMailProviderTest.php @@ -868,6 +868,7 @@ class ShareByMailProviderTest extends TestCase { 'https://example.com/file.txt', 'OwnerUser', 'john@doe.com', + null, ]); } @@ -968,6 +969,7 @@ class ShareByMailProviderTest extends TestCase { 'https://example.com/file.txt', 'InitiatorUser', 'john@doe.com', + null, ]); } } diff --git a/core/Controller/LostController.php b/core/Controller/LostController.php index 0d5988a249..d5548aee09 100644 --- a/core/Controller/LostController.php +++ b/core/Controller/LostController.php @@ -306,6 +306,9 @@ class LostController extends Controller { $link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', array('userId' => $user->getUID(), 'token' => $token)); $emailTemplate = $this->mailer->createEMailTemplate(); + $emailTemplate->setMetaData('core.ResetPassword', [ + 'link' => $link, + ]); $emailTemplate->addHeader(); $emailTemplate->addHeading($this->l10n->t('Password reset')); diff --git a/lib/private/Mail/EMailTemplate.php b/lib/private/Mail/EMailTemplate.php index 8227e69ef0..79749cedfe 100644 --- a/lib/private/Mail/EMailTemplate.php +++ b/lib/private/Mail/EMailTemplate.php @@ -45,6 +45,10 @@ class EMailTemplate implements IEMailTemplate { protected $urlGenerator; /** @var IL10N */ protected $l10n; + /** @var string */ + protected $emailId; + /** @var array */ + protected $data; /** @var string */ protected $htmlBody = ''; @@ -348,6 +352,18 @@ EOF; $this->htmlBody .= $this->head; } + /** + * Set meta data of an email + * + * @param string $emailId + * @param array $data + * @since 12.0.3 + */ + public function setMetaData($emailId, array $data = []) { + $this->emailId = $emailId; + $this->data = $data; + } + /** * Adds a header to the email */ diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 71b81766dc..dda5f005e9 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -693,7 +693,8 @@ class Manager implements IManager { $share->getNode()->getName(), $this->urlGenerator->linkToRouteAbsolute('files.viewcontroller.showFile', [ 'fileid' => $share->getNode()->getId() ]), $share->getSharedBy(), - $emailAddress + $emailAddress, + $share->getExpirationDate() ); $this->logger->debug('Send share notification to ' . $emailAddress . ' for share with ID ' . $share->getId(), ['app' => 'share']); } else { @@ -712,12 +713,14 @@ class Manager implements IManager { * @param string $link link to the file/folder * @param string $initiator user ID of share sender * @param string $shareWith email address of share receiver + * @param \DateTime|null $expiration * @throws \Exception If mail couldn't be sent */ protected function sendMailNotification($filename, $link, $initiator, - $shareWith) { + $shareWith, + \DateTime $expiration = null) { $initiatorUser = $this->userManager->get($initiator); $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; $subject = (string)$this->l->t('%s shared »%s« with you', array($initiatorDisplayName, $filename)); @@ -725,6 +728,12 @@ class Manager implements IManager { $message = $this->mailer->createMessage(); $emailTemplate = $this->mailer->createEMailTemplate(); + $emailTemplate->setMetaData('files_sharing.RecipientNotification', [ + 'filename' => $filename, + 'link' => $link, + 'initiator' => $initiatorDisplayName, + 'expiration' => $expiration, + ]); $emailTemplate->addHeader(); $emailTemplate->addHeading($this->l->t('%s shared »%s« with you', [$initiatorDisplayName, $filename]), false); diff --git a/lib/public/Mail/IEMailTemplate.php b/lib/public/Mail/IEMailTemplate.php index 6df83b4d10..056f4d223b 100644 --- a/lib/public/Mail/IEMailTemplate.php +++ b/lib/public/Mail/IEMailTemplate.php @@ -51,6 +51,13 @@ namespace OCP\Mail; * @since 12.0.0 */ interface IEMailTemplate { + /** + * Set meta data of an email + * + * @since 12.0.3 + */ + public function setMetaData($emailId, array $data = []); + /** * Adds a header to the email *