[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pear-cvs
Subject:    [PEAR-CVS] =?utf-8?q?svn:_/pear/packages/Mail=5FMime/trunk/_mimeDecode.php?=
From:       Alan_Knowles <alan_k () php ! net>
Date:       2011-09-27 8:17:23
Message-ID: svn-alan_k-1317111443-317378-75131431 () svn ! php ! net
[Download RAW message or body]

alan_k                                   Tue, 27 Sep 2011 08:17:23 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=317378

Log:
fix #18876 - support conversion of headers into UTF8 or anything else by using a \
value for decode_headers

Bug: http://pear.php.net/bugs/18876 (unknown) 
      
Changed paths:
    U   pear/packages/Mail_Mime/trunk/mimeDecode.php

Modified: pear/packages/Mail_Mime/trunk/mimeDecode.php
===================================================================
--- pear/packages/Mail_Mime/trunk/mimeDecode.php	2011-09-27 07:59:47 UTC (rev 317377)
+++ pear/packages/Mail_Mime/trunk/mimeDecode.php	2011-09-27 08:17:23 UTC (rev 317378)
@@ -141,11 +141,12 @@

     /**
      * Flag to determine whether to decode headers
-     *
-     * @var    boolean
+     * (set to UTF8 to iconv convert headers)
+     * @var    mixed
      * @access private
      */
     var $_decode_headers;
+

     /**
      * Flag to determine whether to include attached messages
@@ -188,7 +189,9 @@
      *                               object.
      *              decode_bodies  - Whether to decode the bodies
      *                               of the parts. (Transfer encoding)
-     *              decode_headers - Whether to decode headers
+     *              decode_headers - Whether to decode headers,
+     *                             - use "UTF8//IGNORE" to convert charset.
+     *
      *              input          - If called statically, this will be treated
      *                               as the input
      * @return object Decoded results
@@ -220,13 +223,17 @@
 	                             $params['decode_headers'] : false;
             $this->_rfc822_bodies  = isset($params['rfc_822bodies']) ?
 	                             $params['rfc_822bodies']  : false;
-
+
+            if (is_string($this->_decode_headers) && !function_exists('iconv')) {
+                 PEAR::raiseError('header decode conversion requested, however iconv \
is missing'); +            }
+
             $structure = $this->_decode($this->_header, $this->_body);
             if ($structure === false) {
                 $structure = $this->raiseError($this->_error);
             }
         }
-
+
         return $structure;
     }

@@ -247,7 +254,7 @@
         $headers = $this->_parseHeaders($headers);

         foreach ($headers as $value) {
-            $value['value'] = $this->_decode_headers ? \
$this->_decodeHeader($value['value']) : $value['value']; +            $value['value'] \
                =  $this->_decodeHeader($value['value']);
             if (isset($return->headers[strtolower($value['name'])]) AND \
                !is_array($return->headers[strtolower($value['name'])])) {
                 $return->headers[strtolower($value['name'])]   = \
                array($return->headers[strtolower($value['name'])]);
                 $return->headers[strtolower($value['name'])][] = $value['value'];
@@ -507,7 +514,7 @@
     function _parseHeaderValue($input)
     {
          if (($pos = strpos($input, ';')) === false) {
-            $input = $this->_decode_headers ? $this->_decodeHeader($input) : $input;
+            $input = $this->_decodeHeader($input);
             $return['value'] = trim($input);
             return $return;
         }
@@ -515,7 +522,7 @@


         $value = substr($input, 0, $pos);
-        $value = $this->_decode_headers ? $this->_decodeHeader($value) : $value;
+        $value = $this->_decodeHeader($value);
         $return['value'] = trim($value);
         $input = trim(substr($input, $pos+1));

@@ -669,7 +676,10 @@

         // decode values.
         foreach($return['other'] as $key =>$val) {
-            $return['other'][$key] = $this->_decode_headers ? \
$this->_decodeHeader($val) : $val; +            $charset = \
isset($return['other'][$key . '-charset']) ? +                $return['other'][$key . \
'-charset']  : false; +
+            $return['other'][$key] = $this->_decodeHeader($val, $charset);
         }

         return $return;
@@ -719,8 +729,11 @@
      * @return string Decoded header value
      * @access private
      */
-    function _decodeHeader($input)
+    function _decodeHeader($input, $defaut_charset=false)
     {
+        if (!$this->_decode_headers) {
+            return $input;
+        }
         // Remove white space between encoded-words
         $input = preg_replace('/(=\?[^?]+\?(q|b)\?[^?]*\?=)(\s)+=\?/i', '\1=?', \
$input);

@@ -744,10 +757,14 @@
                         $text = str_replace('='.$value, chr(hexdec($value)), $text);
                     break;
             }
-
+            if (is_string($this->_decode_headers)) {
+                $text = @iconv($charset, $this->_decode_headers, $text);
+            }
             $input = str_replace($encoded, $text, $input);
         }
-
+        if ($defaut_charset  && is_string($this->_decode_headers)) {
+                $input = @iconv($charset, $this->_decode_headers, $input);
+        }
         return $input;
     }



-- 
PEAR CVS Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic