Skip to content
Open
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
1 change: 1 addition & 0 deletions src/Commands/DatabaseSeedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
3 changes: 2 additions & 1 deletion src/Forms/ConfigFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down
14 changes: 13 additions & 1 deletion src/Models/Sender.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
) {
}

Expand Down Expand Up @@ -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');
}
}
}
}
Expand Down