function decode_mime_string($subject) {
$string = $subject;
if(($pos = strpos($string,"=?")) === false) return $string;
while(!($pos === false)) {
$newresult .= substr($string,0,$pos);
$string = substr($string,$pos+2,strlen($string));
$intpos = strpos($string,"?");
$charset = substr($string,0,$intpos);
$enctype = strtolower(substr($string,$intpos+1,1));
$string = substr($string,$intpos+3,strlen($string));
$endpos = strpos($string,"?=");
$mystring = substr($string,0,$endpos);
$string = substr($string,$endpos+2,strlen($string));
if($enctype == "q") $mystring = quoted_printable_decode(ereg_replace("_"," ",$mystring));
else if ($enctype == "b") $mystring = base64_decode($mystring);
$newresult .= $mystring;
$pos = strpos($string,"=?");
}
$result = $newresult.$string;
if(ereg("koi8-r", $subject))
{
$result = convert_cyr_string($result, "k", "w");
$result = iconv("windows-1251","utf-8",$result);
}
if(ereg("KOI8-R", $subject))
{
$result = convert_cyr_string($result, "k", "w");
$result = iconv('windows-1251','utf-8',$result);
}
return $result;
}
|