From dfe4787884c739acec428a4958158cdd8287a486 Mon Sep 17 00:00:00 2001 From: Sami Mazouz Date: Sat, 12 Oct 2024 15:15:02 +0100 Subject: [PATCH 1/2] feat: add `List-Unsubscribe` header to emails --- .../core/src/Mail/MailServiceProvider.php | 7 +++++++ framework/core/src/Mail/MutateEmail.php | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 framework/core/src/Mail/MutateEmail.php diff --git a/framework/core/src/Mail/MailServiceProvider.php b/framework/core/src/Mail/MailServiceProvider.php index 9a1d338b5c..749b224128 100644 --- a/framework/core/src/Mail/MailServiceProvider.php +++ b/framework/core/src/Mail/MailServiceProvider.php @@ -12,8 +12,10 @@ 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 @@ public function register(): void $this->container->alias('mailer', MailerContract::class); } + + public function boot(Dispatcher $events): void + { + $events->listen(MessageSending::class, MutateEmail::class); + } } diff --git a/framework/core/src/Mail/MutateEmail.php b/framework/core/src/Mail/MutateEmail.php new file mode 100644 index 0000000000..7a81e1fd98 --- /dev/null +++ b/framework/core/src/Mail/MutateEmail.php @@ -0,0 +1,19 @@ +data['unsubscribeLink'])) { + $headers = $event->message->getHeaders(); + + $headers->addTextHeader('List-Unsubscribe', '<'.$link.'>'); + } + + return true; + } +} From 94a43bca4fec0100efac034e54f116d09008e5fa Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sat, 12 Oct 2024 14:15:14 +0000 Subject: [PATCH 2/2] Apply fixes from StyleCI --- framework/core/src/Mail/MutateEmail.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/framework/core/src/Mail/MutateEmail.php b/framework/core/src/Mail/MutateEmail.php index 7a81e1fd98..b668ce401e 100644 --- a/framework/core/src/Mail/MutateEmail.php +++ b/framework/core/src/Mail/MutateEmail.php @@ -1,5 +1,12 @@