Skip to content

Commit

Permalink
Merge pull request #70 from dniccum/master
Browse files Browse the repository at this point in the history
Adds support for BCC emails.
  • Loading branch information
mpociot authored Sep 16, 2020
2 parents 92bedd4 + 085e4e8 commit 9934976
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ build
composer.lock
vendor
coverage
.phpunit.result.cache
.phpunit.result.cache
.idea
8 changes: 8 additions & 0 deletions src/InboundEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ public function cc(): array
return $this->convertAddressHeader($this->message()->getHeader('Cc'));
}

/**
* @return AddressPart[]
*/
public function bcc(): array
{
return $this->convertAddressHeader($this->message()->getHeader('Bcc'));
}

protected function convertAddressHeader($header): array
{
if ($header instanceof AddressHeader) {
Expand Down
4 changes: 4 additions & 0 deletions src/Routing/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Route
const FROM = 'from';
const TO = 'to';
const CC = 'cc';
const BCC = 'bcc';
const SUBJECT = 'subject';
const FALLBACK = 'fallback';
const CATCH_ALL = 'catch-all';
Expand Down Expand Up @@ -89,6 +90,9 @@ protected function gatherMatchSubjectsFromMessage(InboundEmail $message)
case self::CC:
return $this->convertMessageAddresses($message->cc());
break;
case self::BCC:
return $this->convertMessageAddresses($message->bcc());
break;
case self::SUBJECT:
return [$message->subject()];
break;
Expand Down
5 changes: 5 additions & 0 deletions src/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public function cc(string $pattern, $action): Route
return $this->addRoute(Route::CC, $pattern, $action);
}

public function bcc(string $pattern, $action): Route
{
return $this->addRoute(Route::BCC, $pattern, $action);
}

public function subject(string $pattern, $action): Route
{
return $this->addRoute(Route::SUBJECT, $pattern, $action);
Expand Down
18 changes: 18 additions & 0 deletions tests/MailboxRouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,24 @@ public function it_matches_cc_mails($ccMail, $successfulPattern, $failingPattern
$this->assertFalse($route->matches($message));
}

/**
* @test
* @dataProvider emailDataProvider
*/
public function it_matches_bcc_mails($bccMail, $successfulPattern, $failingPattern)
{
$testMail = (new TestMail())
->setBcc($bccMail);

$message = new InboundEmail(['message' => $testMail->toString()]);

$route = new Route(Route::BCC, $successfulPattern, 'SomeAction@handle');
$this->assertTrue($route->matches($message));

$route = new Route(Route::BCC, $failingPattern, 'SomeAction@handle');
$this->assertFalse($route->matches($message));
}

/**
* @test
* @dataProvider subjectDataProvider
Expand Down

0 comments on commit 9934976

Please sign in to comment.