mirror of
https://github.com/anonaddy/anonaddy
synced 2026-05-09 00:22:27 +02:00
Added new blocklist feature and list-unsubscribe behaviour
This commit is contained in:
54
app/Http/Controllers/BlocklistOneClickController.php
Normal file
54
app/Http/Controllers/BlocklistOneClickController.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Alias;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class BlocklistOneClickController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('signed');
|
||||
$this->middleware('throttle:6,1');
|
||||
}
|
||||
|
||||
public function blockEmailPost(Request $request, string $alias)
|
||||
{
|
||||
$alias = Alias::findOrFail($alias);
|
||||
|
||||
$validated = $request->validate([
|
||||
'email' => ['required', 'string', 'email', 'max:253'],
|
||||
]);
|
||||
|
||||
$value = strtolower(trim($validated['email']));
|
||||
|
||||
$alias->user->blockedSenders()->firstOrCreate(
|
||||
['type' => 'email', 'value' => $value]
|
||||
);
|
||||
|
||||
Log::info('One-Click Unsubscribe blocked email: '.$value.' for alias: '.$alias->email.' ID: '.$alias->id);
|
||||
|
||||
return response('');
|
||||
}
|
||||
|
||||
public function blockDomainPost(Request $request, string $alias)
|
||||
{
|
||||
$alias = Alias::findOrFail($alias);
|
||||
|
||||
$validated = $request->validate([
|
||||
'domain' => ['required', 'string', 'max:253', 'regex:/^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,}$/i'],
|
||||
]);
|
||||
|
||||
$value = strtolower(trim($validated['domain']));
|
||||
|
||||
$alias->user->blockedSenders()->firstOrCreate(
|
||||
['type' => 'domain', 'value' => $value]
|
||||
);
|
||||
|
||||
Log::info('One-Click Unsubscribe blocked domain: '.$value.' for alias: '.$alias->email.' ID: '.$alias->id);
|
||||
|
||||
return response('');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user