Skip to content

Commit bdcaff0

Browse files
authored
Merge pull request #20513 from nextcloud/backport/20246/stable17
[stable17] Provide the proper language to the mailer
2 parents 6bb8ad5 + 1fa8a8e commit bdcaff0

File tree

11 files changed

+40
-31
lines changed

11 files changed

+40
-31
lines changed

apps/theming/lib/ThemingDefaults.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ public function getBaseUrl() {
139139
return $this->config->getAppValue('theming', 'url', $this->url);
140140
}
141141

142-
public function getSlogan() {
143-
return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', parent::getSlogan()));
142+
public function getSlogan(?string $lang = null) {
143+
return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', parent::getSlogan($lang)));
144144
}
145145

146146
public function getImprintUrl() {

lib/private/Mail/EMailTemplate.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
namespace OC\Mail;
3030

3131
use OCP\Defaults;
32-
use OCP\IL10N;
3332
use OCP\IURLGenerator;
33+
use OCP\L10N\IFactory;
3434
use OCP\Mail\IEMailTemplate;
3535

3636
/**
@@ -46,8 +46,8 @@ class EMailTemplate implements IEMailTemplate {
4646
protected $themingDefaults;
4747
/** @var IURLGenerator */
4848
protected $urlGenerator;
49-
/** @var IL10N */
50-
protected $l10n;
49+
/** @var IFactory */
50+
protected $l10nFactory;
5151
/** @var string */
5252
protected $emailId;
5353
/** @var array */
@@ -344,21 +344,14 @@ class EMailTemplate implements IEMailTemplate {
344344
</table>
345345
EOF;
346346

347-
/**
348-
* @param Defaults $themingDefaults
349-
* @param IURLGenerator $urlGenerator
350-
* @param IL10N $l10n
351-
* @param string $emailId
352-
* @param array $data
353-
*/
354347
public function __construct(Defaults $themingDefaults,
355348
IURLGenerator $urlGenerator,
356-
IL10N $l10n,
349+
IFactory $l10nFactory,
357350
$emailId,
358351
array $data) {
359352
$this->themingDefaults = $themingDefaults;
360353
$this->urlGenerator = $urlGenerator;
361-
$this->l10n = $l10n;
354+
$this->l10nFactory = $l10nFactory;
362355
$this->htmlBody .= $this->head;
363356
$this->emailId = $emailId;
364357
$this->data = $data;
@@ -601,9 +594,10 @@ protected function ensureBodyIsClosed() {
601594
*
602595
* @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used
603596
*/
604-
public function addFooter(string $text = '') {
597+
public function addFooter(string $text = '', ?string $lang = null) {
605598
if($text === '') {
606-
$text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan() . '<br>' . $this->l10n->t('This is an automatically sent email, please do not reply.');
599+
$l10n = $this->l10nFactory->get('lib', $lang);
600+
$text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan($lang) . '<br>' . $l10n->t('This is an automatically sent email, please do not reply.');
607601
}
608602

609603
if ($this->footerAdded) {

lib/private/Mail/Mailer.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use OCP\IConfig;
3333
use OCP\IL10N;
3434
use OCP\IURLGenerator;
35+
use OCP\L10N\IFactory;
3536
use OCP\Mail\IAttachment;
3637
use OCP\Mail\IEMailTemplate;
3738
use OCP\Mail\IMailer;
@@ -69,6 +70,8 @@ class Mailer implements IMailer {
6970
private $urlGenerator;
7071
/** @var IL10N */
7172
private $l10n;
73+
/** @var IFactory */
74+
private $l10nFactory;
7275

7376
/**
7477
* @param IConfig $config
@@ -81,12 +84,14 @@ public function __construct(IConfig $config,
8184
ILogger $logger,
8285
Defaults $defaults,
8386
IURLGenerator $urlGenerator,
84-
IL10N $l10n) {
87+
IL10N $l10n,
88+
IFactory $l10nFactory) {
8589
$this->config = $config;
8690
$this->logger = $logger;
8791
$this->defaults = $defaults;
8892
$this->urlGenerator = $urlGenerator;
8993
$this->l10n = $l10n;
94+
$this->l10nFactory = $l10nFactory;
9095
}
9196

9297
/**
@@ -144,7 +149,7 @@ public function createEMailTemplate(string $emailId, array $data = []): IEMailTe
144149
return new EMailTemplate(
145150
$this->defaults,
146151
$this->urlGenerator,
147-
$this->l10n,
152+
$this->l10nFactory,
148153
$emailId,
149154
$data
150155
);

lib/private/Server.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@
151151
use OCP\IServerContainer;
152152
use OCP\ITempManager;
153153
use OCP\IUser;
154+
use OCP\L10N\IFactory;
154155
use OCP\Lock\ILockingProvider;
155156
use OCP\Log\ILogFactory;
156157
use OCP\Remote\Api\IApiFactory;
@@ -832,7 +833,8 @@ public function __construct($webRoot, \OC\Config $config) {
832833
$c->getLogger(),
833834
$c->query(Defaults::class),
834835
$c->getURLGenerator(),
835-
$c->getL10N('lib')
836+
$c->getL10N('lib'),
837+
$c->query(IFactory::class)
836838
);
837839
});
838840
$this->registerAlias('Mailer', \OCP\Mail\IMailer::class);

lib/private/Share20/Manager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -805,9 +805,9 @@ protected function sendMailNotification(IL10N $l,
805805
$initiatorEmail = $initiatorUser->getEMailAddress();
806806
if($initiatorEmail !== null) {
807807
$message->setReplyTo([$initiatorEmail => $initiatorDisplayName]);
808-
$emailTemplate->addFooter($instanceName . ($this->defaults->getSlogan() !== '' ? ' - ' . $this->defaults->getSlogan() : ''));
808+
$emailTemplate->addFooter($instanceName . ($this->defaults->getSlogan($l->getLanguageCode()) !== '' ? ' - ' . $this->defaults->getSlogan($l->getLanguageCode()) : ''));
809809
} else {
810-
$emailTemplate->addFooter();
810+
$emailTemplate->addFooter('', $l->getLanguageCode());
811811
}
812812

813813
$message->useTemplate($emailTemplate);

lib/private/legacy/defaults.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,12 @@ public function getEntity() {
213213
* Returns slogan
214214
* @return string slogan
215215
*/
216-
public function getSlogan() {
216+
public function getSlogan(?string $lang = null) {
217217
if ($this->themeExist('getSlogan')) {
218-
return $this->theme->getSlogan();
218+
return $this->theme->getSlogan($lang);
219219
} else {
220220
if ($this->defaultSlogan === null) {
221-
$l10n = \OC::$server->getL10N('lib');
221+
$l10n = \OC::$server->getL10N('lib', $lang);
222222
$this->defaultSlogan = $l10n->t('a safe home for all your data');
223223
}
224224
return $this->defaultSlogan;

lib/public/Defaults.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ public function getEntity() {
135135
* @return string
136136
* @since 6.0.0
137137
*/
138-
public function getSlogan() {
139-
return $this->defaults->getSlogan();
138+
public function getSlogan(?string $lang = null) {
139+
return $this->defaults->getSlogan($lang);
140140
}
141141

142142
/**

lib/public/Mail/IEMailTemplate.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,11 @@ public function addBodyButton(string $text, string $url, $plainText = '');
138138
* Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email
139139
*
140140
* @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used
141+
* @param string $lang Optional language to set the default footer in
141142
*
142143
* @since 12.0.0
143144
*/
144-
public function addFooter(string $text = '');
145+
public function addFooter(string $text = '', ?string $lang = null);
145146

146147
/**
147148
* Returns the rendered email subject as string

tests/Settings/Mailer/NewUserMailHelperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function setUp() {
7070
$template = new EMailTemplate(
7171
$this->defaults,
7272
$this->urlGenerator,
73-
$this->l10n,
73+
$this->l10nFactory,
7474
'test.TestTemplate',
7575
[]
7676
);

tests/lib/Mail/EMailTemplateTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@
2727
use OCP\Defaults;
2828
use OCP\IL10N;
2929
use OCP\IURLGenerator;
30+
use OCP\L10N\IFactory;
3031
use Test\TestCase;
3132

3233
class EMailTemplateTest extends TestCase {
3334
/** @var Defaults|\PHPUnit_Framework_MockObject_MockObject */
3435
private $defaults;
3536
/** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
3637
private $urlGenerator;
37-
/** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
38+
/** @var IFactory|\PHPUnit_Framework_MockObject_MockObject */
3839
private $l10n;
3940
/** @var EMailTemplate */
4041
private $emailTemplate;
@@ -44,7 +45,11 @@ public function setUp() {
4445

4546
$this->defaults = $this->createMock(Defaults::class);
4647
$this->urlGenerator = $this->createMock(IURLGenerator::class);
47-
$this->l10n = $this->createMock(IL10N::class);
48+
$this->l10n = $this->createMock(IFactory::class);
49+
50+
$this->l10n->method('get')
51+
->with('lib', '')
52+
->willReturn($this->createMock(IL10N::class));
4853

4954
$this->emailTemplate = new EMailTemplate(
5055
$this->defaults,

0 commit comments

Comments
 (0)