diff --git a/.gitignore b/.gitignore index 461ba13..6cc69e4 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ build composer.lock vendor coverage -.phpunit.result.cache \ No newline at end of file +.phpunit.result.cache +.idea diff --git a/src/InboundEmail.php b/src/InboundEmail.php index bb8b8ad..9e7949f 100644 --- a/src/InboundEmail.php +++ b/src/InboundEmail.php @@ -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) { diff --git a/src/Routing/Route.php b/src/Routing/Route.php index 8a3c22d..33e4eca 100644 --- a/src/Routing/Route.php +++ b/src/Routing/Route.php @@ -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'; @@ -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; diff --git a/src/Routing/Router.php b/src/Routing/Router.php index b679557..390d839 100644 --- a/src/Routing/Router.php +++ b/src/Routing/Router.php @@ -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); diff --git a/tests/MailboxRouteTest.php b/tests/MailboxRouteTest.php index 732818b..fe5475e 100644 --- a/tests/MailboxRouteTest.php +++ b/tests/MailboxRouteTest.php @@ -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