From 0b6f44359bdde3a457b67d51243d5c489a7d1328 Mon Sep 17 00:00:00 2001 From: Peter Rotich <peter@osticket.com> Date: Wed, 27 Mar 2013 16:07:36 -0400 Subject: [PATCH] Convert decoded header text to the desired charset/endoding. --- include/pear/Mail/mimeDecode.php | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/include/pear/Mail/mimeDecode.php b/include/pear/Mail/mimeDecode.php index 59b6e1923..b30019582 100644 --- a/include/pear/Mail/mimeDecode.php +++ b/include/pear/Mail/mimeDecode.php @@ -28,8 +28,8 @@ * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * - Neither the name of the authors, nor the names of its contributors - * may be used to endorse or promote products derived from this + * - Neither the name of the authors, nor the names of its contributors + * may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" @@ -174,9 +174,9 @@ class Mail_mimeDecode extends PEAR function getHeader() { return $this->_header; } - - + + /** * Begins the decoding process. If called statically @@ -219,6 +219,8 @@ class Mail_mimeDecode extends PEAR $params['decode_bodies'] : false; $this->_decode_headers = isset($params['decode_headers']) ? $params['decode_headers'] : false; + $this->_charset = isset($params['charset']) ? + $params['charset'] : 'UTF-8'; $structure = $this->_decode($this->_header, $this->_body); if ($structure === false) { @@ -374,7 +376,7 @@ class Mail_mimeDecode extends PEAR } for ($i = 0; $i < count($structure->parts); $i++) { - + if (!empty($structure->headers['content-type']) AND substr(strtolower($structure->headers['content-type']), 0, 8) == 'message/') { $prepend = $prepend . $mime_number . '.'; $_mime_number = ''; @@ -394,7 +396,7 @@ class Mail_mimeDecode extends PEAR $structure->mime_id = $prepend . $mime_number; $no_refs ? $return[$prepend . $mime_number] = '' : $return[$prepend . $mime_number] = &$structure; } - + return $return; } @@ -567,6 +569,16 @@ class Mail_mimeDecode extends PEAR break; } + //Convert decoded text to the desired charset. + if($charset && $this->_charset && strcasecmp($this->_charset, $charset)) { + if(function_exists('iconv')) + $text = iconv($charset, $this->_charset.'//IGNORE', $text); + elseif(function_exists('mb_convert_encoding')) + $text = mb_convert_encoding($text, $this->_charset, $charset); + elseif(!strcasecmp($this->_charset, 'utf-8')) //forced blind utf8 encoding. + $text = function_exists('imap_utf8')?imap_utf8($text):utf8_encode($text); + } + $input = str_replace($encoded, $text, $input); } @@ -698,7 +710,7 @@ class Mail_mimeDecode extends PEAR /** * getSendArray() returns the arguments required for Mail::send() - * used to build the arguments for a mail::send() call + * used to build the arguments for a mail::send() call * * Usage: * $mailtext = Full email (for example generated by a template) @@ -741,7 +753,7 @@ class Mail_mimeDecode extends PEAR } $to = substr($to,1); return array($to,$header,$this->_body); - } + } /** * Returns a xml copy of the output of -- GitLab