* Fixed bug #1268: plainMailEncoded not working with charset conversion
authorMichael Stucki <michael.stucki@typo3.org>
Sun, 3 Sep 2006 22:03:29 +0000 (22:03 +0000)
committerMichael Stucki <michael.stucki@typo3.org>
Sun, 3 Sep 2006 22:03:29 +0000 (22:03 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@1722 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_div.php
t3lib/class.t3lib_formmail.php
typo3/sysext/cms/tslib/class.tslib_fe.php

index 78a2d18..5fd6de6 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2006-09-04  Michael Stucki  <michael@typo3.org>
+
+       * Fixed bug #1268: plainMailEncoded not working with charset conversion
+
 2006-09-03  Sebastian Kurfuerst  <sebastian@garbage-group.de>
 
        * Added su_back.gif image again to gfx
index 7d6ae7c..1c47a58 100755 (executable)
@@ -4056,7 +4056,7 @@ class t3lib_div {
 
        /**
         * Simple substitute for the PHP function mail() which allows you to specify encoding and character set
-        * The fifth parameter, $enc, will allow you to specify 'base64' encryption for the output (set $enc=base64)
+        * The fifth parameter ($encoding) will allow you to specify 'base64' encryption for the output (set $encoding=base64)
         * Further the output has the charset set to ISO-8859-1 by default.
         * Usage: 4
         *
@@ -4065,11 +4065,11 @@ class t3lib_div {
         * @param       string          Message content, non-encoded. (see PHP function mail())
         * @param       string          Headers, separated by chr(10)
         * @param       string          Encoding type: "base64", "quoted-printable", "8bit". Default value is "quoted-printable".
-        * @param       string          Charset used in encoding-headers (only if $enc is set to a valid value which produces such a header)
+        * @param       string          Charset used in encoding-headers (only if $encoding is set to a valid value which produces such a header)
         * @param       boolean         If set, the header content will not be encoded.
         * @return      void
         */
-       function plainMailEncoded($email,$subject,$message,$headers='',$enc='',$charset='',$dontEncodeHeader=false)     {
+       function plainMailEncoded($email,$subject,$message,$headers='',$encoding='quoted-printable',$charset='',$dontEncodeHeader=false)        {
                if (!$charset)  {
                        $charset = $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] ? $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] : 'ISO-8859-1';
                }
@@ -4080,7 +4080,7 @@ class t3lib_div {
                        foreach (explode(chr(10),$headers) as $line)    {       // Split the header in lines and convert each line separately
                                $parts = explode(': ',$line,2); // Field tags must not be encoded
                                if (count($parts)==2)   {
-                                       $parts[1] = t3lib_div::encodeHeader($parts[1],$enc,$charset);
+                                       $parts[1] = t3lib_div::encodeHeader($parts[1],$encoding,$charset);
                                        $newHeaders[] = implode(': ',$parts);
                                } else {
                                        $newHeaders[] = $line;  // Should never happen - is such a mail header valid? Anyway, just add the unchanged line...
@@ -4089,11 +4089,11 @@ class t3lib_div {
                        $headers = implode(chr(10),$newHeaders);
                        unset($newHeaders);
 
-                       $email = t3lib_div::encodeHeader($email,$enc,$charset);         // Email address must not be encoded, but it could be appended by a name which should be so (e.g. "Kasper Skårhøj <kasperYYYY@typo3.com>")
-                       $subject = t3lib_div::encodeHeader($subject,$enc,$charset);
+                       $email = t3lib_div::encodeHeader($email,$encoding,$charset);            // Email address must not be encoded, but it could be appended by a name which should be so (e.g. "Kasper Skårhøj <kasperYYYY@typo3.com>")
+                       $subject = t3lib_div::encodeHeader($subject,$encoding,$charset);
                }
 
-               switch ((string)$enc)   {
+               switch ((string)$encoding)      {
                        case 'base64':
                                $headers=trim($headers).chr(10).
                                'Mime-Version: 1.0'.chr(10).
@@ -4186,7 +4186,7 @@ class t3lib_div {
         * @param       string          Charset used for encoding
         * @return      string          The encoded string
         */
-       function encodeHeader($line,$enc='',$charset='ISO-8859-1')      {
+       function encodeHeader($line,$enc='quoted-printable',$charset='ISO-8859-1')      {
                        // Avoid problems if "###" is found in $line (would conflict with the placeholder which is used below)
                if (strstr($line,'###'))        return $line;
 
@@ -4210,6 +4210,7 @@ class t3lib_div {
                                                $qpValue = str_replace(' ','_',$qpValue);       // Encoded words in the header should not contain non-encoded spaces. "_" is a shortcut for "=20". See RFC 2047 for details.
                                                $part = '=?'.$charset.'?Q?'.$qpValue.'?=';
                                        }
+                               break;
                        }
                        $line = str_replace($oldPart, $part, $line);
                }
index 992863c..e563350 100644 (file)
@@ -95,14 +95,13 @@ class t3lib_formmail extends t3lib_htmlmail {
        function start($V,$base64=false)        {
                $convCharset = FALSE;   // do we need to convert form data?
 
-               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 = $GLOBALS['TSFE']->csConvObj->parse_charset($GLOBALS['TSFE']->config['config']['formMailCharset']);
                        $convCharset = TRUE;
+
+               } elseif ($GLOBALS['TSFE']->metaCharset != $GLOBALS['TSFE']->renderCharset)     {       // Use metaCharset for mail if different from renderCharset
+                       $this->charset = $GLOBALS['TSFE']->metaCharset;
+                       $convCharset = TRUE;
                }
 
                parent::start();
@@ -143,7 +142,7 @@ class t3lib_formmail extends t3lib_htmlmail {
                                                $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.= '<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>';
                                        }
                                }
                        }
index e0a373b..fc92940 100755 (executable)
@@ -3832,14 +3832,33 @@ if (version == "n3") {
         * @see t3lib_div::plainMailEncoded()
         */
        function plainMailEncoded($email,$subject,$message,$headers='') {
-               $urlmode=$this->config['config']['notification_email_urlmode']; // '76', 'all', ''
+               $urlmode = $this->config['config']['notification_email_urlmode'];       // '76', 'all', ''
 
                if ($urlmode)   {
-                       $message=t3lib_div::substUrlsInPlainText($message,$urlmode);
+                       $message = t3lib_div::substUrlsInPlainText($message,$urlmode);
                }
 
-               $encoding = $this->config['config']['notification_email_encoding'] ? $this->config['config']['notification_email_encoding'] : 'quoted-printable';
-               $charset = $this->config['config']['notification_email_charset'] ? $this->config['config']['notification_email_charset'] : ($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] ? $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] : 'ISO-8859-1');
+               $encoding = $this->config['config']['notification_email_encoding'] ? $this->config['config']['notification_email_encoding'] : '';
+               $charset = $this->renderCharset;
+
+               $convCharset = FALSE;   // do we need to convert mail data?
+               if ($this->config['config']['notification_email_charset'])      {       // Respect config.notification_email_charset if it was set
+                       $charset = $this->csConvObj->parse_charset($this->config['config']['notification_email_charset']);
+                       if ($charset != $this->renderCharset)   {
+                               $convCharset = TRUE;
+                       }
+
+               } elseif ($this->metaCharset != $this->renderCharset)   {       // Use metaCharset for mail if different from renderCharset
+                       $charset = $this->metaCharset;
+                       $convCharset = TRUE;
+               }
+
+               if ($convCharset)       {
+                       $email = $this->csConvObj->conv($email,$this->renderCharset,$charset);
+                       $subject = $this->csConvObj->conv($subject,$this->renderCharset,$charset);
+                       $message = $this->csConvObj->conv($message,$this->renderCharset,$charset);
+                       $headers = $this->csConvObj->conv($headers,$this->renderCharset,$charset);
+               }
 
                t3lib_div::plainMailEncoded(
                        $email,