写了个解析方法,测试基本通过。function parse_mime($pending, $to_charset = 'UTF-8') {
$start = strpos($pending, '=?');
if ($start === false) {
return $pending;
}
$end = strpos($pending, '?=', $start + 2);
if ($end === false) {
return $pending;
}
while ($start !== false && $end !== false) {
$segment = substr($pending, $start, $end - $start + 2);
$charset_end = strpos($segment, '?', 2);
$charset = substr($segment, 2, $charset_end - 2);
$encType = strtoupper($segment{$charset_end + 1});
$encoded_text = substr($segment, $charset_end + 3, strlen($segment) - $charset_end -
5);
switch ($encType) {
case 'Q':
$encoded_text = str_replace('_', ' ', $encoded_text);
$text = quoted_printable_decode($encoded_text);
break;
case 'B':
$text = base64_decode($encoded_text);
break;
}
$text = mb_convert_encoding($text, $to_charset, $charset);
$pending = str_replace($segment, $text, $pending);
// next encoded-word.
$start = strpos($pending, '=?');
$end = strpos($pending, '?=', $start + 2);
}
return $pending;
}