Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
use Exception;
use OC\Accounts\AccountManager;
use OC\Group\Manager;
use OC\Mail\IEMailTemplate;
use OCP\Mail\IEMailTemplate;
use OC\Settings\Mailer\NewUserMailHelper;
use OC\SubAdmin;
use OCA\Provisioning_API\Controller\UsersController;
Expand Down
2 changes: 1 addition & 1 deletion lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
'OCP\\Lock\\ILockingProvider' => $baseDir . '/lib/public/Lock/ILockingProvider.php',
'OCP\\Lock\\LockedException' => $baseDir . '/lib/public/Lock/LockedException.php',
'OCP\\Lockdown\\ILockdownManager' => $baseDir . '/lib/public/Lockdown/ILockdownManager.php',
'OCP\\Mail\\IEMailTemplate' => $baseDir . '/lib/public/Mail/IEMailTemplate.php',
'OCP\\Mail\\IMailer' => $baseDir . '/lib/public/Mail/IMailer.php',
'OCP\\Migration\\IOutput' => $baseDir . '/lib/public/Migration/IOutput.php',
'OCP\\Migration\\IRepairStep' => $baseDir . '/lib/public/Migration/IRepairStep.php',
Expand Down Expand Up @@ -638,7 +639,6 @@
'OC\\Log\\Rotate' => $baseDir . '/lib/private/Log/Rotate.php',
'OC\\Log\\Syslog' => $baseDir . '/lib/private/Log/Syslog.php',
'OC\\Mail\\EMailTemplate' => $baseDir . '/lib/private/Mail/EMailTemplate.php',
'OC\\Mail\\IEMailTemplate' => $baseDir . '/lib/private/Mail/IEMailTemplate.php',
'OC\\Mail\\Mailer' => $baseDir . '/lib/private/Mail/Mailer.php',
'OC\\Mail\\Message' => $baseDir . '/lib/private/Mail/Message.php',
'OC\\Memcache\\APCu' => $baseDir . '/lib/private/Memcache/APCu.php',
Expand Down
2 changes: 1 addition & 1 deletion lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OCP\\Lock\\ILockingProvider' => __DIR__ . '/../../..' . '/lib/public/Lock/ILockingProvider.php',
'OCP\\Lock\\LockedException' => __DIR__ . '/../../..' . '/lib/public/Lock/LockedException.php',
'OCP\\Lockdown\\ILockdownManager' => __DIR__ . '/../../..' . '/lib/public/Lockdown/ILockdownManager.php',
'OCP\\Mail\\IEMailTemplate' => __DIR__ . '/../../..' . '/lib/public/Mail/IEMailTemplate.php',
'OCP\\Mail\\IMailer' => __DIR__ . '/../../..' . '/lib/public/Mail/IMailer.php',
'OCP\\Migration\\IOutput' => __DIR__ . '/../../..' . '/lib/public/Migration/IOutput.php',
'OCP\\Migration\\IRepairStep' => __DIR__ . '/../../..' . '/lib/public/Migration/IRepairStep.php',
Expand Down Expand Up @@ -668,7 +669,6 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\Log\\Rotate' => __DIR__ . '/../../..' . '/lib/private/Log/Rotate.php',
'OC\\Log\\Syslog' => __DIR__ . '/../../..' . '/lib/private/Log/Syslog.php',
'OC\\Mail\\EMailTemplate' => __DIR__ . '/../../..' . '/lib/private/Mail/EMailTemplate.php',
'OC\\Mail\\IEMailTemplate' => __DIR__ . '/../../..' . '/lib/private/Mail/IEMailTemplate.php',
'OC\\Mail\\Mailer' => __DIR__ . '/../../..' . '/lib/private/Mail/Mailer.php',
'OC\\Mail\\Message' => __DIR__ . '/../../..' . '/lib/private/Mail/Message.php',
'OC\\Memcache\\APCu' => __DIR__ . '/../../..' . '/lib/private/Memcache/APCu.php',
Expand Down
1 change: 1 addition & 0 deletions lib/private/Mail/EMailTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use OCP\Defaults;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\Mail\IEMailTemplate;

/**
* Class EMailTemplate
Expand Down
24 changes: 22 additions & 2 deletions lib/private/Mail/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

use OCP\Defaults;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\Mail\IMailer;
use OCP\ILogger;

Expand Down Expand Up @@ -54,18 +56,28 @@ class Mailer implements IMailer {
private $logger;
/** @var Defaults */
private $defaults;
/** @var IURLGenerator */
private $urlGenerator;
/** @var IL10N */
private $l10n;

/**
* @param IConfig $config
* @param ILogger $logger
* @param Defaults $defaults
* @param IURLGenerator $urlGenerator
* @param IL10N $l10n
*/
function __construct(IConfig $config,
public function __construct(IConfig $config,
ILogger $logger,
Defaults $defaults) {
Defaults $defaults,
IURLGenerator $urlGenerator,
IL10N $l10n) {
$this->config = $config;
$this->logger = $logger;
$this->defaults = $defaults;
$this->urlGenerator = $urlGenerator;
$this->l10n = $l10n;
}

/**
Expand All @@ -77,6 +89,14 @@ public function createMessage() {
return new Message(new \Swift_Message());
}

public function createEMailTemplate() {
return new EMailTemplate(
$this->defaults,
$this->urlGenerator,
$this->l10n
);
}

/**
* Send the specified message. Also sets the from address to the value defined in config.php
* if no-one has been passed.
Expand Down
4 changes: 3 additions & 1 deletion lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,9 @@ public function __construct($webRoot, \OC\Config $config) {
return new Mailer(
$c->getConfig(),
$c->getLogger(),
$c->query(Defaults::class)
$c->query(Defaults::class),
$c->getURLGenerator(),
$c->getL10N('lib')
);
});
$this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
*
*/

namespace OC\Mail;

use OCP\Defaults;
namespace OCP\Mail;

/**
* Interface IEMailTemplate
Expand All @@ -49,33 +47,32 @@
*
* $htmlContent = $emailTemplate->renderHTML();
* $plainContent = $emailTemplate->renderText();
*
* @since 12.0.0
*/
interface IEMailTemplate {
/**
* @param Defaults $themingDefaults
* @param \OCP\IURLGenerator $urlGenerator
* @param \OCP\IL10N $l10n
*/
public function __construct(Defaults $themingDefaults,
\OCP\IURLGenerator $urlGenerator,
\OCP\IL10N $l10n);

/**
* Adds a header to the email
*
* @since 12.0.0
*/
public function addHeader();

/**
* Adds a heading to the email
*
* @param string $title
*
* @since 12.0.0
*/
public function addHeading($title);

/**
* Adds a paragraph to the body of the email
*
* @param string $text
*
* @since 12.0.0
*/
public function addBodyText($text);

Expand All @@ -86,27 +83,35 @@ public function addBodyText($text);
* @param string $urlLeft URL of left button
* @param string $textRight Text of right button
* @param string $urlRight URL of right button
*
* @since 12.0.0
*/
public function addBodyButtonGroup($textLeft, $urlLeft, $textRight, $urlRight);

/**
* 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
*
* @since 12.0.0
*/
public function addFooter($text = '');

/**
* Returns the rendered HTML email as string
*
* @return string
*
* @since 12.0.0
*/
public function renderHTML();

/**
* Returns the rendered plain text email as string
*
* @return string
*
* @since 12.0.0
*/
public function renderText();
}
8 changes: 8 additions & 0 deletions lib/public/Mail/IMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ interface IMailer {
*/
public function createMessage();

/**
* Creates a new email template object
*
* @return IEMailTemplate
* @since 12.0.0
*/
public function createEMailTemplate();

/**
* Send the specified message. Also sets the from address to the value defined in config.php
* if no-one has been passed.
Expand Down
2 changes: 1 addition & 1 deletion settings/Mailer/NewUserMailHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
namespace OC\Settings\Mailer;

use OC\Mail\EMailTemplate;
use OC\Mail\IEMailTemplate;
use OCP\Mail\IEMailTemplate;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Defaults;
use OCP\IConfig;
Expand Down
2 changes: 1 addition & 1 deletion tests/Settings/Mailer/NewUserMailHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace Tests\Settings\Mailer;

use OC\Mail\IEMailTemplate;
use OCP\Mail\IEMailTemplate;
use OC\Mail\Message;
use OC\Settings\Mailer\NewUserMailHelper;
use OCP\AppFramework\Utility\ITimeFactory;
Expand Down
37 changes: 26 additions & 11 deletions tests/lib/Mail/MailerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,44 @@

namespace Test\Mail;

use OC\Mail\EMailTemplate;
use OC\Mail\Mailer;
use OCP\Defaults;
use OCP\IConfig;
use OCP\IL10N;
use OCP\ILogger;
use OCP\IURLGenerator;
use Test\TestCase;

class MailerTest extends TestCase {
/** @var IConfig */
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
private $config;
/** @var Defaults */
/** @var Defaults|\PHPUnit_Framework_MockObject_MockObject */
private $defaults;
/** @var ILogger */
/** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
private $logger;
/** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
private $urlGenerator;
/** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
private $l10n;
/** @var Mailer */
private $mailer;

function setUp() {
public function setUp() {
parent::setUp();

$this->config = $this->getMockBuilder('\OCP\IConfig')
->disableOriginalConstructor()->getMock();
$this->defaults = $this->getMockBuilder('\OCP\Defaults')
->disableOriginalConstructor()->getMock();
$this->logger = $this->getMockBuilder('\OCP\ILogger')
->disableOriginalConstructor()->getMock();
$this->mailer = new Mailer($this->config, $this->logger, $this->defaults);
$this->config = $this->createMock(IConfig::class);
$this->defaults = $this->createMock(Defaults::class);
$this->logger = $this->createMock(ILogger::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->l10n = $this->createMock(IL10N::class);
$this->mailer = new Mailer(
$this->config,
$this->logger,
$this->defaults,
$this->urlGenerator,
$this->l10n
);
}

public function testGetMailInstance() {
Expand Down Expand Up @@ -120,4 +132,7 @@ public function testValidateMailAddress($email, $expected) {
$this->assertSame($expected, $this->mailer->validateMailAddress($email));
}

public function testCreateEMailTemplate() {
$this->assertSame(EMailTemplate::class, get_class($this->mailer->createEMailTemplate()));
}
}