[TASK] Encapsulate bootstrap base code
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_formmail.php
index 5554ebb..78f6a30 100644 (file)
 /**
  * Contains a class for formmail
  *
- * $Id$
  * Revised for TYPO3 3.6 July/2003 by Kasper Skårhøj
  *
- * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
+ * @author Kasper Skårhøj <kasperYYYY@typo3.com>
  */
-/**
- * [CLASS/FUNCTION INDEX of SCRIPT]
- *
- *
- *
- *   69: class t3lib_formmail
- *   95:        function start($V,$base64=false)
- *  172:        function addAttachment($file, $filename)
- *
- * TOTAL FUNCTIONS: 2
- * (This index is automatically created/updated by the extension "extdeveval")
- *
- */
-
 
 /**
  * Formmail class, used by the TYPO3 "cms" extension (default frontend) to send email forms.
  *
- * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
+ * @author Kasper Skårhøj <kasperYYYY@typo3.com>
  * @package TYPO3
  * @subpackage t3lib
  * @see tslib_fe::sendFormmail(), t3lib/formmail.php
  */
 class t3lib_formmail {
        protected $reserved_names = 'recipient,recipient_copy,auto_respond_msg,auto_respond_checksum,redirect,subject,attachment,from_email,from_name,replyto_email,replyto_name,organisation,priority,html_enabled,quoted_printable,submit_x,submit_y';
-       protected $dirtyHeaders = array(); // collection of suspicious header data, used for logging
+               // Collection of suspicious header data, used for logging
+       protected $dirtyHeaders = array();
 
        protected $characterSet;
        protected $subject;
@@ -73,7 +59,6 @@ class t3lib_formmail {
        /** @var t3lib_mail_Message */
        protected $mailMessage;
        protected $recipient;
-       protected $returnPath;
        protected $plainContent = '';
 
        /** @var array Files to clean up at the end (attachments) */
@@ -97,26 +82,23 @@ class t3lib_formmail {
         * [html_enabled]:              If mail is sent as html
         * [use_base64]:                If set, base64 encoding will be used instead of quoted-printable
         *
-        * @param       array           Contains values for the field names listed above (with slashes removed if from POST input)
-        * @param       boolean         Whether to base64 encode the mail content
-        * @return      void
+        * @param array $valueList Contains values for the field names listed above (with slashes removed if from POST input)
+        * @param boolean $base64 Whether to base64 encode the mail content
+        * @return void
         */
-       function start($valueList, $base64 = false) {
+       function start($valueList, $base64 = FALSE) {
 
                $this->mailMessage = t3lib_div::makeInstance('t3lib_mail_Message');
 
-               if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['forceReturnPath']) {
-                       $this->returnPath = $GLOBALS['TYPO3_CONF_VARS']['SYS']['forceReturnPath'];
-                       $this->mailMessage->setReturnPath($this->returnPath);
-               }
-               $this->mailMessage->getHeaders()->addTextHeader('X-Mailer', 'TYPO3');
-
                if ($GLOBALS['TSFE']->config['config']['formMailCharset']) {
                                // Respect formMailCharset if it was set
                        $this->characterSet = $GLOBALS['TSFE']->csConvObj->parse_charset($GLOBALS['TSFE']->config['config']['formMailCharset']);
                } elseif ($GLOBALS['TSFE']->metaCharset != $GLOBALS['TSFE']->renderCharset) {
                                // Use metaCharset for mail if different from renderCharset
                        $this->characterSet = $GLOBALS['TSFE']->metaCharset;
+               } else {
+                               // Otherwise use renderCharset as default
+                       $this->characterSet = $GLOBALS['TSFE']->renderCharset;
                }
 
                if ($base64 || $valueList['use_base64']) {
@@ -124,7 +106,7 @@ class t3lib_formmail {
                }
 
                if (isset($valueList['recipient'])) {
-                               // convert form data from renderCharset to mail charset
+                               // Convert form data from renderCharset to mail charset
                        $this->subject = ($valueList['subject'])
                                        ? $valueList['subject']
                                        : 'Formmail on ' . t3lib_div::getIndpEnv('HTTP_HOST');
@@ -134,11 +116,9 @@ class t3lib_formmail {
                                        ? $valueList['from_name']
                                        : (($valueList['name']) ? $valueList['name'] : '');
                        $this->fromName = $this->sanitizeHeaderString($this->fromName);
-                       $this->fromName = preg_match('/\s|,/', $this->fromName) >= 1 ? '"' . $this->fromName . '"' : $this->fromName;
 
                        $this->replyToName = ($valueList['replyto_name']) ? $valueList['replyto_name'] : $this->fromName;
                        $this->replyToName = $this->sanitizeHeaderString($this->replyToName);
-                       $this->replyToName = preg_match('/\s|,/', $this->replyToName) >= 1 ? '"' . $this->replyToName . '"' : $this->replyToName;
 
                        $this->organisation = ($valueList['organisation']) ? $valueList['organisation'] : '';
                        $this->organisation = $this->sanitizeHeaderString($this->organisation);
@@ -146,18 +126,16 @@ class t3lib_formmail {
                        $this->fromAddress = ($valueList['from_email']) ? $valueList['from_email'] : (
                                ($valueList['email']) ? $valueList['email'] : ''
                        );
-                       $this->fromAddress = t3lib_div::validEmail($this->fromAddress)
-                                       ? $this->fromAddress
-                                       : t3lib_utility_Mail::getSystemFromAddress();
+                       if (!t3lib_div::validEmail($this->fromAddress)) {
+                               $this->fromAddress = t3lib_utility_Mail::getSystemFromAddress();
+                               $this->fromName = t3lib_utility_Mail::getSystemFromName();
+                       }
 
                        $this->replyToAddress = ($valueList['replyto_email']) ? $valueList['replyto_email'] : $this->fromAddress;
-                       $this->replyToAddress = t3lib_div::validEmail($this->replyToAddress)
-                                       ? $this->replyToAddress
-                                       : t3lib_utility_Mail::getSystemFromAddress();
 
-                       $this->priority = ($valueList['priority']) ? t3lib_div::intInRange($valueList['priority'], 1, 5) : 3;
+                       $this->priority = ($valueList['priority']) ? t3lib_utility_Math::forceIntegerInRange($valueList['priority'], 1, 5) : 3;
 
-                               // auto responder
+                               // Auto responder
                        $this->autoRespondMessage = (trim($valueList['auto_respond_msg']) && $this->fromAddress)
                                        ? trim($valueList['auto_respond_msg'])
                                        : '';
@@ -186,7 +164,7 @@ class t3lib_formmail {
                                                $space = (strlen($val) > 60) ? LF : '';
                                                $val = (is_array($val) ? implode($val, LF) : $val);
 
-                                                       // convert form data from renderCharset to mail charset (HTML may use entities)
+                                                       // Convert form data from renderCharset to mail charset (HTML may use entities)
                                                $plainTextValue = $val;
                                                $HtmlValue = htmlspecialchars($val);
 
@@ -202,10 +180,10 @@ class t3lib_formmail {
                        $this->plainContent = $plainTextContent;
 
                        if ($valueList['html_enabled']) {
-                               $this->mailMessage->setBody($htmlContent, 'text/html');
-                               $this->mailMessage->addPart($plainTextContent, 'text/plain');
+                               $this->mailMessage->setBody($htmlContent, 'text/html', $this->characterSet);
+                               $this->mailMessage->addPart($plainTextContent, 'text/plain', $this->characterSet);
                        } else {
-                               $this->mailMessage->setBody($plainTextContent, 'text/plain');
+                               $this->mailMessage->setBody($plainTextContent, 'text/plain', $this->characterSet);
                        }
 
                        for ($a = 0; $a < 10; $a++) {
@@ -233,22 +211,24 @@ class t3lib_formmail {
                                $this->temporaryFiles[] = $theFile;
                        }
 
+                       $from = $this->fromName ? array($this->fromAddress => $this->fromName) : array($this->fromAddress);
                        $this->recipient = $this->parseAddresses($valueList['recipient']);
                        $this->mailMessage->setSubject($this->subject)
-                                       ->setFrom(array($this->fromAddress => $this->fromName))
+                                       ->setFrom($from)
                                        ->setTo($this->recipient)
                                        ->setPriority($this->priority);
+                       $replyTo = $this->replyToName ? array($this->replyToAddress => $this->replyToName) : array($this->replyToAddress);
+                       $this->mailMessage->setReplyTo($replyTo);
                        $this->mailMessage->getHeaders()->addTextHeader('Organization', $this->organisation);
                        if ($valueList['recipient_copy']) {
-                               $this->mailMessage->addCc($this->parseAddresses($valueList['recipient_copy']));
-                       }
-                       if ($this->characterSet) {
-                               $this->mailMessage->setCharset($this->characterSet);
+                               $this->mailMessage->setCc($this->parseAddresses($valueList['recipient_copy']));
                        }
+                       $this->mailMessage->setCharset($this->characterSet);
+
                                // Ignore target encoding. This is handled automatically by Swift Mailer and overriding the defaults
                                // is not worth the trouble
 
-                               // log dirty header lines
+                               // Log dirty header lines
                        if ($this->dirtyHeaders) {
                                t3lib_div::sysLog('Possible misuse of t3lib_formmail: see TYPO3 devLog', 'Core', 3);
                                if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_DLOG']) {
@@ -261,8 +241,8 @@ class t3lib_formmail {
        /**
         * Checks string for suspicious characters
         *
-        * @param       string  String to check
-        * @return      string  Valid or empty string
+        * @param string $string String to check
+        * @return string Valid or empty string
         */
        protected function sanitizeHeaderString($string) {
                $pattern = '/[\r\n\f\e]/';
@@ -272,7 +252,7 @@ class t3lib_formmail {
                }
                return $string;
        }
-       
+
        /**
         * Parses mailbox headers and turns them into an array.
         *
@@ -291,10 +271,10 @@ class t3lib_formmail {
                $addressList = array();
                foreach ($addresses as $address) {
                        if ($address->personal) {
-                               // item with name found ( name <email@example.org> )
+                               // Item with name found ( name <email@example.org> )
                                $addressList[$address->mailbox . '@' . $address->host] = $address->personal;
                        } else {
-                               // item without name found ( email@example.org )
+                               // Item without name found ( email@example.org )
                                $addressList[] = $address->mailbox . '@' . $address->host;
                        }
                }
@@ -319,8 +299,8 @@ class t3lib_formmail {
                if ($this->autoRespondMessage) {
                        $theParts = explode('/', $this->autoRespondMessage, 2);
                        $theParts[0] = str_replace('###SUBJECT###', $this->subject, $theParts[0]);
-                       $theParts[1] = str_replace("/", LF, $theParts[1]);
-                       $theParts[1] = str_replace("###MESSAGE###", $this->plainContent, $theParts[1]);
+                       $theParts[1] = str_replace('/', LF, $theParts[1]);
+                       $theParts[1] = str_replace('###MESSAGE###', $this->plainContent, $theParts[1]);
 
                                /** @var $autoRespondMail t3lib_mail_Message */
                        $autoRespondMail = t3lib_div::makeInstance('t3lib_mail_Message');
@@ -328,9 +308,6 @@ class t3lib_formmail {
                                        ->setSubject($theParts[0])
                                        ->setFrom($this->recipient)
                                        ->setBody($theParts[1]);
-                       if ($this->returnPath) {
-                               $autoRespondMail->setReturnPath($this->returnPath);
-                       }
                        $autoRespondMail->send();
                }
                return $this->mailMessage->isSent();
@@ -341,14 +318,11 @@ class t3lib_formmail {
         */
        public function __destruct() {
                foreach ($this->temporaryFiles as $file) {
-                       t3lib_div::unlink_tempfile($file);
+                       if (t3lib_div::isAllowedAbsPath($file) && t3lib_div::isFirstPartOfStr($file, PATH_site . 'typo3temp/upload_temp_')) {
+                               t3lib_div::unlink_tempfile($file);
+                       }
                }
        }
 }
 
-
-if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_formmail.php'])) {
-       include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_formmail.php']);
-}
-
-?>
+?>
\ No newline at end of file