Commit 01446c14 authored by Simon Gilli's avatar Simon Gilli Committed by Benjamin Franzke
Browse files

[TASK] Add EventDispatcher and Logger support to transports

This patch adds EventDispatcher and Logger support to the various
transports where it was missing so far. Now the Mailer API should be
compatible to the underlaying Symfony Mailer and all features can be
used.

Resolves: #93000
Releases: master, 10.4
Change-Id: Iea222586a0f4d3e35e462c3cf27c16eec914b5c4
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/66145

Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: default avatarMarkus Gerdes <markus@madaxel.de>
Tested-by: Benjamin Franzke's avatarBenjamin Franzke <bfr@qbus.de>
Reviewed-by: default avatarMarkus Gerdes <markus@madaxel.de>
Reviewed-by: Wouter Wolters's avatarWouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Benjamin Franzke's avatarBenjamin Franzke <bfr@qbus.de>
parent efa49dd7
......@@ -18,8 +18,7 @@ declare(strict_types=1);
namespace TYPO3\CMS\Core\Mail;
use DirectoryIterator;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\LoggerInterface;
use Symfony\Component\Mailer\DelayedEnvelope;
use Symfony\Component\Mailer\Envelope;
use Symfony\Component\Mailer\Exception\TransportException;
......@@ -29,6 +28,7 @@ use Symfony\Component\Mailer\Transport\TransportInterface;
use Symfony\Component\Mime\Email;
use Symfony\Component\Mime\Message;
use Symfony\Component\Mime\RawMessage;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
......@@ -36,16 +36,21 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
*
* @internal This class is experimental and subject to change!
*/
class FileSpool extends AbstractTransport implements DelayedTransportInterface, LoggerAwareInterface
class FileSpool extends AbstractTransport implements DelayedTransportInterface
{
use LoggerAwareTrait;
/**
* The spool directory
* @var string
*/
protected $path;
/**
* The logger instance.
*
* @var LoggerInterface
*/
protected $logger;
/**
* File WriteRetry Limit.
*
......@@ -69,11 +74,18 @@ class FileSpool extends AbstractTransport implements DelayedTransportInterface,
* Create a new FileSpool.
*
* @param string $path
* @param EventDispatcherInterface $dispatcher
* @param LoggerInterface $logger
*/
public function __construct(string $path)
{
parent::__construct();
public function __construct(
string $path,
EventDispatcherInterface $dispatcher = null,
LoggerInterface $logger = null
) {
parent::__construct($dispatcher, $logger);
$this->path = $path;
$this->logger = $logger;
if (!file_exists($this->path)) {
GeneralUtility::mkdir_deep($this->path);
......
......@@ -15,8 +15,10 @@
namespace TYPO3\CMS\Core\Mail;
use Psr\Log\LoggerInterface;
use Symfony\Component\Mailer\SentMessage;
use Symfony\Component\Mailer\Transport\AbstractTransport;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use TYPO3\CMS\Core\Locking\LockFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
......@@ -30,15 +32,30 @@ class MboxTransport extends AbstractTransport
*/
private $mboxFile;
/**
* The logger instance.
*
* @var LoggerInterface
*/
protected $logger;
/**
* Create a new MailTransport
*
* @param string $mboxFile
* @param EventDispatcherInterface $dispatcher
* @param LoggerInterface $logger
*/
public function __construct($mboxFile)
{
parent::__construct();
public function __construct(
string $mboxFile,
EventDispatcherInterface $dispatcher = null,
LoggerInterface $logger = null
) {
parent::__construct($dispatcher, $logger);
$this->mboxFile = $mboxFile;
$this->logger = $logger;
$this->setMaxPerSecond(0);
}
......
......@@ -17,12 +17,12 @@ declare(strict_types=1);
namespace TYPO3\CMS\Core\Mail;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\LoggerInterface;
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
use Symfony\Component\Mailer\SentMessage;
use Symfony\Component\Mailer\Transport\AbstractTransport;
use Symfony\Component\Mailer\Transport\TransportInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use TYPO3\CMS\Core\Security\BlockSerializationTrait;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
......@@ -37,10 +37,16 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
*
* @internal This class is experimental and subject to change!
*/
class MemorySpool extends AbstractTransport implements SingletonInterface, LoggerAwareInterface, DelayedTransportInterface
class MemorySpool extends AbstractTransport implements SingletonInterface, DelayedTransportInterface
{
use BlockSerializationTrait;
use LoggerAwareTrait;
/**
* The logger instance.
*
* @var LoggerInterface
*/
protected $logger;
/**
* @var SentMessage[]
......@@ -54,6 +60,23 @@ class MemorySpool extends AbstractTransport implements SingletonInterface, Logge
*/
protected $retries = 3;
/**
* Create a new MemorySpool
*
* @param EventDispatcherInterface $dispatcher
* @param LoggerInterface $logger
*/
public function __construct(
EventDispatcherInterface $dispatcher = null,
LoggerInterface $logger = null
) {
parent::__construct($dispatcher, $logger);
$this->logger = $logger;
$this->setMaxPerSecond(0);
}
/**
* Sends out the messages in the memory
*/
......
......@@ -142,7 +142,12 @@ class TransportFactory implements SingletonInterface, LoggerAwareInterface
throw new Exception('$GLOBALS[\'TYPO3_CONF_VARS\'][\'MAIL\'][\'transport_mbox_file\'] needs to be set when transport is set to "mbox".', 1294586645);
}
// Create our transport
$transport = GeneralUtility::makeInstance(MboxTransport::class, $mboxFile);
$transport = GeneralUtility::makeInstance(
MboxTransport::class,
$mboxFile,
$this->dispatcher,
$this->logManager->getLogger(MboxTransport::class)
);
break;
// Used for testing purposes
case 'null':
......@@ -188,10 +193,19 @@ class TransportFactory implements SingletonInterface, LoggerAwareInterface
if (empty($path)) {
throw new \RuntimeException('The Spool Type filepath must be configured for TYPO3 in order to be used. Be sure that it\'s not accessible via the web.', 1518558797);
}
$spool = GeneralUtility::makeInstance(FileSpool::class, $path);
$spool = GeneralUtility::makeInstance(
FileSpool::class,
$path,
$this->dispatcher,
$this->logManager->getLogger(FileSpool::class)
);
break;
case self::SPOOL_MEMORY:
$spool = GeneralUtility::makeInstance(MemorySpool::class);
$spool = GeneralUtility::makeInstance(
MemorySpool::class,
$this->dispatcher,
$this->logManager->getLogger(MemorySpool::class)
);
break;
default:
$spool = GeneralUtility::makeInstance($mailSettings['transport_spool_type'], $mailSettings);
......
Markdown is supported
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