Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added SES Driver #79

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/Drivers/Ses.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace BeyondCode\Mailbox\Drivers;

use BeyondCode\Mailbox\Http\Controllers\SesController;
use Illuminate\Support\Facades\Route;

class Ses implements DriverInterface
{
public function register()
{
Route::prefix(config('mailbox.path'))->group(function () {
Route::post('/ses', SesController::class);
});
}
}
22 changes: 22 additions & 0 deletions src/Http/Controllers/SesController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace BeyondCode\Mailbox\Http\Controllers;

use BeyondCode\Mailbox\Facades\Mailbox;
use BeyondCode\Mailbox\Http\Requests\MailCareRequest;
use BeyondCode\Mailbox\Http\Requests\SesRequest;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;

class SesController extends Controller
{
public function __construct()
{
$this->middleware('laravel-mailbox');
}

public function __invoke(SesRequest $request)
{
Mailbox::callMailboxes($request->email());
}
}
2 changes: 1 addition & 1 deletion src/Http/Middleware/MailboxBasicAuthentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public function handle($request, Closure $next)
return $next($request);
}

throw new UnauthorizedHttpException('Laravel Mailbox');
throw new UnauthorizedHttpException('Basic realm=Mailer','Laravel Mailbox');
}
}
25 changes: 25 additions & 0 deletions src/Http/Requests/SesRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace BeyondCode\Mailbox\Http\Requests;

use BeyondCode\Mailbox\InboundEmail;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Validator;

class SesRequest extends FormRequest
{
public function validator()
{
return Validator::make(json_decode($this->getContent(), true), [
'Message' => 'required',
]);
}

public function email()
{
/** @var InboundEmail $modelClass */
$modelClass = config('mailbox.model');

return $modelClass::fromMessage(json_decode(json_decode($this->getContent(), true)['Message'],true)['content']);
}
}
6 changes: 6 additions & 0 deletions src/MailboxManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use BeyondCode\Mailbox\Drivers\Mailgun;
use BeyondCode\Mailbox\Drivers\Postmark;
use BeyondCode\Mailbox\Drivers\SendGrid;
use BeyondCode\Mailbox\Drivers\Ses;
use Illuminate\Support\Manager;

class MailboxManager extends Manager
Expand Down Expand Up @@ -41,6 +42,11 @@ public function createPostmarkDriver()
return new Postmark;
}

public function createSESDriver()
{
return new Ses;
}

public function getDefaultDriver()
{
return $this->container['config']['mailbox.driver'];
Expand Down