Initial commit

This commit is contained in:
2019-11-20 07:44:43 +01:00
commit 5bf49c4a81
41188 changed files with 5459177 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
* 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,135 @@
<?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\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Helper\Table;
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 ContainerAwareCommand
{
/** @var SymfonyStyle */
private $io;
/**
* @see Command
*/
protected function configure()
{
$this
->setName('debug:swiftmailer')
->setAliases(array(
'swiftmailer:debug',
))
->setDefinition(array(
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 = array('Name', 'Transport', 'Spool', 'Delivery', 'Single Address');
$tableRows = array();
$mailers = $this->getContainer()->getParameter('swiftmailer.mailers');
foreach ($mailers as $name => $mailer) {
$mailer = $this->getContainer()->get($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[] = array($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 = array('Property', 'Value');
$tableRows = array();
$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[] = array('Name', $name);
$tableRows[] = array('Service', $service);
$tableRows[] = array('Class', get_class($mailer));
$tableRows[] = array('Transport', sprintf('%s (%s)', sprintf('swiftmailer.mailer.%s.transport.name', $name), get_class($transport)));
$tableRows[] = array('Spool', $spool);
if ($this->getContainer()->hasParameter(sprintf('swiftmailer.spool.%s.file.path', $name))) {
$tableRows[] = array('Spool file', $this->getContainer()->getParameter(sprintf('swiftmailer.spool.%s.file.path', $name)));
}
$tableRows[] = array('Delivery', $delivery);
$tableRows[] = array('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,139 @@
<?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\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
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 ContainerAwareCommand
{
/** @var SymfonyStyle */
private $io;
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('swiftmailer:email:send')
->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 ($content === false) {
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 ($value === null) {
$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,113 @@
<?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\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
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 ContainerAwareCommand
{
/** @var SymfonyStyle */
private $io;
protected function configure()
{
$this
->setName('swiftmailer:spool:send')
->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, OutputInterface $output)
{
if ($transport instanceof \Swift_Transport_SpoolTransport) {
$spool = $transport->getSpool();
if ($spool instanceof \Swift_ConfigurableSpool) {
$spool->setMessageLimit($input->getOption('message-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,177 @@
<?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] = array(
'messages' => $logger->getMessages(),
'messageCount' => $logger->countMessages(),
'isSpool' => $this->container->getParameter(sprintf('swiftmailer.mailer.%s.spool.enabled', $name)),
);
$this->data['messageCount'] += $logger->countMessages();
}
}
}
}
/**
* {@inheritdoc}
*/
public function reset()
{
$this->data = array(
'mailer' => array(),
'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 (is_null($name)) {
return $this->data['messageCount'];
} elseif ($data = $this->getMailerData($name)) {
return $data['messageCount'];
}
return;
}
/**
* Returns the messages of a mailer.
*
* @return array The messages.
*/
public function getMessages($name = 'default')
{
if ($data = $this->getMailerData($name)) {
return $data['messages'];
}
return array();
}
/**
* 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 = array();
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,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', array(new Reference($id)));
}
}
}
/**
* @return array
*/
private function findSortedByPriorityTaggedServiceIds(ContainerBuilder $container, $tag)
{
$taggedServices = $container->findTaggedServiceIds($tag);
uasort(
$taggedServices,
function ($tagA, $tagB) {
$priorityTagA = isset($tagA[0]['priority']) ? $tagA[0]['priority'] : 0;
$priorityTagB = isset($tagB[0]['priority']) ? $tagB[0]['priority'] : 0;
return $priorityTagA - $priorityTagB;
}
);
return $taggedServices;
}
}

View File

@@ -0,0 +1,197 @@
<?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 = (Boolean) $debug;
}
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('swiftmailer');
$rootNode
->beforeNormalization()
->ifTrue(function ($v) { return is_array($v) && !array_key_exists('mailers', $v) && !array_key_exists('mailer', $v); })
->then(function ($v) {
$mailer = array();
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'] = array($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();
$node = $treeBuilder->root('mailers');
$node
->requiresAtLeastOneElement()
->useAttributeAsKey('name')
->prototype('array')
// BC layer for "delivery_address: null" (the case of a string goes through the XML normalization too)
->beforeNormalization()
->ifTrue(function ($v) {
return is_array($v) && array_key_exists('delivery_address', $v) && null === $v['delivery_address'];
})
->then(function ($v) {
@trigger_error('The swiftmailer.delivery_address configuration key is deprecated since version 2.3.10 and will be removed in 3.0. Use the swiftmailer.delivery_addresses configuration key instead (or remove the empty setting)', E_USER_DEPRECATED);
unset($v['delivery_address']);
if (!isset($v['delivery_addresses'])) {
$v['delivery_addresses'] = array();
}
return $v;
})
->end()
->children()
->scalarNode('url')->defaultNull()->end()
->scalarNode('transport')->defaultValue('smtp')->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($array);
}
$n = array();
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()
->validate()
->ifNotInArray(array('tls', 'ssl', null))
->thenInvalid('The %s encryption is not supported')
->end()
->end()
->scalarNode('auth_mode')
->defaultNull()
->validate()
->ifNotInArray(array('plain', 'login', 'cram-md5', null))
->thenInvalid('The %s authentication mode is not supported')
->end()
->end()
->scalarNode('sender_address')->end()
->arrayNode('delivery_addresses')
->performNoDeepMerging()
->beforeNormalization()
->ifArray()
->then(function ($v) { return 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_whitelist_pattern', 'delivery_whitelist')
->fixXmlConfig('delivery_address', 'delivery_addresses')
->children()
->arrayNode('delivery_whitelist')
->prototype('scalar')
->end()
->end()
->booleanNode('disable_delivery')->end()
->end()
;
return $node;
}
}

View File

@@ -0,0 +1,39 @@
<?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\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');
$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);
$mailers = array();
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', array('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 = array();
$envVariablesAllowed = array('transport', 'url', 'username', 'password', 'host', 'port', 'timeout', 'source_ip', 'local_domain', 'encryption', 'auth_mode');
foreach ($envVariablesAllowed as $key) {
$container->resolveEnvPlaceholders($mailer[$key], null, $usedEnvs);
$options[$key] = $mailer[$key];
}
}
if ($usedEnvs && !$disableDelivery) {
$transportId = sprintf('swiftmailer.mailer.%s.transport.dynamic', $name);
$definitionDecorator = new Definition('\Swift_Transport');
$definitionDecorator->setFactory(array('Symfony\Bundle\SwiftmailerBundle\DependencyInjection\SwiftmailerTransportFactory', 'createTransport'));
$definitionDecorator->setArguments(array(
$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, array('smtp', 'sendmail', 'null', 'mail'))
? 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', sprintf('swiftmailer.mailer.%s.transport', $name));
$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 (array('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', array(sprintf('%%swiftmailer.mailer.%s.transport.smtp.username%%', $name)))
->addMethodCall('setPassword', array(sprintf('%%swiftmailer.mailer.%s.transport.smtp.password%%', $name)))
->addMethodCall('setAuthMode', array(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(array(
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(array(
new Reference(sprintf('swiftmailer.mailer.%s.transport.buffer', $name)),
array(new Reference(sprintf('swiftmailer.mailer.%s.transport.authhandler', $name))),
new Reference(sprintf('swiftmailer.mailer.%s.transport.eventdispatcher', $name)),
))
->addMethodCall('setHost', array(sprintf('%%swiftmailer.mailer.%s.transport.smtp.host%%', $name)))
->addMethodCall('setPort', array(sprintf('%%swiftmailer.mailer.%s.transport.smtp.port%%', $name)))
->addMethodCall('setEncryption', array(sprintf('%%swiftmailer.mailer.%s.transport.smtp.encryption%%', $name)))
->addMethodCall('setTimeout', array(sprintf('%%swiftmailer.mailer.%s.transport.smtp.timeout%%', $name)))
->addMethodCall('setSourceIp', array(sprintf('%%swiftmailer.mailer.%s.transport.smtp.source_ip%%', $name)))
->setConfigurator(array(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', array(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(array(
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(array(
new Reference(sprintf('swiftmailer.mailer.%s.transport.buffer', $name)),
new Reference(sprintf('swiftmailer.mailer.%s.transport.eventdispatcher', $name)),
))
->setConfigurator(array(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 ('mail' === $transport) {
// deprecated
$definitionDecorator = $this->createChildDefinition(sprintf('swiftmailer.transport.%s.abstract', $transport));
$container
->setDefinition(sprintf('swiftmailer.mailer.%s.transport.%s', $name, $transport), $definitionDecorator)
->addArgument(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));
} elseif ('null' === $transport) {
$definitionDecorator = $this->createChildDefinition('swiftmailer.transport.null.abstract');
$container
->setDefinition(sprintf('swiftmailer.mailer.%s.transport.null', $name, $transport), $definitionDecorator)
->setArguments(array(
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('Symfony\Component\DependencyInjection\Alias', '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 (array('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(array(
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(array(
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(array(
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(array(
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,140 @@
<?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);
if ('smtp' === $options['transport']) {
$smtpAuthHandler = new \Swift_Transport_Esmtp_AuthHandler(array(
new \Swift_Transport_Esmtp_Auth_CramMd5Authenticator(),
new \Swift_Transport_Esmtp_Auth_LoginAuthenticator(),
new \Swift_Transport_Esmtp_Auth_PlainAuthenticator(),
));
$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()),
array($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(null, $requestContext);
$smtpTransportConfigurator->configure($transport);
} elseif ('sendmail' === $options['transport']) {
$transport = new \Swift_Transport_SendmailTransport(
new \Swift_Transport_StreamBuffer(new \Swift_StreamFilters_StringReplacementFilterFactory()),
$eventDispatcher
);
$smtpTransportConfigurator = new SmtpTransportConfigurator(null, $requestContext);
$smtpTransportConfigurator->configure($transport);
} elseif ('mail' === $options['transport']) {
$transport = new \Swift_Transport_MailTransport(new \Swift_Transport_SimpleMailInvoker(), $eventDispatcher);
} 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 += array(
'transport' => null,
'username' => null,
'password' => null,
'host' => null,
'port' => null,
'timeout' => null,
'source_ip' => null,
'local_domain' => null,
'encryption' => null,
'auth_mode' => null,
);
if (isset($options['url'])) {
$parts = parse_url($options['url']);
if (isset($parts['scheme'])) {
$options['transport'] = $parts['scheme'];
}
if (isset($parts['user'])) {
$options['username'] = $parts['user'];
}
if (isset($parts['pass'])) {
$options['password'] = $parts['pass'];
}
if (isset($parts['host'])) {
$options['host'] = $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])) {
$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;
}
}

View File

@@ -0,0 +1,88 @@
<?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 = array(
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;
}
}

View File

@@ -0,0 +1,104 @@
<?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="delivery-address" 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: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: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: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,97 @@
<?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">
<parameters>
<parameter key="swiftmailer.class">Swift_Mailer</parameter>
<parameter key="swiftmailer.transport.sendmail.class">Swift_Transport_SendmailTransport</parameter>
<parameter key="swiftmailer.transport.mail.class">Swift_Transport_MailTransport</parameter>
<parameter key="swiftmailer.transport.failover.class">Swift_Transport_FailoverTransport</parameter>
<parameter key="swiftmailer.plugin.redirecting.class">Swift_Plugins_RedirectingPlugin</parameter>
<parameter key="swiftmailer.plugin.impersonate.class">Swift_Plugins_ImpersonatePlugin</parameter>
<parameter key="swiftmailer.plugin.messagelogger.class">Swift_Plugins_MessageLogger</parameter>
<parameter key="swiftmailer.plugin.antiflood.class">Swift_Plugins_AntiFloodPlugin</parameter>
<parameter key="swiftmailer.transport.smtp.class">Swift_Transport_EsmtpTransport</parameter>
<parameter key="swiftmailer.plugin.blackhole.class">Swift_Plugins_BlackholePlugin</parameter>
<parameter key="swiftmailer.spool.file.class">Swift_FileSpool</parameter>
<parameter key="swiftmailer.spool.memory.class">Swift_MemorySpool</parameter>
<parameter key="swiftmailer.email_sender.listener.class">Symfony\Bundle\SwiftmailerBundle\EventListener\EmailSenderListener</parameter>
<parameter key="swiftmailer.data_collector.class">Symfony\Bundle\SwiftmailerBundle\DataCollector\MessageDataCollector</parameter>
</parameters>
<services>
<service id="swiftmailer.mailer.abstract" class="%swiftmailer.class%" 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="%swiftmailer.transport.sendmail.class%" abstract="true" public="false" />
<service id="swiftmailer.transport.mail.abstract" class="%swiftmailer.transport.mail.class%" abstract="true" public="false">
<argument type="service" id="swiftmailer.transport.mailinvoker" />
</service>
<service id="swiftmailer.transport.null.abstract" class="Swift_Transport_NullTransport" abstract="true" public="false">
</service>
<service id="swiftmailer.transport.failover" class="%swiftmailer.transport.failover.class%" public="false" />
<service id="swiftmailer.transport.mailinvoker" class="Swift_Transport_SimpleMailInvoker" 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>
</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="%swiftmailer.plugin.redirecting.class%" abstract="true" public="false" />
<service id="swiftmailer.plugin.antiflood.abstract" class="%swiftmailer.plugin.antiflood.class%" abstract="true" public="false" />
<service id="swiftmailer.plugin.impersonate.abstract" class="%swiftmailer.plugin.impersonate.class%" abstract="true" public="false" />
<service id="swiftmailer.plugin.messagelogger.abstract" class="%swiftmailer.plugin.messagelogger.class%" abstract="true" />
<service id="swiftmailer.transport.smtp.abstract" class="%swiftmailer.transport.smtp.class%" 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="%swiftmailer.spool.file.class%" public="false" abstract="true">
<argument>%kernel.root_dir%/../data/swiftmailer/spool</argument>
</service>
<service id="swiftmailer.spool.memory.abstract" class="%swiftmailer.spool.memory.class%" public="false" abstract="true" />
<service id="swiftmailer.email_sender.listener" class="%swiftmailer.email_sender.listener.class%">
<tag name="kernel.event_subscriber" />
<argument type="service" id="service_container" />
<argument type="service" id="logger" on-invalid="null" />
</service>
<service id="swiftmailer.data_collector" class="%swiftmailer.data_collector.class%" public="false">
<argument type="service" id="service_container" />
</service>
</services>
</container>

View File

@@ -0,0 +1,19 @@
Copyright (c) 2004-2014 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,204 @@
{% 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 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">Message headers</span>
<pre>{% for header in message.headers.all %}
{{- header -}}
{% endfor %}</pre>
</div>
<div class="card-block">
<span class="label">Message body</span>
<pre>
{%- if messagePart.charset is defined and message.charset %}
{{- message.body|convert_encoding('UTF-8', message.charset) }}
{%- else %}
{{- message.body }}
{%- endif -%}
</pre>
</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>
{%- 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,29 @@
<?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\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());
}
}