Skip to content

Commit 9934976

Browse files
authored
Merge pull request #70 from dniccum/master
Adds support for BCC emails.
2 parents 92bedd4 + 085e4e8 commit 9934976

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ build
22
composer.lock
33
vendor
44
coverage
5-
.phpunit.result.cache
5+
.phpunit.result.cache
6+
.idea

src/InboundEmail.php

+8
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ public function cc(): array
114114
return $this->convertAddressHeader($this->message()->getHeader('Cc'));
115115
}
116116

117+
/**
118+
* @return AddressPart[]
119+
*/
120+
public function bcc(): array
121+
{
122+
return $this->convertAddressHeader($this->message()->getHeader('Bcc'));
123+
}
124+
117125
protected function convertAddressHeader($header): array
118126
{
119127
if ($header instanceof AddressHeader) {

src/Routing/Route.php

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class Route
2121
const FROM = 'from';
2222
const TO = 'to';
2323
const CC = 'cc';
24+
const BCC = 'bcc';
2425
const SUBJECT = 'subject';
2526
const FALLBACK = 'fallback';
2627
const CATCH_ALL = 'catch-all';
@@ -89,6 +90,9 @@ protected function gatherMatchSubjectsFromMessage(InboundEmail $message)
8990
case self::CC:
9091
return $this->convertMessageAddresses($message->cc());
9192
break;
93+
case self::BCC:
94+
return $this->convertMessageAddresses($message->bcc());
95+
break;
9296
case self::SUBJECT:
9397
return [$message->subject()];
9498
break;

src/Routing/Router.php

+5
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ public function cc(string $pattern, $action): Route
4646
return $this->addRoute(Route::CC, $pattern, $action);
4747
}
4848

49+
public function bcc(string $pattern, $action): Route
50+
{
51+
return $this->addRoute(Route::BCC, $pattern, $action);
52+
}
53+
4954
public function subject(string $pattern, $action): Route
5055
{
5156
return $this->addRoute(Route::SUBJECT, $pattern, $action);

tests/MailboxRouteTest.php

+18
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,24 @@ public function it_matches_cc_mails($ccMail, $successfulPattern, $failingPattern
7070
$this->assertFalse($route->matches($message));
7171
}
7272

73+
/**
74+
* @test
75+
* @dataProvider emailDataProvider
76+
*/
77+
public function it_matches_bcc_mails($bccMail, $successfulPattern, $failingPattern)
78+
{
79+
$testMail = (new TestMail())
80+
->setBcc($bccMail);
81+
82+
$message = new InboundEmail(['message' => $testMail->toString()]);
83+
84+
$route = new Route(Route::BCC, $successfulPattern, 'SomeAction@handle');
85+
$this->assertTrue($route->matches($message));
86+
87+
$route = new Route(Route::BCC, $failingPattern, 'SomeAction@handle');
88+
$this->assertFalse($route->matches($message));
89+
}
90+
7391
/**
7492
* @test
7593
* @dataProvider subjectDataProvider

0 commit comments

Comments
 (0)