Provide the proper language to the mailer
Else we can't properly translate the footer in the recipients e-mail language. Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
parent
078ac97939
commit
bb4dedb015
|
@ -78,7 +78,7 @@ class NewUserMailHelperTest extends TestCase {
|
||||||
$template = new EMailTemplate(
|
$template = new EMailTemplate(
|
||||||
$this->defaults,
|
$this->defaults,
|
||||||
$this->urlGenerator,
|
$this->urlGenerator,
|
||||||
$this->l10n,
|
$this->l10nFactory,
|
||||||
'test.TestTemplate',
|
'test.TestTemplate',
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
@ -377,8 +377,8 @@ Set your password: https://example.com/resetPassword/MySuperLongSecureRandomToke
|
||||||
Install Client: https://nextcloud.com/install/#install-clients
|
Install Client: https://nextcloud.com/install/#install-clients
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
TestCloud -
|
TestCloud -
|
||||||
This is an automatically sent email, please do not reply.
|
This is an automatically sent email, please do not reply.
|
||||||
EOF;
|
EOF;
|
||||||
|
|
||||||
|
|
|
@ -145,8 +145,8 @@ class ThemingDefaults extends \OC_Defaults {
|
||||||
return $this->config->getAppValue('theming', 'url', $this->url);
|
return $this->config->getAppValue('theming', 'url', $this->url);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSlogan() {
|
public function getSlogan(?string $lang = null) {
|
||||||
return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', parent::getSlogan()));
|
return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', parent::getSlogan($lang)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getImprintUrl() {
|
public function getImprintUrl() {
|
||||||
|
|
|
@ -35,8 +35,8 @@ declare(strict_types=1);
|
||||||
namespace OC\Mail;
|
namespace OC\Mail;
|
||||||
|
|
||||||
use OCP\Defaults;
|
use OCP\Defaults;
|
||||||
use OCP\IL10N;
|
|
||||||
use OCP\IURLGenerator;
|
use OCP\IURLGenerator;
|
||||||
|
use OCP\L10N\IFactory;
|
||||||
use OCP\Mail\IEMailTemplate;
|
use OCP\Mail\IEMailTemplate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,8 +52,8 @@ class EMailTemplate implements IEMailTemplate {
|
||||||
protected $themingDefaults;
|
protected $themingDefaults;
|
||||||
/** @var IURLGenerator */
|
/** @var IURLGenerator */
|
||||||
protected $urlGenerator;
|
protected $urlGenerator;
|
||||||
/** @var IL10N */
|
/** @var IFactory */
|
||||||
protected $l10n;
|
protected $l10nFactory;
|
||||||
/** @var string */
|
/** @var string */
|
||||||
protected $emailId;
|
protected $emailId;
|
||||||
/** @var array */
|
/** @var array */
|
||||||
|
@ -350,21 +350,14 @@ EOF;
|
||||||
</table>
|
</table>
|
||||||
EOF;
|
EOF;
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Defaults $themingDefaults
|
|
||||||
* @param IURLGenerator $urlGenerator
|
|
||||||
* @param IL10N $l10n
|
|
||||||
* @param string $emailId
|
|
||||||
* @param array $data
|
|
||||||
*/
|
|
||||||
public function __construct(Defaults $themingDefaults,
|
public function __construct(Defaults $themingDefaults,
|
||||||
IURLGenerator $urlGenerator,
|
IURLGenerator $urlGenerator,
|
||||||
IL10N $l10n,
|
IFactory $l10nFactory,
|
||||||
$emailId,
|
$emailId,
|
||||||
array $data) {
|
array $data) {
|
||||||
$this->themingDefaults = $themingDefaults;
|
$this->themingDefaults = $themingDefaults;
|
||||||
$this->urlGenerator = $urlGenerator;
|
$this->urlGenerator = $urlGenerator;
|
||||||
$this->l10n = $l10n;
|
$this->l10nFactory = $l10nFactory;
|
||||||
$this->htmlBody .= $this->head;
|
$this->htmlBody .= $this->head;
|
||||||
$this->emailId = $emailId;
|
$this->emailId = $emailId;
|
||||||
$this->data = $data;
|
$this->data = $data;
|
||||||
|
@ -605,9 +598,10 @@ EOF;
|
||||||
*
|
*
|
||||||
* @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used
|
* @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used
|
||||||
*/
|
*/
|
||||||
public function addFooter(string $text = '') {
|
public function addFooter(string $text = '', ?string $lang = null) {
|
||||||
if ($text === '') {
|
if ($text === '') {
|
||||||
$text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan() . '<br>' . $this->l10n->t('This is an automatically sent email, please do not reply.');
|
$l10n = $this->l10nFactory->get('lib', $lang);
|
||||||
|
$text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan($lang) . '<br>' . $l10n->t('This is an automatically sent email, please do not reply.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->footerAdded) {
|
if ($this->footerAdded) {
|
||||||
|
|
|
@ -41,6 +41,7 @@ use OCP\IConfig;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
use OCP\ILogger;
|
use OCP\ILogger;
|
||||||
use OCP\IURLGenerator;
|
use OCP\IURLGenerator;
|
||||||
|
use OCP\L10N\IFactory;
|
||||||
use OCP\Mail\IAttachment;
|
use OCP\Mail\IAttachment;
|
||||||
use OCP\Mail\IEMailTemplate;
|
use OCP\Mail\IEMailTemplate;
|
||||||
use OCP\Mail\IMailer;
|
use OCP\Mail\IMailer;
|
||||||
|
@ -80,6 +81,8 @@ class Mailer implements IMailer {
|
||||||
private $l10n;
|
private $l10n;
|
||||||
/** @var IEventDispatcher */
|
/** @var IEventDispatcher */
|
||||||
private $dispatcher;
|
private $dispatcher;
|
||||||
|
/** @var IFactory */
|
||||||
|
private $l10nFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param IConfig $config
|
* @param IConfig $config
|
||||||
|
@ -94,13 +97,15 @@ class Mailer implements IMailer {
|
||||||
Defaults $defaults,
|
Defaults $defaults,
|
||||||
IURLGenerator $urlGenerator,
|
IURLGenerator $urlGenerator,
|
||||||
IL10N $l10n,
|
IL10N $l10n,
|
||||||
IEventDispatcher $dispatcher) {
|
IEventDispatcher $dispatcher,
|
||||||
|
IFactory $l10nFactory) {
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
$this->defaults = $defaults;
|
$this->defaults = $defaults;
|
||||||
$this->urlGenerator = $urlGenerator;
|
$this->urlGenerator = $urlGenerator;
|
||||||
$this->l10n = $l10n;
|
$this->l10n = $l10n;
|
||||||
$this->dispatcher = $dispatcher;
|
$this->dispatcher = $dispatcher;
|
||||||
|
$this->l10nFactory = $l10nFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -158,7 +163,7 @@ class Mailer implements IMailer {
|
||||||
return new EMailTemplate(
|
return new EMailTemplate(
|
||||||
$this->defaults,
|
$this->defaults,
|
||||||
$this->urlGenerator,
|
$this->urlGenerator,
|
||||||
$this->l10n,
|
$this->l10nFactory,
|
||||||
$emailId,
|
$emailId,
|
||||||
$data
|
$data
|
||||||
);
|
);
|
||||||
|
|
|
@ -995,7 +995,8 @@ class Server extends ServerContainer implements IServerContainer {
|
||||||
$c->query(Defaults::class),
|
$c->query(Defaults::class),
|
||||||
$c->getURLGenerator(),
|
$c->getURLGenerator(),
|
||||||
$c->getL10N('lib'),
|
$c->getL10N('lib'),
|
||||||
$c->query(IEventDispatcher::class)
|
$c->query(IEventDispatcher::class),
|
||||||
|
$c->getL10NFactory()
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
$this->registerDeprecatedAlias('Mailer', IMailer::class);
|
$this->registerDeprecatedAlias('Mailer', IMailer::class);
|
||||||
|
|
|
@ -891,9 +891,9 @@ class Manager implements IManager {
|
||||||
$initiatorEmail = $initiatorUser->getEMailAddress();
|
$initiatorEmail = $initiatorUser->getEMailAddress();
|
||||||
if ($initiatorEmail !== null) {
|
if ($initiatorEmail !== null) {
|
||||||
$message->setReplyTo([$initiatorEmail => $initiatorDisplayName]);
|
$message->setReplyTo([$initiatorEmail => $initiatorDisplayName]);
|
||||||
$emailTemplate->addFooter($instanceName . ($this->defaults->getSlogan() !== '' ? ' - ' . $this->defaults->getSlogan() : ''));
|
$emailTemplate->addFooter($instanceName . ($this->defaults->getSlogan($l->getLanguageCode()) !== '' ? ' - ' . $this->defaults->getSlogan($l->getLanguageCode()) : ''));
|
||||||
} else {
|
} else {
|
||||||
$emailTemplate->addFooter();
|
$emailTemplate->addFooter('', $l->getLanguageCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
$message->useTemplate($emailTemplate);
|
$message->useTemplate($emailTemplate);
|
||||||
|
|
|
@ -214,12 +214,12 @@ class OC_Defaults {
|
||||||
* Returns slogan
|
* Returns slogan
|
||||||
* @return string slogan
|
* @return string slogan
|
||||||
*/
|
*/
|
||||||
public function getSlogan() {
|
public function getSlogan(?string $lang = null) {
|
||||||
if ($this->themeExist('getSlogan')) {
|
if ($this->themeExist('getSlogan')) {
|
||||||
return $this->theme->getSlogan();
|
return $this->theme->getSlogan($lang);
|
||||||
} else {
|
} else {
|
||||||
if ($this->defaultSlogan === null) {
|
if ($this->defaultSlogan === null) {
|
||||||
$l10n = \OC::$server->getL10N('lib');
|
$l10n = \OC::$server->getL10N('lib', $lang);
|
||||||
$this->defaultSlogan = $l10n->t('a safe home for all your data');
|
$this->defaultSlogan = $l10n->t('a safe home for all your data');
|
||||||
}
|
}
|
||||||
return $this->defaultSlogan;
|
return $this->defaultSlogan;
|
||||||
|
|
|
@ -137,8 +137,8 @@ class Defaults {
|
||||||
* @return string
|
* @return string
|
||||||
* @since 6.0.0
|
* @since 6.0.0
|
||||||
*/
|
*/
|
||||||
public function getSlogan() {
|
public function getSlogan(?string $lang = null) {
|
||||||
return $this->defaults->getSlogan();
|
return $this->defaults->getSlogan($lang);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -140,10 +140,11 @@ interface IEMailTemplate {
|
||||||
* Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email
|
* Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email
|
||||||
*
|
*
|
||||||
* @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used
|
* @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used
|
||||||
|
* @param string $lang Optional language to set the default footer in
|
||||||
*
|
*
|
||||||
* @since 12.0.0
|
* @since 12.0.0
|
||||||
*/
|
*/
|
||||||
public function addFooter(string $text = '');
|
public function addFooter(string $text = '', ?string $lang = null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the rendered email subject as string
|
* Returns the rendered email subject as string
|
||||||
|
|
|
@ -27,6 +27,7 @@ use OC\Mail\EMailTemplate;
|
||||||
use OCP\Defaults;
|
use OCP\Defaults;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
use OCP\IURLGenerator;
|
use OCP\IURLGenerator;
|
||||||
|
use OCP\L10N\IFactory;
|
||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
|
|
||||||
class EMailTemplateTest extends TestCase {
|
class EMailTemplateTest extends TestCase {
|
||||||
|
@ -34,7 +35,7 @@ class EMailTemplateTest extends TestCase {
|
||||||
private $defaults;
|
private $defaults;
|
||||||
/** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
|
/** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $urlGenerator;
|
private $urlGenerator;
|
||||||
/** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
|
/** @var IFactory|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $l10n;
|
private $l10n;
|
||||||
/** @var EMailTemplate */
|
/** @var EMailTemplate */
|
||||||
private $emailTemplate;
|
private $emailTemplate;
|
||||||
|
@ -44,7 +45,11 @@ class EMailTemplateTest extends TestCase {
|
||||||
|
|
||||||
$this->defaults = $this->createMock(Defaults::class);
|
$this->defaults = $this->createMock(Defaults::class);
|
||||||
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
||||||
$this->l10n = $this->createMock(IL10N::class);
|
$this->l10n = $this->createMock(IFactory::class);
|
||||||
|
|
||||||
|
$this->l10n->method('get')
|
||||||
|
->with('lib', '')
|
||||||
|
->willReturn($this->createMock(IL10N::class));
|
||||||
|
|
||||||
$this->emailTemplate = new EMailTemplate(
|
$this->emailTemplate = new EMailTemplate(
|
||||||
$this->defaults,
|
$this->defaults,
|
||||||
|
|
|
@ -20,6 +20,7 @@ use OCP\IConfig;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
use OCP\ILogger;
|
use OCP\ILogger;
|
||||||
use OCP\IURLGenerator;
|
use OCP\IURLGenerator;
|
||||||
|
use OCP\L10N\IFactory;
|
||||||
use OCP\Mail\Events\BeforeMessageSent;
|
use OCP\Mail\Events\BeforeMessageSent;
|
||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
use Swift_SwiftException;
|
use Swift_SwiftException;
|
||||||
|
@ -56,7 +57,8 @@ class MailerTest extends TestCase {
|
||||||
$this->defaults,
|
$this->defaults,
|
||||||
$this->urlGenerator,
|
$this->urlGenerator,
|
||||||
$this->l10n,
|
$this->l10n,
|
||||||
$this->dispatcher
|
$this->dispatcher,
|
||||||
|
$this->createMock(IFactory::class)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,7 +155,7 @@ class MailerTest extends TestCase {
|
||||||
$this->assertInstanceOf('\OC\Mail\Message', $this->mailer->createMessage());
|
$this->assertInstanceOf('\OC\Mail\Message', $this->mailer->createMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testSendInvalidMailException() {
|
public function testSendInvalidMailException() {
|
||||||
$this->expectException(\Exception::class);
|
$this->expectException(\Exception::class);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue