42 lines
1.3 KiB
PHP
42 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Mail\Concerns;
|
|
|
|
use App\Enums\EmailNotificationType;
|
|
use App\Models\User;
|
|
use Illuminate\Mail\Mailables\Headers;
|
|
use Illuminate\Support\Facades\URL;
|
|
|
|
/**
|
|
* Macht eine Benachrichtigungs-Mail abbestellbar: signierter Abmelde-Link
|
|
* für den Mail-Footer (ohne Login nutzbar, ohne Ablauf — der Link aus alten
|
|
* Mails bleibt gültig) plus die List-Unsubscribe-Header nach RFC 8058, mit
|
|
* denen Mail-Clients (Gmail, Apple Mail …) einen nativen
|
|
* „Abbestellen"-Button anbieten.
|
|
*
|
|
* Der Link wird im Konstruktor der Mailable erzeugt (configureUnsubscribe),
|
|
* damit er beim Queuen mit serialisiert wird.
|
|
*/
|
|
trait Unsubscribable
|
|
{
|
|
public string $unsubscribeUrl;
|
|
|
|
public EmailNotificationType $notificationType;
|
|
|
|
protected function configureUnsubscribe(User $user, EmailNotificationType $type): void
|
|
{
|
|
$this->notificationType = $type;
|
|
$this->unsubscribeUrl = URL::signedRoute('email-preferences.unsubscribe', [
|
|
'user' => $user->id,
|
|
'type' => $type->value,
|
|
]);
|
|
}
|
|
|
|
public function headers(): Headers
|
|
{
|
|
return new Headers(text: [
|
|
'List-Unsubscribe' => '<'.$this->unsubscribeUrl.'>',
|
|
'List-Unsubscribe-Post' => 'List-Unsubscribe=One-Click',
|
|
]);
|
|
}
|
|
}
|