Skip to content

Commit a7b2e3d

Browse files
committed
Merge branch 'master' of github.com:beyondcode/laravel-mailbox
2 parents 19c88d4 + 38e2a44 commit a7b2e3d

26 files changed

+71
-85
lines changed

config/mailbox.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
*/
4545
'basic_auth' => [
4646
'username' => env('MAILBOX_HTTP_USERNAME', 'laravel-mailbox'),
47-
'password' => env('MAILBOX_HTTP_PASSWORD')
47+
'password' => env('MAILBOX_HTTP_PASSWORD'),
4848
],
4949

5050
/*
@@ -56,6 +56,6 @@
5656
'key' => env('MAILBOX_MAILGUN_KEY'),
5757
],
5858

59-
]
59+
],
6060

61-
];
61+
];

src/Concerns/HandlesParameters.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ protected function matchToKeys(array $matches)
3737
return is_string($value) && strlen($value) > 0;
3838
});
3939
}
40-
}
40+
}

src/Concerns/HandlesRegularExpressions.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ protected function parseWhere($name, $expression)
4646
{
4747
return is_array($name) ? $name : [$name => $expression];
4848
}
49-
}
49+
}

src/Console/CleanEmails.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ public function handle()
2626

2727
$this->comment('All done!');
2828
}
29-
}
29+
}

src/Drivers/DriverInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
interface DriverInterface
66
{
77
public function register();
8-
}
8+
}

src/Drivers/Log.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
class Log implements DriverInterface
1010
{
11-
1211
public function register()
1312
{
1413
app('events')->listen(MessageLogged::class, [$this, 'processLog']);
@@ -20,4 +19,4 @@ public function processLog(MessageLogged $log)
2019

2120
Mailbox::callMailboxes($email);
2221
}
23-
}
22+
}

src/Drivers/Mailgun.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77

88
class Mailgun implements DriverInterface
99
{
10-
1110
public function register()
1211
{
1312
Route::prefix(config('mailbox.path'))->group(function () {
1413
Route::post('/mailgun/mime', MailgunController::class);
1514
});
1615
}
17-
}
16+
}

src/Drivers/SendGrid.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22

33
namespace BeyondCode\Mailbox\Drivers;
44

5-
use BeyondCode\Mailbox\Http\Controllers\SendGridController;
65
use Illuminate\Support\Facades\Route;
6+
use BeyondCode\Mailbox\Http\Controllers\SendGridController;
77

88
class SendGrid implements DriverInterface
99
{
10-
1110
public function register()
1211
{
1312
Route::prefix(config('mailbox.path'))->group(function () {
1413
Route::post('/sendgrid', SendGridController::class);
1514
});
1615
}
17-
}
16+
}

src/Facades/Mailbox.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ protected static function getFacadeAccessor()
1010
{
1111
return 'mailbox';
1212
}
13-
}
13+
}

src/Http/Controllers/MailgunController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ public function __invoke(MailgunRequest $request)
1111
{
1212
Mailbox::callMailboxes($request->email());
1313
}
14-
}
14+
}

src/Http/Controllers/SendGridController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ public function __invoke(SendGridRequest $request)
1717
{
1818
Mailbox::callMailboxes($request->email());
1919
}
20-
}
20+
}

src/Http/Middleware/MailboxBasicAuthentication.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ public function handle($request, Closure $next)
1818

1919
throw new UnauthorizedHttpException('Laravel Mailbox');
2020
}
21-
}
21+
}

src/Http/Requests/MailgunRequest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace BeyondCode\Mailbox\Http\Requests;
44

5-
use BeyondCode\Mailbox\InboundEmail;
65
use Carbon\Carbon;
7-
use Illuminate\Foundation\Http\FormRequest;
6+
use BeyondCode\Mailbox\InboundEmail;
87
use Illuminate\Support\Facades\Validator;
8+
use Illuminate\Foundation\Http\FormRequest;
99

1010
class MailgunRequest extends FormRequest
1111
{
@@ -15,7 +15,7 @@ public function validator()
1515
'body-mime' => 'required',
1616
'timestamp' => 'required',
1717
'token' => 'required',
18-
'signature' => 'required'
18+
'signature' => 'required',
1919
]);
2020

2121
$validator->after(function () {
@@ -45,4 +45,4 @@ protected function isFresh($timestamp): bool
4545
{
4646
return now()->subMinutes(2)->lte(Carbon::createFromTimestamp($timestamp));
4747
}
48-
}
48+
}

src/Http/Requests/SendGridRequest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
namespace BeyondCode\Mailbox\Http\Requests;
44

55
use BeyondCode\Mailbox\InboundEmail;
6-
use Illuminate\Foundation\Http\FormRequest;
76
use Illuminate\Support\Facades\Validator;
7+
use Illuminate\Foundation\Http\FormRequest;
88

99
class SendGridRequest extends FormRequest
1010
{
@@ -19,4 +19,4 @@ public function email()
1919
{
2020
return InboundEmail::fromMessage($this->get('email'));
2121
}
22-
}
22+
}

src/InboundEmail.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
namespace BeyondCode\Mailbox;
44

55
use Carbon\Carbon;
6-
use Illuminate\Contracts\Mail\Mailable;
7-
use Illuminate\Database\Eloquent\Model;
86
use Illuminate\Support\Collection;
97
use Illuminate\Support\Facades\Mail;
10-
use ZBateson\MailMimeParser\Message as MimeMessage;
8+
use Illuminate\Contracts\Mail\Mailable;
9+
use Illuminate\Database\Eloquent\Model;
1110
use ZBateson\MailMimeParser\Header\AddressHeader;
11+
use ZBateson\MailMimeParser\Message as MimeMessage;
1212
use ZBateson\MailMimeParser\Header\Part\AddressPart;
1313
use ZBateson\MailMimeParser\Message\Part\MessagePart;
1414

@@ -20,7 +20,7 @@ class InboundEmail extends Model
2020
protected $mimeMessage;
2121

2222
protected $fillable = [
23-
'message'
23+
'message',
2424
];
2525

2626
protected static function boot()
@@ -159,4 +159,4 @@ public function isValid(): bool
159159
{
160160
return $this->from() !== '' && ($this->text() !== '' || $this->html() !== '');
161161
}
162-
}
162+
}

src/MailboxManager.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
namespace BeyondCode\Mailbox;
44

5-
use BeyondCode\Mailbox\Drivers\SendGrid;
65
use Illuminate\Support\Manager;
76
use BeyondCode\Mailbox\Drivers\Log;
87
use BeyondCode\Mailbox\Drivers\Mailgun;
8+
use BeyondCode\Mailbox\Drivers\SendGrid;
99

1010
class MailboxManager extends Manager
1111
{
12-
1312
public function mailbox($name = null)
1413
{
1514
return $this->driver($name);
@@ -34,4 +33,4 @@ public function getDefaultDriver()
3433
{
3534
return $this->app['config']['mailbox.driver'];
3635
}
37-
}
36+
}

src/MailboxServiceProvider.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace BeyondCode\Mailbox;
44

5-
use BeyondCode\Mailbox\Http\Middleware\MailboxBasicAuthentication;
6-
use BeyondCode\Mailbox\Routing\Router;
75
use Illuminate\Support\Facades\Route;
6+
use BeyondCode\Mailbox\Routing\Router;
87
use Illuminate\Support\ServiceProvider;
8+
use BeyondCode\Mailbox\Http\Middleware\MailboxBasicAuthentication;
99

1010
class MailboxServiceProvider extends ServiceProvider
1111
{
@@ -21,13 +21,13 @@ public function boot()
2121
}
2222

2323
$this->publishes([
24-
__DIR__.'/../config/mailbox.php' => config_path('mailbox.php')
24+
__DIR__.'/../config/mailbox.php' => config_path('mailbox.php'),
2525
], 'config');
2626

2727
Route::aliasMiddleware('laravel-mailbox', MailboxBasicAuthentication::class);
2828

2929
$this->commands([
30-
Console\CleanEmails::class
30+
Console\CleanEmails::class,
3131
]);
3232

3333
$this->registerDriver();

src/Routing/Route.php

+7-8
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
namespace BeyondCode\Mailbox\Routing;
44

5-
use BeyondCode\Mailbox\Concerns\HandlesParameters;
6-
use BeyondCode\Mailbox\Concerns\HandlesRegularExpressions;
7-
use BeyondCode\Mailbox\InboundEmail;
5+
use ReflectionFunction;
6+
use Illuminate\Support\Str;
7+
use Illuminate\Support\Collection;
88
use Illuminate\Container\Container;
9+
use BeyondCode\Mailbox\InboundEmail;
10+
use BeyondCode\Mailbox\Concerns\HandlesParameters;
911
use Illuminate\Routing\RouteDependencyResolverTrait;
10-
use Illuminate\Support\Collection;
11-
use Illuminate\Support\Str;
12-
use ReflectionFunction;
1312
use ZBateson\MailMimeParser\Header\Part\AddressPart;
13+
use BeyondCode\Mailbox\Concerns\HandlesRegularExpressions;
1414

1515
class Route
1616
{
@@ -173,5 +173,4 @@ protected function parseMailboxCallback()
173173
{
174174
return Str::parseCallback($this->action);
175175
}
176-
177-
}
176+
}

src/Routing/RouteCollection.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace BeyondCode\Mailbox\Routing;
44

5-
use BeyondCode\Mailbox\InboundEmail;
65
use Illuminate\Support\Collection;
6+
use BeyondCode\Mailbox\InboundEmail;
77

88
class RouteCollection
99
{
@@ -20,4 +20,4 @@ public function match(InboundEmail $message): Collection
2020
return $route->matches($message);
2121
});
2222
}
23-
}
23+
}

src/Routing/Router.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace BeyondCode\Mailbox\Routing;
44

5-
use BeyondCode\Mailbox\InboundEmail;
6-
use Illuminate\Container\Container;
75
use Illuminate\Support\Collection;
6+
use Illuminate\Container\Container;
7+
use BeyondCode\Mailbox\InboundEmail;
88

99
class Router
1010
{
@@ -71,7 +71,6 @@ protected function createRoute(string $subject, string $pattern, $action)
7171
public function callMailboxes(InboundEmail $email)
7272
{
7373
if ($email->isValid()) {
74-
7574
$matchedRoutes = $this->routes->match($email)->map(function (Route $route) use ($email) {
7675
$route->run($email);
7776
});
@@ -116,5 +115,4 @@ protected function storeEmail(InboundEmail $email)
116115
{
117116
$email->save();
118117
}
119-
120-
}
118+
}

tests/Console/CleanEmailsTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
namespace BeyondCode\Mailbox\Tests\Console;
44

55
use Artisan;
6-
use BeyondCode\Mailbox\InboundEmail;
7-
use BeyondCode\Mailbox\Tests\TestCase;
86
use Carbon\Carbon;
9-
use Illuminate\Support\Collection;
107
use Illuminate\Support\Str;
8+
use Illuminate\Support\Collection;
9+
use BeyondCode\Mailbox\InboundEmail;
10+
use BeyondCode\Mailbox\Tests\TestCase;
1111

1212
class CleanEmailsTest extends TestCase
1313
{
@@ -40,4 +40,4 @@ public function it_can_clean_the_statistics()
4040

4141
$this->assertCount(0, InboundEmail::where('created_at', '<', $cutOffDate)->get());
4242
}
43-
}
43+
}

tests/Controllers/MailgunTest.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@ public function it_verifies_mailgun_signatures()
2020
'body-mime' => 'mime',
2121
'timestamp' => 1548104992,
2222
'token' => 'something',
23-
'signature' => 'something'
23+
'signature' => 'something',
2424
])->assertStatus(401);
2525

2626
$timestamp = time();
2727
$token = uniqid();
2828

2929
$this->app['config']['mailbox.services.mailgun.key'] = '12345';
3030

31-
$validSignature = hash_hmac('sha256', $timestamp . $token, '12345');
31+
$validSignature = hash_hmac('sha256', $timestamp.$token, '12345');
3232

3333
$this->post('/laravel-mailbox/mailgun/mime', [
3434
'body-mime' => 'mime',
3535
'timestamp' => $timestamp,
3636
'token' => $token,
37-
'signature' => $validSignature
37+
'signature' => $validSignature,
3838
])->assertStatus(200);
3939
}
4040

@@ -46,14 +46,13 @@ public function it_verifies_fresh_timestamps()
4646

4747
$this->app['config']['mailbox.services.mailgun.key'] = '12345';
4848

49-
$validSignature = hash_hmac('sha256', $timestamp . $token, '12345');
49+
$validSignature = hash_hmac('sha256', $timestamp.$token, '12345');
5050

5151
$this->post('/laravel-mailbox/mailgun/mime', [
5252
'body-mime' => 'mime',
5353
'timestamp' => $timestamp,
5454
'token' => $token,
55-
'signature' => $validSignature
55+
'signature' => $validSignature,
5656
])->assertStatus(401);
5757
}
58-
59-
}
58+
}

0 commit comments

Comments
 (0)