Add List-Unsubscribe header
authorTim Düsterhus <duesterhus@woltlab.com>
Mon, 29 Jun 2020 14:11:11 +0000 (16:11 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Mon, 29 Jun 2020 14:14:24 +0000 (16:14 +0200)
Resolves #3379

wcfsetup/install/files/lib/system/cronjob/DailyMailNotificationCronjob.class.php
wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php

index aac7ac0c02b8a0b04a1389b7023643a1c838d410..deed3785b469decdd1bd5231e48d6bfa9ae21149 100644 (file)
@@ -7,12 +7,14 @@ use wcf\data\user\User;
 use wcf\data\user\UserEditor;
 use wcf\data\user\UserList;
 use wcf\data\user\UserProfile;
+use wcf\form\NotificationUnsubscribeForm;
 use wcf\system\cache\runtime\UserProfileRuntimeCache;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
 use wcf\system\email\mime\MimePartFacade;
 use wcf\system\email\mime\RecipientAwareTextMimePart;
 use wcf\system\email\Email;
 use wcf\system\email\UserMailbox;
+use wcf\system\request\LinkHandler;
 use wcf\system\user\notification\event\IUserNotificationEvent;
 use wcf\system\user\notification\UserNotificationHandler;
 use wcf\system\WCF;
@@ -213,6 +215,10 @@ class DailyMailNotificationCronjob extends AbstractCronjob {
                        $email->setSubject($user->getLanguage()->getDynamicVariable('wcf.user.notification.mail.daily.subject', ['count' => count($notifications)]));
                        $email->addRecipient(new UserMailbox($user));
                        $email->setListID('daily.notification');
+                       $email->setListUnsubscribe(LinkHandler::getInstance()->getControllerLink(NotificationUnsubscribeForm::class, [
+                               'userID' => $user->userID,
+                               'token' => $user->notificationMailToken,
+                       ]), true);
                        
                        $html = new RecipientAwareTextMimePart('text/html', 'email_dailyNotification', 'wcf', ['notifications' => $notifications]);
                        $plainText = new RecipientAwareTextMimePart('text/plain', 'email_dailyNotification', 'wcf', ['notifications' => $notifications]);
index f554090071948615f26360be6cf3f69f433a9b2f..3f229b60397e9d3bdf1f74325499c4e1dbf6fe7d 100644 (file)
@@ -9,6 +9,7 @@ use wcf\data\user\notification\UserNotificationAction;
 use wcf\data\user\User;
 use wcf\data\user\UserEditor;
 use wcf\data\user\UserProfile;
+use wcf\form\NotificationUnsubscribeForm;
 use wcf\system\background\job\NotificationEmailDeliveryBackgroundJob;
 use wcf\system\background\BackgroundQueueHandler;
 use wcf\system\cache\builder\UserNotificationEventCacheBuilder;
@@ -697,6 +698,15 @@ class UserNotificationHandler extends SingletonFactory {
                $email->addRecipient(new UserMailbox($user));
                $humanReadableListId = $user->getLanguage()->getDynamicVariable('wcf.user.notification.'.$event->objectType.'.'.$event->eventName);
                $email->setListID($event->eventName.'.'.$event->objectType.'.instant.notification', $humanReadableListId);
+               $email->setListUnsubscribe(LinkHandler::getInstance()->getControllerLink(NotificationUnsubscribeForm::class, [
+                       // eventID is not part of the parameter list, because we can't communicate that
+                       // only a single type would be unsubscribed.
+                       // The recipient's expectations when performing the One-Click unsubscribing are that
+                       // no further emails will be received. Not following that expectation might result in
+                       // harsh filtering.
+                       'userID' => $user->userID,
+                       'token' => $user->notificationMailToken,
+               ]), true);
                
                $message = $event->getEmailMessage('instant');
                if (is_array($message)) {