diff --git a/src/Commands/DatabaseSeedCommand.php b/src/Commands/DatabaseSeedCommand.php index 40b44f4..5303205 100644 --- a/src/Commands/DatabaseSeedCommand.php +++ b/src/Commands/DatabaseSeedCommand.php @@ -47,6 +47,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $configValues = [ ['default_mailer', 'Default Mailer', SmtpMailer::ALIAS, '', 'string'], [RtmClickReplace::CONFIG_NAME, 'Mail click tracker', false, '', 'boolean'], + ['enable_one_click_unsubscribing', 'Enable One-Click Unsubscribing', false, 'Add a header to emails that signals support for One-Click unsubscribe from the newsletter according to RFC 8058. The unsubscribe URL must support the POST method, must immediately unsubscribe the user from the newsletter, must not use redirection or any additional user verification; all the necessary data for unsubscribing must be part of the URL address.', 'boolean'] ]; foreach ($configValues as $configValue) { $config = $this->configsRepository->findBy('name', $configValue['0']); diff --git a/src/Forms/ConfigFormFactory.php b/src/Forms/ConfigFormFactory.php index 0d9e349..325cf48 100644 --- a/src/Forms/ConfigFormFactory.php +++ b/src/Forms/ConfigFormFactory.php @@ -123,7 +123,8 @@ public function create(): Form break; case Config::TYPE_BOOLEAN: $othersContainer->addCheckbox($config['name'], $config['display_name']) - ->setDefaultValue($config['value']); + ->setDefaultValue($config['value']) + ->setOption('description', $config['description']); break; case Config::TYPE_INT: $othersContainer->addText($config['name'], $config['display_name']) diff --git a/src/Models/Sender.php b/src/Models/Sender.php index 2cd1ef4..d9bc36c 100644 --- a/src/Models/Sender.php +++ b/src/Models/Sender.php @@ -9,6 +9,7 @@ use Nette\Utils\Json; use Psr\Log\LoggerInterface; use Remp\MailerModule\Models\Auth\AutoLogin; +use Remp\MailerModule\Models\Config\Config; use Remp\MailerModule\Models\Config\ConfigNotExistsException; use Remp\MailerModule\Models\ContentGenerator\ContentGenerator; use Remp\MailerModule\Models\ContentGenerator\GeneratorInputFactory; @@ -40,7 +41,8 @@ public function __construct( private ContentGenerator $contentGenerator, private GeneratorInputFactory $generatorInputFactory, private ServiceParamsProviderInterface $serviceParamsProvider, - private EmailAllowList $emailAllowList + private EmailAllowList $emailAllowList, + private Config $config ) { } @@ -350,18 +352,28 @@ private function setMessageAttachments(Message $message): ?int private function setMessageHeaders(Message $message, $mailSenderId, ?array $templateParams, bool $isBatch = false): void { + $enableOneClickUnsubscribing = $this->config->get('enable_one_click_unsubscribing'); if (!$this->template->mail_type->locked) { if ($isBatch) { $message->setHeader('List-Unsubscribe', '%recipient.list_unsubscribe%'); + if ($enableOneClickUnsubscribing) { + $message->setHeader('List-Unsubscribe-Post', '%recipient.list_unsubscribe_post%'); + } foreach ($templateParams as $email => $variables) { if (isset($variables['unsubscribe'])) { $templateParams[$email]['list_unsubscribe'] = "<{$variables['unsubscribe']}>"; + if ($enableOneClickUnsubscribing) { + $templateParams[$email]['list_unsubscribe_post'] = 'List-Unsubscribe=One-Click'; + } } } } else { foreach ($templateParams as $email => $variables) { if (isset($variables['unsubscribe'])) { $message->setHeader('List-Unsubscribe', "<{$variables['unsubscribe']}>"); + if ($enableOneClickUnsubscribing) { + $message->setHeader('List-Unsubscribe-Post', 'List-Unsubscribe=One-Click'); + } } } }