Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add List-Unsubscribe header to emails #4069

Merged
merged 2 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions framework/core/src/Mail/MailServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}
26 changes: 26 additions & 0 deletions framework/core/src/Mail/MutateEmail.php
Original file line number Diff line number Diff line change
@@ -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