Skip to content

Commit 96b2d57

Browse files
committed
feat(sharebymail): improve share email format
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
1 parent 669e4e7 commit 96b2d57

File tree

2 files changed

+210
-43
lines changed

2 files changed

+210
-43
lines changed

apps/sharebymail/lib/ShareByMailProvider.php

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -328,21 +328,36 @@ protected function sendEmail(IShare $share, array $emails): void {
328328
'note' => $note
329329
]);
330330

331-
$emailTemplate->setSubject($this->l->t('%1$s shared »%2$s« with you', [$initiatorDisplayName, $filename]));
331+
$emailTemplate->setSubject($this->l->t('%1$s shared %2$s with you', [$initiatorDisplayName, $filename]));
332332
$emailTemplate->addHeader();
333-
$emailTemplate->addHeading($this->l->t('%1$s shared »%2$s« with you', [$initiatorDisplayName, $filename]), false);
334-
$text = $this->l->t('%1$s shared »%2$s« with you.', [$initiatorDisplayName, $filename]);
333+
$emailTemplate->addHeading($this->l->t('%1$s shared %2$s with you', [$initiatorDisplayName, $filename]), false);
334+
$text = $this->l->t('%1$s shared %2$s with you.', [$initiatorDisplayName, $filename]);
335335

336336
if ($note !== '') {
337-
$emailTemplate->addBodyText(htmlspecialchars($note), $note);
337+
$emailTemplate->addBodyListItem(
338+
htmlspecialchars($note),
339+
$this->l->t('Note:'),
340+
$this->getAbsoluteImagePath('caldav/description.png'),
341+
$note
342+
);
343+
}
344+
345+
if ($expiration !== null) {
346+
$dateString = (string)$this->l->l('date', $expiration, ['width' => 'medium']);
347+
$emailTemplate->addBodyListItem(
348+
$this->l->t('This share is valid until %s at midnight', [$dateString]),
349+
$this->l->t('Expiration:'),
350+
$this->getAbsoluteImagePath('caldav/time.png'),
351+
);
338352
}
339353

340354
$emailTemplate->addBodyText(
341355
htmlspecialchars($text . ' ' . $this->l->t('Click the button below to open it.')),
342356
$text
343357
);
358+
344359
$emailTemplate->addBodyButton(
345-
$this->l->t('Open »%s«', [$filename]),
360+
$this->l->t('Open %s', [$filename]),
346361
$link
347362
);
348363

@@ -415,8 +430,8 @@ protected function sendPassword(IShare $share, string $password, array $emails):
415430
$initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
416431
$initiatorEmailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;
417432

418-
$plainBodyPart = $this->l->t("%1\$s shared »%2\$s« with you.\nYou should have already received a separate mail with a link to access it.\n", [$initiatorDisplayName, $filename]);
419-
$htmlBodyPart = $this->l->t('%1$s shared »%2$s« with you. You should have already received a separate mail with a link to access it.', [$initiatorDisplayName, $filename]);
433+
$plainBodyPart = $this->l->t("%1\$s shared %2\$s with you.\nYou should have already received a separate mail with a link to access it.\n", [$initiatorDisplayName, $filename]);
434+
$htmlBodyPart = $this->l->t('%1$s shared %2$s with you. You should have already received a separate mail with a link to access it.', [$initiatorDisplayName, $filename]);
420435

421436
$message = $this->mailer->createMessage();
422437

@@ -428,9 +443,9 @@ protected function sendPassword(IShare $share, string $password, array $emails):
428443
'shareWith' => $shareWith,
429444
]);
430445

431-
$emailTemplate->setSubject($this->l->t('Password to access »%1$s« shared to you by %2$s', [$filename, $initiatorDisplayName]));
446+
$emailTemplate->setSubject($this->l->t('Password to access %1$s shared to you by %2$s', [$filename, $initiatorDisplayName]));
432447
$emailTemplate->addHeader();
433-
$emailTemplate->addHeading($this->l->t('Password to access »%s«', [$filename]), false);
448+
$emailTemplate->addHeading($this->l->t('Password to access %s', [$filename]), false);
434449
$emailTemplate->addBodyText(htmlspecialchars($htmlBodyPart), $plainBodyPart);
435450
$emailTemplate->addBodyText($this->l->t('It is protected with the following password:'));
436451
$emailTemplate->addBodyText($password);
@@ -501,22 +516,22 @@ protected function sendNote(IShare $share): void {
501516
$initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
502517
$initiatorEmailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;
503518

504-
$plainHeading = $this->l->t('%1$s shared »%2$s« with you and wants to add:', [$initiatorDisplayName, $filename]);
505-
$htmlHeading = $this->l->t('%1$s shared »%2$s« with you and wants to add', [$initiatorDisplayName, $filename]);
519+
$plainHeading = $this->l->t('%1$s shared %2$s with you and wants to add:', [$initiatorDisplayName, $filename]);
520+
$htmlHeading = $this->l->t('%1$s shared %2$s with you and wants to add', [$initiatorDisplayName, $filename]);
506521

507522
$message = $this->mailer->createMessage();
508523

509524
$emailTemplate = $this->mailer->createEMailTemplate('shareByMail.sendNote');
510525

511-
$emailTemplate->setSubject($this->l->t('»%s« added a note to a file shared with you', [$initiatorDisplayName]));
526+
$emailTemplate->setSubject($this->l->t('%s added a note to a file shared with you', [$initiatorDisplayName]));
512527
$emailTemplate->addHeader();
513528
$emailTemplate->addHeading(htmlspecialchars($htmlHeading), $plainHeading);
514529
$emailTemplate->addBodyText(htmlspecialchars($note), $note);
515530

516531
$link = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare',
517532
['token' => $share->getToken()]);
518533
$emailTemplate->addBodyButton(
519-
$this->l->t('Open »%s«', [$filename]),
534+
$this->l->t('Open %s', [$filename]),
520535
$link
521536
);
522537

@@ -564,7 +579,7 @@ protected function sendPasswordToOwner(IShare $share, string $password): bool {
564579
);
565580
}
566581

567-
$bodyPart = $this->l->t('You just shared »%1$s« with %2$s. The share was already sent to the recipient. Due to the security policies defined by the administrator of %3$s each share needs to be protected by password and it is not allowed to send the password directly to the recipient. Therefore you need to forward the password manually to the recipient.', [$filename, $shareWith, $this->defaults->getName()]);
582+
$bodyPart = $this->l->t('You just shared %1$s with %2$s. The share was already sent to the recipient. Due to the security policies defined by the administrator of %3$s each share needs to be protected by password and it is not allowed to send the password directly to the recipient. Therefore you need to forward the password manually to the recipient.', [$filename, $shareWith, $this->defaults->getName()]);
568583

569584
$message = $this->mailer->createMessage();
570585
$emailTemplate = $this->mailer->createEMailTemplate('sharebymail.OwnerPasswordNotification', [
@@ -575,9 +590,9 @@ protected function sendPasswordToOwner(IShare $share, string $password): bool {
575590
'shareWith' => $shareWith,
576591
]);
577592

578-
$emailTemplate->setSubject($this->l->t('Password to access »%1$s« shared by you with %2$s', [$filename, $shareWith]));
593+
$emailTemplate->setSubject($this->l->t('Password to access %1$s shared by you with %2$s', [$filename, $shareWith]));
579594
$emailTemplate->addHeader();
580-
$emailTemplate->addHeading($this->l->t('Password to access »%s«', [$filename]), false);
595+
$emailTemplate->addHeading($this->l->t('Password to access %s', [$filename]), false);
581596
$emailTemplate->addBodyText($bodyPart);
582597
$emailTemplate->addBodyText($this->l->t('This is the password:'));
583598
$emailTemplate->addBodyText($password);
@@ -611,6 +626,12 @@ protected function sendPasswordToOwner(IShare $share, string $password): bool {
611626
return true;
612627
}
613628

629+
private function getAbsoluteImagePath(string $path):string {
630+
return $this->urlGenerator->getAbsoluteURL(
631+
$this->urlGenerator->imagePath('core', $path)
632+
);
633+
}
634+
614635
/**
615636
* generate share token
616637
*/

0 commit comments

Comments
 (0)