From: Tim Düsterhus Date: Sun, 31 Jul 2016 17:54:15 +0000 (+0200) Subject: Convert MailWorker to new email API X-Git-Tag: 3.0.0_Beta_1~833 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=60fdb91aa69edc4b3d73cd35a2dc1962f93b6b00;p=GitHub%2FWoltLab%2FWCF.git Convert MailWorker to new email API --- diff --git a/com.woltlab.wcf/templates/email_mailWorker.tpl b/com.woltlab.wcf/templates/email_mailWorker.tpl new file mode 100644 index 0000000000..96ebd9527b --- /dev/null +++ b/com.woltlab.wcf/templates/email_mailWorker.tpl @@ -0,0 +1,9 @@ +{assign var='text' value="\x7Busername\x7D"|str_replace:$mailbox->getUser()->username:$text}{if $mimeType === 'text/plain'} +{include file='email_plaintext' content=$text} +{else} + {if $enableHTML} + {include file='email_html' content=$text} + {else} + {include file='email_html' content=$text|newlineToBreak} + {/if} +{/if} diff --git a/wcfsetup/install/files/lib/system/worker/MailWorker.class.php b/wcfsetup/install/files/lib/system/worker/MailWorker.class.php index 7a7286a160..a3125eee38 100644 --- a/wcfsetup/install/files/lib/system/worker/MailWorker.class.php +++ b/wcfsetup/install/files/lib/system/worker/MailWorker.class.php @@ -1,10 +1,15 @@ setSubject($this->mailData['subject']); + $from = new Mailbox($this->mailData['from']); + $email->setSender($from); + $email->setReplyTo($from); + $variables = [ + 'text' => $this->mailData['text'], + 'enableHTML' => $this->mailData['enableHTML'] ? true : false + ]; + if ($this->mailData['enableHTML']) { + $email->setBody(new RecipientAwareTextMimePart('text/html', 'email_mailWorker', 'wcf', $variables)); + } + else { + $email->setBody(new MimePartFacade([ + new RecipientAwareTextMimePart('text/html', 'email_mailWorker', 'wcf', $variables), + new RecipientAwareTextMimePart('text/plain', 'email_mailWorker', 'wcf', $variables) + ])); + } + // get users $sql = "SELECT user_option.*, user.* FROM wcf".WCF_N."_user user @@ -115,25 +139,23 @@ class MailWorker extends AbstractWorker { $user = new User(null, $row); $adminCanMail = $user->adminCanMail; if ($adminCanMail === null || $adminCanMail) { - $this->sendMail($user); + $this->sendMail($email, $user); } } } /** - * Sends the mail to given user. + * Sends the given blueprint (Email without recipients) to the given user. * - * @param \wcf\data\user\User $user + * @param Email $blueprint + * @param User $user */ - protected function sendMail(User $user) { - try { - $mail = new Mail([$user->username => $user->email], $this->mailData['subject'], str_replace('{$username}', $user->username, $this->mailData['text']), $this->mailData['from']); - if ($this->mailData['enableHTML']) $mail->setContentType('text/html'); - $mail->setLanguage($user->getLanguage()); - $mail->send(); - } - catch (SystemException $e) { - // ignore errors + protected function sendMail(Email $blueprint, User $user) { + $email = clone $blueprint; + $email->addRecipient(new UserMailbox($user)); + $jobs = $email->getJobs(); + foreach ($jobs as $job) { + BackgroundQueueHandler::getInstance()->performJob($job); } } diff --git a/wcfsetup/install/files/lib/system/worker/SendNewPasswordWorker.class.php b/wcfsetup/install/files/lib/system/worker/SendNewPasswordWorker.class.php index 46c8dff862..81ce47de48 100644 --- a/wcfsetup/install/files/lib/system/worker/SendNewPasswordWorker.class.php +++ b/wcfsetup/install/files/lib/system/worker/SendNewPasswordWorker.class.php @@ -4,6 +4,7 @@ use wcf\data\user\User; use wcf\data\user\UserAction; use wcf\data\user\UserEditor; use wcf\data\user\UserList; +use wcf\system\background\BackgroundQueueHandler; use wcf\system\clipboard\ClipboardHandler; use wcf\system\email\mime\MimePartFacade; use wcf\system\email\mime\RecipientAwareTextMimePart; @@ -125,7 +126,10 @@ class SendNewPasswordWorker extends AbstractWorker { new RecipientAwareTextMimePart('text/html', 'email_sendNewPassword'), new RecipientAwareTextMimePart('text/plain', 'email_sendNewPassword') ])); - $email->send(); + $jobs = $email->getJobs(); + foreach ($jobs as $job) { + BackgroundQueueHandler::getInstance()->performJob($job); + } } /**