作者 邓超

1

... ... @@ -51,7 +51,7 @@ class DeCoding {
if (!($bEmulate_imap_8bit && ($i==count($aLines)-1)))
if (($iLastChar==0x09)||($iLastChar==0x20)) {
$sLine{$iLength-1}='=';
$sLine[$iLength-1]='=';
$sLine .= ($iLastChar==0x09)?'09':'20';
}
} // imap_8bit encodes x20 before chr(13), too
... ...
... ... @@ -26,36 +26,6 @@ class MailFun {
}
/**
* 解码
* @param $string
* @param string $charset
* @return string
* @time 2022/8/15 9:31
*/
public static function decodeMimeStr($string, $charset = 'utf-8') {
$newString = '';
$elements = \imap_mime_header_decode($string);
// print_r($elements);
for($i = 0; $i < count($elements); $i++) {
if($elements[$i]->charset == 'default') {
$elements[$i]->charset = 'iso-8859-1';
}
$newString .= self::convertStringEncoding($elements[$i]->text, $elements[$i]->charset, $charset);
}
return $newString;
}
public static function convertStringEncoding($string, $fromEncoding, $toEncoding) {
$convertedString = null;
if($string && $fromEncoding != $toEncoding) {
$convertedString = @iconv($fromEncoding, $toEncoding . '//IGNORE', $string);
if(!$convertedString && extension_loaded('mbstring')) {
$convertedString = @mb_convert_encoding($string, $toEncoding, $fromEncoding);
}
}
return $convertedString ?: $string;
}
/**
... ...