Download project

This commit is contained in:
Roman Pyrih
2024-11-20 09:09:44 +01:00
parent 547a138d6a
commit 5ff041757f
40737 changed files with 7766183 additions and 0 deletions

View File

@@ -0,0 +1,147 @@
* 3.2.4 (2018-10-27)
* fixed deprecations for Symfony 4.2
* made swiftmailer.transport service public
* 3.2.3 (2018-08-29)
* fixed EmailSenderListener that was not resetting wasExceptionThrown properly
* 3.2.2 (2018-04-03)
* fixed the profiler panel when To: or From: headers are empty
* fixed rendered content in the web profiler
* do not set time/message limit on Configurable Spool if null
* 3.2.1 (2018-03-08)
* fixed the handling of null as top-level extension config
* fixed compatibility with the inline_class_loader optimization of the container dumper
* fixed template variable reference
* added `command` to the list of parameters that can be set from environment variables and default config values
* 3.2.0 (2018-02-14)
* improved the Symfony profiler panel
* fixed missing local_domain config support
* 3.1.6 (2017-10-23)
* added missing NTLM Authenticator to swiftmailer.xml
* 3.1.5 (2017-10-19)
* fixed Composer constraints
* 3.1.4 (2017-10-18)
* fixed deprecations when accessing to private services from container
* 3.1.3 (2017-10-18)
* fixed Symfony 3.4 support
* 3.1.2 (2017-10-18)
* fixed Symfony 4 support
* 3.1.1 (2017-10-13)
* fixed missing reset() method on MessageDataCollector
* 3.1.0 (2017-09-27)
* changed commands as services
* added support for Symfony 4
* 3.0.4 (2017-09-10)
* fixed encryption and auth_mode empty usage when empty in MAILER_URL
* added support for ntlm auth_mode
* made sendmail command customizable
* bumped min PHP version to 7.0 (as this is PHP min version for Swiftmailer 6.0)
* 3.0.3 (2017-06-08)
* allowed env values for auth_mode
* 3.0.2 (2017-06-05)
* removed empty delivery_addresses
* removed usage of deprecated ConsoleExceptionEvent for 3.3+
* fixed encryption option when using env variable
* 3.0.1 (2017-05-19)
* removed deprecated delivery_address configuration setting
* removed class parameters in the container configuration
* removed obsolete support for the mail transport
* 3.0.0 (2017-05-19)
* removed the swiftmailer:debug command alias
* added compatibility with Swiftmailer 6.0
* 2.6.6 (2017-10-19)
* fixed compat with Symfony < 3.4
* 2.6.5 (2017-10-19)
* fixed a deprecation when accessing the mailer service
* 2.6.3 (2017-07-22)
* fixed compat with Symfony 3.3+
* 2.6.2 (2017-05-22)
* fixed Swiftmailer dependency
* 2.6.1 (2017-05-20)
* reverted support for Swiftmailer 6.0
* 2.6.0 (2017-05-19)
* added compatibility with Swiftmailer 6.0
* 2.5.4 (2017-03-21)
* fixed for "Swiftmailer still sends email if exception is thrown"
* added autowiring aliases
* 2.5.3 (2017-03-02)
* fixed SMTP usage without request context
* 2.5.2 (2017-03-02)
* fixed deprecated mail transport
* 2.5.1 (2017-03-01)
* fixed disabling delivery with env vars config
* 2.5.0 (2017-02-23)
* allow using env variables in transport configuration
* 2.4.2 (2016-12-20)
* fixed compatibility with Symfony 3.3
* 2.4.1 (2016-12-20)
* added missing attachments in the web profiler
* 2.4.0 (2016-10-09)
* added support for setLocalDomain() and setStreamOptions()
* updated the styles of the SwiftMailer commands
* removed support for deprecated versions of Symfony
* added support for LoadBalancedTransport in SendEmailCommand
* fixed messagePart.charset not defined in the web profiler
* fixed performance on Symfony 3 (IntrospectableContainerInterface does not exist anymore)
* allowed empty transport configs
* added a priority flag on plugins tag

View File

@@ -0,0 +1,50 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\SwiftmailerBundle\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* @internal
*/
abstract class AbstractSwiftMailerCommand extends Command
{
/**
* @var ContainerInterface|null
*/
private $container;
public function setContainer(ContainerInterface $container = null)
{
$this->container = $container;
}
/**
* @return ContainerInterface
*
* @throws \LogicException
*/
protected function getContainer()
{
if (null === $this->container) {
$application = $this->getApplication();
if (null === $application) {
throw new \LogicException('The container cannot be retrieved as the application instance is not yet set.');
}
$this->container = $application->getKernel()->getContainer();
}
return $this->container;
}
}

View File

@@ -0,0 +1,132 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\SwiftmailerBundle\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
/**
* A console command for retrieving information about mailers.
*
* @author Jérémy Romey <jeremy@free-agent.fr>
*/
class DebugCommand extends AbstractSwiftMailerCommand
{
protected static $defaultName = 'debug:swiftmailer';
/** @var SymfonyStyle */
private $io;
/**
* @see Command
*/
protected function configure()
{
$this
->setName(static::$defaultName) // BC with 2.7
->setDefinition([
new InputArgument('name', InputArgument::OPTIONAL, 'A mailer name'),
])
->setDescription('Displays current mailers for an application')
->setHelp(
<<<EOF
The <info>%command.name%</info> displays the configured mailers:
<info>php %command.full_name% mailer-name</info>
EOF
)
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->io = new SymfonyStyle($input, $output);
$name = $input->getArgument('name');
if ($name) {
$this->outputMailer($name);
} else {
$this->outputMailers();
}
}
protected function outputMailers($routes = null)
{
$this->io->title('Configured SwiftMailer Mailers');
$tableHeaders = ['Name', 'Transport', 'Spool', 'Delivery', 'Single Address'];
$tableRows = [];
$mailers = $this->getContainer()->getParameter('swiftmailer.mailers');
foreach ($mailers as $name => $mailer) {
$transport = $this->getContainer()->getParameter(sprintf('swiftmailer.mailer.%s.transport.name', $name));
$spool = $this->getContainer()->getParameter(sprintf('swiftmailer.mailer.%s.spool.enabled', $name)) ? 'YES' : 'NO';
$delivery = $this->getContainer()->getParameter(sprintf('swiftmailer.mailer.%s.delivery.enabled', $name)) ? 'YES' : 'NO';
$singleAddress = $this->getContainer()->getParameter(sprintf('swiftmailer.mailer.%s.single_address', $name));
if ($this->isDefaultMailer($name)) {
$name = sprintf('%s (default mailer)', $name);
}
$tableRows[] = [$name, $transport, $spool, $delivery, $singleAddress];
}
$this->io->table($tableHeaders, $tableRows);
}
/**
* @throws \InvalidArgumentException When route does not exist
*/
protected function outputMailer($name)
{
try {
$service = sprintf('swiftmailer.mailer.%s', $name);
$mailer = $this->getContainer()->get($service);
} catch (ServiceNotFoundException $e) {
throw new \InvalidArgumentException(sprintf('The mailer "%s" does not exist.', $name));
}
$tableHeaders = ['Property', 'Value'];
$tableRows = [];
$transport = $mailer->getTransport();
$spool = $this->getContainer()->getParameter(sprintf('swiftmailer.mailer.%s.spool.enabled', $name)) ? 'YES' : 'NO';
$delivery = $this->getContainer()->getParameter(sprintf('swiftmailer.mailer.%s.delivery.enabled', $name)) ? 'YES' : 'NO';
$singleAddress = $this->getContainer()->getParameter(sprintf('swiftmailer.mailer.%s.single_address', $name));
$this->io->title(sprintf('Configuration of the Mailer "%s"', $name));
if ($this->isDefaultMailer($name)) {
$this->io->comment('This is the default mailer');
}
$tableRows[] = ['Name', $name];
$tableRows[] = ['Service', $service];
$tableRows[] = ['Class', \get_class($mailer)];
$tableRows[] = ['Transport', sprintf('%s (%s)', sprintf('swiftmailer.mailer.%s.transport.name', $name), \get_class($transport))];
$tableRows[] = ['Spool', $spool];
if ($this->getContainer()->hasParameter(sprintf('swiftmailer.spool.%s.file.path', $name))) {
$tableRows[] = ['Spool file', $this->getContainer()->getParameter(sprintf('swiftmailer.spool.%s.file.path', $name))];
}
$tableRows[] = ['Delivery', $delivery];
$tableRows[] = ['Single Address', $singleAddress];
$this->io->table($tableHeaders, $tableRows);
}
private function isDefaultMailer($name)
{
return $this->getContainer()->getParameter('swiftmailer.default_mailer') === $name || 'default' === $name;
}
}

View File

@@ -0,0 +1,141 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\SwiftmailerBundle\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
/**
* A console command for creating and sending simple emails.
*
* @author Gusakov Nikita <dev@nkt.me>
*/
class NewEmailCommand extends AbstractSwiftMailerCommand
{
protected static $defaultName = 'swiftmailer:email:send';
/** @var SymfonyStyle */
private $io;
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName(static::$defaultName) // BC with 2.7
->setDescription('Send simple email message')
->addOption('from', null, InputOption::VALUE_REQUIRED, 'The from address of the message')
->addOption('to', null, InputOption::VALUE_REQUIRED, 'The to address of the message')
->addOption('subject', null, InputOption::VALUE_REQUIRED, 'The subject of the message')
->addOption('body', null, InputOption::VALUE_REQUIRED, 'The body of the message')
->addOption('mailer', null, InputOption::VALUE_REQUIRED, 'The mailer name', 'default')
->addOption('content-type', null, InputOption::VALUE_REQUIRED, 'The body content type of the message', 'text/html')
->addOption('charset', null, InputOption::VALUE_REQUIRED, 'The body charset of the message', 'UTF8')
->addOption('body-source', null, InputOption::VALUE_REQUIRED, 'The source where body come from [stdin|file]', 'stdin')
->setHelp(
<<<EOF
The <info>%command.name%</info> command creates and sends a simple email message.
<info>php %command.full_name% --mailer=custom_mailer --content-type=text/xml</info>
You can get body of message from a file:
<info>php %command.full_name% --body-source=file --body=/path/to/file</info>
EOF
);
}
/**
* {@inheritdoc}
*/
protected function initialize(InputInterface $input, OutputInterface $output)
{
$this->io = new SymfonyStyle($input, $output);
$this->io->title('SwiftMailer\'s Interactive Email Sender');
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$mailerServiceName = sprintf('swiftmailer.mailer.%s', $input->getOption('mailer'));
if (!$this->getContainer()->has($mailerServiceName)) {
throw new \InvalidArgumentException(sprintf('The mailer "%s" does not exist.', $input->getOption('mailer')));
}
switch ($input->getOption('body-source')) {
case 'file':
$filename = $input->getOption('body');
$content = file_get_contents($filename);
if (false === $content) {
throw new \Exception(sprintf('Could not get contents from "%s".', $filename));
}
$input->setOption('body', $content);
break;
case 'stdin':
break;
default:
throw new \InvalidArgumentException('Body-input option should be "stdin" or "file".');
}
$message = $this->createMessage($input);
$mailer = $this->getContainer()->get($mailerServiceName);
$sentMessages = $mailer->send($message);
$this->io->success(sprintf('%s emails were successfully sent.', $sentMessages));
}
/**
* {@inheritdoc}
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
foreach ($input->getOptions() as $option => $value) {
if (null === $value) {
$input->setOption($option, $this->io->ask(sprintf('%s', ucfirst($option))));
}
}
}
/**
* {@inheritdoc}
*/
public function isEnabled()
{
return $this->getContainer()->has('mailer');
}
/**
* Creates new message from input options.
*
* @param InputInterface $input An InputInterface instance
*
* @return \Swift_Message New message
*/
private function createMessage(InputInterface $input)
{
$message = new \Swift_Message(
$input->getOption('subject'),
$input->getOption('body'),
$input->getOption('content-type'),
$input->getOption('charset')
);
$message->setFrom($input->getOption('from'));
$message->setTo($input->getOption('to'));
return $message;
}
}

View File

@@ -0,0 +1,119 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\SwiftmailerBundle\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
/**
* Send Emails from the spool.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Clément JOBEILI <clement.jobeili@gmail.com>
* @author Toni Uebernickel <tuebernickel@gmail.com>
*/
class SendEmailCommand extends AbstractSwiftMailerCommand
{
protected static $defaultName = 'swiftmailer:spool:send';
/** @var SymfonyStyle */
private $io;
protected function configure()
{
$this
->setName(static::$defaultName) // BC with 2.7
->setDescription('Sends emails from the spool')
->addOption('message-limit', null, InputOption::VALUE_REQUIRED, 'The maximum number of messages to send.')
->addOption('time-limit', null, InputOption::VALUE_REQUIRED, 'The time limit for sending messages (in seconds).')
->addOption('recover-timeout', null, InputOption::VALUE_REQUIRED, 'The timeout for recovering messages that have taken too long to send (in seconds).')
->addOption('mailer', null, InputOption::VALUE_REQUIRED, 'The mailer name.')
->addOption('transport', null, InputOption::VALUE_REQUIRED, 'The service of the transport to use to send the messages.')
->setHelp(
<<<EOF
The <info>%command.name%</info> command sends all emails from the spool.
<info>php %command.full_name% --message-limit=10 --time-limit=10 --recover-timeout=900 --mailer=default</info>
EOF
)
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->io = new SymfonyStyle($input, $output);
$name = $input->getOption('mailer');
if ($name) {
$this->processMailer($name, $input, $output);
} else {
$mailers = array_keys($this->getContainer()->getParameter('swiftmailer.mailers'));
foreach ($mailers as $name) {
$this->processMailer($name, $input, $output);
}
}
}
private function processMailer($name, InputInterface $input, OutputInterface $output)
{
if (!$this->getContainer()->has(sprintf('swiftmailer.mailer.%s', $name))) {
throw new \InvalidArgumentException(sprintf('The mailer "%s" does not exist.', $name));
}
$this->io->text(sprintf('<info>[%s]</info> Processing <info>%s</info> mailer spool... ', date('Y-m-d H:i:s'), $name));
if ($this->getContainer()->getParameter(sprintf('swiftmailer.mailer.%s.spool.enabled', $name))) {
$mailer = $this->getContainer()->get(sprintf('swiftmailer.mailer.%s', $name));
$transport = $mailer->getTransport();
if ($transport instanceof \Swift_Transport_LoadBalancedTransport) {
foreach ($transport->getTransports() as $eachTransport) {
$this->recoverSpool($name, $eachTransport, $input, $output);
}
} else {
$this->recoverSpool($name, $transport, $input, $output);
}
} else {
$this->io->warning('There are no emails to send because the spool is disabled.');
}
}
private function recoverSpool($name, \Swift_Transport $transport, InputInterface $input)
{
if ($transport instanceof \Swift_Transport_SpoolTransport) {
$spool = $transport->getSpool();
if ($spool instanceof \Swift_ConfigurableSpool) {
if (null !== $input->getOption('message-limit')) {
$spool->setMessageLimit($input->getOption('message-limit'));
}
if (null !== $input->getOption('time-limit')) {
$spool->setTimeLimit($input->getOption('time-limit'));
}
}
if ($spool instanceof \Swift_FileSpool) {
if (null !== $input->getOption('recover-timeout')) {
$spool->recover($input->getOption('recover-timeout'));
} else {
$spool->recover();
}
}
$transportService = $input->getOption('transport') ?: sprintf('swiftmailer.mailer.%s.transport.real', $name);
$sent = $spool->flushQueue($this->getContainer()->get($transportService));
$this->io->text(sprintf('<comment>%d</comment> emails sent', $sent));
}
}
}

View File

@@ -0,0 +1,193 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\SwiftmailerBundle\DataCollector;
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* MessageDataCollector.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Clément JOBEILI <clement.jobeili@gmail.com>
* @author Jérémy Romey <jeremy@free-agent.fr>
*/
class MessageDataCollector extends DataCollector
{
private $container;
/**
* We don't inject the message logger and mailer here
* to avoid the creation of these objects when no emails are sent.
*/
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
{
$this->reset();
// only collect when Swiftmailer has already been initialized
if (class_exists('Swift_Mailer', false)) {
$mailers = $this->container->getParameter('swiftmailer.mailers');
foreach ($mailers as $name => $mailer) {
if ($this->container->getParameter('swiftmailer.default_mailer') == $name) {
$this->data['defaultMailer'] = $name;
}
$loggerName = sprintf('swiftmailer.mailer.%s.plugin.messagelogger', $name);
if ($this->container->has($loggerName)) {
$logger = $this->container->get($loggerName);
$this->data['mailer'][$name] = [
'messages' => [],
'messageCount' => $logger->countMessages(),
'isSpool' => $this->container->getParameter(sprintf('swiftmailer.mailer.%s.spool.enabled', $name)),
];
foreach ($logger->getMessages() as $message) {
$message->__contentType = $message->getBodyContentType();
$message->__base64EncodedBody = base64_encode($message->getBody());
if ('text/plain' === $message->__contentType) {
foreach ($message->getChildren() as $child) {
if ('text/html' === $child->getContentType()) {
$message->__contentType = 'text/html';
$message->__base64EncodedBody = base64_encode($child->getBody());
break;
}
}
}
$this->data['mailer'][$name]['messages'][] = $message;
}
$this->data['messageCount'] += $logger->countMessages();
}
}
}
}
/**
* {@inheritdoc}
*/
public function reset()
{
$this->data = [
'mailer' => [],
'messageCount' => 0,
'defaultMailer' => '',
];
}
/**
* Returns the mailer names.
*
* @return array the mailer names
*/
public function getMailers()
{
return array_keys($this->data['mailer']);
}
/**
* Returns the data collected of a mailer.
*
* @return array the data of the mailer
*/
public function getMailerData($name)
{
if (!isset($this->data['mailer'][$name])) {
throw new \LogicException(sprintf('Missing "%s" data in "%s".', $name, \get_class($this)));
}
return $this->data['mailer'][$name];
}
/**
* Returns the message count of a mailer or the total.
*
* @return int the number of messages
*/
public function getMessageCount($name = null)
{
if (null === $name) {
return $this->data['messageCount'];
} elseif ($data = $this->getMailerData($name)) {
return $data['messageCount'];
}
return;
}
/**
* Returns the messages of a mailer.
*
* @return \Swift_Message[] the messages
*/
public function getMessages($name = 'default')
{
if ($data = $this->getMailerData($name)) {
return $data['messages'];
}
return [];
}
/**
* Returns if the mailer has spool.
*
* @return bool
*/
public function isSpool($name)
{
if ($data = $this->getMailerData($name)) {
return $data['isSpool'];
}
return;
}
/**
* Returns if the mailer is the default mailer.
*
* @return bool
*/
public function isDefaultMailer($name)
{
return $this->data['defaultMailer'] == $name;
}
public function extractAttachments(\Swift_Message $message)
{
$attachments = [];
foreach ($message->getChildren() as $child) {
if ($child instanceof \Swift_Attachment) {
$attachments[] = $child;
}
}
return $attachments;
}
/**
* {@inheritdoc}
*/
public function getName()
{
return 'swiftmailer';
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace Symfony\Bundle\SwiftmailerBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass;
use Symfony\Component\DependencyInjection\Definition;
/**
* Ensures that autoloading of Swiftmailer classes is not optimized by the hot path optimization.
*
* Swiftmailer has a special autoloader triggering the initialization of the library lazily.
* Bypassing the autoloader would thus break the library.
* This logic allows to keep applying the autoloading optimization on the container, forcing an
* opt-out only for the Swiftmailer classes, which is better than disabling the optimization
* entirely.
*
* @author Christophe Coevoet <stof@notk.org>
*/
class EnsureNoHotPathPass extends AbstractRecursivePass
{
protected function processValue($value, $isRoot = false)
{
if ($value instanceof Definition && 0 === strpos($value->getClass(), 'Swift_')) {
$value->clearTag('container.hot_path');
}
return parent::processValue($value, $isRoot);
}
}

View File

@@ -0,0 +1,60 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\SwiftmailerBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
/**
* RegisterPluginsPass registers Swiftmailer plugins.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class RegisterPluginsPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if (!$container->findDefinition('swiftmailer.mailer') || !$container->getParameter('swiftmailer.mailers')) {
return;
}
$mailers = $container->getParameter('swiftmailer.mailers');
foreach ($mailers as $name => $mailer) {
$plugins = $this->findSortedByPriorityTaggedServiceIds($container, sprintf('swiftmailer.%s.plugin', $name));
$transport = sprintf('swiftmailer.mailer.%s.transport', $name);
$definition = $container->findDefinition($transport);
foreach ($plugins as $id => $args) {
$definition->addMethodCall('registerPlugin', [new Reference($id)]);
}
}
}
/**
* @return array
*/
private function findSortedByPriorityTaggedServiceIds(ContainerBuilder $container, $tag)
{
$taggedServices = $container->findTaggedServiceIds($tag);
uasort(
$taggedServices,
function ($tagA, $tagB) {
$priorityTagA = $tagA[0]['priority'] ?? 0;
$priorityTagB = $tagB[0]['priority'] ?? 0;
return $priorityTagA - $priorityTagB;
}
);
return $taggedServices;
}
}

View File

@@ -0,0 +1,190 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\SwiftmailerBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
/**
* This class contains the configuration information for the bundle.
*
* This information is solely responsible for how the different configuration
* sections are normalized, and merged.
*
* @author Christophe Coevoet <stof@notk.org>
*/
class Configuration implements ConfigurationInterface
{
private $debug;
/**
* @param bool $debug The kernel.debug value
*/
public function __construct($debug)
{
$this->debug = (bool) $debug;
}
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('swiftmailer');
$rootNode = method_exists(TreeBuilder::class, 'getRootNode') ? $treeBuilder->getRootNode() : $treeBuilder->root('swiftmailer');
$rootNode
->beforeNormalization()
->ifNull()
->thenEmptyArray()
->end()
->beforeNormalization()
->ifTrue(function ($v) {
return \is_array($v) && !\array_key_exists('mailers', $v) && !\array_key_exists('mailer', $v);
})
->then(function ($v) {
$mailer = [];
foreach ($v as $key => $value) {
if ('default_mailer' == $key) {
continue;
}
$mailer[$key] = $v[$key];
unset($v[$key]);
}
$v['default_mailer'] = isset($v['default_mailer']) ? (string) $v['default_mailer'] : 'default';
$v['mailers'] = [$v['default_mailer'] => $mailer];
return $v;
})
->end()
->children()
->scalarNode('default_mailer')->end()
->append($this->getMailersNode())
->end()
->fixXmlConfig('mailer')
;
return $treeBuilder;
}
/**
* @return ArrayNodeDefinition
*/
private function getMailersNode()
{
$treeBuilder = new TreeBuilder('mailers');
$node = method_exists(TreeBuilder::class, 'getRootNode') ? $treeBuilder->getRootNode() : $treeBuilder->root('mailers');
$node
->requiresAtLeastOneElement()
->useAttributeAsKey('name')
->prototype('array')
->children()
->scalarNode('url')->defaultNull()->end()
->scalarNode('transport')->defaultValue('smtp')->end()
->scalarNode('command')->defaultValue('/usr/sbin/sendmail -bs')->end()
->scalarNode('username')->defaultNull()->end()
->scalarNode('password')->defaultNull()->end()
->scalarNode('host')->defaultValue('localhost')->end()
->scalarNode('port')->defaultNull()->end()
->scalarNode('timeout')->defaultValue(30)->end()
->scalarNode('source_ip')->defaultNull()->end()
->scalarNode('local_domain')->defaultNull()->end()
->arrayNode('stream_options')
->ignoreExtraKeys(false)
->normalizeKeys(false)
->beforeNormalization()
->ifTrue(function ($v) {
return isset($v['stream-option']);
})
->then(function ($v) {
$recurse = function ($array) use (&$recurse) {
if (isset($array['name'])) {
$array = [$array];
}
$n = [];
foreach ($array as $v) {
$k = $v['name'];
if (isset($v['value'])) {
$n[$k] = $v['value'];
} elseif (isset($v['stream-option'])) {
$n[$k] = $recurse($v['stream-option']);
}
}
return $n;
};
return $recurse($v['stream-option']);
})
->end()
->validate()
->ifTrue(function ($v) {
return !method_exists('Swift_Transport_EsmtpTransport', 'setStreamOptions');
})
->thenInvalid('stream_options is only available in Swiftmailer 5.4.2 or later.')
->end()
->end()
->scalarNode('encryption')
->defaultNull()
->end()
->scalarNode('auth_mode')
->defaultNull()
->end()
->scalarNode('sender_address')->end()
->arrayNode('delivery_addresses')
->performNoDeepMerging()
->beforeNormalization()
->ifArray()
->then(function ($v) {
return array_filter(array_values($v));
})
->end()
->prototype('scalar')
->end()
->end()
->arrayNode('antiflood')
->children()
->scalarNode('threshold')->defaultValue(99)->end()
->scalarNode('sleep')->defaultValue(0)->end()
->end()
->end()
->booleanNode('logging')->defaultValue($this->debug)->end()
->arrayNode('spool')
->children()
->scalarNode('type')->defaultValue('file')->end()
->scalarNode('path')->defaultValue('%kernel.cache_dir%/swiftmailer/spool')->end()
->scalarNode('id')->defaultNull()->info('Used by "service" type')->end()
->end()
->validate()
->ifTrue(function ($v) {
return 'service' === $v['type'] && empty($v['id']);
})
->thenInvalid('You have to configure the service id')
->end()
->end()
->end()
->fixXmlConfig('delivery_address', 'delivery_addresses')
->fixXmlConfig('delivery_whitelist_pattern', 'delivery_whitelist')
->children()
->arrayNode('delivery_whitelist')
->prototype('scalar')
->end()
->end()
->booleanNode('disable_delivery')->end()
->end()
;
return $node;
}
}

View File

@@ -0,0 +1,38 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\SwiftmailerBundle\DependencyInjection;
use Symfony\Component\Routing\RequestContext;
class SmtpTransportConfigurator
{
private $localDomain;
private $requestContext;
public function __construct($localDomain, RequestContext $requestContext = null)
{
$this->localDomain = $localDomain;
$this->requestContext = $requestContext;
}
/**
* Sets the local domain based on the current request context.
*/
public function configure(\Swift_Transport_AbstractSmtpTransport $transport)
{
if ($this->localDomain) {
$transport->setLocalDomain($this->localDomain);
} elseif ($this->requestContext) {
$transport->setLocalDomain($this->requestContext->getHost());
}
}
}

View File

@@ -0,0 +1,407 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\SwiftmailerBundle\DependencyInjection;
use Symfony\Component\Console\Application;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
/**
* SwiftmailerExtension is an extension for the SwiftMailer library.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class SwiftmailerExtension extends Extension
{
/**
* Loads the Swift Mailer configuration.
*
* Usage example:
*
* <swiftmailer:config transport="gmail">
* <swiftmailer:username>fabien</swift:username>
* <swiftmailer:password>xxxxx</swift:password>
* <swiftmailer:spool path="/path/to/spool/" />
* </swiftmailer:config>
*
* @param array $configs An array of configuration settings
* @param ContainerBuilder $container A ContainerBuilder instance
*/
public function load(array $configs, ContainerBuilder $container)
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('swiftmailer.xml');
if (class_exists(Application::class)) {
$loader->load('console.xml');
}
$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);
$mailers = [];
foreach ($config['mailers'] as $name => $mailer) {
$isDefaultMailer = $config['default_mailer'] === $name;
$this->configureMailer($name, $mailer, $container, $isDefaultMailer);
$mailers[$name] = sprintf('swiftmailer.mailer.%s', $name);
}
ksort($mailers);
$container->setParameter('swiftmailer.mailers', $mailers);
$container->setParameter('swiftmailer.default_mailer', $config['default_mailer']);
$container->findDefinition('swiftmailer.data_collector')->addTag('data_collector', ['template' => '@Swiftmailer/Collector/swiftmailer.html.twig', 'id' => 'swiftmailer', 'priority' => 245]);
$container->setAlias('mailer', 'swiftmailer.mailer');
$container->getAlias('mailer')->setPublic(true);
}
protected function configureMailer($name, array $mailer, ContainerBuilder $container, $isDefaultMailer = false)
{
$definitionDecorator = $this->createChildDefinition('swiftmailer.transport.eventdispatcher.abstract');
$container
->setDefinition(sprintf('swiftmailer.mailer.%s.transport.eventdispatcher', $name), $definitionDecorator)
;
$usedEnvs = null;
$disableDelivery = isset($mailer['disable_delivery']) && $mailer['disable_delivery'];
if (method_exists($container, 'resolveEnvPlaceholders')) {
$options = [];
$envVariablesAllowed = ['transport', 'url', 'username', 'password', 'host', 'port', 'timeout', 'source_ip', 'local_domain', 'encryption', 'auth_mode', 'command'];
foreach ($envVariablesAllowed as $key) {
$container->resolveEnvPlaceholders($mailer[$key], null, $usedEnvs);
$options[$key] = $mailer[$key];
}
}
if (!$usedEnvs) {
SwiftmailerTransportFactory::validateConfig($mailer);
}
if ($usedEnvs && !$disableDelivery) {
$transportId = sprintf('swiftmailer.mailer.%s.transport.dynamic', $name);
$definitionDecorator = new Definition('\Swift_Transport');
$definitionDecorator->setFactory(['Symfony\Bundle\SwiftmailerBundle\DependencyInjection\SwiftmailerTransportFactory', 'createTransport']);
$definitionDecorator->setArguments([
$options,
new Reference('router.request_context', ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference(sprintf('swiftmailer.mailer.%s.transport.eventdispatcher', $name)),
]);
$container->setDefinition(sprintf('swiftmailer.mailer.%s.transport.dynamic', $name), $definitionDecorator);
$container->setAlias(sprintf('swiftmailer.mailer.%s.transport', $name), $transportId);
$definitionDecorator = $this->createChildDefinition('swiftmailer.mailer.abstract');
$container
->setDefinition(sprintf('swiftmailer.mailer.%s', $name), $definitionDecorator)
->replaceArgument(0, new Reference(sprintf('swiftmailer.mailer.%s.transport', $name)))
;
$container->setParameter(sprintf('swiftmailer.mailer.%s.transport.name', $name), 'dynamic');
} else {
$mailer = SwiftmailerTransportFactory::resolveOptions($mailer);
$transport = $disableDelivery ? 'null' : $mailer['transport'];
$container->setParameter(sprintf('swiftmailer.mailer.%s.transport.name', $name), $transport);
$transportId = \in_array($transport, ['smtp', 'sendmail', 'null'])
? sprintf('swiftmailer.mailer.%s.transport.%s', $name, $transport)
: $transport;
$this->configureMailerTransport($name, $mailer, $container, $transport, $isDefaultMailer);
}
$this->configureMailerSpool($name, $mailer, $container, $transportId, $isDefaultMailer);
$this->configureMailerSenderAddress($name, $mailer, $container, $isDefaultMailer);
$this->configureMailerAntiFlood($name, $mailer, $container, $isDefaultMailer);
$this->configureMailerDeliveryAddress($name, $mailer, $container, $isDefaultMailer);
$this->configureMailerLogging($name, $mailer, $container, $isDefaultMailer);
$container->setParameter(sprintf('swiftmailer.mailer.%s.delivery.enabled', $name), !$disableDelivery);
// alias
if ($isDefaultMailer) {
$container->setAlias('swiftmailer.mailer', sprintf('swiftmailer.mailer.%s', $name));
$container->setAlias('swiftmailer.transport', new Alias(sprintf('swiftmailer.mailer.%s.transport', $name), true));
$container->setParameter('swiftmailer.spool.enabled', $container->getParameter(sprintf('swiftmailer.mailer.%s.spool.enabled', $name)));
$container->setParameter('swiftmailer.delivery.enabled', $container->getParameter(sprintf('swiftmailer.mailer.%s.delivery.enabled', $name)));
$container->setParameter('swiftmailer.single_address', $container->getParameter(sprintf('swiftmailer.mailer.%s.single_address', $name)));
$container->setAlias('Swift_Mailer', new Alias('swiftmailer.mailer', false));
$container->setAlias('Swift_Transport', new Alias('swiftmailer.transport', false));
}
}
protected function configureMailerTransport($name, array $mailer, ContainerBuilder $container, $transport, $isDefaultMailer = false)
{
foreach (['encryption', 'port', 'host', 'username', 'password', 'auth_mode', 'timeout', 'source_ip', 'local_domain'] as $key) {
$container->setParameter(sprintf('swiftmailer.mailer.%s.transport.smtp.%s', $name, $key), $mailer[$key]);
}
if ('smtp' === $transport) {
$authDecorator = $this->createChildDefinition('swiftmailer.transport.authhandler.abstract');
$container
->setDefinition(sprintf('swiftmailer.mailer.%s.transport.authhandler', $name), $authDecorator)
->addMethodCall('setUsername', [sprintf('%%swiftmailer.mailer.%s.transport.smtp.username%%', $name)])
->addMethodCall('setPassword', [sprintf('%%swiftmailer.mailer.%s.transport.smtp.password%%', $name)])
->addMethodCall('setAuthMode', [sprintf('%%swiftmailer.mailer.%s.transport.smtp.auth_mode%%', $name)]);
$bufferDecorator = $this->createChildDefinition('swiftmailer.transport.buffer.abstract');
$container
->setDefinition(sprintf('swiftmailer.mailer.%s.transport.buffer', $name), $bufferDecorator);
$configuratorDecorator = $this->createChildDefinition('swiftmailer.transport.smtp.configurator.abstract');
$container
->setDefinition(sprintf('swiftmailer.transport.configurator.%s', $name), $configuratorDecorator)
->setArguments([
sprintf('%%swiftmailer.mailer.%s.transport.smtp.local_domain%%', $name),
new Reference('router.request_context', ContainerInterface::NULL_ON_INVALID_REFERENCE),
])
;
$definitionDecorator = $this->createChildDefinition('swiftmailer.transport.smtp.abstract');
$container
->setDefinition(sprintf('swiftmailer.mailer.%s.transport.smtp', $name), $definitionDecorator)
->setArguments([
new Reference(sprintf('swiftmailer.mailer.%s.transport.buffer', $name)),
[new Reference(sprintf('swiftmailer.mailer.%s.transport.authhandler', $name))],
new Reference(sprintf('swiftmailer.mailer.%s.transport.eventdispatcher', $name)),
])
->addMethodCall('setHost', [sprintf('%%swiftmailer.mailer.%s.transport.smtp.host%%', $name)])
->addMethodCall('setPort', [sprintf('%%swiftmailer.mailer.%s.transport.smtp.port%%', $name)])
->addMethodCall('setEncryption', [sprintf('%%swiftmailer.mailer.%s.transport.smtp.encryption%%', $name)])
->addMethodCall('setTimeout', [sprintf('%%swiftmailer.mailer.%s.transport.smtp.timeout%%', $name)])
->addMethodCall('setSourceIp', [sprintf('%%swiftmailer.mailer.%s.transport.smtp.source_ip%%', $name)])
->setConfigurator([new Reference(sprintf('swiftmailer.transport.configurator.%s', $name)), 'configure'])
;
if (isset($mailer['stream_options'])) {
$container->setParameter(sprintf('swiftmailer.mailer.%s.transport.smtp.stream_options', $name), $mailer['stream_options']);
$definitionDecorator->addMethodCall('setStreamOptions', [sprintf('%%swiftmailer.mailer.%s.transport.smtp.stream_options%%', $name)]);
}
$container->setAlias(sprintf('swiftmailer.mailer.%s.transport', $name), sprintf('swiftmailer.mailer.%s.transport.%s', $name, $transport));
} elseif ('sendmail' === $transport) {
$bufferDecorator = $this->createChildDefinition('swiftmailer.transport.buffer.abstract');
$container
->setDefinition(sprintf('swiftmailer.mailer.%s.transport.buffer', $name), $bufferDecorator);
$configuratorDecorator = $this->createChildDefinition('swiftmailer.transport.smtp.configurator.abstract');
$container
->setDefinition(sprintf('swiftmailer.transport.configurator.%s', $name), $configuratorDecorator)
->setArguments([
sprintf('%%swiftmailer.mailer.%s.transport.smtp.local_domain%%', $name),
new Reference('router.request_context', ContainerInterface::NULL_ON_INVALID_REFERENCE),
])
;
$definitionDecorator = $this->createChildDefinition(sprintf('swiftmailer.transport.%s.abstract', $transport));
$container
->setDefinition(sprintf('swiftmailer.mailer.%s.transport.%s', $name, $transport), $definitionDecorator)
->setArguments([
new Reference(sprintf('swiftmailer.mailer.%s.transport.buffer', $name)),
new Reference(sprintf('swiftmailer.mailer.%s.transport.eventdispatcher', $name)),
])
->setConfigurator([new Reference(sprintf('swiftmailer.transport.configurator.%s', $name)), 'configure'])
;
$container->setAlias(sprintf('swiftmailer.mailer.%s.transport', $name), sprintf('swiftmailer.mailer.%s.transport.%s', $name, $transport));
} elseif ('null' === $transport) {
$definitionDecorator = $this->createChildDefinition('swiftmailer.transport.null.abstract');
$container
->setDefinition(sprintf('swiftmailer.mailer.%s.transport.null', $name), $definitionDecorator)
->setArguments([
new Reference(sprintf('swiftmailer.mailer.%s.transport.eventdispatcher', $name)),
])
;
$container->setAlias(sprintf('swiftmailer.mailer.%s.transport', $name), sprintf('swiftmailer.mailer.%s.transport.%s', $name, $transport));
} else {
$container->setAlias(sprintf('swiftmailer.mailer.%s.transport', $name), sprintf('swiftmailer.mailer.transport.%s', $transport));
}
if (method_exists(Alias::class, 'setPrivate')) {
$container->getAlias(sprintf('swiftmailer.mailer.%s.transport', $name))->setPrivate(false);
}
$definitionDecorator = $this->createChildDefinition('swiftmailer.mailer.abstract');
$container
->setDefinition(sprintf('swiftmailer.mailer.%s', $name), $definitionDecorator)
->replaceArgument(0, new Reference(sprintf('swiftmailer.mailer.%s.transport', $name)))
;
}
protected function configureMailerSpool($name, array $mailer, ContainerBuilder $container, $transport, $isDefaultMailer = false)
{
if (isset($mailer['spool'])) {
$type = $mailer['spool']['type'];
if ('service' === $type) {
$container->setAlias(sprintf('swiftmailer.mailer.%s.spool.service', $name), $mailer['spool']['id']);
} else {
foreach (['path'] as $key) {
$container->setParameter(sprintf('swiftmailer.spool.%s.%s.%s', $name, $type, $key), $mailer['spool'][$key].'/'.$name);
}
}
$definitionDecorator = $this->createChildDefinition(sprintf('swiftmailer.spool.%s.abstract', $type));
if ('file' === $type) {
$container
->setDefinition(sprintf('swiftmailer.mailer.%s.spool.file', $name), $definitionDecorator)
->replaceArgument(0, sprintf('%%swiftmailer.spool.%s.file.path%%', $name))
;
} elseif ('memory' === $type) {
$container
->setDefinition(sprintf('swiftmailer.mailer.%s.spool.memory', $name), $definitionDecorator)
;
}
$container->setAlias(sprintf('swiftmailer.mailer.%s.spool', $name), sprintf('swiftmailer.mailer.%s.spool.%s', $name, $type));
$definitionDecorator = $this->createChildDefinition('swiftmailer.transport.spool.abstract');
$container
->setDefinition(sprintf('swiftmailer.mailer.%s.transport.spool', $name), $definitionDecorator)
->setArguments([
new Reference(sprintf('swiftmailer.mailer.%s.transport.eventdispatcher', $name)),
new Reference(sprintf('swiftmailer.mailer.%s.spool', $name)),
])
;
$container->setAlias(sprintf('swiftmailer.mailer.%s.transport.real', $name), $transport);
$container->getAlias(sprintf('swiftmailer.mailer.%s.transport.real', $name))->setPublic(true);
$container->setAlias(sprintf('swiftmailer.mailer.%s.transport', $name), sprintf('swiftmailer.mailer.%s.transport.spool', $name));
$container->setParameter(sprintf('swiftmailer.mailer.%s.spool.enabled', $name), true);
if (true === $isDefaultMailer) {
$container->setAlias('swiftmailer.spool', sprintf('swiftmailer.mailer.%s.spool', $name));
$container->setAlias('swiftmailer.transport.real', sprintf('swiftmailer.mailer.%s.transport.real', $name));
$container->setAlias('Swift_Spool', new Alias('swiftmailer.spool', false));
}
} else {
$container->setParameter(sprintf('swiftmailer.mailer.%s.spool.enabled', $name), false);
}
}
protected function configureMailerSenderAddress($name, array $mailer, ContainerBuilder $container, $isDefaultMailer = false)
{
if (isset($mailer['sender_address']) && $mailer['sender_address']) {
$container->setParameter(sprintf('swiftmailer.mailer.%s.sender_address', $name), $mailer['sender_address']);
$definitionDecorator = $this->createChildDefinition('swiftmailer.plugin.impersonate.abstract');
$container
->setDefinition(sprintf('swiftmailer.mailer.%s.plugin.impersonate', $name), $definitionDecorator)
->setArguments([
sprintf('%%swiftmailer.mailer.%s.sender_address%%', $name),
])
;
$container->getDefinition(sprintf('swiftmailer.mailer.%s.plugin.impersonate', $name))->addTag(sprintf('swiftmailer.%s.plugin', $name));
if (true === $isDefaultMailer) {
$container->setAlias('swiftmailer.plugin.impersonate', sprintf('swiftmailer.mailer.%s.plugin.impersonate', $name));
$container->setParameter('swiftmailer.sender_address', $container->getParameter(sprintf('swiftmailer.mailer.%s.sender_address', $name)));
}
} else {
$container->setParameter(sprintf('swiftmailer.mailer.%s.plugin.impersonate', $name), null);
}
}
protected function configureMailerAntiFlood($name, array $mailer, ContainerBuilder $container, $isDefaultMailer = false)
{
if (isset($mailer['antiflood'])) {
$container->setParameter(sprintf('swiftmailer.mailer.%s.antiflood.threshold', $name), $mailer['antiflood']['threshold']);
$container->setParameter(sprintf('swiftmailer.mailer.%s.antiflood.sleep', $name), $mailer['antiflood']['sleep']);
$definitionDecorator = $this->createChildDefinition('swiftmailer.plugin.antiflood.abstract');
$container
->setDefinition(sprintf('swiftmailer.mailer.%s.plugin.antiflood', $name), $definitionDecorator)
->setArguments([
sprintf('%%swiftmailer.mailer.%s.antiflood.threshold%%', $name),
sprintf('%%swiftmailer.mailer.%s.antiflood.sleep%%', $name),
])
;
$container->getDefinition(sprintf('swiftmailer.mailer.%s.plugin.antiflood', $name))->addTag(sprintf('swiftmailer.%s.plugin', $name));
if (true === $isDefaultMailer) {
$container->setAlias('swiftmailer.mailer.plugin.antiflood', sprintf('swiftmailer.mailer.%s.plugin.antiflood', $name));
}
}
}
protected function configureMailerDeliveryAddress($name, array $mailer, ContainerBuilder $container, $isDefaultMailer = false)
{
if (\count($mailer['delivery_addresses']) > 0) {
$container->setParameter(sprintf('swiftmailer.mailer.%s.single_address', $name), $mailer['delivery_addresses'][0]);
$container->setParameter(sprintf('swiftmailer.mailer.%s.delivery_addresses', $name), $mailer['delivery_addresses']);
$container->setParameter(sprintf('swiftmailer.mailer.%s.delivery_whitelist', $name), $mailer['delivery_whitelist']);
$definitionDecorator = $this->createChildDefinition('swiftmailer.plugin.redirecting.abstract');
$container
->setDefinition(sprintf('swiftmailer.mailer.%s.plugin.redirecting', $name), $definitionDecorator)
->setArguments([
sprintf('%%swiftmailer.mailer.%s.delivery_addresses%%', $name),
sprintf('%%swiftmailer.mailer.%s.delivery_whitelist%%', $name),
])
;
$container->getDefinition(sprintf('swiftmailer.mailer.%s.plugin.redirecting', $name))->addTag(sprintf('swiftmailer.%s.plugin', $name));
if (true === $isDefaultMailer) {
$container->setAlias('swiftmailer.plugin.redirecting', sprintf('swiftmailer.mailer.%s.plugin.redirecting', $name));
}
} else {
$container->setParameter(sprintf('swiftmailer.mailer.%s.single_address', $name), null);
}
}
protected function configureMailerLogging($name, array $mailer, ContainerBuilder $container, $isDefaultMailer = false)
{
if ($mailer['logging']) {
$container->getDefinition('swiftmailer.plugin.messagelogger.abstract');
$definitionDecorator = $this->createChildDefinition('swiftmailer.plugin.messagelogger.abstract');
$container
->setDefinition(sprintf('swiftmailer.mailer.%s.plugin.messagelogger', $name), $definitionDecorator)
;
$container->getDefinition(sprintf('swiftmailer.mailer.%s.plugin.messagelogger', $name))
->setPublic(true)
->addTag(sprintf('swiftmailer.%s.plugin', $name));
if (true === $isDefaultMailer) {
$container->setAlias('swiftmailer.plugin.messagelogger', sprintf('swiftmailer.mailer.%s.plugin.messagelogger', $name));
}
}
}
/**
* Returns the base path for the XSD files.
*
* @return string The XSD base path
*/
public function getXsdValidationBasePath()
{
return __DIR__.'/../Resources/config/schema';
}
/**
* Returns the namespace to be used for this extension (XML namespace).
*
* @return string The XML namespace
*/
public function getNamespace()
{
return 'http://symfony.com/schema/dic/swiftmailer';
}
public function getConfiguration(array $config, ContainerBuilder $container)
{
return new Configuration($container->getParameter('kernel.debug'));
}
private function createChildDefinition($id)
{
if (class_exists('Symfony\Component\DependencyInjection\ChildDefinition')) {
return new ChildDefinition($id);
}
return new DefinitionDecorator($id);
}
}

View File

@@ -0,0 +1,159 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\SwiftmailerBundle\DependencyInjection;
use Symfony\Component\Routing\RequestContext;
/**
* Factory to create a \Swift_Transport object.
*
* @author Romain Gautier <mail@romain.sh>
*/
class SwiftmailerTransportFactory
{
/**
* @param array $options
* @param RequestContext|null $requestContext
* @param \Swift_Events_EventDispatcher $eventDispatcher
*
* @return \Swift_Transport
*
* @throws \InvalidArgumentException if the scheme is not a built-in Swiftmailer transport
*/
public static function createTransport(array $options, RequestContext $requestContext = null, \Swift_Events_EventDispatcher $eventDispatcher)
{
$options = static::resolveOptions($options);
self::validateConfig($options);
if ('smtp' === $options['transport']) {
$smtpAuthHandler = new \Swift_Transport_Esmtp_AuthHandler([
new \Swift_Transport_Esmtp_Auth_CramMd5Authenticator(),
new \Swift_Transport_Esmtp_Auth_LoginAuthenticator(),
new \Swift_Transport_Esmtp_Auth_PlainAuthenticator(),
new \Swift_Transport_Esmtp_Auth_NTLMAuthenticator(),
]);
$smtpAuthHandler->setUsername($options['username']);
$smtpAuthHandler->setPassword($options['password']);
$smtpAuthHandler->setAuthMode($options['auth_mode']);
$transport = new \Swift_Transport_EsmtpTransport(
new \Swift_Transport_StreamBuffer(new \Swift_StreamFilters_StringReplacementFilterFactory()),
[$smtpAuthHandler],
$eventDispatcher
);
$transport->setHost($options['host']);
$transport->setPort($options['port']);
$transport->setEncryption($options['encryption']);
$transport->setTimeout($options['timeout']);
$transport->setSourceIp($options['source_ip']);
$smtpTransportConfigurator = new SmtpTransportConfigurator($options['local_domain'], $requestContext);
$smtpTransportConfigurator->configure($transport);
} elseif ('sendmail' === $options['transport']) {
$transport = new \Swift_Transport_SendmailTransport(
new \Swift_Transport_StreamBuffer(new \Swift_StreamFilters_StringReplacementFilterFactory()),
$eventDispatcher
);
$transport->setCommand($options['command']);
$smtpTransportConfigurator = new SmtpTransportConfigurator($options['local_domain'], $requestContext);
$smtpTransportConfigurator->configure($transport);
} elseif ('null' === $options['transport']) {
$transport = new \Swift_Transport_NullTransport($eventDispatcher);
} else {
throw new \InvalidArgumentException(sprintf('Not a built-in Swiftmailer transport: %s.', $options['transport']));
}
return $transport;
}
/**
* @param array $options
*
* @return array options
*/
public static function resolveOptions(array $options)
{
$options += [
'transport' => null,
'username' => null,
'password' => null,
'host' => null,
'port' => null,
'timeout' => null,
'source_ip' => null,
'local_domain' => null,
'encryption' => null,
'auth_mode' => null,
'command' => null,
];
if (isset($options['url'])) {
if (false === $parts = parse_url($options['url'])) {
throw new \InvalidArgumentException(sprintf('The Swiftmailer URL "%s" is not a valid.', $options['url']));
}
if (isset($parts['scheme'])) {
$options['transport'] = $parts['scheme'];
}
if (isset($parts['user'])) {
$options['username'] = rawurldecode($parts['user']);
}
if (isset($parts['pass'])) {
$options['password'] = rawurldecode($parts['pass']);
}
if (isset($parts['host'])) {
$options['host'] = rawurldecode($parts['host']);
}
if (isset($parts['port'])) {
$options['port'] = $parts['port'];
}
if (isset($parts['query'])) {
parse_str($parts['query'], $query);
foreach ($options as $key => $value) {
if (isset($query[$key]) && '' != $query[$key]) {
$options[$key] = $query[$key];
}
}
}
}
if (!isset($options['transport'])) {
$options['transport'] = 'null';
} elseif ('gmail' === $options['transport']) {
$options['encryption'] = 'ssl';
$options['auth_mode'] = 'login';
$options['host'] = 'smtp.gmail.com';
$options['transport'] = 'smtp';
}
if (!isset($options['port'])) {
$options['port'] = 'ssl' === $options['encryption'] ? 465 : 25;
}
return $options;
}
/**
* @throws \InvalidArgumentException if the encryption is not valid
*/
public static function validateConfig($options)
{
if (!\in_array($options['encryption'], ['tls', 'ssl', null], true)) {
throw new \InvalidArgumentException(sprintf('The %s encryption is not supported', $options['encryption']));
}
if (!\in_array($options['auth_mode'], ['plain', 'login', 'cram-md5', 'ntlm', null], true)) {
throw new \InvalidArgumentException(sprintf('The %s authentication mode is not supported', $options['auth_mode']));
}
}
}

View File

@@ -0,0 +1,93 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\SwiftmailerBundle\EventListener;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Sends emails for the memory spool.
*
* Emails are sent on the kernel.terminate event.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class EmailSenderListener implements EventSubscriberInterface
{
private $container;
private $logger;
private $wasExceptionThrown = false;
public function __construct(ContainerInterface $container, LoggerInterface $logger = null)
{
$this->container = $container;
$this->logger = $logger;
}
public function onException()
{
$this->wasExceptionThrown = true;
}
public function onTerminate()
{
if (!$this->container->has('mailer') || $this->wasExceptionThrown) {
return;
}
$mailers = array_keys($this->container->getParameter('swiftmailer.mailers'));
foreach ($mailers as $name) {
if (method_exists($this->container, 'initialized') ? $this->container->initialized(sprintf('swiftmailer.mailer.%s', $name)) : true) {
if ($this->container->getParameter(sprintf('swiftmailer.mailer.%s.spool.enabled', $name))) {
$mailer = $this->container->get(sprintf('swiftmailer.mailer.%s', $name));
$transport = $mailer->getTransport();
if ($transport instanceof \Swift_Transport_SpoolTransport) {
$spool = $transport->getSpool();
if ($spool instanceof \Swift_MemorySpool) {
try {
$spool->flushQueue($this->container->get(sprintf('swiftmailer.mailer.%s.transport.real', $name)));
} catch (\Swift_TransportException $exception) {
if (null !== $this->logger) {
$this->logger->error(sprintf('Exception occurred while flushing email queue: %s', $exception->getMessage()));
}
}
}
}
}
}
}
}
public static function getSubscribedEvents()
{
$listeners = [
KernelEvents::EXCEPTION => 'onException',
KernelEvents::TERMINATE => 'onTerminate',
];
if (class_exists('Symfony\Component\Console\ConsoleEvents')) {
$listeners[class_exists('Symfony\Component\Console\Event\ConsoleErrorEvent') ? ConsoleEvents::ERROR : ConsoleEvents::EXCEPTION] = 'onException';
$listeners[ConsoleEvents::TERMINATE] = 'onTerminate';
}
return $listeners;
}
public function reset()
{
$this->wasExceptionThrown = false;
}
}

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="swiftmailer.command.debug" class="Symfony\Bundle\SwiftmailerBundle\Command\DebugCommand">
<tag name="console.command" command="debug:swiftmailer" />
</service>
<service id="swiftmailer.command.new_email" class="Symfony\Bundle\SwiftmailerBundle\Command\NewEmailCommand">
<tag name="console.command" command="swiftmailer:email:send" />
</service>
<service id="swiftmailer.command.send_email" class="Symfony\Bundle\SwiftmailerBundle\Command\SendEmailCommand">
<tag name="console.command" command="swiftmailer:spool:send" />
</service>
</services>
</container>

View File

@@ -0,0 +1,106 @@
<?xml version="1.0" encoding="UTF-8" ?>
<xsd:schema xmlns="http://symfony.com/schema/dic/swiftmailer"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://symfony.com/schema/dic/swiftmailer"
elementFormDefault="qualified">
<xsd:element name="config" type="config" />
<xsd:complexType name="config">
<xsd:sequence>
<xsd:element name="mailer" type="mailer" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="stream-options" type="stream-options" minOccurs="0" maxOccurs="1" />
<xsd:element name="antiflood" type="antiflood" minOccurs="0" maxOccurs="1" />
<xsd:element name="spool" type="spool" minOccurs="0" maxOccurs="1" />
<xsd:element name="delivery-whitelist-pattern" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="delivery-address" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="default-mailer" type="xsd:string" />
<xsd:attributeGroup ref="mailer-config" />
</xsd:complexType>
<xsd:complexType name="stream-options">
<xsd:choice minOccurs="1" maxOccurs="unbounded">
<xsd:element name="stream-option" type="stream-option" />
</xsd:choice>
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
<xsd:complexType name="stream-option" mixed="true">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="stream-option" type="stream-option" />
</xsd:choice>
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
<xsd:attributeGroup name="mailer-config">
<xsd:attribute name="username" type="xsd:string" />
<xsd:attribute name="password" type="xsd:string" />
<xsd:attribute name="host" type="xsd:string" />
<xsd:attribute name="port" type="xsd:string" />
<xsd:attribute name="encryption" type="encryption" />
<xsd:attribute name="auth-mode" type="auth_mode" />
<xsd:attribute name="timeout" type="xsd:string"/>
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="source-ip" type="xsd:string"/>
<xsd:attribute name="local-domain" type="xsd:string"/>
<xsd:attribute name="transport" type="xsd:string" />
<xsd:attribute name="logging" type="xsd:string" />
<xsd:attribute name="disable-delivery" type="xsd:boolean" />
<xsd:attribute name="sender-address" type="xsd:boolean" />
<xsd:attribute name="url" type="xsd:string" />
<xsd:attribute name="command" type="xsd:string" />
</xsd:attributeGroup>
<xsd:complexType name="mailer">
<xsd:sequence>
<xsd:element name="stream-options" type="stream-options" minOccurs="0" maxOccurs="1" />
<xsd:element name="antiflood" type="antiflood" minOccurs="0" maxOccurs="1" />
<xsd:element name="spool" type="spool" minOccurs="0" maxOccurs="1" />
<xsd:element name="delivery-whitelist-pattern" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="delivery-address" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attributeGroup ref="mailer-config" />
</xsd:complexType>
<xsd:complexType name="spool">
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="path" type="xsd:string" />
<xsd:attribute name="id" type="xsd:string" />
</xsd:complexType>
<xsd:complexType name="antiflood">
<xsd:attribute name="threshold" type="xsd:string" />
<xsd:attribute name="sleep" type="xsd:string" />
</xsd:complexType>
<xsd:simpleType name="encryption">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="tls" />
<xsd:enumeration value="ssl" />
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="auth_mode">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="plain" />
<xsd:enumeration value="login" />
<xsd:enumeration value="cram-md5" />
<xsd:enumeration value="ntlm" />
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="delivery_strategy">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="realtime" />
<xsd:enumeration value="spool" />
<xsd:enumeration value="single-address" />
<xsd:enumeration value="none" />
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>

View File

@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="swiftmailer.mailer.abstract" class="Swift_Mailer" public="true" abstract="true">
<argument type="service" id="swiftmailer.transport" />
</service>
<service id="swiftmailer.transport.smtp.configurator.abstract" class="Symfony\Bundle\SwiftmailerBundle\DependencyInjection\SmtpTransportConfigurator" abstract="true" public="false" />
<service id="swiftmailer.transport.sendmail.abstract" class="Swift_Transport_SendmailTransport" abstract="true" public="false" />
<service id="swiftmailer.transport.null.abstract" class="Swift_Transport_NullTransport" abstract="true" public="false">
</service>
<service id="swiftmailer.transport.failover" class="Swift_Transport_FailoverTransport" public="false" />
<service id="swiftmailer.transport.buffer.abstract" class="Swift_Transport_StreamBuffer" abstract="true" public="false">
<argument type="service" id="swiftmailer.transport.replacementfactory" />
</service>
<service id="swiftmailer.transport.authhandler.abstract" class="Swift_Transport_Esmtp_AuthHandler" abstract="true" public="false">
<argument type="collection">
<argument type="service"><service class="Swift_Transport_Esmtp_Auth_CramMd5Authenticator" public="false" /></argument>
<argument type="service"><service class="Swift_Transport_Esmtp_Auth_LoginAuthenticator" public="false" /></argument>
<argument type="service"><service class="Swift_Transport_Esmtp_Auth_PlainAuthenticator" public="false" /></argument>
<argument type="service"><service class="Swift_Transport_Esmtp_Auth_NTLMAuthenticator" public="false" /></argument>
</argument>
</service>
<service id="swiftmailer.transport.eventdispatcher.abstract" class="Swift_Events_SimpleEventDispatcher" abstract="true" public="false" />
<service id="swiftmailer.transport.replacementfactory" class="Swift_StreamFilters_StringReplacementFilterFactory" public="false" />
<service id="swiftmailer.plugin.redirecting.abstract" class="Swift_Plugins_RedirectingPlugin" abstract="true" public="false" />
<service id="swiftmailer.plugin.antiflood.abstract" class="Swift_Plugins_AntiFloodPlugin" abstract="true" public="false" />
<service id="swiftmailer.plugin.impersonate.abstract" class="Swift_Plugins_ImpersonatePlugin" abstract="true" public="false" />
<service id="swiftmailer.plugin.messagelogger.abstract" class="Swift_Plugins_MessageLogger" abstract="true" />
<service id="swiftmailer.transport.smtp.abstract" class="Swift_Transport_EsmtpTransport" public="false" abstract="true" />
<service id="swiftmailer.transport.spool.abstract" class="Swift_Transport_SpoolTransport" public="false" abstract="true" />
<service id="swiftmailer.spool.file.abstract" class="Swift_FileSpool" public="false" abstract="true">
<argument>%kernel.root_dir%/../data/swiftmailer/spool</argument>
</service>
<service id="swiftmailer.spool.memory.abstract" class="Swift_MemorySpool" public="false" abstract="true" />
<service id="swiftmailer.email_sender.listener" class="Symfony\Bundle\SwiftmailerBundle\EventListener\EmailSenderListener">
<tag name="kernel.event_subscriber" />
<tag name="kernel.reset" method="reset" />
<argument type="service" id="service_container" />
<argument type="service" id="logger" on-invalid="null" />
</service>
<service id="swiftmailer.data_collector" class="Symfony\Bundle\SwiftmailerBundle\DataCollector\MessageDataCollector" public="false">
<argument type="service" id="service_container" />
</service>
</services>
</container>

View File

@@ -0,0 +1,19 @@
Copyright (c) 2004-2018 Fabien Potencier
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,3 @@
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" height="24" viewBox="0 0 24 24" enable-background="new 0 0 24 24" xml:space="preserve">
<path fill="#AAAAAA" d="M22,4.9C22,3.9,21.1,3,20.1,3H3.9C2.9,3,2,3.9,2,4.9v13.1C2,19.1,2.9,20,3.9,20h16.1c1.1,0,1.9-0.9,1.9-1.9V4.9z M8.3,14.1l-3.1,3.1c-0.2,0.2-0.5,0.3-0.7,0.3S4,17.4,3.8,17.2c-0.4-0.4-0.4-1,0-1.4l3.1-3.1c0.4-0.4,1-0.4,1.4,0S8.7,13.7,8.3,14.1z M20.4,17.2c-0.2,0.2-0.5,0.3-0.7,0.3s-0.5-0.1-0.7-0.3l-3.1-3.1c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l3.1,3.1C20.8,16.2,20.8,16.8,20.4,17.2z M20.4,7.2l-7.6,7.6c-0.2,0.2-0.5,0.3-0.7,0.3s-0.5-0.1-0.7-0.3L3.8,7.2c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6.9,6.9L19,5.8c0.4-0.4,1-0.4,1.4,0S20.8,6.8,20.4,7.2z"/>
</svg>

After

Width:  |  Height:  |  Size: 723 B

View File

@@ -0,0 +1,271 @@
{% extends '@WebProfiler/Profiler/layout.html.twig' %}
{% block toolbar %}
{% set profiler_markup_version = profiler_markup_version|default(1) %}
{% if collector.messageCount %}
{% set icon %}
{% if profiler_markup_version == 1 %}
<img width="23" height="28" alt="Swiftmailer" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABcAAAAcCAYAAACK7SRjAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6N0NEOTU1MjM0OThFMTFFMDg3NzJBNTE2ODgwQzMxMzQiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6N0NEOTU1MjQ0OThFMTFFMDg3NzJBNTE2ODgwQzMxMzQiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDoxMEQ5OTQ5QzQ5OEMxMUUwODc3MkE1MTY4ODBDMzEzNCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo3Q0Q5NTUyMjQ5OEUxMUUwODc3MkE1MTY4ODBDMzEzNCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PpkRnSAAAAJ0SURBVHjaYvz//z8DrQATAw3BqOFYAaO9vT1FBhw4cGCAXA5MipxBQUHT3r17l0AVAxkZ/wkLC89as2ZNIcjlYkALXKnlWqBZTH/+/PEDmQsynLW/v3+NoaHhN2oYDjJn8uTJK4BMNpDhPwsLCwOKiop2+fn5vafEYC8vrw8gc/Lz8wOB3B8gw/nev38vn5WV5eTg4LA/Ly/vESsrK2npmYmJITU19SnQ8L0gc4DxpwgyF2S4EEjB58+f+crLy31YWFjOt7S0XBYUFPxHjMEcHBz/6+rqboqJiZ0qKSnxBpkDlRICGc4MU/j792+2CRMm+L18+fLSxIkTDykoKPzBZ7CoqOi/np6eE8rKylvb29v9fvz4wYEkzYKRzjk5OX/LyMjcnDRpEkjjdisrK6wRraOj8wvokAMLFy788ejRoxcaGhrPCWai4ODgB8DUE3/mzBknYMToASNoMzAfvEVW4+Tk9LmhoWFbTU2NwunTpx2BjiiMjo6+hm4WCzJHUlLyz+vXrxkfP36sDOI/ffpUPikpibe7u3sLsJjQW7VqlSrQxe+Avjmanp7u9PbtWzGQOmCCkARmmu/m5uYfT548yY/V5UpKSl+2b9+uiiz26dMnIWBSDTp27NgdYGrYCIzwE7m5uR4wg2Hg/PnzSsDI/QlKOcjZ3wGUBLm5uf+DwLdv38gub4AG/xcSEvr35s0bZmCB5sgCE/z69SsjyDJKMtG/f/8YQQYD8wkoGf8H51AbG5sH1CpbQBnQ09PzBiiHgoIFFHlBQGwLxLxUMP8dqJgH4k3gIhfIkAKVYkDMTmmhCHIxEL8A4peMo02L4WU4QIABANxZAoDIQDv3AAAAAElFTkSuQmCC" />
<span class="sf-toolbar-status">{{ collector.messageCount }}</span>
{% else %}
{{ include('@Swiftmailer/Collector/icon.svg') }}
<span class="sf-toolbar-value">{{ collector.messageCount }}</span>
{% endif %}
{% endset %}
{% set text %}
<div class="sf-toolbar-info-piece">
<b>Sent messages</b>
<span class="sf-toolbar-status">{{ collector.messageCount }}</span>
</div>
{% if profiler_markup_version == 1 %}
{% for name in collector.mailers %}
<div class="sf-toolbar-info-piece">
<b>{{ name }}</b>
<span>{{ collector.messageCount(name) }}</span>
</div>
<div class="sf-toolbar-info-piece">
<b>Is spooled?</b>
<span>{{ collector.isSpool(name) ? 'yes' : 'no' }}</span>
</div>
{% if not loop.first %}
<hr>
{% endif %}
{% endfor %}
{% else %}
{% for name in collector.mailers %}
<div class="sf-toolbar-info-piece">
<b>{{ name }} mailer</b>
<span class="sf-toolbar-status">{{ collector.messageCount(name)|default(0) }}</span>
&nbsp; (<small>{{ collector.isSpool(name) ? 'spooled' : 'sent' }}</small>)
</div>
{% endfor %}
{% endif %}
{% endset %}
{{ include('@WebProfiler/Profiler/toolbar_item.html.twig', { 'link': profiler_url }) }}
{% endif %}
{% endblock %}
{% block head %}
{{ parent() }}
<style type="text/css">
/* utility classes */
.m-t-0 { margin-top: 0 !important; }
.m-t-10 { margin-top: 10px !important; }
/* basic grid */
.row {
display: flex;
flex-wrap: wrap;
margin-right: -15px;
margin-left: -15px;
}
.col {
flex-basis: 0;
flex-grow: 1;
max-width: 100%;
position: relative;
width: 100%;
min-height: 1px;
padding-right: 15px;
padding-left: 15px;
}
.col-4 {
flex: 0 0 33.333333%;
max-width: 33.333333%;
}
/* small tabs */
.sf-tabs-sm .tab-navigation li {
font-size: 14px;
padding: .3em .5em;
}
</style>
{% endblock %}
{% block menu %}
{% set profiler_markup_version = profiler_markup_version|default(1) %}
<span class="label {{ collector.messageCount ? '' : 'disabled' }}">
{% if profiler_markup_version == 1 %}
<span class="icon"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACoAAAAeCAYAAABaKIzgAAAEDElEQVR42u2XWUhUURjHy6isILAebO+lonpJ8qkHM3NFVFxAUVFM0RSXUKnwwdAQn3wQE0MyA1MwBEUQcxvHZTTTHNcZl9DUGqd0JBOzcsZ7+n8XJ0Z0GueOVwg68GfmnLn3O7/7Lee7s4cxZpHq6uos0bb3+Q+6DrG3u7v7RHt7u3tbW9uD5ubm8qamJnlDQ4NKIpG8HhkZOU3X7BYoD9Tb22sjk8mcWltb70ul0pcAegugBfzOjKmzs/MJ7j0kCujw8PBhADkAKAVAz+EZGYA+08bmCN79qdFo7sGmjaWg+wgIIUtoaWl5CqDmxsbGj7SJpYK3uYWFBRnsDmEfWyGg+zs6OkIBNEoGxVB9fT2bnZ1VIHff03xmZuY29rUyF9QWT6sWC5I0OTk5rVAo3unnSqXyEfa1Nhf0Kp5UKRYk8lsDD0oM1/r6+l5h32Pmgl5UqVTP5ubmlEgBHRlCobC8vDzm5eXFHB0dRZWzs/OXsLCwu5SCpkBPo4DaMVRI9rbp6Wk1vnP+/v5kaFfk4eGhAcdJU6Dn+/v7q9aTnpPL5YqVlRV5eXm5Fk+7Gx7lCgsL68Fx2RToWST7C8McQgr8yMrKWkLu/hQz/LDNIZojycnJb8BxwRTocYT8oSEoQs8bSkpK0k5MTGgiIiK4nYYMDg7mcBLIo6OjP9Ec44opUGvIF+eoTg/a1dX1x2BISMgyKncpLS1tbacgU1NT2djY2HxoaOi8fg3jhilQK+gmQvBVD4qQbzDs4+ND6bBWUFCgtRQyJyeHdwSKdcODY9zaTgu9jheMcWOgJFdXV1ZZWclqamp0bm5uQoqGVVRUrFHBuru782tCQC+hW0j/BkpCPlGXIY9wfn5+5hQN5T3dS+cz5btg0DNTU1NFpkBra2tZaWkpy8jIYOPj4ywmJmY7RcMGBwdZZmYmKykpoa7ELPGozeLiYrIetKenZ5OhuLg4ft3T05OfJyQk8LDp6el/LRq6JiUlheb8vXgzY7m5uYJBD0LeeDnRApQ8sKloqK3GxsZuWEPrYzhiWHFx8ZZFMzo6yiIjIw1DTTZ+qNXqMRcXF0GgVpADKltDoCisDcbj4+NZfn7+ll5D9fKeprYbFRXFwsPDWVVV1SodPwEBAVueEtnZ2QNIhTkhoKRrAxhb5WhRURFzcnIyGmIcX9rq6uoPq6urAzqdrresrGwIHtMZux62OOT6AD4FgZ5bXl5+DMhv6P16j/KhCwoK2vHO5O3t/SsxMfG7ENAjkAOUBUkMvMVDiiFKDSGge6Gj0CUoGmffpvwSEfg7dUch/0LtkWcdvr6+a2JDBgYG6tDt6DXPTgjoKegOVAo1QVKR1AgVQ8GQrRDQA+uw9ushuSWSyLYdQRr7K/JP6DcTwr8i7Fj8pwAAAABJRU5ErkJggg==" alt="Swiftmailer" /></span>
{% else %}
<span class="icon">{{ include('@Swiftmailer/Collector/icon.svg') }}</span>
{% endif %}
<strong>E-mails</strong>
{% if collector.messageCount > 0 %}
<span class="count">
<span>{{ collector.messageCount }}</span>
</span>
{% endif %}
</span>
{% endblock %}
{% block panel %}
{% set profiler_markup_version = profiler_markup_version|default(1) %}
{% if profiler_markup_version == 1 %}
<style>
h3 { margin-top: 2em; }
h3 span { color: #999; font-weight: normal; }
h3 small { color: #999; }
h4 { font-size: 14px; font-weight: bold; }
.card { background: #F5F5F5; margin: .5em 0 1em; padding: .5em; }
.card .label { display: block; font-size: 13px; font-weight: bold; margin-bottom: .5em; }
.card .card-block { margin-bottom: 1em; }
</style>
{% endif %}
<h2>E-mails</h2>
{% if not collector.mailers %}
<div class="empty">
<p>No e-mail messages were sent.</p>
</div>
{% endif %}
{% if profiler_markup_version == 1 or collector.mailers|length > 1 %}
<table>
<thead>
<tr>
<th scope="col">Mailer Name</th>
<th scope="col">Num. of messages</th>
<th scope="col">Messages status</th>
<th scope="col">Notes</th>
</tr>
</thead>
<tbody>
{% for name in collector.mailers %}
<tr>
<th class="font-normal">{{ name }}</th>
<td class="font-normal">{{ collector.messageCount(name) }}</td>
<td class="font-normal">{{ collector.isSpool(name) ? 'spooled' : 'sent' }}</td>
<td class="font-normal">{{ collector.isDefaultMailer(name) ? 'This is the default mailer' }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<div class="metrics">
{% for name in collector.mailers %}
<div class="metric">
<span class="value">{{ collector.messageCount(name) }}</span>
<span class="label">{{ collector.isSpool(name) ? 'spooled' : 'sent' }} {{ collector.messageCount(name) == 1 ? 'message' : 'messages' }}</span>
</div>
{% endfor %}
</div>
{% endif %}
{% for name in collector.mailers %}
{% if collector.mailers|length > 1 %}
<h3>
{{ name }} <span>mailer</span>
<small>{{ collector.isDefaultMailer(name) ? '(default app mailer)' }}</small>
</h3>
{% endif %}
{% if not collector.messages(name) %}
<div class="empty">
<p>No e-mail messages were sent.</p>
</div>
{% else %}
{% for message in collector.messages(name) %}
{% if loop.length > 1 %}
<h4>E-mail #{{ loop.index }} details</h4>
{% else %}
<h4>E-mail details</h4>
{% endif %}
<div class="card">
<div class="card-block">
<span class="label">Subject</span>
<h2 class="m-t-10">{{ message.headers.get('subject').value ?? '(empty)' }}</h2>
</div>
<div class="card-block">
<div class="row">
<div class="col col-4">
<span class="label">From</span>
<pre class="prewrap">{{ (message.headers.get('from').toString ?? '(empty)')|replace({'From:': ''}) }}</pre>
<span class="label">To</span>
<pre class="prewrap">{{ (message.headers.get('to').toString ?? '(empty)')|replace({'To:': ''}) }}</pre>
</div>
<div class="col">
<span class="label">Headers</span>
<pre class="prewrap">{% for header in message.headers.all if (header.fieldName ?? '') not in ['Subject', 'From', 'To'] %}
{{- header -}}
{% endfor %}</pre>
</div>
</div>
</div>
<div class="card-block">
<div class="sf-tabs sf-tabs-sm">
<div class="tab">
<h3 class="tab-title">Raw content</h3>
<div class="tab-content">
<pre class="prewrap" style="max-height: 600px">
{%- if message.charset is defined and message.charset %}
{{- message.body|convert_encoding('UTF-8', message.charset) }}
{%- else %}
{{- message.body }}
{%- endif -%}
</pre>
</div>
</div>
<div class="tab">
<h3 class="tab-title">Rendered content</h3>
<div class="tab-content">
<iframe class="full-width" style="min-height: 600px" src="data:{{ message.__contentType }};base64,{{ message.__base64EncodedBody }}"></iframe>
</div>
</div>
</div>
</div>
{% for messagePart in message.children if messagePart.contentType in ['text/plain', 'text/html'] %}
<div class="card-block">
<span class="label">Alternative part ({{ messagePart.contentType }})</span>
<pre class="prewrap">
{%- if messagePart.charset is defined and messagePart.charset %}
{{- messagePart.body|convert_encoding('UTF-8', messagePart.charset) }}
{%- else %}
{{- messagePart.body }}
{%- endif -%}
</pre>
</div>
{% endfor %}
{% set attachments = collector.extractAttachments(message) %}
{% if attachments %}
<div class="card-block">
<span class="label">
{% if attachments|length > 1 %}
{{ attachments|length }} Attachments
{% else %}
1 Attachment
{% endif %}
</span>
<ol>
{% for attachment in attachments %}
<li>
Filename:
{{ attachment.filename }}
</li>
{% endfor %}
</ol>
</div>
{% endif %}
</div>
{% endfor %}
{% endif %}
{% endfor %}
{% endblock %}

View File

@@ -0,0 +1,43 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\SwiftmailerBundle;
use Symfony\Bundle\SwiftmailerBundle\DependencyInjection\Compiler\EnsureNoHotPathPass;
use Symfony\Component\Console\Application;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Bundle\SwiftmailerBundle\DependencyInjection\Compiler\RegisterPluginsPass;
/**
* @author Fabien Potencier <fabien@symfony.com>
*/
class SwiftmailerBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
parent::build($container);
$container->addCompilerPass(new RegisterPluginsPass());
// Older supported versions of Symfony don't have the parent class that EnsureNoHotPathPass extends from.
// But they don't have the hot_path optimization either, so not being able to register our pass is not an issue.
if (class_exists('Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass')) {
$container->addCompilerPass(new EnsureNoHotPathPass(), PassConfig::TYPE_AFTER_REMOVING);
}
}
public function registerCommands(Application $application)
{
// noop
}
}