|
<br> function decode_mime_string ($string) { <BR> $pos = strpos($string, '=?'); <BR> if (!is_int($pos)) { <BR> return $string; <BR> } <BR> <BR> $preceding = substr($string, 0, $pos); // save any preceding text <BR> <BR> $search = substr($string, $pos+2, 75); /* the mime header spec says this is the longest a single encoded word can be */ <BR> $d1 = strpos($search, '?'); <BR> if (!is_int($d1)) { <BR> return $string; <BR> } <BR> <BR> $charset = substr($string, $pos+2, $d1); <BR> $search = substr($search, $d1+1); <BR> <BR> $d2 = strpos($search, '?'); <BR> if (!is_int($d2)) { <BR> return $string; <BR> } <BR> <BR> $encoding = substr($search, 0, $d2); <BR> $search = substr($search, $d2+1); <BR> <BR> $end = strpos($search, '?='); <BR> if (!is_int($end)) { <BR> return $string; <BR> } <BR> <BR> $encoded_text = substr($search, 0, $end); <BR> $rest = substr($string, (strlen($preceding . $charset . $encoding . $encoded_text)+6)); <BR> <BR> switch ($encoding) { <BR> case 'Q': <BR> case 'q': <BR> $encoded_text = str_replace('_', '%20', $encoded_text); <BR> $encoded_text = str_replace('=', '%', $encoded_text); <BR> $decoded = urldecode($encoded_text); <BR> <BR> if (strtolower($charset) == 'windows-1251') { <BR> $decoded = convert_cyr_string($decoded, 'w', 'k'); <BR> } <BR> break; <BR> <BR> case 'B': <BR> case 'b': <BR> $decoded = urldecode(base64_decode($encoded_text)); <BR> <BR> if (strtolower($charset) == 'windows-1251') { <BR> $decoded = convert_cyr_string($decoded, 'w', 'k'); <BR> } <BR> break; <BR> <BR> default: <BR> $decoded = '=?' . $charset . '?' . $encoding . '?' . $encoded_text . '?='; <BR> break; <BR> } <BR> <BR> return $preceding . $decoded . decode_mime_string($rest); <BR>} // decode_mime_string() <br><br> |
|