--- /dev/null
+{if $mimeType === 'text/plain'}
+{capture assign='content'}
+{lang}wcf.user.notification.mail.plaintext.intro{/lang}
+
+{foreach from=$notifications item='notification'}
+{assign var='event' value=$notification[event]}
+{assign var='notificationContent' value=$notification[notificationContent]}
+{assign var='notificationType' value=$notification[notificationType]}
+{if $notificationContent|is_array}{include file=$notificationContent[template] application=$notificationContent[application] variables=$notificationContent[variables]}{*
+*}{else}{@$notificationContent}{/if}
+{/foreach}
+
+{*lang}TODO: wcf.user.notification.mail.plaintext.outro{/lang*}
+{/capture}
+{include file='email_plaintext'}
+{else}
+ {capture assign='content'}
+ {lang}wcf.user.notification.mail.html.intro{/lang}
+
+ {foreach from=$notifications item='notification'}
+ {assign var='event' value=$notification[event]}
+ {assign var='notificationContent' value=$notification[notificationContent]}
+ {assign var='notificationType' value=$notification[notificationType]}
+ <div>
+ {if $notificationContent|is_array}
+ {include file=$notificationContent[template] application=$notificationContent[application] variables=$notificationContent[variables]}
+ {else}
+ {@$notificationContent}
+ {/if}
+ </div>
+ {/foreach}
+
+ {*lang}TODO: wcf.user.notification.mail.html.outro{/lang*}
+ {/capture}
+ {include file='email_html'}
+{/if}
use wcf\data\user\UserProfile;
use wcf\system\cache\runtime\UserProfileRuntimeCache;
use wcf\system\database\util\PreparedStatementConditionBuilder;
-use wcf\system\mail\Mail;
+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\user\notification\event\IUserNotificationEvent;
use wcf\system\user\notification\UserNotificationHandler;
use wcf\system\WCF;
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute([
0,
- TIME_NOW - 3600 * 23,
+ TIME_NOW/*TODO - 3600 * 23*/,
0
]);
$userIDs = $statement->fetchAll(\PDO::FETCH_COLUMN);
$eventList->readObjects();
$eventObjects = $eventList->getObjects();
- foreach ($eventsToUser as $userID => $events) {
+ foreach ($eventsToUser as $userID => $notificationIDs) {
if (!isset($users[$userID])) continue;
$user = $users[$userID];
if ($user->activationCode) continue;
if ($user->banned) continue;
- // add mail header
- $message = $user->getLanguage()->getDynamicVariable('wcf.user.notification.mail.header', [
- 'user' => $user
- ]);
-
- foreach ($events as $notificationID) {
+ $notifications = array_map(function ($notificationID) use ($notificationObjects, $eventObjects, $user, $objectTypes, $authors, $authorToNotification) {
$notification = $notificationObjects[$notificationID];
$className = $eventObjects[$notification->eventID]->className;
}
}
- $message .= "\n\n";
- $message .= $class->getEmailMessage('daily');
- }
+ $message = $class->getEmailMessage('daily');
+ if (is_array($message)) {
+ $variables = [
+ 'notificationContent' => $message,
+ 'event' => $class,
+ 'notificationType' => 'daily'
+ ];
+ if (isset($message['variables'])) {
+ $variables['variables'] = $message['variables'];
+ }
+
+ return $variables;
+ }
+ else {
+ return [
+ 'notificationContent' => $message,
+ 'event' => $class,
+ 'notificationType' => 'daily'
+ ];
+ }
+ }, $notificationIDs);
- // append notification mail footer
- $token = $user->notificationMailToken;
- if (!$token) {
- // generate token if not present
- $token = mb_substr(StringUtil::getHash(serialize([$user->userID, StringUtil::getRandomID()])), 0, 20);
+ // generate token if not present
+ if (!$user->notificationMailToken) {
+ $token = bin2hex(CryptoUtil::randomBytes(10));
$editor = new UserEditor($user);
$editor->update(['notificationMailToken' => $token]);
+
+ // reload user
+ $user = new User($user->userID);
}
- $message .= "\n\n";
- $message .= $user->getLanguage()->getDynamicVariable('wcf.user.notification.mail.daily.footer', [
- 'user' => $user,
- 'token' => $token
- ]);
+ $email = new Email();
+ $email->setSubject($user->getLanguage()->getDynamicVariable('wcf.user.notification.mail.daily.subject', ['count' => count($notifications)]));
+ $email->addRecipient(new UserMailbox($user));
+
+ $html = new RecipientAwareTextMimePart('text/html', 'email_dailyNotification', 'wcf', ['notifications' => $notifications]);
+ $plainText = new RecipientAwareTextMimePart('text/plain', 'email_dailyNotification', 'wcf', ['notifications' => $notifications]);
+ $email->setBody(new MimePartFacade([$html, $plainText]));
- // build mail
- $mail = new Mail([$user->username => $user->email], $user->getLanguage()->getDynamicVariable('wcf.user.notification.mail.daily.subject', ['count' => count($events)]), $message);
- $mail->setLanguage($user->getLanguage());
- $mail->send();
+ $email->send();
}
}
}