note 101150 added to function.imap-mime-header-decode
| From: | anonymouse at example dot com | Date: | Mon, 29 Nov 2010 22:55:13 +0000 |
| Subject: | note 101150 added to function.imap-mime-header-decode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-174456@lists.php.net to get a copy of this message | ||
both functions called mime_decode_string() below are broken. i made some syntax changes for
readability and style:
// return a string with a mail header
// decoded to a specified charset. if the charset
// isn't supported by mb_convert_encoding(),
// def_charset will be used to decode it.
function decode_mime_string($mime_str, $in_charset='utf-8',
$target_charset='utf-8', $def_charset='iso-8859-1')
{
// valid encodings in lowercase array
$encs = array_flip(array_change_key_case(array_flip(mb_list_encodings())));
$in_charset = strtolower($in_charset);
$target_charset = strtolower($target_charset);
$def_charset = strtolower($def_charset);
$decoded_str = '';
$mime_strs = imap_mime_header_decode($mime_str);
$charset_match = ($in_charset === $target_charset);
foreach ($mime_strs as $mime_str)
{
$mime_str->charset = strtolower($mime_str->charset);
if ( ( $mime_str === 'default' AND $charset_match ) OR
( $mime_str->charset === $target_charset ) )
{
$decoded_str .= $mime_str->text;
}
else
{
$charset = ( in_array( $mime_str->charset, $encs ) ) ? $mime_str->charset : $def_charset;
$decoded_str .= mb_convert_encoding( $mime_str->text, $target_charset, $charset );
}
}
return $decoded_str;
}
----
Server IP: 69.147.83.197
Probable Submitter: 71.245.243.251
----
Manual Page -- http://www.php.net/manual/en/function.imap-mime-header-decode.php
Edit -- https://master.php.net/note/edit/101150
Del: integrated -- https://master.php.net/note/delete/101150/integrated
Del: useless -- https://master.php.net/note/delete/101150/useless
Del: bad code -- https://master.php.net/note/delete/101150/bad+code
Del: spam -- https://master.php.net/note/delete/101150/spam
Del: non-english -- https://master.php.net/note/delete/101150/non-english
Del: in docs -- https://master.php.net/note/delete/101150/in+docs
Del: other reasons-- https://master.php.net/note/delete/101150
Reject -- https://master.php.net/note/reject/101150
Search -- https://master.php.net/manage/user-notes.php