如果您無法使用 imap_* 函式,而且不想使用
?$message = chunk_split( base64_encode($message) );?
因為您希望能夠讀取郵件的「原始碼」,您可以嘗試這個方法
(非常歡迎任何建議!)
function qp_enc($input = "quoted-printable 編碼測試字串", $line_max = 76) {
$hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
$lines = preg_split("/(?:\r\n|\r|\n)/", $input);
$eol = "\r\n";
$escape = "=";
$output = "";
while( list(, $line) = each($lines) ) {
//$line = rtrim($line); // 移除尾端的空白字元 -> 不需要 =20\r\n
$linlen = strlen($line);
$newline = "";
for($i = 0; $i < $linlen; $i++) {
$c = substr($line, $i, 1);
$dec = ord($c);
if ( ($dec == 32) && ($i == ($linlen - 1)) ) { // 只轉換行尾的空格
$c = "=20";
} elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // 永遠編碼 "\t",這並*非*必要
$h2 = floor($dec/16); $h1 = floor($dec%16);
$c = $escape.$hex["$h2"].$hex["$h1"];
}
if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF 不計入
$output .= $newline.$escape.$eol; // 軟換行;" =\r\n" 可以
$newline = "";
}
$newline .= $c;
} // for 迴圈結束
$output .= $newline.$eol;
}
return trim($output);
}
$eight_bit = "\xA7 \xC4 \xD6 \xDC \xE4 \xF6 \xFC \xDF = xxx yyy zzz \r\n"
." \xA7 \r \xC4 \n \xD6 \x09 ";
print $eight_bit."\r\n---------------\r\n";
$encoded = qp_enc($eight_bit);
print $encoded;