mirror of
https://github.com/flarum/framework.git
synced 2024-11-22 12:48:28 +08:00
feat: add List-Unsubscribe
header to emails (#4069)
This commit is contained in:
parent
abe1a4cc30
commit
7383bc94df
|
@ -12,8 +12,10 @@ namespace Flarum\Mail;
|
|||
use Flarum\Foundation\AbstractServiceProvider;
|
||||
use Flarum\Settings\SettingsRepositoryInterface;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Contracts\Mail\Mailer as MailerContract;
|
||||
use Illuminate\Contracts\Validation\Factory;
|
||||
use Illuminate\Mail\Events\MessageSending;
|
||||
use Illuminate\Support\Arr;
|
||||
use Symfony\Component\Mailer\Transport\TransportInterface;
|
||||
|
||||
|
@ -82,4 +84,9 @@ class MailServiceProvider extends AbstractServiceProvider
|
|||
|
||||
$this->container->alias('mailer', MailerContract::class);
|
||||
}
|
||||
|
||||
public function boot(Dispatcher $events): void
|
||||
{
|
||||
$events->listen(MessageSending::class, MutateEmail::class);
|
||||
}
|
||||
}
|
||||
|
|
26
framework/core/src/Mail/MutateEmail.php
Normal file
26
framework/core/src/Mail/MutateEmail.php
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user