Skip to content

Commit fc2e17d

Browse files
authored
Merge pull request #20246 from nextcloud/fix/untranslated_mail_footer
Provide the proper language to the mailer
2 parents 1f2df2f + bb4dedb commit fc2e17d

File tree

11 files changed

+42
-34
lines changed

11 files changed

+42
-34
lines changed

apps/settings/tests/Mailer/NewUserMailHelperTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ protected function setUp(): void {
7878
$template = new EMailTemplate(
7979
$this->defaults,
8080
$this->urlGenerator,
81-
$this->l10n,
81+
$this->l10nFactory,
8282
'test.TestTemplate',
8383
[]
8484
);
@@ -377,8 +377,8 @@ public function testGenerateTemplateWithPasswordResetToken() {
377377
Install Client: https://nextcloud.com/install/#install-clients
378378
379379
380-
--
381-
TestCloud -
380+
--
381+
TestCloud -
382382
This is an automatically sent email, please do not reply.
383383
EOF;
384384

apps/theming/lib/ThemingDefaults.php

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

148-
public function getSlogan() {
149-
return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', parent::getSlogan()));
148+
public function getSlogan(?string $lang = null) {
149+
return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', parent::getSlogan($lang)));
150150
}
151151

152152
public function getImprintUrl() {

lib/private/Mail/EMailTemplate.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
namespace OC\Mail;
3636

3737
use OCP\Defaults;
38-
use OCP\IL10N;
3938
use OCP\IURLGenerator;
39+
use OCP\L10N\IFactory;
4040
use OCP\Mail\IEMailTemplate;
4141

4242
/**
@@ -52,8 +52,8 @@ class EMailTemplate implements IEMailTemplate {
5252
protected $themingDefaults;
5353
/** @var IURLGenerator */
5454
protected $urlGenerator;
55-
/** @var IL10N */
56-
protected $l10n;
55+
/** @var IFactory */
56+
protected $l10nFactory;
5757
/** @var string */
5858
protected $emailId;
5959
/** @var array */
@@ -350,21 +350,14 @@ class EMailTemplate implements IEMailTemplate {
350350
</table>
351351
EOF;
352352

353-
/**
354-
* @param Defaults $themingDefaults
355-
* @param IURLGenerator $urlGenerator
356-
* @param IL10N $l10n
357-
* @param string $emailId
358-
* @param array $data
359-
*/
360353
public function __construct(Defaults $themingDefaults,
361354
IURLGenerator $urlGenerator,
362-
IL10N $l10n,
355+
IFactory $l10nFactory,
363356
$emailId,
364357
array $data) {
365358
$this->themingDefaults = $themingDefaults;
366359
$this->urlGenerator = $urlGenerator;
367-
$this->l10n = $l10n;
360+
$this->l10nFactory = $l10nFactory;
368361
$this->htmlBody .= $this->head;
369362
$this->emailId = $emailId;
370363
$this->data = $data;
@@ -605,9 +598,10 @@ protected function ensureBodyIsClosed() {
605598
*
606599
* @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used
607600
*/
608-
public function addFooter(string $text = '') {
601+
public function addFooter(string $text = '', ?string $lang = null) {
609602
if ($text === '') {
610-
$text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan() . '<br>' . $this->l10n->t('This is an automatically sent email, please do not reply.');
603+
$l10n = $this->l10nFactory->get('lib', $lang);
604+
$text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan($lang) . '<br>' . $l10n->t('This is an automatically sent email, please do not reply.');
611605
}
612606

613607
if ($this->footerAdded) {

lib/private/Mail/Mailer.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
use OCP\IL10N;
4242
use OCP\ILogger;
4343
use OCP\IURLGenerator;
44+
use OCP\L10N\IFactory;
4445
use OCP\Mail\IAttachment;
4546
use OCP\Mail\IEMailTemplate;
4647
use OCP\Mail\IMailer;
@@ -80,6 +81,8 @@ class Mailer implements IMailer {
8081
private $l10n;
8182
/** @var IEventDispatcher */
8283
private $dispatcher;
84+
/** @var IFactory */
85+
private $l10nFactory;
8386

8487
/**
8588
* @param IConfig $config
@@ -94,13 +97,15 @@ public function __construct(IConfig $config,
9497
Defaults $defaults,
9598
IURLGenerator $urlGenerator,
9699
IL10N $l10n,
97-
IEventDispatcher $dispatcher) {
100+
IEventDispatcher $dispatcher,
101+
IFactory $l10nFactory) {
98102
$this->config = $config;
99103
$this->logger = $logger;
100104
$this->defaults = $defaults;
101105
$this->urlGenerator = $urlGenerator;
102106
$this->l10n = $l10n;
103107
$this->dispatcher = $dispatcher;
108+
$this->l10nFactory = $l10nFactory;
104109
}
105110

106111
/**
@@ -158,7 +163,7 @@ public function createEMailTemplate(string $emailId, array $data = []): IEMailTe
158163
return new EMailTemplate(
159164
$this->defaults,
160165
$this->urlGenerator,
161-
$this->l10n,
166+
$this->l10nFactory,
162167
$emailId,
163168
$data
164169
);

lib/private/Server.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,8 @@ public function __construct($webRoot, \OC\Config $config) {
995995
$c->query(Defaults::class),
996996
$c->getURLGenerator(),
997997
$c->getL10N('lib'),
998-
$c->query(IEventDispatcher::class)
998+
$c->query(IEventDispatcher::class),
999+
$c->getL10NFactory()
9991000
);
10001001
});
10011002
$this->registerDeprecatedAlias('Mailer', IMailer::class);

lib/private/Share20/Manager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,9 +891,9 @@ protected function sendMailNotification(IL10N $l,
891891
$initiatorEmail = $initiatorUser->getEMailAddress();
892892
if ($initiatorEmail !== null) {
893893
$message->setReplyTo([$initiatorEmail => $initiatorDisplayName]);
894-
$emailTemplate->addFooter($instanceName . ($this->defaults->getSlogan() !== '' ? ' - ' . $this->defaults->getSlogan() : ''));
894+
$emailTemplate->addFooter($instanceName . ($this->defaults->getSlogan($l->getLanguageCode()) !== '' ? ' - ' . $this->defaults->getSlogan($l->getLanguageCode()) : ''));
895895
} else {
896-
$emailTemplate->addFooter();
896+
$emailTemplate->addFooter('', $l->getLanguageCode());
897897
}
898898

899899
$message->useTemplate($emailTemplate);

lib/private/legacy/OC_Defaults.php

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

lib/public/Defaults.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ public function getEntity() {
137137
* @return string
138138
* @since 6.0.0
139139
*/
140-
public function getSlogan() {
141-
return $this->defaults->getSlogan();
140+
public function getSlogan(?string $lang = null) {
141+
return $this->defaults->getSlogan($lang);
142142
}
143143

144144
/**

lib/public/Mail/IEMailTemplate.php

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

148149
/**
149150
* Returns the rendered email subject as string

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 @@ protected function setUp(): void {
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)