feat: add List-Unsubscribe header to emails (#4069)

This commit is contained in:
Sami Mazouz 2024-10-16 17:51:20 +01:00 committed by GitHub
parent abe1a4cc30
commit 7383bc94df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 0 deletions

View File

@ -12,8 +12,10 @@ namespace Flarum\Mail;
use Flarum\Foundation\AbstractServiceProvider; use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Settings\SettingsRepositoryInterface; use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\Container\Container; use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Contracts\Mail\Mailer as MailerContract; use Illuminate\Contracts\Mail\Mailer as MailerContract;
use Illuminate\Contracts\Validation\Factory; use Illuminate\Contracts\Validation\Factory;
use Illuminate\Mail\Events\MessageSending;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Symfony\Component\Mailer\Transport\TransportInterface; use Symfony\Component\Mailer\Transport\TransportInterface;
@ -82,4 +84,9 @@ class MailServiceProvider extends AbstractServiceProvider
$this->container->alias('mailer', MailerContract::class); $this->container->alias('mailer', MailerContract::class);
} }
public function boot(Dispatcher $events): void
{
$events->listen(MessageSending::class, MutateEmail::class);
}
} }

View File

@ -0,0 +1,26 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Mail;
use Illuminate\Mail\Events\MessageSending;
class MutateEmail
{
public function handle(MessageSending $event): bool
{
if (! empty($link = $event->data['unsubscribeLink'])) {
$headers = $event->message->getHeaders();
$headers->addTextHeader('List-Unsubscribe', '<'.$link.'>');
}
return true;
}
}