Skip to content

Commit

Permalink
Merge pull request #34255 from owncloud/fix-recipient-mail-stable10
Browse files Browse the repository at this point in the history
[stable10] Backport of Fixing email sent to recipient using recipient…
  • Loading branch information
phil-davis authored Feb 8, 2019
2 parents b5fe5c7 + 17f85e6 commit 345da18
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/private/Share/MailNotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,16 @@ public function sendInternalShareMail($recipientList, $itemSource, $itemType) {
$filename = $filter->getFile();
$link = $filter->getLink();

$subject = (string) $this->l->t('%s shared »%s« with you', [$this->senderDisplayName, $unescapedFilename]);
list($htmlBody, $textBody) = $this->createMailBody($filename, $link, $expiration, null, 'internal');
$recipientLanguageCode = $this->config->getUserValue($recipient->getUID(), 'core', 'lang', 'en');
$recipientL10N = \OC::$server->getL10N('core');
if ($this->l->getLanguageCode() !== $recipientLanguageCode) {
$recipientL10N = \OC::$server->getL10N('core', $recipientLanguageCode);
$subject = (string)$recipientL10N->t('%s shared »%s« with you', [$this->senderDisplayName, $unescapedFilename]);
} else {
$subject = (string)$this->l->t('%s shared »%s« with you', [$this->senderDisplayName, $unescapedFilename]);
}

list($htmlBody, $textBody) = $this->createMailBody($filename, $link, $expiration, null, 'internal', $recipientL10N);

// send it out now
try {
Expand Down
68 changes: 68 additions & 0 deletions tests/lib/Share/MailNotificationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\Mail\IMailer;
use OCP\Share\IShare;
use OCP\Util;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\GenericEvent;
Expand Down Expand Up @@ -651,4 +652,71 @@ protected function setupMailerMock($subject, $to, $exceptionOnSend = true) {
->will($this->throwException(new \Exception('Some Exception Message')));
}
}

public function providesLanguages() {
return [
['es', 'en'],
['en', 'en']
];
}

/**
* @dataProvider providesLanguages
* @param string $recipientLanguage
* @param string $senderLanguage
*/
public function testSendInternalShareWithRecipientLanguageCode($recipientLanguage, $senderLanguage) {
$this->setupMailerMock('TestUser shared »<welcome>.txt« with you', ['recipient@owncloud.com' => 'Recipient'], false);
$mailNotifications = $this->getMockBuilder('OC\Share\MailNotifications')
->setMethods(['getItemSharedWithUser'])
->setConstructorArgs([
$this->user,
$this->l10n,
$this->mailer,
$this->config,
$this->logger,
$this->defaults,
$this->urlGenerator,
$this->eventDispatcher
])
->getMock();

$mailNotifications->method('getItemSharedWithUser')
->withAnyParameters()
->willReturn([
['file_target' => '/<welcome>.txt', 'item_source' => 123, 'expiration' => '2017-01-01T15:03:01.012345Z'],
]);

$recipient = $this->createMock(IUser::class);
$recipient->expects($this->once())
->method('getEMailAddress')
->willReturn('recipient@owncloud.com');
$recipient->expects($this->once())
->method('getDisplayName')
->willReturn('Recipient');
$recipient->method('getUID')
->willReturn('Recipient');

$this->config->expects($this->once())
->method('getUserValue')
->with('Recipient', 'core', 'lang', 'en')
->willReturn($recipientLanguage);

$this->l10n->method('getLanguageCode')
->willReturn($senderLanguage);

$this->urlGenerator->expects($this->once())
->method('linkToRouteAbsolute')
->with(
$this->equalTo('files.viewcontroller.showFile'),
$this->equalTo([
'fileId' => 123,
])
);

$recipientList = [$recipient];

$result = $mailNotifications->sendInternalShareMail($recipientList, '3', 'file');
$this->assertSame([], $result);
}
}

0 comments on commit 345da18

Please sign in to comment.