Skip to content

Commit bc336a1

Browse files
committed
[Mailer] Add support for allowing some users even if recipients is defined in EnvelopeListener
1 parent 5a3570d commit bc336a1

File tree

11 files changed

+30
-2
lines changed

11 files changed

+30
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ CHANGELOG
1313
* Add `secrets:reveal` command
1414
* Add `rate_limiter` option to `http_client.default_options` and `http_client.scoped_clients`
1515
* Attach the workflow's configuration to the `workflow` tag
16+
* Add the `allowed_recipients` option for mailer to allow some users to receive
17+
emails even if `recipients` is defined.
1618

1719
7.0
1820
---

DependencyInjection/Configuration.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2117,12 +2117,23 @@ 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+
->example(['.*@example\.com'])
2134+
->performNoDeepMerging()
2135+
->beforeNormalization()
2136+
->ifArray()
21262137
->then(fn ($v) => array_filter(array_values($v)))
21272138
->end()
21282139
->prototype('scalar')->end()

DependencyInjection/FrameworkExtension.php

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

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

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

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' => '[email protected]',
1515
'recipients' => ['[email protected]'],
16+
'allowed_recipients' => ['foobar@example\.org'],
1617
],
1718
'headers' => [
1819
'from' => '[email protected]',

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' => '[email protected]',
1818
'recipients' => ['[email protected]', '[email protected]'],
19+
'allowed_recipients' => ['foobar@example\.org', '.*@example\.com'],
1920
],
2021
'headers' => [
2122
'from' => '[email protected]',

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>[email protected]</framework:sender>
1515
<framework:recipient>[email protected]</framework:recipient>
16+
<framework:allowed-recipient>foobar@example\.org</framework:allowed-recipient>
1617
</framework:envelope>
1718
<framework:header name="from">[email protected]</framework:header>
1819
<framework:header name="bcc">[email protected]</framework:header>

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>[email protected]</framework:sender>
1717
<framework:recipient>[email protected]</framework:recipient>
1818
<framework:recipient>[email protected]</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">[email protected]</framework:header>
2123
<framework:header name="bcc">[email protected]</framework:header>

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
1111
recipients:
1212
13+
allowed_recipients:
14+
- foobar@example\.org
1315
headers:
1416
1517

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
1515
16+
allowed_recipients:
17+
- foobar@example\.org
18+
- .*@example\.com
1619
headers:
1720
1821

0 commit comments

Comments
 (0)