Convert MailForm to new email API
authorTim Düsterhus <duesterhus@woltlab.com>
Sun, 31 Jul 2016 11:57:40 +0000 (13:57 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Sun, 31 Jul 2016 11:57:53 +0000 (13:57 +0200)
com.woltlab.wcf/templates/email_mail.tpl [new file with mode: 0644]
wcfsetup/install/files/lib/form/MailForm.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

diff --git a/com.woltlab.wcf/templates/email_mail.tpl b/com.woltlab.wcf/templates/email_mail.tpl
new file mode 100644 (file)
index 0000000..f66cf12
--- /dev/null
@@ -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}
index d5ddc691f74489663898200efccfe93c09b79dd8..03c3da60d345e2ea1a9b70c02d9f2db52e09f2b0 100644 (file)
@@ -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
index 320c13d548491f2e7a3fa78324803e4dc58df051..842549db193ea0d3724ad66f639a06509a0f5a94 100644 (file)
@@ -3413,11 +3413,17 @@ Benachrichtigungen auf <a href="{link isEmail=true}{/link}">{PAGE_TITLE|language
        
        <category name="wcf.user.mail">
                <item name="wcf.user.mail.information"><![CDATA[Informationen]]></item>
-               <item name="wcf.user.mail.mail"><![CDATA[Hallo {@$recipient->username},
+               <item name="wcf.user.mail.mail.subject"><![CDATA[Nachricht von {@$username}: {@$subject}]]></item>
+               <item name="wcf.user.mail.mail.plaintext"><![CDATA[Hallo {@$mailbox->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}]]></item>
-               <item name="wcf.user.mail.mail.subject"><![CDATA[Nachricht von {@$username}: {@$subject}]]></item>
+               <item name="wcf.user.mail.mail.html"><![CDATA[<h1>Hallo {$mailbox->getUser()->username},</h1>
+
+<p>„{$username}“ hat {if LANGUAGE_USE_INFORMAL_VARIANT}dir{else}Ihnen{/if} über die Website <a href="{link isEmail=true}{/link}">{PAGE_TITLE|language}</a> folgende Nachricht gesandt:</p>
+
+<p>{@$message|newlineToBreak}</p>]]></item>
                <item name="wcf.user.mail.message"><![CDATA[Nachricht]]></item>
                <item name="wcf.user.mail.senderEmail"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Deine{else}Ihre{/if} E-Mail-Adresse]]></item>
                <item name="wcf.user.mail.sent"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Deine{else}Ihre{/if} Nachricht an {$user->username} wurde erfolgreich versandt.]]></item>
index 7d4f6fa61532ecb743821dfbc66cab6eac56244f..f07a1b37365520cad1b99493834ab0b6ba377e5b 100644 (file)
@@ -3440,11 +3440,17 @@ your notifications on <a href="{link isEmail=true}{/link}">{PAGE_TITLE|language}
        
        <category name="wcf.user.mail">
                <item name="wcf.user.mail.information"><![CDATA[Details]]></item>
-               <item name="wcf.user.mail.mail"><![CDATA[Dear {@$recipient->username},
+               <item name="wcf.user.mail.mail.subject"><![CDATA[Message From {@$username}: {@$subject}]]></item>
+               <item name="wcf.user.mail.mail.plaintext"><![CDATA[Dear {@$mailbox->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}]]></item>
-               <item name="wcf.user.mail.mail.subject"><![CDATA[Message From {@$username}: {@$subject}]]></item>
+<item name="wcf.user.mail.mail.html"><![CDATA[<h1>Dear {$mailbox->getUser()->username},</h1>
+
+<p>„{$username}“ sent you a message on <a href="{link isEmail=true}{/link}">{PAGE_TITLE|language}</a>:</p>
+
+<p>{@$message|newlineToBreak}</p>]]></item>
                <item name="wcf.user.mail.message"><![CDATA[Message]]></item>
                <item name="wcf.user.mail.senderEmail"><![CDATA[Your email address]]></item>
                <item name="wcf.user.mail.sent"><![CDATA[Message has been sent to {$user->username}.]]></item>