Skip to content

Commit

Permalink
Added default alias domain option
Browse files Browse the repository at this point in the history
  • Loading branch information
willbrowningme committed Feb 28, 2020
1 parent a61368b commit 50bbc9d
Show file tree
Hide file tree
Showing 16 changed files with 251 additions and 56 deletions.
6 changes: 3 additions & 3 deletions app/Console/Commands/ReceiveEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function handle()
$this->checkRateLimit($user);

// Check whether this email is a reply/send from or a new email to be forwarded.
if (filter_var(Str::replaceLast('=', '@', $recipient['extension']), FILTER_VALIDATE_EMAIL)) {
if (filter_var(Str::replaceLast('=', '@', $recipient['extension']), FILTER_VALIDATE_EMAIL) && $user->isVerifiedRecipient($this->option('sender'))) {
if ($this->parser->getHeader('In-Reply-To')) {
$this->handleReply($user, $recipient);
} else {
Expand Down Expand Up @@ -161,7 +161,7 @@ protected function handleReply($user, $recipient)
{
$alias = $user->aliases()->where('email', $recipient['local_part'] . '@' . $recipient['domain'])->first();

if ($alias && $user->isVerifiedRecipient($this->option('sender'))) {
if ($alias) {
$sendTo = Str::replaceLast('=', '@', $recipient['extension']);

$emailData = new EmailData($this->parser);
Expand All @@ -188,7 +188,7 @@ protected function handleSendFrom($user, $recipient, $aliasable)
]);

// This is a new alias but at a shared domain or the sender is not a verified recipient.
if ((!isset($alias->id) && in_array($recipient['domain'], config('anonaddy.all_domains'))) || !$user->isVerifiedRecipient($this->option('sender'))) {
if (!isset($alias->id) && in_array($recipient['domain'], config('anonaddy.all_domains'))) {
exit(0);
}

Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/Api/DomainOptionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class DomainOptionController extends Controller
public function index()
{
return response()->json([
'data' => user()->domainOptions()
'data' => user()->domainOptions(),
'defaultAliasDomain' => user()->default_alias_domain
]);
}
}
16 changes: 16 additions & 0 deletions app/Http/Controllers/DefaultAliasDomainController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Http\Controllers;

use App\Http\Requests\UpdateDefaultAliasDomainRequest;

class DefaultAliasDomainController extends Controller
{
public function update(UpdateDefaultAliasDomainRequest $request)
{
user()->default_alias_domain = $request->domain;
user()->save();

return back()->with(['status' => 'Default Alias Domain Updated Successfully']);
}
}
3 changes: 2 additions & 1 deletion app/Http/Controllers/ShowAliasController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public function index()
'totalReplies' => user()->totalEmailsReplied(),
'domain' => user()->username.'.'.config('anonaddy.domain'),
'bandwidthMb' => user()->bandwidth_mb,
'domainOptions' => user()->domainOptions()
'domainOptions' => user()->domainOptions(),
'defaultAliasDomain' => user()->default_alias_domain
]);
}
}
35 changes: 35 additions & 0 deletions app/Http/Requests/UpdateDefaultAliasDomainRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class UpdateDefaultAliasDomainRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'domain' => [
'required',
'string',
Rule::in($this->user()->domainOptions())
]
];
}
}
70 changes: 35 additions & 35 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddDefaultAliasDomainToUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->string('default_alias_domain')->after('default_recipient_id')->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('default_alias_domain');
});
}
}
Loading

0 comments on commit 50bbc9d

Please sign in to comment.