php 邮件解析 主题解析

$position=strpos($row["f_Subject"],"=");
if(strlen($position)==1){
//先判断是否存在=?xxxx?B?这种格式
if(preg_match("/=\?[\w-]+\?B\?/",$row["f_Subject"])){
//echo "如果存在先把编码取出";
//preg_match_all ("|<[^>]+>(.*)</[^>]+>|U",
    //"<b>example: </b><div align=left>this is a test</div>",
    //$out, PREG_PATTERN_ORDER);
//print $out[0][0].", ".$out[0][1]."\n";
//print $out[1][0].", ".$out[1][1]."\n";


preg_match_all("/=\?([\w-]+)\?B\?(.*)\?=+/",$row["f_Subject"],$contentArr,PREG_PATTERN_ORDER);
//echo "length=====".count($contentArr)."<br>";
//echo "content1==".$contentArr[0][0]."<br>";//=?utf-8?B?
//echo "content2==".$contentArr[1][0]."<br>";//utf-8
//echo PREG_PATTERN_ORDER."<br>";//1
for($n=0;$n<count($contentArr[0]);$n++){
//echo "0000=".$contentArr[2][$n]."<br>";
//echo "1111=".$contentArr[1][$n]."<br>";
$tem_subject=base64_decode($contentArr[2][$n]);
if($contentArr[1][$n]=="utf-8"){
echo $tem_subject;
}else if($contentArr[1][$n]=="big5"){
//echo "big5===".$tem_subject;
$tem_subject=iconv("big5","utf-8",$tem_subject);
echo $tem_subject;
}else{
$tem_subject=iconv("gbk","utf-8",$tem_subject);
echo $tem_subject;
}
}

}else{
//echo "dddd5";
//echo $row["f_Subject"]."<br><br>";
//if(ereg('/=\?[\w-]+\?B\?.*=*\?=+/',$row["f_Subject"])){
//preg_match_all ('/=\?[\w-]+\?B\?.*=*\?=+/',$row["f_Subject"],$matchs);
//echo count($matchs[0]);
//for($k=0;$k<count($matchs[0]);$k++){
//echo $matchs[0][$k]."jjjj<br><br>";
//$tem_subject = preg_replace('/=\?[\w-]+\?B\?/','',$matchs[0][$k]);
//$tem_subject = preg_replace('/\?=+/','',$tem_subject);
//echo $tem_subject;
//$tem_subject=base64_decode($tem_subject);
//echo $tem_subject;
//}
//}
if(preg_match('/=\?[\w-]+\?Q\?.*=*\?=+/',$row["f_Subject"])){
//echo "ddd6";
preg_match_all ('/=\?([\w-]+)\?Q\?(.*:_)*(.*)\?=+/',$row["f_Subject"],$matchs);
for($k=0;$k<count($matchs[0]);$k++){
//$tem_subject = preg_replace('/=\?[\w-]+\?Q\?(.*:_)*/','',$matchs[0][$k]);
//$tem_subject = preg_replace('/\?=+/','',$tem_subject);
echo $matchs[3][$k];
}
}else{
echo $row["f_Subject"];
}

}

}else{
if($row["f_Subject"]==""){
echo "Subject: Blank";
}else{
echo $row["f_Subject"];
}
}

你可能感兴趣的:(PHP,F#)