Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions apps/sharebymail/lib/ShareByMailProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@ protected function createMailShare(IShare $share) {
$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());
Expand All @@ -369,19 +370,27 @@ protected function createMailShare(IShare $share) {
* @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,
$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));

$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);
Expand Down
2 changes: 2 additions & 0 deletions apps/sharebymail/tests/ShareByMailProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,7 @@ public function testSendMailNotificationWithSameUserAndUserEmail() {
'https://example.com/file.txt',
'OwnerUser',
'john@doe.com',
null,
]);
}

Expand Down Expand Up @@ -968,6 +969,7 @@ public function testSendMailNotificationWithDifferentUserAndNoUserEmail() {
'https://example.com/file.txt',
'InitiatorUser',
'john@doe.com',
null,
]);
}
}
3 changes: 3 additions & 0 deletions core/Controller/LostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ protected function sendEmail($input) {
$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'));
Expand Down
16 changes: 16 additions & 0 deletions lib/private/Mail/EMailTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand Down Expand Up @@ -348,6 +352,18 @@ public function __construct(Defaults $themingDefaults,
$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
*/
Expand Down
13 changes: 11 additions & 2 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,8 @@ public function createShare(\OCP\Share\IShare $share) {
$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 {
Expand All @@ -681,19 +682,27 @@ public function createShare(\OCP\Share\IShare $share) {
* @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));

$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);
Expand Down
7 changes: 7 additions & 0 deletions lib/public/Mail/IEMailTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@
* @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
*
Expand Down