Skip to content

Commit

Permalink
Add OriginalToListHeader in Email when use bcc transformation modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
Dumazeau committed Jan 15, 2024
1 parent 0e913c7 commit 5bc815a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on: [push, pull_request]

jobs:
build-and-test:
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04
steps:
- name: Checkout 🛎️
uses: actions/checkout@v2
Expand Down
29 changes: 29 additions & 0 deletions src/Domain/Header/OriginalToListHeader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace RichId\MailerBundle\Domain\Header;

use Symfony\Component\Mime\Header\UnstructuredHeader;

final class OriginalToListHeader extends UnstructuredHeader
{
public const NAME = 'X-Metadata-Original-To-List';

/** @var string[] */
private array $toList;

/** @param string[] $toList */
public function __construct(array $toList)
{
$this->toList = $toList;

parent::__construct(self::NAME, '');
}

/** @return string[] */
public function getToList(): array
{
return $this->toList;
}
}
2 changes: 2 additions & 0 deletions src/Domain/Updater/BccTransformerEmailUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace RichId\MailerBundle\Domain\Updater;

use RichId\MailerBundle\Domain\Header\OriginalToListHeader;
use RichId\MailerBundle\Domain\Port\ConfigurationInterface;
use RichId\MailerBundle\Domain\Port\TemplatingInterface;
use RichId\MailerBundle\Infrastructure\DependencyInjection\Configuration;
Expand Down Expand Up @@ -44,6 +45,7 @@ public function __invoke(Email $email): void
);

$email->html($head . ($email->getHtmlBody() ?? ''));
$email->getHeaders()->add(new OriginalToListHeader($toList));

$email->to($bccAddress);
$email->cc();
Expand Down
12 changes: 12 additions & 0 deletions tests/SendEmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use RichCongress\TestFramework\TestConfiguration\Annotation\TestConfig;
use RichCongress\TestSuite\TestCase\TestCase;
use RichId\MailerBundle\Domain\Email;
use RichId\MailerBundle\Domain\Header\OriginalToListHeader;
use RichId\MailerBundle\Infrastructure\TestCase\MailerAssertionsTrait;
use RichId\MailerBundle\Tests\Resources\Stub\ParameterBagStub;
use Symfony\Component\Mailer\MailerInterface;
Expand Down Expand Up @@ -70,6 +71,7 @@ public function testSendEmailMinimumConfiguration(): void
self::assertEmpty($email->getCc());
self::assertEmpty($email->getBcc());
self::assertEmpty($email->getAttachments());
self::assertNull($email->getHeaders()->get(OriginalToListHeader::NAME));
}

public function testSendEmailWithReturnPath(): void
Expand All @@ -96,6 +98,7 @@ public function testSendEmailWithReturnPath(): void
self::assertEmpty($email->getCc());
self::assertEmpty($email->getBcc());
self::assertEmpty($email->getAttachments());
self::assertNull($email->getHeaders()->get(OriginalToListHeader::NAME));
}

public function testSendEmailWithBcc(): void
Expand All @@ -122,6 +125,7 @@ public function testSendEmailWithBcc(): void
self::assertNull($email->getReturnPath());
self::assertEmpty($email->getCc());
self::assertEmpty($email->getAttachments());
self::assertNull($email->getHeaders()->get(OriginalToListHeader::NAME));
}

public function testSendEmailWithYopmailTransformer(): void
Expand Down Expand Up @@ -149,6 +153,7 @@ public function testSendEmailWithYopmailTransformer(): void
self::assertNull($email->getReturnPath());
self::assertEmpty($email->getCc());
self::assertEmpty($email->getAttachments());
self::assertNull($email->getHeaders()->get(OriginalToListHeader::NAME));
}

public function testSendEmailWithBccTransformer(): void
Expand Down Expand Up @@ -181,6 +186,10 @@ public function testSendEmailWithBccTransformer(): void
self::assertNull($email->getReturnPath());
self::assertEmpty($email->getCc());
self::assertEmpty($email->getAttachments());

$originalToListHeader = $email->getHeaders()->get(OriginalToListHeader::NAME);
self::assertInstanceOf(OriginalToListHeader::class, $originalToListHeader);
self::assertSame(['[email protected]'], $originalToListHeader->getToList());
}

public function testSendEmailWithSubjectPrefix(): void
Expand Down Expand Up @@ -208,6 +217,7 @@ public function testSendEmailWithSubjectPrefix(): void
self::assertEmpty($email->getCc());
self::assertEmpty($email->getBcc());
self::assertEmpty($email->getAttachments());
self::assertNull($email->getHeaders()->get(OriginalToListHeader::NAME));
}

public function testSendEmailWithFooter(): void
Expand All @@ -229,6 +239,7 @@ public function testSendEmailWithFooter(): void
self::assertEmpty($email->getCc());
self::assertEmpty($email->getBcc());
self::assertEmpty($email->getAttachments());
self::assertNull($email->getHeaders()->get(OriginalToListHeader::NAME));
}

public function testSendEmailWithFooterButDisabled(): void
Expand All @@ -251,5 +262,6 @@ public function testSendEmailWithFooterButDisabled(): void
self::assertEmpty($email->getCc());
self::assertEmpty($email->getBcc());
self::assertEmpty($email->getAttachments());
self::assertNull($email->getHeaders()->get(OriginalToListHeader::NAME));
}
}

0 comments on commit 5bc815a

Please sign in to comment.