Add $language parameter to \wcf\system\email\Mailbox
authorTim Düsterhus <duesterhus@woltlab.com>
Fri, 24 Jul 2015 15:17:43 +0000 (17:17 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Fri, 24 Jul 2015 15:17:43 +0000 (17:17 +0200)
wcfsetup/install/files/lib/system/email/Mailbox.class.php

index f94858e4e51f7a2df23e6bdde41d7e89694b8142..65abde2d9302807bc31c0d0206dda1f556f408a2 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 namespace wcf\system\email;
+use wcf\data\language\Language;
 use wcf\system\exception\SystemException;
+use wcf\system\language\LanguageFactory;
 
 /**
  * Represents a RFC 5322 mailbox.
@@ -28,16 +30,21 @@ class Mailbox {
        /**
         * Creates a new Mailbox.
         * 
-        * @param       string  $address        email address of this mailbox
-        * @param       string  $name           human readable name of this mailbox (or null)
+        * @param       string                          $address        email address of this mailbox
+        * @param       string                          $name           human readable name of this mailbox (or null)
+        * @param       \wcf\data\language\Language     $language       Language to use for localization (or null for the default language)
         */
-       public function __construct($address, $name = null) {
+       public function __construct($address, $name = null, Language $language = null) {
                if (!preg_match('(^'.EmailGrammar::getGrammar('addr-spec').'$)', $address)) {
                        throw new SystemException("The given email address '".$address."' is invalid.");
                }
                
                $this->address = $address;
                $this->name = $name;
+               if ($language === null) {
+                       $language = LanguageFactory::getInstance()->getLanguage(LanguageFactory::getInstance()->getDefaultLanguageID());
+               }
+               $this->language = $language;
        }
        
        /**
@@ -58,6 +65,16 @@ class Mailbox {
                return $this->address;
        }
        
+       /**
+        * Returns the language the recipient of this mailbox wants.
+        * This is used for localization of the email template.
+        * 
+        * @return      \wcf\data\language\Language
+        */
+       public function getLanguage() {
+               return $this->language;
+       }
+       
        /**
         * Returns a string representation for use in a RFC 5233 message.
         *