Commit d7c7808a authored by Lukas Reschke's avatar Lukas Reschke
Browse files

Add debug log message back

parent e32f1582
......@@ -10,6 +10,7 @@ namespace OC\Mail;
use OCP\IConfig;
use OCP\Mail\IMailer;
use OCP\ILogger;
/**
* Class Mailer provides some basic functions to create a mail message that can be used in combination with
......@@ -34,15 +35,21 @@ class Mailer implements IMailer {
private $instance = null;
/** @var IConfig */
private $config;
/** @var ILogger */
private $logger;
/** @var \OC_Defaults */
private $defaults;
/**
* @param IConfig $config
* @param ILogger $logger
* @param \OC_Defaults $defaults
*/
function __construct(IConfig $config, \OC_Defaults $defaults) {
function __construct(IConfig $config,
ILogger $logger,
\OC_Defaults $defaults) {
$this->config = $config;
$this->logger = $logger;
$this->defaults = $defaults;
}
......@@ -67,12 +74,14 @@ class Mailer implements IMailer {
*/
public function send(Message $message) {
if (sizeof($message->getFrom()) === 0) {
$message->setFrom(array(\OCP\Util::getDefaultEmailAddress($this->defaults->getName())));
$message->setFrom([\OCP\Util::getDefaultEmailAddress($this->defaults->getName())]);
}
$failedRecipients = array();
$failedRecipients = [];
$this->getInstance()->send($message->getSwiftMessage(), $failedRecipients);
$logMessage = sprintf('Sent mail to "%s" with subject "%s"', print_r($message->getTo(), true), $message->getSubject());
$this->logger->debug($logMessage, ['app' => 'core']);
return $failedRecipients;
}
......
......@@ -314,7 +314,11 @@ class Server extends SimpleContainer implements IServerContainer {
);
});
$this->registerService('Mailer', function(Server $c) {
return new Mailer($c->getConfig(), new \OC_Defaults());
return new Mailer(
$c->getConfig(),
$c->getLogger(),
new \OC_Defaults()
);
});
}
......
......@@ -10,12 +10,15 @@ namespace Test;
use OC\Mail\Mailer;
use OCP\IConfig;
use OC_Defaults;
use OCP\ILogger;
class MailerTest extends TestCase {
/** @var IConfig */
private $config;
/** @var OC_Defaults */
private $defaults;
/** @var ILogger */
private $logger;
/** @var Mailer */
private $mailer;
......@@ -26,7 +29,9 @@ class MailerTest extends TestCase {
->disableOriginalConstructor()->getMock();
$this->defaults = $this->getMockBuilder('\OC_Defaults')
->disableOriginalConstructor()->getMock();
$this->mailer = new Mailer($this->config, $this->defaults);
$this->logger = $this->getMockBuilder('\OCP\ILogger')
->disableOriginalConstructor()->getMock();
$this->mailer = new Mailer($this->config, $this->logger, $this->defaults);
}
public function testGetMailInstance() {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment