diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 9d0d7c2b..4db77595 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -108,6 +108,36 @@ private function getMailersNode()
->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()
diff --git a/DependencyInjection/SmtpTransportConfigurator.php b/DependencyInjection/SmtpTransportConfigurator.php
new file mode 100644
index 00000000..6135d1cf
--- /dev/null
+++ b/DependencyInjection/SmtpTransportConfigurator.php
@@ -0,0 +1,39 @@
+
+ *
+ * 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());
+ }
+ }
+}
diff --git a/DependencyInjection/SwiftmailerExtension.php b/DependencyInjection/SwiftmailerExtension.php
index 15ce2c39..066d751f 100644
--- a/DependencyInjection/SwiftmailerExtension.php
+++ b/DependencyInjection/SwiftmailerExtension.php
@@ -12,6 +12,7 @@
namespace Symfony\Bundle\SwiftmailerBundle\DependencyInjection;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
+use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
@@ -138,13 +139,15 @@ protected function configureMailer($name, array $mailer, ContainerBuilder $conta
protected function configureMailerTransport($name, array $mailer, ContainerBuilder $container, $transport, $isDefaultMailer = false)
{
- foreach (array('encryption', 'port', 'host', 'username', 'password', 'auth_mode', 'timeout', 'source_ip') as $key) {
+ 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]);
}
+
$definitionDecorator = new DefinitionDecorator('swiftmailer.transport.eventdispatcher.abstract');
$container
->setDefinition(sprintf('swiftmailer.mailer.%s.transport.eventdispatcher', $name), $definitionDecorator)
;
+
if ('smtp' === $transport) {
$authDecorator = new DefinitionDecorator('swiftmailer.transport.authhandler.abstract');
$container
@@ -157,6 +160,15 @@ protected function configureMailerTransport($name, array $mailer, ContainerBuild
$container
->setDefinition(sprintf('swiftmailer.mailer.%s.transport.buffer', $name), $bufferDecorator);
+ $configuratorDecorator = new DefinitionDecorator('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 = new DefinitionDecorator('swiftmailer.transport.smtp.abstract');
$container
->setDefinition(sprintf('swiftmailer.mailer.%s.transport.smtp', $name), $definitionDecorator)
@@ -170,13 +182,29 @@ protected function configureMailerTransport($name, array $mailer, ContainerBuild
->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 = new DefinitionDecorator('swiftmailer.transport.buffer.abstract');
$container
->setDefinition(sprintf('swiftmailer.mailer.%s.transport.buffer', $name), $bufferDecorator);
+ $configuratorDecorator = new DefinitionDecorator('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 = new DefinitionDecorator(sprintf('swiftmailer.transport.%s.abstract', $transport));
$container
->setDefinition(sprintf('swiftmailer.mailer.%s.transport.%s', $name, $transport), $definitionDecorator)
@@ -184,7 +212,9 @@ protected function configureMailerTransport($name, array $mailer, ContainerBuild
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) {
$definitionDecorator = new DefinitionDecorator(sprintf('swiftmailer.transport.%s.abstract', $transport));
diff --git a/Resources/config/schema/swiftmailer-1.0.xsd b/Resources/config/schema/swiftmailer-1.0.xsd
index ea227fde..eb02fa5d 100644
--- a/Resources/config/schema/swiftmailer-1.0.xsd
+++ b/Resources/config/schema/swiftmailer-1.0.xsd
@@ -10,6 +10,7 @@
+
@@ -21,6 +22,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -31,6 +46,7 @@
+
@@ -41,6 +57,7 @@
+
diff --git a/Resources/config/swiftmailer.xml b/Resources/config/swiftmailer.xml
index cd3cb4e2..1e5312ea 100644
--- a/Resources/config/swiftmailer.xml
+++ b/Resources/config/swiftmailer.xml
@@ -34,6 +34,8 @@
+
+
diff --git a/Tests/DependencyInjection/Fixtures/config/php/full.php b/Tests/DependencyInjection/Fixtures/config/php/full.php
index 5b3cdc99..08b42b99 100644
--- a/Tests/DependencyInjection/Fixtures/config/php/full.php
+++ b/Tests/DependencyInjection/Fixtures/config/php/full.php
@@ -10,6 +10,7 @@
'auth-mode' => 'login',
'timeout' => '1000',
'source_ip' => '127.0.0.1',
+ 'local_domain' => 'local.example.com',
'logging' => true,
'spool' => array('type' => 'memory'),
'delivery_address' => 'single@host.com',
diff --git a/Tests/DependencyInjection/Fixtures/config/php/many_mailers.php b/Tests/DependencyInjection/Fixtures/config/php/many_mailers.php
index 90254132..58bb98a6 100644
--- a/Tests/DependencyInjection/Fixtures/config/php/many_mailers.php
+++ b/Tests/DependencyInjection/Fixtures/config/php/many_mailers.php
@@ -13,6 +13,7 @@
'auth-mode' => 'login',
'timeout' => '1000',
'source_ip' => '127.0.0.1',
+ 'local_domain' => 'first.example.org',
'logging' => true,
'sender_address' => 'first-sender@example.org',
'delivery_address' => 'first@example.org',
@@ -31,6 +32,7 @@
'auth-mode' => 'login',
'timeout' => '1000',
'source_ip' => '127.0.0.1',
+ 'local_domain' => 'second.example.org',
'logging' => true,
'spool' => array(
'type' => 'memory',
@@ -51,6 +53,7 @@
'auth-mode' => 'login',
'timeout' => '1000',
'source_ip' => '127.0.0.1',
+ 'local_domain' => 'third.example.org',
'logging' => true,
'spool' => array(
'type' => 'file',
diff --git a/Tests/DependencyInjection/Fixtures/config/php/one_mailer.php b/Tests/DependencyInjection/Fixtures/config/php/one_mailer.php
index f5989e9d..77592e14 100644
--- a/Tests/DependencyInjection/Fixtures/config/php/one_mailer.php
+++ b/Tests/DependencyInjection/Fixtures/config/php/one_mailer.php
@@ -13,6 +13,7 @@
'auth-mode' => 'login',
'timeout' => '1000',
'source_ip' => '127.0.0.1',
+ 'local_domain' => 'local.example.org',
),
),
));
diff --git a/Tests/DependencyInjection/Fixtures/config/php/sendmail.php b/Tests/DependencyInjection/Fixtures/config/php/sendmail.php
index 77963c02..3325ca9d 100644
--- a/Tests/DependencyInjection/Fixtures/config/php/sendmail.php
+++ b/Tests/DependencyInjection/Fixtures/config/php/sendmail.php
@@ -2,4 +2,5 @@
$container->loadFromExtension('swiftmailer', array(
'transport' => 'sendmail',
+ 'local_domain' => 'local.example.org',
));
diff --git a/Tests/DependencyInjection/Fixtures/config/php/smtp.php b/Tests/DependencyInjection/Fixtures/config/php/smtp.php
index 61a5b6fa..bba0524f 100644
--- a/Tests/DependencyInjection/Fixtures/config/php/smtp.php
+++ b/Tests/DependencyInjection/Fixtures/config/php/smtp.php
@@ -11,4 +11,5 @@
'timeout' => '1000',
'source_ip' => '127.0.0.1',
'logging' => true,
+ 'local_domain' => 'local.example.org',
));
diff --git a/Tests/DependencyInjection/Fixtures/config/php/stream_options.php b/Tests/DependencyInjection/Fixtures/config/php/stream_options.php
new file mode 100644
index 00000000..f379e1c4
--- /dev/null
+++ b/Tests/DependencyInjection/Fixtures/config/php/stream_options.php
@@ -0,0 +1,15 @@
+loadFromExtension('swiftmailer', array(
+ 'transport' => 'smtp',
+ 'host' => 'example.org',
+ 'port' => '12345',
+ 'source_ip' => '127.0.0.1',
+ 'stream_options' => array(
+ 'ssl' => array(
+ 'verify_peer' => true,
+ 'verify_depth' => 5,
+ 'cafile' => '/etc/ssl/cacert.pem',
+ 'CN_match' => 'ssl.example.com',
+ ),
+ ),
+));
diff --git a/Tests/DependencyInjection/Fixtures/config/xml/full.xml b/Tests/DependencyInjection/Fixtures/config/xml/full.xml
index f2a18705..263d2939 100644
--- a/Tests/DependencyInjection/Fixtures/config/xml/full.xml
+++ b/Tests/DependencyInjection/Fixtures/config/xml/full.xml
@@ -15,6 +15,7 @@
auth-mode="login"
timeout="1000"
source-ip="127.0.0.1"
+ local-domain="local.example.com"
logging="true"
delivery-address="single@host.com">
diff --git a/Tests/DependencyInjection/Fixtures/config/xml/many_mailers.xml b/Tests/DependencyInjection/Fixtures/config/xml/many_mailers.xml
index 0a0bf27e..13922e55 100644
--- a/Tests/DependencyInjection/Fixtures/config/xml/many_mailers.xml
+++ b/Tests/DependencyInjection/Fixtures/config/xml/many_mailers.xml
@@ -16,6 +16,7 @@
auth-mode="login"
timeout="1000"
source-ip="127.0.0.1"
+ local-domain="first.example.org"
logging="true"
delivery-address="single@host.com">
@@ -30,6 +31,7 @@
auth-mode="login"
timeout="1000"
source-ip="127.0.0.1"
+ local-domain="second.example.org"
logging="true"
delivery-address="single@host.com">
@@ -44,6 +46,7 @@
auth-mode="login"
timeout="1000"
source-ip="127.0.0.1"
+ local-domain="third.example.org"
logging="true"
delivery-address="single@host.com">
diff --git a/Tests/DependencyInjection/Fixtures/config/xml/one_mailer.xml b/Tests/DependencyInjection/Fixtures/config/xml/one_mailer.xml
index 046dd50f..a5d0f0cb 100644
--- a/Tests/DependencyInjection/Fixtures/config/xml/one_mailer.xml
+++ b/Tests/DependencyInjection/Fixtures/config/xml/one_mailer.xml
@@ -15,7 +15,8 @@
encryption="tls"
auth-mode="login"
timeout="1000"
- source-ip="127.0.0.1">
+ source-ip="127.0.0.1"
+ local-domain="local.example.org">
diff --git a/Tests/DependencyInjection/Fixtures/config/xml/sendmail.xml b/Tests/DependencyInjection/Fixtures/config/xml/sendmail.xml
index 43ecab6a..a7b92fca 100644
--- a/Tests/DependencyInjection/Fixtures/config/xml/sendmail.xml
+++ b/Tests/DependencyInjection/Fixtures/config/xml/sendmail.xml
@@ -8,5 +8,6 @@
diff --git a/Tests/DependencyInjection/Fixtures/config/xml/smtp.xml b/Tests/DependencyInjection/Fixtures/config/xml/smtp.xml
index d337f1ed..0026de8a 100644
--- a/Tests/DependencyInjection/Fixtures/config/xml/smtp.xml
+++ b/Tests/DependencyInjection/Fixtures/config/xml/smtp.xml
@@ -16,5 +16,7 @@
auth-mode="login"
timeout="1000"
source-ip="127.0.0.1"
- logging="true"/>
+ local-domain="local.example.org"
+ logging="true">
+
diff --git a/Tests/DependencyInjection/Fixtures/config/xml/stream_options.xml b/Tests/DependencyInjection/Fixtures/config/xml/stream_options.xml
new file mode 100644
index 00000000..8e8eb632
--- /dev/null
+++ b/Tests/DependencyInjection/Fixtures/config/xml/stream_options.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+ true
+ 5
+ /etc/ssl/cacert.pem
+ ssl.example.com
+
+
+
+
diff --git a/Tests/DependencyInjection/Fixtures/config/yml/full.yml b/Tests/DependencyInjection/Fixtures/config/yml/full.yml
index 7b5eea85..96a47b51 100644
--- a/Tests/DependencyInjection/Fixtures/config/yml/full.yml
+++ b/Tests/DependencyInjection/Fixtures/config/yml/full.yml
@@ -1,14 +1,15 @@
swiftmailer:
- transport: smtp
- username: user
- password: pass
- host: example.org
- port: 12345
- encryption: tls
- auth-mode: login
- timeout: 1000
- source_ip: 127.0.0.1
- logging: true
+ transport: smtp
+ username: user
+ password: pass
+ host: example.org
+ port: 12345
+ encryption: tls
+ auth-mode: login
+ timeout: 1000
+ source_ip: 127.0.0.1
+ local_domain: local.example.com
+ logging: true
spool:
type: memory
delivery_address: single@host.com
diff --git a/Tests/DependencyInjection/Fixtures/config/yml/many_mailers.yml b/Tests/DependencyInjection/Fixtures/config/yml/many_mailers.yml
index b31f2014..ecf18f32 100644
--- a/Tests/DependencyInjection/Fixtures/config/yml/many_mailers.yml
+++ b/Tests/DependencyInjection/Fixtures/config/yml/many_mailers.yml
@@ -2,32 +2,34 @@ swiftmailer:
default_mailer: secondary_mailer
mailers:
first_mailer:
- transport: smtp
- username: user_first
- password: pass_first
- host: example.org
- port: 12345
- encryption: tls
- auth-mode: login
- timeout: 1000
- source_ip: 127.0.0.1
- logging: true
- sender_address: first-sender@example.org
+ transport: smtp
+ username: user_first
+ password: pass_first
+ host: example.org
+ port: 12345
+ encryption: tls
+ auth-mode: login
+ timeout: 1000
+ source_ip: 127.0.0.1
+ local_domain: first.example.org
+ logging: true
+ sender_address: first-sender@example.org
delivery_address: first@example.org
delivery_whitelist:
- /firstfoo@.*/
- /.*@firstbar.com$/
secondary_mailer:
- transport: smtp
- username: user_secondary
- password: pass_secondary
- host: example.org
- port: 54321
- encryption: tls
- auth-mode: login
- timeout: 1000
- source_ip: 127.0.0.1
- logging: true
+ transport: smtp
+ username: user_secondary
+ password: pass_secondary
+ host: example.org
+ port: 54321
+ encryption: tls
+ auth-mode: login
+ timeout: 1000
+ source_ip: 127.0.0.1
+ local_domain: second.example.org
+ logging: true
spool:
type: memory
delivery_address: secondary@example.org
@@ -35,19 +37,20 @@ swiftmailer:
- /secondaryfoo@.*/
- /.*@secondarybar.com$/
third_mailer:
- transport: smtp
- username: user_third
- password: pass_third
- host: example.org
- port: 12345
- encryption: tls
- auth-mode: login
- timeout: 1000
- source_ip: 127.0.0.1
- logging: true
+ transport: smtp
+ username: user_third
+ password: pass_third
+ host: example.org
+ port: 12345
+ encryption: tls
+ auth-mode: login
+ timeout: 1000
+ source_ip: 127.0.0.1
+ local_domain: third.example.org
+ logging: true
spool:
type: file
- sender_address: third-sender@example.org
+ sender_address: third-sender@example.org
delivery_address: third@example.org
delivery_whitelist:
- /thirdfoo@.*/
diff --git a/Tests/DependencyInjection/Fixtures/config/yml/one_mailer.yml b/Tests/DependencyInjection/Fixtures/config/yml/one_mailer.yml
index 6cfc7eb9..c868bd6f 100644
--- a/Tests/DependencyInjection/Fixtures/config/yml/one_mailer.yml
+++ b/Tests/DependencyInjection/Fixtures/config/yml/one_mailer.yml
@@ -11,3 +11,4 @@ swiftmailer:
auth-mode: login
timeout: 1000
source_ip: 127.0.0.1
+ local_domain: local.example.org
diff --git a/Tests/DependencyInjection/Fixtures/config/yml/sendmail.yml b/Tests/DependencyInjection/Fixtures/config/yml/sendmail.yml
index c1e8ed2c..b78f2079 100644
--- a/Tests/DependencyInjection/Fixtures/config/yml/sendmail.yml
+++ b/Tests/DependencyInjection/Fixtures/config/yml/sendmail.yml
@@ -1,2 +1,3 @@
swiftmailer:
transport: sendmail
+ local_domain: local.example.org
diff --git a/Tests/DependencyInjection/Fixtures/config/yml/smtp.yml b/Tests/DependencyInjection/Fixtures/config/yml/smtp.yml
index b508e4a1..49a63ca0 100644
--- a/Tests/DependencyInjection/Fixtures/config/yml/smtp.yml
+++ b/Tests/DependencyInjection/Fixtures/config/yml/smtp.yml
@@ -1,11 +1,12 @@
swiftmailer:
- transport: smtp
- username: user
- password: pass
- host: example.org
- port: 12345
- encryption: tls
- auth-mode: login
- timeout: 1000
- source_ip: 127.0.0.1
- logging: true
+ transport: smtp
+ username: user
+ password: pass
+ host: example.org
+ port: 12345
+ encryption: tls
+ auth-mode: login
+ timeout: 1000
+ source_ip: 127.0.0.1
+ local_domain: local.example.org
+ logging: true
diff --git a/Tests/DependencyInjection/Fixtures/config/yml/stream_options.yml b/Tests/DependencyInjection/Fixtures/config/yml/stream_options.yml
new file mode 100644
index 00000000..315c3860
--- /dev/null
+++ b/Tests/DependencyInjection/Fixtures/config/yml/stream_options.yml
@@ -0,0 +1,11 @@
+swiftmailer:
+ transport: smtp
+ host: example.org
+ port: 12345
+ source_ip: 127.0.0.1
+ stream_options:
+ ssl:
+ verify_peer: true
+ cafile: /etc/ssl/cacert.pem
+ verify_depth: 5
+ CN_match: ssl.example.com
diff --git a/Tests/DependencyInjection/SwiftmailerExtensionTest.php b/Tests/DependencyInjection/SwiftmailerExtensionTest.php
index 6058cd2a..8cbdf4ef 100644
--- a/Tests/DependencyInjection/SwiftmailerExtensionTest.php
+++ b/Tests/DependencyInjection/SwiftmailerExtensionTest.php
@@ -12,6 +12,7 @@
namespace Symfony\Bundle\SwiftmailerBundle\Tests\DependencyInjection;
use Symfony\Bundle\SwiftmailerBundle\DependencyInjection\SwiftmailerExtension;
+use Symfony\Component\DependencyInjection\Compiler\ResolveDefinitionTemplatesPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
@@ -34,10 +35,20 @@ public function getConfigTypes()
*/
public function testDefaultConfig($type)
{
- $container = $this->loadContainerFromFile('empty', $type);
+ $requestContext = $this->getMock('Symfony\Component\Routing\RequestContext', array('getHost'));
+ $requestContext->expects($this->once())->method('getHost')->will($this->returnValue('example.org'));
+ $services = array('router.request_context' => $requestContext);
+
+ $container = $this->loadContainerFromFile('empty', $type, $services);
$this->assertEquals('swiftmailer.mailer.default.transport', (string) $container->getAlias('swiftmailer.transport'));
$this->assertEquals('swiftmailer.mailer.default.transport.smtp', (string) $container->getAlias('swiftmailer.mailer.default.transport'));
+
+ $this->assertEquals('localhost', $container->getParameter('swiftmailer.mailer.default.transport.smtp.host'));
+ $this->assertEquals(25, $container->getParameter('swiftmailer.mailer.default.transport.smtp.port'));
+ $this->assertFalse($container->hasParameter('swiftmailer.mailer.default.transport.smtp.stream_options'));
+
+ $this->assertEquals('example.org', $container->get('swiftmailer.mailer.default.transport')->getLocalDomain());
}
/**
@@ -54,10 +65,17 @@ public function testMailerNullConfig($type)
*/
public function testSendmailConfig($type)
{
- $container = $this->loadContainerFromFile('sendmail', $type);
+ // Local domain is specified explicitly, so the request context host is ignored.
+ $requestContext = $this->getMock('Symfony\Component\Routing\RequestContext', array('getHost'));
+ $requestContext->expects($this->any())->method('getHost')->will($this->returnValue('example.org'));
+ $services = array('router.request_context' => $requestContext);
+
+ $container = $this->loadContainerFromFile('sendmail', $type, $services);
$this->assertEquals('swiftmailer.mailer.default.transport', (string) $container->getAlias('swiftmailer.transport'));
$this->assertEquals('swiftmailer.mailer.default.transport.sendmail', (string) $container->getAlias('swiftmailer.mailer.default.transport'));
+
+ $this->assertEquals('local.example.org', $container->get('swiftmailer.mailer.default.transport')->getLocalDomain());
}
/**
@@ -102,6 +120,7 @@ public function testFull($type)
$this->assertEquals('login', $container->getParameter('swiftmailer.mailer.default.transport.smtp.auth_mode'));
$this->assertEquals('1000', $container->getParameter('swiftmailer.mailer.default.transport.smtp.timeout'));
$this->assertEquals('127.0.0.1', $container->getParameter('swiftmailer.mailer.default.transport.smtp.source_ip'));
+ $this->assertEquals('local.example.com', $container->getParameter('swiftmailer.mailer.default.transport.smtp.local_domain'));
$this->assertSame(array('swiftmailer.default.plugin' => array(array())), $container->getDefinition('swiftmailer.mailer.default.plugin.redirecting')->getTags());
$this->assertSame('single@host.com', $container->getParameter('swiftmailer.mailer.default.single_address'));
$this->assertEquals(array('/foo@.*/', '/.*@bar.com$/'), $container->getParameter('swiftmailer.mailer.default.delivery_whitelist'));
@@ -126,6 +145,8 @@ public function testManyMailers($type)
$this->assertEquals('login', $container->getParameter('swiftmailer.mailer.first_mailer.transport.smtp.auth_mode'));
$this->assertEquals('1000', $container->getParameter('swiftmailer.mailer.first_mailer.transport.smtp.timeout'));
$this->assertEquals('127.0.0.1', $container->getParameter('swiftmailer.mailer.first_mailer.transport.smtp.source_ip'));
+ $this->assertEquals('first.example.org', $container->getParameter('swiftmailer.mailer.first_mailer.transport.smtp.local_domain'));
+
$this->assertEquals('example.org', $container->getParameter('swiftmailer.mailer.secondary_mailer.transport.smtp.host'));
$this->assertEquals('54321', $container->getParameter('swiftmailer.mailer.secondary_mailer.transport.smtp.port'));
$this->assertEquals('tls', $container->getParameter('swiftmailer.mailer.secondary_mailer.transport.smtp.encryption'));
@@ -133,7 +154,9 @@ public function testManyMailers($type)
$this->assertEquals('pass_secondary', $container->getParameter('swiftmailer.mailer.secondary_mailer.transport.smtp.password'));
$this->assertEquals('login', $container->getParameter('swiftmailer.mailer.secondary_mailer.transport.smtp.auth_mode'));
$this->assertEquals('1000', $container->getParameter('swiftmailer.mailer.secondary_mailer.transport.smtp.timeout'));
- $this->assertEquals('127.0.0.1', $container->getParameter('swiftmailer.mailer.third_mailer.transport.smtp.source_ip'));
+ $this->assertEquals('127.0.0.1', $container->getParameter('swiftmailer.mailer.secondary_mailer.transport.smtp.source_ip'));
+ $this->assertEquals('second.example.org', $container->getParameter('swiftmailer.mailer.secondary_mailer.transport.smtp.local_domain'));
+
$this->assertEquals('example.org', $container->getParameter('swiftmailer.mailer.third_mailer.transport.smtp.host'));
$this->assertEquals('12345', $container->getParameter('swiftmailer.mailer.third_mailer.transport.smtp.port'));
$this->assertEquals('tls', $container->getParameter('swiftmailer.mailer.third_mailer.transport.smtp.encryption'));
@@ -142,7 +165,9 @@ public function testManyMailers($type)
$this->assertEquals('login', $container->getParameter('swiftmailer.mailer.third_mailer.transport.smtp.auth_mode'));
$this->assertEquals('1000', $container->getParameter('swiftmailer.mailer.third_mailer.transport.smtp.timeout'));
$this->assertEquals('127.0.0.1', $container->getParameter('swiftmailer.mailer.third_mailer.transport.smtp.source_ip'));
+ $this->assertEquals('third.example.org', $container->getParameter('swiftmailer.mailer.third_mailer.transport.smtp.local_domain'));
}
+
/**
* @dataProvider getConfigTypes
*/
@@ -175,6 +200,8 @@ public function testOneMailer($type)
$this->assertEquals('pass', $container->getParameter('swiftmailer.mailer.main_mailer.transport.smtp.password'));
$this->assertEquals('login', $container->getParameter('swiftmailer.mailer.main_mailer.transport.smtp.auth_mode'));
$this->assertEquals('1000', $container->getParameter('swiftmailer.mailer.main_mailer.transport.smtp.timeout'));
+ $this->assertEquals('127.0.0.1', $container->getParameter('swiftmailer.mailer.main_mailer.transport.smtp.source_ip'));
+ $this->assertEquals('local.example.org', $container->getParameter('swiftmailer.mailer.main_mailer.transport.smtp.local_domain'));
}
/**
@@ -247,6 +274,23 @@ public function testSmtpConfig($type)
$this->assertEquals('login', $container->getParameter('swiftmailer.mailer.default.transport.smtp.auth_mode'));
$this->assertEquals('1000', $container->getParameter('swiftmailer.mailer.default.transport.smtp.timeout'));
$this->assertEquals('127.0.0.1', $container->getParameter('swiftmailer.mailer.default.transport.smtp.source_ip'));
+ $this->assertEquals('local.example.org', $container->getParameter('swiftmailer.mailer.default.transport.smtp.local_domain'));
+ }
+
+ /**
+ * @dataProvider getConfigTypes
+ */
+ public function testStreamOptions($type)
+ {
+ if (!method_exists('Swift_Transport_EsmtpTransport', 'setStreamOptions')) {
+ $this->markTestSkipped('This test requires Swiftmailer 5.4.2 or later.');
+ }
+
+ $container = $this->loadContainerFromFile('stream_options', $type);
+ $this->assertEquals('example.org', $container->getParameter('swiftmailer.mailer.default.transport.smtp.host'));
+ $this->assertEquals('12345', $container->getParameter('swiftmailer.mailer.default.transport.smtp.port'));
+ $this->assertEquals('127.0.0.1', $container->getParameter('swiftmailer.mailer.default.transport.smtp.source_ip'));
+ $this->assertEquals(array('ssl' => array('verify_peer' => true, 'verify_depth' => 5, 'cafile' => '/etc/ssl/cacert.pem', 'CN_match' => 'ssl.example.com')), $container->getParameter('swiftmailer.mailer.default.transport.smtp.stream_options'));
}
/**
@@ -310,16 +354,21 @@ public function testSenderAddress($type)
/**
* @param string $file
* @param string $type
+ * @param array $services
*
* @return ContainerBuilder
*/
- private function loadContainerFromFile($file, $type)
+ private function loadContainerFromFile($file, $type, array $services = array())
{
$container = new ContainerBuilder();
$container->setParameter('kernel.debug', false);
$container->setParameter('kernel.cache_dir', '/tmp');
+ foreach ($services as $id => $service) {
+ $container->set($id, $service);
+ }
+
$container->registerExtension(new SwiftmailerExtension());
$locator = new FileLocator(__DIR__.'/Fixtures/config/'.$type);
@@ -339,7 +388,9 @@ private function loadContainerFromFile($file, $type)
$loader->load($file.'.'.$type);
- $container->getCompilerPassConfig()->setOptimizationPasses(array());
+ $container->getCompilerPassConfig()->setOptimizationPasses(array(
+ new ResolveDefinitionTemplatesPass()
+ ));
$container->getCompilerPassConfig()->setRemovingPasses(array());
$container->compile();