File tree Expand file tree Collapse file tree 4 files changed +35
-10
lines changed Expand file tree Collapse file tree 4 files changed +35
-10
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace BeyondCode \Mailbox \Http \Controllers ;
4
4
5
+ use BeyondCode \Mailbox \Facades \Mailbox ;
6
+ use BeyondCode \Mailbox \Http \Requests \SendGridRequest ;
7
+
5
8
class SendGridController
6
9
{
7
- public function __invoke ()
10
+ public function __invoke (SendGridRequest $ request )
8
11
{
9
-
12
+ Mailbox:: callMailboxes ( $ request -> email ());
10
13
}
11
14
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace BeyondCode \Mailbox \Http \Requests ;
4
+
5
+ use BeyondCode \Mailbox \InboundEmail ;
6
+ use Illuminate \Foundation \Http \FormRequest ;
7
+ use Illuminate \Support \Facades \Validator ;
8
+
9
+ class SendGridRequest extends FormRequest
10
+ {
11
+ public function validator ()
12
+ {
13
+ return Validator::make ($ this ->all (), [
14
+ 'email ' => 'required ' ,
15
+ ]);
16
+ }
17
+
18
+ public function email ()
19
+ {
20
+ return InboundEmail::fromMessage ($ this ->get ('email ' ));
21
+ }
22
+ }
Original file line number Diff line number Diff line change @@ -55,13 +55,13 @@ public function callMailboxes(InboundEmail $email)
55
55
{
56
56
if ($ email ->isValid ()) {
57
57
58
- if ($ this ->shouldStoreInboundEmails ()) {
59
- $ this ->storeEmail ($ email );
60
- }
61
-
62
- $ this ->routes ->match ($ email )->map (function (Route $ route ) use ($ email ) {
58
+ $ matchedRoutes = $ this ->routes ->match ($ email )->map (function (Route $ route ) use ($ email ) {
63
59
$ route ->run ($ email );
64
60
});
61
+
62
+ if ($ this ->shouldStoreInboundEmails () && $ matchedRoutes ->isNotEmpty ()) {
63
+ $ this ->storeEmail ($ email );
64
+ }
65
65
}
66
66
}
67
67
Original file line number Diff line number Diff line change @@ -21,13 +21,13 @@ protected function getEnvironmentSetUp($app)
21
21
/** @test */
22
22
public function it_stores_inbound_emails ()
23
23
{
24
- Mailbox::from ( ' example @beyondco.de ' , function ($ email ) {
24
+ Mailbox::to ( ' someone @beyondco.de ' , function ($ email ) {
25
25
});
26
26
27
27
Mail::
to (
'[email protected] ' )->
send (
new TestMail );
28
- Mail::
to (
'[email protected] ' )->
send (
new TestMail );
28
+ Mail::to ('someone-else @beyondco.de ' )->send (new TestMail );
29
29
30
- $ this ->assertSame (2 , InboundEmail::query ()->count ());
30
+ $ this ->assertSame (1 , InboundEmail::query ()->count ());
31
31
}
32
32
33
33
/** @test */
You can’t perform that action at this time.
0 commit comments