From f5ce800a4fd526c6e08845364a6fc37ab118c66a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Sun, 31 Jul 2016 13:57:40 +0200 Subject: [PATCH] Convert MailForm to new email API --- com.woltlab.wcf/templates/email_mail.tpl | 9 +++++ .../install/files/lib/form/MailForm.class.php | 36 +++++++++++-------- wcfsetup/install/lang/de.xml | 12 +++++-- wcfsetup/install/lang/en.xml | 12 +++++-- 4 files changed, 48 insertions(+), 21 deletions(-) create mode 100644 com.woltlab.wcf/templates/email_mail.tpl diff --git a/com.woltlab.wcf/templates/email_mail.tpl b/com.woltlab.wcf/templates/email_mail.tpl new file mode 100644 index 0000000000..f66cf12f28 --- /dev/null +++ b/com.woltlab.wcf/templates/email_mail.tpl @@ -0,0 +1,9 @@ +{if $mimeType === 'text/plain'} +{capture assign='content'}{lang}wcf.user.mail.mail.plaintext{/lang}{/capture} +{include file='email_plaintext'} +{else} + {capture assign='content'} + {lang}wcf.user.mail.mail.html{/lang} + {/capture} + {include file='email_html'} +{/if} diff --git a/wcfsetup/install/files/lib/form/MailForm.class.php b/wcfsetup/install/files/lib/form/MailForm.class.php index d5ddc691f7..03c3da60d3 100644 --- a/wcfsetup/install/files/lib/form/MailForm.class.php +++ b/wcfsetup/install/files/lib/form/MailForm.class.php @@ -2,10 +2,14 @@ namespace wcf\form; use wcf\data\user\UserProfile; use wcf\system\cache\runtime\UserProfileRuntimeCache; +use wcf\system\email\mime\MimePartFacade; +use wcf\system\email\mime\RecipientAwareTextMimePart; +use wcf\system\email\Email; +use wcf\system\email\Mailbox; +use wcf\system\email\UserMailbox; use wcf\system\exception\IllegalLinkException; use wcf\system\exception\PermissionDeniedException; use wcf\system\exception\UserInputException; -use wcf\system\mail\Mail; use wcf\system\page\PageLocationManager; use wcf\system\request\LinkHandler; use wcf\system\WCF; @@ -37,7 +41,7 @@ class MailForm extends AbstractCaptchaForm { * recipient's user object * @var UserProfile */ - public $user = 0; + public $user = null; /** * true to add the reply-to header @@ -131,34 +135,36 @@ class MailForm extends AbstractCaptchaForm { public function save() { parent::save(); - // get recipient's language - $userLanguage = $this->user->getLanguage(); - // build message data - $subjectData = [ - 'username' => WCF::getUser()->userID ? WCF::getUser()->username : $this->email, - 'subject' => $this->subject - ]; $messageData = [ 'message' => $this->message, - 'recipient' => $this->user, 'username' => WCF::getUser()->userID ? WCF::getUser()->username : $this->email ]; // build mail - $mail = new Mail([$this->user->username => $this->user->email], $userLanguage->getDynamicVariable('wcf.user.mail.mail.subject', $subjectData), $userLanguage->getDynamicVariable('wcf.user.mail.mail', $messageData)); - $mail->setLanguage($userLanguage); + $email = new Email(); + $email->addRecipient(new UserMailbox($this->user->getDecoratedObject())); + $email->setSubject($this->user->getLanguage()->getDynamicVariable('wcf.user.mail.mail.subject', [ + 'username' => WCF::getUser()->userID ? WCF::getUser()->username : $this->email, + 'subject' => $this->subject + ])); + $email->setBody(new MimePartFacade([ + new RecipientAwareTextMimePart('text/html', 'email_mail', 'wcf', $messageData), + new RecipientAwareTextMimePart('text/plain', 'email_mail', 'wcf', $messageData) + ])); // add reply-to tag if (WCF::getUser()->userID) { - if ($this->showAddress) $mail->setHeader('Reply-To: '.Mail::buildAddress(WCF::getUser()->username, WCF::getUser()->email)); + if ($this->showAddress) { + $email->setReplyTo(new UserMailbox(WCF::getUser())); + } } else { - $mail->setHeader('Reply-To: '.$this->email); + $email->setReplyTo(new Mailbox($this->email)); } // send mail - $mail->send(); + $email->send(); $this->saved(); // forward to profile page diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 320c13d548..842549db19 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -3413,11 +3413,17 @@ Benachrichtigungen auf {PAGE_TITLE|language - username}, + + getUser()->username}, + +„{@$username}“ hat {if LANGUAGE_USE_INFORMAL_VARIANT}dir{else}Ihnen{/if} über die Website {@PAGE_TITLE|language} [URL:{link isEmail=true}{/link}] folgende Nachricht gesandt: -"{@$username}" hat {if LANGUAGE_USE_INFORMAL_VARIANT}dir{else}Ihnen{/if} über die Website "{@PAGE_TITLE|language}" folgende Nachricht gesandt: {@$message}]]> - + Hallo {$mailbox->getUser()->username}, + +

„{$username}“ hat {if LANGUAGE_USE_INFORMAL_VARIANT}dir{else}Ihnen{/if} über die Website {PAGE_TITLE|language} folgende Nachricht gesandt:

+ +

{@$message|newlineToBreak}

]]> username} wurde erfolgreich versandt.]]> diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 7d4f6fa615..f07a1b3736 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -3440,11 +3440,17 @@ your notifications on {PAGE_TITLE|language} - username}, + + getUser()->username}, + +“{@$username}” sent you a message on {@PAGE_TITLE|language} [URL:{link isEmail=true}{/link}]: -"{@$username}" sent you a message on "{@PAGE_TITLE|language}": {@$message}]]> - +Dear {$mailbox->getUser()->username}, + +

„{$username}“ sent you a message on {PAGE_TITLE|language}:

+ +

{@$message|newlineToBreak}

]]> username}.]]> -- 2.20.1