Fix bug #3600
authorMartin Kutschker <martin.t.kutschker@blackbox.net>
Wed, 12 Jul 2006 14:16:29 +0000 (14:16 +0000)
committerMartin Kutschker <martin.t.kutschker@blackbox.net>
Wed, 12 Jul 2006 14:16:29 +0000 (14:16 +0000)
Do charset conversion for mails when config.formMailCharset is set or config.metaCharset different from config.renderCharset
Use ->messageid of base class

git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@1630 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_formmail.php

index f095b83..b60495c 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2006-07-12  Martin Kutschker  <martin.t.kutschker@blackbox.net>
+
+       * Fix bug #3600: config.formMailCharset is not honoured
+       * t3lib_formmail: do charset conversion for mails when config.formMailCharset is set or config.metaCharset different from config.renderCharset
+       * t3lib_formmail: use $this->messageid of base class 
+
 2006-07-12 Dmitry Dulepov <typo3@accio.lv>
 
        * Fixed bug #3594: No lang resolution for title in <tx_templavoila> element
index fc74155..992863c 100644 (file)
@@ -93,24 +93,35 @@ class t3lib_formmail extends t3lib_htmlmail {
         * @return      void
         */
        function start($V,$base64=false)        {
-               parent::start();
+               $convCharset = FALSE;   // do we need to convert form data?
 
-               if ($base64 || $V['use_base64'])        { $this->useBase64(); }
+               if ($GLOBALS['TSFE']->metaCharset != $GLOBALS['TSFE']->renderCharset)   {       // Use metaCharset for mail if different from renderCharset
+                       $this->charset = $GLOBALS['TSFE']->metaCharset;
+                       $convCharset = TRUE;
+               }
 
-               if ($GLOBALS['TSFE']->config['config']['formMailCharset'])      {       // Respect formMailCharset if it was set
-                       $this->charset = trim($GLOBALS['TSFE']->config['config']['formMailCharset']);
+               if ($GLOBALS['TSFE']->config['config']['formMailCharset'])      {       // Respect formMailCharset if it was set
+                       $this->charset = $GLOBALS['TSFE']->csConvObj->parse_charset($GLOBALS['TSFE']->config['config']['formMailCharset']);
+                       $convCharset = TRUE;
                }
 
+               parent::start();
+
+               if ($base64 || $V['use_base64'])        { $this->useBase64(); }
+
                if (isset($V['recipient']))     {
-                               // Sets the message id
-                       $this->messageid = md5(microtime()).'@domain.tld';
+                               // convert form data from renderCharset to mail charset
+                       $val = ($V['subject']) ? $V['subject'] : 'Formmail on '.t3lib_div::getIndpEnv('HTTP_HOST');
+                       $this->subject = ($convCharset && strlen($val)) ? $GLOBALS['TSFE']->csConvObj->conv($val,$GLOBALS['TSFE']->renderCharset,$this->charset) : $val;
+                       $val = ($V['from_name']) ? $V['from_name'] : (($V['name'])?$V['name']:'');
+                       $this->from_name = ($convCharset && strlen($val)) ? $GLOBALS['TSFE']->csConvObj->conv($val,$GLOBALS['TSFE']->renderCharset,$this->charset) : $val;
+                       $val = ($V['replyto_name']) ? $V['replyto_name'] : $this->from_name;
+                       $this->replyto_name = ($convCharset && strlen($val)) ? $GLOBALS['TSFE']->csConvObj->conv($val,$GLOBALS['TSFE']->renderCharset,$this->charset) : $val;
+                       $val = ($V['organisation']) ? $V['organisation'] : '';
+                       $this->organisation = ($convCharset && strlen($val)) ? $GLOBALS['TSFE']->csConvObj->conv($val,$GLOBALS['TSFE']->renderCharset,$this->charset) : $val;
 
-                       $this->subject = ($V['subject']) ? $V['subject'] : 'Formmail on '.t3lib_div::getIndpEnv('HTTP_HOST');
                        $this->from_email = ($V['from_email']) ? $V['from_email'] : (($V['email'])?$V['email']:'');
-                       $this->from_name = ($V['from_name']) ? $V['from_name'] : (($V['name'])?$V['name']:'');
                        $this->replyto_email = ($V['replyto_email']) ? $V['replyto_email'] : $this->from_email;
-                       $this->replyto_name = ($V['replyto_name']) ? $V['replyto_name'] : $this->from_name;
-                       $this->organisation = ($V['organisation']) ? $V['organisation'] : '';
                        $this->priority = ($V['priority']) ? t3lib_div::intInRange($V['priority'],1,5) : 3;
 
                                // Auto responder.
@@ -126,14 +137,18 @@ class t3lib_formmail extends t3lib_htmlmail {
                                        if (!t3lib_div::inList($this->reserved_names,$key))     {
                                                $space = (strlen($val)>60)?chr(10):'';
                                                $val = (is_array($val) ? implode($val,chr(10)) : $val);
-                                               $Plain_content.= strtoupper($key).':  '.$space.$val."\n".$space;
-                                               $HTML_content.='<tr><td bgcolor="#eeeeee"><font face="Verdana" size="1"><b>'.strtoupper($key).'</b></font></td><td bgcolor="#eeeeee"><font face="Verdana" size="1">'.nl2br(HTMLSpecialChars($val)).'&nbsp;</font></td></tr>';
+
+                                                       // convert form data from renderCharset to mail charset (HTML may use entities)
+                                               $Plain_val = ($convCharset && strlen($val)) ? $GLOBALS['TSFE']->csConvObj->conv($val,$GLOBALS['TSFE']->renderCharset,$this->charset,0) : $val;
+                                               $HTML_val = ($convCharset && strlen($val)) ? $GLOBALS['TSFE']->csConvObj->conv(htmlspecialchars($val),$GLOBALS['TSFE']->renderCharset,$this->charset,1) : htmlspecialchars($val);
+
+                                               $Plain_content.= strtoupper($key).':  '.$space.$Plain_val."\n".$space;
+                                               $HTML_content.='<tr><td bgcolor="#eeeeee"><font face="Verdana" size="1"><b>'.strtoupper($key).'</b></font></td><td bgcolor="#eeeeee"><font face="Verdana" size="1">'.nl2br($HTML_val).'&nbsp;</font></td></tr>';
                                        }
                                }
                        }
                        $HTML_content.= '</table>';
 
-
                        if ($V['html_enabled']) {
                                $this->setHTML($this->encodeMsg($HTML_content));
                        }
@@ -192,4 +207,4 @@ class t3lib_formmail extends t3lib_htmlmail {
 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_formmail.php']) {
        include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_formmail.php']);
 }
-?>
\ No newline at end of file
+?>