Skip to content
Snippets Groups Projects
Commit 0b6f4435 authored by Peter Rotich's avatar Peter Rotich
Browse files

Convert decoded header text to the desired charset/endoding.

parent 463484ad
Branches
Tags
No related merge requests found
...@@ -28,8 +28,8 @@ ...@@ -28,8 +28,8 @@
* - Redistributions in binary form must reproduce the above copyright * - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* - Neither the name of the authors, nor the names of its contributors * - Neither the name of the authors, nor the names of its contributors
* may be used to endorse or promote products derived from this * may be used to endorse or promote products derived from this
* software without specific prior written permission. * software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
...@@ -174,9 +174,9 @@ class Mail_mimeDecode extends PEAR ...@@ -174,9 +174,9 @@ class Mail_mimeDecode extends PEAR
function getHeader() { function getHeader() {
return $this->_header; return $this->_header;
} }
/** /**
* Begins the decoding process. If called statically * Begins the decoding process. If called statically
...@@ -219,6 +219,8 @@ class Mail_mimeDecode extends PEAR ...@@ -219,6 +219,8 @@ class Mail_mimeDecode extends PEAR
$params['decode_bodies'] : false; $params['decode_bodies'] : false;
$this->_decode_headers = isset($params['decode_headers']) ? $this->_decode_headers = isset($params['decode_headers']) ?
$params['decode_headers'] : false; $params['decode_headers'] : false;
$this->_charset = isset($params['charset']) ?
$params['charset'] : 'UTF-8';
$structure = $this->_decode($this->_header, $this->_body); $structure = $this->_decode($this->_header, $this->_body);
if ($structure === false) { if ($structure === false) {
...@@ -374,7 +376,7 @@ class Mail_mimeDecode extends PEAR ...@@ -374,7 +376,7 @@ class Mail_mimeDecode extends PEAR
} }
for ($i = 0; $i < count($structure->parts); $i++) { for ($i = 0; $i < count($structure->parts); $i++) {
if (!empty($structure->headers['content-type']) AND substr(strtolower($structure->headers['content-type']), 0, 8) == 'message/') { if (!empty($structure->headers['content-type']) AND substr(strtolower($structure->headers['content-type']), 0, 8) == 'message/') {
$prepend = $prepend . $mime_number . '.'; $prepend = $prepend . $mime_number . '.';
$_mime_number = ''; $_mime_number = '';
...@@ -394,7 +396,7 @@ class Mail_mimeDecode extends PEAR ...@@ -394,7 +396,7 @@ class Mail_mimeDecode extends PEAR
$structure->mime_id = $prepend . $mime_number; $structure->mime_id = $prepend . $mime_number;
$no_refs ? $return[$prepend . $mime_number] = '' : $return[$prepend . $mime_number] = &$structure; $no_refs ? $return[$prepend . $mime_number] = '' : $return[$prepend . $mime_number] = &$structure;
} }
return $return; return $return;
} }
...@@ -567,6 +569,16 @@ class Mail_mimeDecode extends PEAR ...@@ -567,6 +569,16 @@ class Mail_mimeDecode extends PEAR
break; 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); $input = str_replace($encoded, $text, $input);
} }
...@@ -698,7 +710,7 @@ class Mail_mimeDecode extends PEAR ...@@ -698,7 +710,7 @@ class Mail_mimeDecode extends PEAR
/** /**
* getSendArray() returns the arguments required for Mail::send() * 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: * Usage:
* $mailtext = Full email (for example generated by a template) * $mailtext = Full email (for example generated by a template)
...@@ -741,7 +753,7 @@ class Mail_mimeDecode extends PEAR ...@@ -741,7 +753,7 @@ class Mail_mimeDecode extends PEAR
} }
$to = substr($to,1); $to = substr($to,1);
return array($to,$header,$this->_body); return array($to,$header,$this->_body);
} }
/** /**
* Returns a xml copy of the output of * Returns a xml copy of the output of
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment