Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #54044 [Mailer] Add support for allowing some users even if `…
…recipients` is defined in `EnvelopeListener` (lyrixx) This PR was merged into the 7.1 branch. Discussion ---------- [Mailer] Add support for allowing some users even if `recipients` is defined in `EnvelopeListener` | Q | A | ------------- | --- | Branch? | 7.1 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | - | License | MIT I'm migrate an application from SwiftMailer to symfony/mailer, and this options was used. --- depends on #54292 Commits ------- 6228896 [Mailer] Add support for allowing some users even if `recipients` is defined in `EnvelopeListener`
- Loading branch information
Showing
14 changed files
with
106 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/Symfony/Component/Mailer/Tests/EventListener/EnvelopeListenerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?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\Component\Mailer\Tests\EventListener; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Mailer\Envelope; | ||
use Symfony\Component\Mailer\Event\MessageEvent; | ||
use Symfony\Component\Mailer\EventListener\EnvelopeListener; | ||
use Symfony\Component\Mime\Address; | ||
use Symfony\Component\Mime\RawMessage; | ||
|
||
class EnvelopeListenerTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider provideRecipientsTests | ||
*/ | ||
public function testRecipients(array $expected, ?array $recipients = null, array $allowedRecipients = []) | ||
{ | ||
$listener = new EnvelopeListener(null, $recipients, $allowedRecipients); | ||
$message = new RawMessage('message'); | ||
$envelope = new Envelope(new Address('sender@example.com'), [new Address('r1@example.com'), new Address('r2@symfony.com')]); | ||
$event = new MessageEvent($message, $envelope, 'default'); | ||
|
||
$listener->onMessage($event); | ||
|
||
$recipients = array_map(fn (Address $a): string => $a->getAddress(), $event->getEnvelope()->getRecipients()); | ||
$this->assertSame($expected, $recipients); | ||
} | ||
|
||
public static function provideRecipientsTests(): iterable | ||
{ | ||
yield [['r1@example.com', 'r2@symfony.com'], null, []]; | ||
yield [['admin@admin.com'], ['admin@admin.com'], []]; | ||
yield [['admin@admin.com', 'r1@example.com'], ['admin@admin.com'], ['.*@example\.com']]; | ||
yield [['admin@admin.com', 'r1@example.com', 'r2@symfony.com'], ['admin@admin.com'], ['.*@example\.com', '.*@symfony\.com']]; | ||
yield [['r1@example.com', 'r2@symfony.com'], ['r1@example.com'], ['.*@example\.com', '.*@symfony\.com']]; | ||
} | ||
} |