diff options
author | Joas Schilling <coding@schilljs.com> | 2017-08-24 17:54:22 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2017-08-24 17:54:22 +0200 |
commit | 09747b296ac48789bf636d230afd5e4499166838 (patch) | |
tree | a36750d64b7bf4ed0b95175a1e99267bffe18007 | |
parent | a7f2dc6dd660179682f7d03ac8e07649b59cdd6f (diff) | |
download | nextcloud-server-09747b296ac48789bf636d230afd5e4499166838.tar.gz nextcloud-server-09747b296ac48789bf636d230afd5e4499166838.zip |
Add meta information to emails for better customisation
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | apps/sharebymail/lib/ShareByMailProvider.php | 13 | ||||
-rw-r--r-- | lib/private/Mail/EMailTemplate.php | 16 | ||||
-rw-r--r-- | lib/private/Share20/Manager.php | 13 | ||||
-rw-r--r-- | lib/public/Mail/IEMailTemplate.php | 7 |
4 files changed, 45 insertions, 4 deletions
diff --git a/apps/sharebymail/lib/ShareByMailProvider.php b/apps/sharebymail/lib/ShareByMailProvider.php index 32fa51d94a2..5538a94bee2 100644 --- a/apps/sharebymail/lib/ShareByMailProvider.php +++ b/apps/sharebymail/lib/ShareByMailProvider.php @@ -347,7 +347,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()); @@ -369,12 +370,14 @@ class ShareByMailProvider implements IShareProvider { * @param string $link * @param string $initiator * @param string $shareWith + * @param \DateTime $expiration * @throws \Exception If mail couldn't be sent */ protected function sendMailNotification($filename, $link, $initiator, - $shareWith) { + $shareWith, + \DateTime $expiration) { $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)); @@ -382,6 +385,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/lib/private/Mail/EMailTemplate.php b/lib/private/Mail/EMailTemplate.php index a55e6f9e5b5..32cb01f30b3 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 = ''; @@ -349,6 +353,18 @@ EOF; } /** + * 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 */ public function addHeader() { diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index ad78a0db745..e53f0130a7f 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -662,7 +662,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 { @@ -681,12 +682,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 $expiration * @throws \Exception If mail couldn't be sent */ protected function sendMailNotification($filename, $link, $initiator, - $shareWith) { + $shareWith, + \DateTime $expiration) { $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)); @@ -694,6 +697,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 6d0591b019b..2ff4a486f75 100644 --- a/lib/public/Mail/IEMailTemplate.php +++ b/lib/public/Mail/IEMailTemplate.php @@ -52,6 +52,13 @@ namespace OCP\Mail; */ interface IEMailTemplate { /** + * Set meta data of an email + * + * @since 12.0.3 + */ + public function setMetaData($emailId, array $data = []); + + /** * Adds a header to the email * * @since 12.0.0 |