Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable10] Backport of Fixing email sent to recipient using recipient… #34255

Merged
merged 1 commit into from
Feb 8, 2019
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
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);
}
}