diff --git a/app/Alias.php b/app/Alias.php index 41ff114..1435a96 100644 --- a/app/Alias.php +++ b/app/Alias.php @@ -18,6 +18,7 @@ class Alias extends Model ]; protected $fillable = [ + 'id', 'active', 'description', 'email', diff --git a/app/Console/Commands/ReceiveEmail.php b/app/Console/Commands/ReceiveEmail.php index 9ef3d36..5417337 100644 --- a/app/Console/Commands/ReceiveEmail.php +++ b/app/Console/Commands/ReceiveEmail.php @@ -97,10 +97,10 @@ public function handle() $user = $customDomain->user; } - // TODO add check here for uuid pre-generated aliases e.g. 68699f3b-a8c3-4374-9dbf-bdde64afd3e4@anonaddy.me - - // Check if this is the root domain e.g. anonaddy.me - if ($recipient['domain'] === $parentDomain && !empty(config('anonaddy.admin_username'))) { + // check if this is a uuid generated alias + if ($alias = Alias::find($recipient['local_part'])) { + $user = $alias->user; + } elseif ($recipient['domain'] === $parentDomain && !empty(config('anonaddy.admin_username'))) { $user = User::where('username', config('anonaddy.admin_username'))->first(); } } diff --git a/app/Http/Controllers/AliasController.php b/app/Http/Controllers/AliasController.php index ecf87b6..963c6b6 100644 --- a/app/Http/Controllers/AliasController.php +++ b/app/Http/Controllers/AliasController.php @@ -4,6 +4,7 @@ use App\Http\Requests\UpdateAliasRequest; use App\Http\Resources\AliasResource; +use Ramsey\Uuid\Uuid; class AliasController extends Controller { @@ -21,6 +22,24 @@ public function index() ]); } + public function store() + { + if (user()->hasExceededNewAliasLimit()) { + return response('', 429); + } + + $uuid = Uuid::uuid4(); + + $alias = user()->aliases()->create([ + 'id' => $uuid, + 'email' => $uuid . '@anonaddy.me', + 'local_part' => $uuid, + 'domain' => 'anonaddy.me' + ]); + + return new AliasResource($alias->fresh()); + } + public function update(UpdateAliasRequest $request, $id) { $alias = user()->aliases()->findOrFail($id); diff --git a/app/Http/Resources/AliasResource.php b/app/Http/Resources/AliasResource.php index 086dd04..40265a3 100644 --- a/app/Http/Resources/AliasResource.php +++ b/app/Http/Resources/AliasResource.php @@ -12,6 +12,9 @@ public function toArray($request) 'id' => $this->id, 'user_id' => $this->user_id, 'domain_id' => $this->domain_id, + 'local_part' => $this->local_part, + 'extension' => $this->extension, + 'domain' => $this->domain, 'email' => $this->email, 'active' => $this->active, 'description' => $this->description, diff --git a/resources/js/pages/Aliases.vue b/resources/js/pages/Aliases.vue index fbe513f..33c33cf 100644 --- a/resources/js/pages/Aliases.vue +++ b/resources/js/pages/Aliases.vue @@ -118,6 +118,14 @@ class="absolute right-0 inset-y-0 w-5 h-full text-grey-300 fill-current pointer-events-none mr-2 flex items-center" /> +