Skip to content

Commit 22d2b54

Browse files
committed
[Mailer] Add support for allowing some users even if recipients is defined in EnvelopeListener
1 parent 60d0315 commit 22d2b54

File tree

13 files changed

+93
-5
lines changed

13 files changed

+93
-5
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2117,12 +2117,22 @@ private function addMailerSection(ArrayNodeDefinition $rootNode, callable $enabl
21172117
->arrayNode('envelope')
21182118
->info('Mailer Envelope configuration')
21192119
->fixXmlConfig('recipient')
2120+
->fixXmlConfig('allowed_recipient')
21202121
->children()
21212122
->scalarNode('sender')->end()
21222123
->arrayNode('recipients')
21232124
->performNoDeepMerging()
21242125
->beforeNormalization()
2125-
->ifArray()
2126+
->ifArray()
2127+
->then(fn ($v) => array_filter(array_values($v)))
2128+
->end()
2129+
->prototype('scalar')->end()
2130+
->end()
2131+
->arrayNode('allowed_recipients')
2132+
->info('A list of regular expressions that allow recipients when "recipients" option is defined.')
2133+
->performNoDeepMerging()
2134+
->beforeNormalization()
2135+
->ifArray()
21262136
->then(fn ($v) => array_filter(array_values($v)))
21272137
->end()
21282138
->prototype('scalar')->end()

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2670,6 +2670,7 @@ private function registerMailerConfiguration(array $config, ContainerBuilder $co
26702670
$envelopeListener = $container->getDefinition('mailer.envelope_listener');
26712671
$envelopeListener->setArgument(0, $config['envelope']['sender'] ?? null);
26722672
$envelopeListener->setArgument(1, $config['envelope']['recipients'] ?? null);
2673+
$envelopeListener->setArgument(2, $config['envelope']['allowed_recipients'] ?? []);
26732674

26742675
if ($config['headers']) {
26752676
$headers = new Definition(Headers::class);

src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,7 @@
764764
<xsd:sequence>
765765
<xsd:element name="sender" type="xsd:string" minOccurs="0" maxOccurs="1" />
766766
<xsd:element name="recipient" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
767+
<xsd:element name="allowed-recipient" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
767768
</xsd:sequence>
768769
</xsd:complexType>
769770

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/mailer_with_dsn.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
'envelope' => [
1414
'sender' => 'sender@example.org',
1515
'recipients' => ['redirected@example.org'],
16+
'allowed_recipients' => ['/^foobar@example.org$/'],
1617
],
1718
'headers' => [
1819
'from' => 'from@example.org',

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/mailer_with_transports.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
'envelope' => [
1717
'sender' => 'sender@example.org',
1818
'recipients' => ['redirected@example.org', 'redirected1@example.org'],
19+
'allowed_recipients' => ['/^foobar@example.org$/', '/@example.com$/'],
1920
],
2021
'headers' => [
2122
'from' => 'from@example.org',

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/mailer_with_dsn.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<framework:envelope>
1414
<framework:sender>sender@example.org</framework:sender>
1515
<framework:recipient>redirected@example.org</framework:recipient>
16+
<framework:allowed-recipient>/^foobar@example.org$/</framework:allowed-recipient>
1617
</framework:envelope>
1718
<framework:header name="from">from@example.org</framework:header>
1819
<framework:header name="bcc">bcc1@example.org</framework:header>

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/mailer_with_transports.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
<framework:sender>sender@example.org</framework:sender>
1717
<framework:recipient>redirected@example.org</framework:recipient>
1818
<framework:recipient>redirected1@example.org</framework:recipient>
19+
<framework:allowed-recipient>/^foobar@example.org$/</framework:allowed-recipient>
20+
<framework:allowed-recipient>/@example.com$/</framework:allowed-recipient>
1921
</framework:envelope>
2022
<framework:header name="from">from@example.org</framework:header>
2123
<framework:header name="bcc">bcc1@example.org</framework:header>

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/mailer_with_dsn.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ framework:
1010
sender: sender@example.org
1111
recipients:
1212
- redirected@example.org
13+
allowed_recipients:
14+
- /^foobar@example.org$/
1315
headers:
1416
from: from@example.org
1517
bcc: [bcc1@example.org, bcc2@example.org]

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/mailer_with_transports.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ framework:
1313
recipients:
1414
- redirected@example.org
1515
- redirected1@example.org
16+
allowed_recipients:
17+
- /^foobar@example.org$/
18+
- /@example.com$/
1619
headers:
1720
from: from@example.org
1821
bcc: [bcc1@example.org, bcc2@example.org]

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2043,6 +2043,7 @@ public static function provideMailer(): iterable
20432043
'mailer_with_dsn',
20442044
['main' => 'smtp://example.com'],
20452045
['redirected@example.org'],
2046+
['/^foobar@example.org$/'],
20462047
];
20472048
yield [
20482049
'mailer_with_transports',
@@ -2051,13 +2052,14 @@ public static function provideMailer(): iterable
20512052
'transport2' => 'smtp://example2.com',
20522053
],
20532054
['redirected@example.org', 'redirected1@example.org'],
2055+
['/^foobar@example.org$/', '/@example.com$/'],
20542056
];
20552057
}
20562058

20572059
/**
20582060
* @dataProvider provideMailer
20592061
*/
2060-
public function testMailer(string $configFile, array $expectedTransports, array $expectedRecipients)
2062+
public function testMailer(string $configFile, array $expectedTransports, array $expectedRecipients, array $expectedAllowedRecipients)
20612063
{
20622064
$container = $this->createContainerFromFile($configFile);
20632065

@@ -2070,6 +2072,7 @@ public function testMailer(string $configFile, array $expectedTransports, array
20702072
$l = $container->getDefinition('mailer.envelope_listener');
20712073
$this->assertSame('sender@example.org', $l->getArgument(0));
20722074
$this->assertSame($expectedRecipients, $l->getArgument(1));
2075+
$this->assertSame($expectedAllowedRecipients, $l->getArgument(2));
20732076
$this->assertEquals(new Reference('messenger.default_bus', ContainerInterface::NULL_ON_INVALID_REFERENCE), $container->getDefinition('mailer.mailer')->getArgument(1));
20742077

20752078
$this->assertTrue($container->hasDefinition('mailer.message_listener'));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy