diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2023-04-14 14:48:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-14 14:48:47 +0200 |
commit | 0b88b513bee2bf40b4c1f321183cba37b4facbc3 (patch) | |
tree | bcc6f4261a3a6940ae21b9d7a0e7251fb495819d /apps/encryption | |
parent | 8a79636bcb407229a677f12f4ececaeaefdcb5b4 (diff) | |
parent | f60e1f751d5362d9652c253b8c01a5d058e49101 (diff) | |
download | nextcloud-server-0b88b513bee2bf40b4c1f321183cba37b4facbc3.tar.gz nextcloud-server-0b88b513bee2bf40b4c1f321183cba37b4facbc3.zip |
Merge pull request #36351 from nextcloud/bugfix/noid/move-encryption-password-email-to-template
Move encrypt-all password email to EmailTemplate
Diffstat (limited to 'apps/encryption')
-rw-r--r-- | apps/encryption/lib/Crypto/EncryptAll.php | 73 | ||||
-rw-r--r-- | apps/encryption/templates/altmail.php | 16 | ||||
-rw-r--r-- | apps/encryption/templates/mail.php | 38 | ||||
-rw-r--r-- | apps/encryption/tests/Crypto/EncryptAllTest.php | 8 |
4 files changed, 42 insertions, 93 deletions
diff --git a/apps/encryption/lib/Crypto/EncryptAll.php b/apps/encryption/lib/Crypto/EncryptAll.php index 1889c557cdc..72d9646f41a 100644 --- a/apps/encryption/lib/Crypto/EncryptAll.php +++ b/apps/encryption/lib/Crypto/EncryptAll.php @@ -34,7 +34,10 @@ use OCA\Encryption\Users\Setup; use OCA\Encryption\Util; use OCP\IConfig; use OCP\IL10N; +use OCP\IUser; use OCP\IUserManager; +use OCP\L10N\IFactory; +use OCP\Mail\Headers\AutoSubmitted; use OCP\Mail\IMailer; use OCP\Security\ISecureRandom; use Symfony\Component\Console\Helper\ProgressBar; @@ -73,6 +76,9 @@ class EncryptAll { /** @var IL10N */ protected $l; + /** @var IFactory */ + protected $l10nFactory; + /** @var QuestionHelper */ protected $questionHelper; @@ -85,18 +91,6 @@ class EncryptAll { /** @var ISecureRandom */ protected $secureRandom; - /** - * @param Setup $userSetup - * @param IUserManager $userManager - * @param View $rootView - * @param KeyManager $keyManager - * @param Util $util - * @param IConfig $config - * @param IMailer $mailer - * @param IL10N $l - * @param QuestionHelper $questionHelper - * @param ISecureRandom $secureRandom - */ public function __construct( Setup $userSetup, IUserManager $userManager, @@ -106,6 +100,7 @@ class EncryptAll { IConfig $config, IMailer $mailer, IL10N $l, + IFactory $l10nFactory, QuestionHelper $questionHelper, ISecureRandom $secureRandom ) { @@ -117,6 +112,7 @@ class EncryptAll { $this->config = $config; $this->mailer = $mailer; $this->l = $l; + $this->l10nFactory = $l10nFactory; $this->questionHelper = $questionHelper; $this->secureRandom = $secureRandom; // store one time passwords for the users @@ -413,6 +409,10 @@ class EncryptAll { $progress->advance(); if (!empty($password)) { $recipient = $this->userManager->get($uid); + if (!$recipient instanceof IUser) { + continue; + } + $recipientDisplayName = $recipient->getDisplayName(); $to = $recipient->getEMailAddress(); @@ -421,20 +421,33 @@ class EncryptAll { continue; } - $subject = $this->l->t('one-time password for server-side-encryption'); - [$htmlBody, $textBody] = $this->createMailBody($password); + $l = $this->l10nFactory->get('encryption', $this->l10nFactory->getUserLanguage($recipient)); + + $template = $this->mailer->createEMailTemplate('encryption.encryptAllPassword', [ + 'user' => $recipient->getUID(), + 'password' => $password, + ]); + + $template->setSubject($l->t('one-time password for server-side-encryption')); + // 'Hey there,<br><br>The administration enabled server-side-encryption. Your files were encrypted using the password <strong>%s</strong>.<br><br> + // Please login to the web interface, go to the section "Basic encryption module" of your personal settings and update your encryption password by entering this password into the "Old log-in password" field and your current login-password.<br><br>' + $template->addHeader(); + $template->addHeading($l->t('Encryption password')); + $template->addBodyText( + $l->t('The administration enabled server-side-encryption. Your files were encrypted using the password <strong>%s</strong>.', [htmlspecialchars($password)]), + $l->t('The administration enabled server-side-encryption. Your files were encrypted using the password "%s".', $password) + ); + $template->addBodyText( + $l->t('Please login to the web interface, go to the "Security" section of your personal settings and update your encryption password by entering this password into the "Old log-in password" field and your current login-password.') + ); + $template->addFooter(); // send it out now try { $message = $this->mailer->createMessage(); - $message->setSubject($subject); $message->setTo([$to => $recipientDisplayName]); - $message->setHtmlBody($htmlBody); - $message->setPlainBody($textBody); - $message->setFrom([ - \OCP\Util::getDefaultEmailAddress('admin-noreply') - ]); - + $message->useTemplate($template); + $message->setAutoSubmitted(AutoSubmitted::VALUE_AUTO_GENERATED); $this->mailer->send($message); } catch (\Exception $e) { $noMail[] = $uid; @@ -458,22 +471,4 @@ class EncryptAll { $table->render(); } } - - /** - * create mail body for plain text and html mail - * - * @param string $password one-time encryption password - * @return array an array of the html mail body and the plain text mail body - */ - protected function createMailBody($password) { - $html = new \OC_Template("encryption", "mail", ""); - $html->assign('password', $password); - $htmlMail = $html->fetchPage(); - - $plainText = new \OC_Template("encryption", "altmail", ""); - $plainText->assign('password', $password); - $plainTextMail = $plainText->fetchPage(); - - return [$htmlMail, $plainTextMail]; - } } diff --git a/apps/encryption/templates/altmail.php b/apps/encryption/templates/altmail.php deleted file mode 100644 index 2044fd8e74c..00000000000 --- a/apps/encryption/templates/altmail.php +++ /dev/null @@ -1,16 +0,0 @@ -<?php -/** @var OC_Theme $theme */ -/** @var array $_ */ - -print_unescaped($l->t("Hey there,\n\nThe administration enabled server-side-encryption. Your files were encrypted using the password \"%s\".\n\nPlease login to the web interface, go to the section \"Basic encryption module\" of your personal settings and update your encryption password by entering this password into the \"Old log-in password\" field and your current login-password.\n\n", [$_['password']])); -if (isset($_['expiration'])) { - print_unescaped($l->t("The share will expire on %s.", [$_['expiration']])); - print_unescaped("\n\n"); -} -// TRANSLATORS term at the end of a mail -p($l->t("Cheers!")); -?> - - -- -<?php p($theme->getName() . ' - ' . $theme->getSlogan()); ?> -<?php print_unescaped("\n".$theme->getBaseUrl()); diff --git a/apps/encryption/templates/mail.php b/apps/encryption/templates/mail.php deleted file mode 100644 index 0db4b67d08d..00000000000 --- a/apps/encryption/templates/mail.php +++ /dev/null @@ -1,38 +0,0 @@ -<?php -/** @var OC_Theme $theme */ -/** @var array $_ */ -?> -<table cellspacing="0" cellpadding="0" border="0" width="100%"> - <tr><td> - <table cellspacing="0" cellpadding="0" border="0" width="600px"> - <tr> - <td colspan="2" bgcolor="<?php p($theme->getColorPrimary());?>"> - <img src="<?php p(\OC::$server->getURLGenerator()->getAbsoluteURL(image_path('core', 'logo-mail.png'))); ?>" alt="<?php p($theme->getName()); ?>"/> - </td> - </tr> - <tr><td colspan="2"> </td></tr> - <tr> - <td width="20px"> </td> - <td style="font-weight:normal; font-size:0.8em; line-height:1.2em; font-family:verdana,'arial',sans;"> - <?php - print_unescaped($l->t('Hey there,<br><br>The administration enabled server-side-encryption. Your files were encrypted using the password <strong>%s</strong>.<br><br>Please login to the web interface, go to the section "Basic encryption module" of your personal settings and update your encryption password by entering this password into the "Old log-in password" field and your current login-password.<br><br>', [$_['password']])); - // TRANSLATORS term at the end of a mail - p($l->t('Cheers!')); - ?> - </td> - </tr> - <tr><td colspan="2"> </td></tr> - <tr> - <td width="20px"> </td> - <td style="font-weight:normal; font-size:0.8em; line-height:1.2em; font-family:verdana,'arial',sans;">--<br> - <?php p($theme->getName()); ?> - - <?php p($theme->getSlogan()); ?> - <br><a href="<?php p($theme->getBaseUrl()); ?>"><?php p($theme->getBaseUrl());?></a> - </td> - </tr> - <tr> - <td colspan="2"> </td> - </tr> - </table> - </td></tr> -</table> diff --git a/apps/encryption/tests/Crypto/EncryptAllTest.php b/apps/encryption/tests/Crypto/EncryptAllTest.php index 126dbec680e..b99e9144be8 100644 --- a/apps/encryption/tests/Crypto/EncryptAllTest.php +++ b/apps/encryption/tests/Crypto/EncryptAllTest.php @@ -36,6 +36,7 @@ use OCP\Files\FileInfo; use OCP\IConfig; use OCP\IL10N; use OCP\IUserManager; +use OCP\L10N\IFactory; use OCP\Mail\IMailer; use OCP\Security\ISecureRandom; use OCP\UserInterface; @@ -106,6 +107,7 @@ class EncryptAllTest extends TestCase { ->disableOriginalConstructor()->getMock(); $this->mailer = $this->getMockBuilder(IMailer::class) ->disableOriginalConstructor()->getMock(); + $this->l10nFactory = $this->createMock(IFactory::class); $this->l = $this->getMockBuilder(IL10N::class) ->disableOriginalConstructor()->getMock(); $this->questionHelper = $this->getMockBuilder(QuestionHelper::class) @@ -140,6 +142,7 @@ class EncryptAllTest extends TestCase { $this->config, $this->mailer, $this->l, + $this->l10nFactory, $this->questionHelper, $this->secureRandom ); @@ -158,6 +161,7 @@ class EncryptAllTest extends TestCase { $this->config, $this->mailer, $this->l, + $this->l10nFactory, $this->questionHelper, $this->secureRandom ] @@ -186,6 +190,7 @@ class EncryptAllTest extends TestCase { $this->config, $this->mailer, $this->l, + $this->l10nFactory, $this->questionHelper, $this->secureRandom ] @@ -215,6 +220,7 @@ class EncryptAllTest extends TestCase { $this->config, $this->mailer, $this->l, + $this->l10nFactory, $this->questionHelper, $this->secureRandom ] @@ -264,6 +270,7 @@ class EncryptAllTest extends TestCase { $this->config, $this->mailer, $this->l, + $this->l10nFactory, $this->questionHelper, $this->secureRandom ] @@ -299,6 +306,7 @@ class EncryptAllTest extends TestCase { $this->config, $this->mailer, $this->l, + $this->l10nFactory, $this->questionHelper, $this->secureRandom ] |