Skip to content

Commit 4303147

Browse files
committed
wip
1 parent fcf1620 commit 4303147

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed

src/Http/Controllers/SendGridController.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
namespace BeyondCode\Mailbox\Http\Controllers;
44

5+
use BeyondCode\Mailbox\Facades\Mailbox;
6+
use BeyondCode\Mailbox\Http\Requests\SendGridRequest;
7+
58
class SendGridController
69
{
7-
public function __invoke()
10+
public function __invoke(SendGridRequest $request)
811
{
9-
12+
Mailbox::callMailboxes($request->email());
1013
}
1114
}

src/Http/Requests/SendGridRequest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
}

src/Routing/Router.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ public function callMailboxes(InboundEmail $email)
5555
{
5656
if ($email->isValid()) {
5757

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) {
6359
$route->run($email);
6460
});
61+
62+
if ($this->shouldStoreInboundEmails() && $matchedRoutes->isNotEmpty()) {
63+
$this->storeEmail($email);
64+
}
6565
}
6666
}
6767

tests/InboundEmailTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ protected function getEnvironmentSetUp($app)
2121
/** @test */
2222
public function it_stores_inbound_emails()
2323
{
24-
Mailbox::from('example@beyondco.de', function($email) {
24+
Mailbox::to('someone@beyondco.de', function($email) {
2525
});
2626

2727
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);
2929

30-
$this->assertSame(2, InboundEmail::query()->count());
30+
$this->assertSame(1, InboundEmail::query()->count());
3131
}
3232

3333
/** @test */

0 commit comments

Comments
 (0)