function decode_mime_string ($string) {
$pos = Strpos ($string, ' =? ');
if (!is_int ($pos)) {
return $string;
}
$preceding = substr ($string, 0, $pos); Save any preceding text
$search = substr ($string, $pos +2, 75); /* The MIME header spec says this are the longest a single encoded word can * *
$d 1 = strpos ($search, '? ');
if (!is_int ($d 1)) {
return $string;
}
$charset = substr ($string, $pos +2, $d 1);
$search = substr ($search, $d 1+1);
$d 2 = Strpos ($search, '? ');
if (!is_int ($d 2)) {
return $string;
}
$encoding = substr ($search, 0, $d 2);
$search = substr ($search, $d 2+1);
$end = Strpos ($search, '? = ');
if (!is_int ($end)) {
return $string;
}
$encoded _text = substr ($search, 0, $end);
$rest = substr ($string, (strlen ($preceding. $charset. $encoding. $encoded _text) +6));
Switch ($encoding) {
Case ' Q ':
Case ' Q ':
$encoded _text = Str_replace (' _ ', '%20 ', $encoded _text);
$encoded _text = str_replace (' = ', '% ', $encoded _text);
$decoded = UrlDecode ($encoded _text);
if (Strtolower ($charset) = = ' windows-1251 ') {
$decoded = convert_cyr_string ($decoded, ' w ', ' K ');
}
Break
Case ' B ':
Case ' B ':
$decoded = UrlDecode (Base64_decode ($encoded _text));
if (Strtolower ($charset) = = ' windows-1251 ') {
$decoded = convert_cyr_string ($decoded, ' w ', ' K ');
}
Break
Default
$decoded = ' =? '. $charset. '?' . $encoding. '?' . $encoded _text. '?=';
Break
}
Return $preceding. $decoded. Decode_mime_string ($rest);
}//Decode_mime_string ()