POP邮件处理---H_pop.php

<?php
/*************************************
*	POP邮件处理---H_pop.php
*	创建人: huang_xiang
*	创建时间:2009-2-18 13:34
*	更新时间:2009-2-18 13:34
*	Email:yin273642232@163.com QQ:273642232
*************************************/
/*************************************
实例代码
	include_once("H_smtp.php");													//引入文件
	$H_pop = new H_pop();														//产生对象
	$pop3 = $H_pop -> pop3_open("pop.163.com", "110");
	if(!$pop3){
		echo "[ERROR] Failed to connect to localhost<BR>\n";
		return false;
	}
	if(!$H_pop -> pop3_user("yin273642232@163.com")){
		echo "[ERROR] Username failed!<BR>\n";
		return false;
	}
	if(!$H_pop -> pop3_pass("password")){
		echo "[ERROR] PASS failed!<BR>\n"; 
		return false;
	}
	//$H_pop -> pop3_top(1,0);
	$H_pop -> pop3_retr(5);	//text/html
	//$H_pop -> pop3_retr(1);
	$H_pop -> get_heads();	//获得头信息
	$H_pop -> get_bodys();	//获得邮件内容和附件
	
	echo "<pre>";
	print_r($H_pop -> H_data["head"]);
	echo "<hr>";
	print_r($H_pop -> H_data["body"]);
	echo "<hr>";
	print_r($H_pop -> H_data["attc"]);
	echo "</pre>";
	//时间
	echo $H_pop -> H_data["head"]["date"]["week"]." ".$H_pop -> H_data["head"]["date"]["year"]."年".$H_pop -> H_data["head"]["date"]["moth"][0]."月".$H_pop -> H_data["head"]["date"]["days"]."日".$H_pop -> H_data["head"]["date"]["hous"].":".$H_pop -> H_data["head"]["date"]["mins"].":".$H_pop -> H_data["head"]["date"]["sect"];
	echo "<hr>";
	//发件人
	echo $H_pop -> H_data["head"]["from"][0]." - ".$H_pop -> H_data["head"]["from"][1];
	echo "<hr>";
	//收件人
	echo $H_pop -> H_data["head"]["to"][0]." - ".$H_pop -> H_data["head"]["to"][1];
	echo "<hr>";
	//主题
	echo $H_pop -> H_data["head"]["subject"];
	echo "<hr>";
	//内容
	echo $H_pop -> H_data["body"][0]["size"];
	echo $H_pop -> H_data["body"][0]["cont"];
	echo "<hr>附件:<br>";
	//附件
	for($H_i = 1; $H_i <= count($H_pop -> H_data["attc"]);$H_i++){
		echo $H_pop -> H_data["attc"][$H_i]["content-type"];
		echo $H_pop -> H_data["attc"][$H_i]["size"];
		echo $H_pop -> H_data["attc"][$H_i]["filename"];
	}
	//附件下载
	$H_pop -> get_attc(1,'');
	$H_pop -> pop3_quit();
*************************************/
//Start Class
class H_pop{ 
    public $Hsocket;            //连接的socket 
    public $Hline; 				//返回信息
    public $Hstatus; 			//状态
    
    public $H_desce;					//描述
    public $H_ROOT_DIR;					//文件地址路径
    public $H_head;						//头信息
    public $H_body;						//邮件内容
    public $H_attc;						//附件
    public $H_headf = false;
    public $H_data;						//数据
	
	public function __construct(){
		//当实例化一个对象的时候,这个对象的这个方法首先被调用
		return '';
 	}
 	public function __destruct(){
 		//当删除一个对象或对象操作终止的时候,调用该方法
 		return '';
 	}
 	public function __get($key){
 		//当试图读取一个并不存在的属性的时候被调用
  		return '['.$key.'] Variable not find';
  	}
  	public function __set($key,$val){
 		//当试图向一个并不存在的属性写入值的时候被调用
  		return '['.$key.'] Variable not find';
  	}
  	public function __call($key,$args){
  		//当试图调用一个对象并不存在的方法时,调用该方法
  		return '['.$key.'] Function not find';
	}
	public function __toString(){
		//当打印一个对象的时候被调用
		return $this -> H_desce();
  	}
  	public function __clone(){
  		//当对象被克隆时,被调用
  		return "clone";
  	}
	public function H_desce(){
		//返回描述
		$this -> H_desce .= '类名:H_pop-收取E-mail处理;';
		$this -> H_desce .= '函数:pop3_open($Hserver,$Hport),返回:打开sock连接,参数:$Hserver-服务器地址.$Hport-端口;';
		$this -> H_desce .= '函数:pop3_user($user),返回:设置用户名,参数:$user-用户名;';
		$this -> H_desce .= '函数:pop3_pass($pass),返回:设置密码,参数:$pass-密码;';
		$this -> H_desce .= '函数:pop3_stat(),返回:邮箱的统计资料,参数:无;';
		$this -> H_desce .= '函数:pop3_list(),返回:邮件数量和每个邮件的大小,参数:无;';
		$this -> H_desce .= '函数:pop3_retr($nr),返回:由标识的邮件的全部文本,参数:$nr-指定信件id;';
		$this -> H_desce .= '函数:pop3_dele($nr),返回:将邮件标记为删除,由quit命令执行,参数:$nr-指定信件id;';
		$this -> H_desce .= '函数:pop3_quit(),返回:更新并退出,参数:无;';
		return $this -> H_desce;
	}
	
	public function pop3_open($Hserver,$Hport){ 
		//打开sock连接
		set_time_limit(3600);
		$this -> Hsocket = fsockopen($Hserver, $Hport); 
		if($this -> Hsocket <= 0) return false;
		$this -> Hline = fgets($this -> Hsocket, 1024); 
		$this -> Hstatus["LASTRESULT"] = substr($this -> Hline, 0, 1); 
		$this -> Hstatus["LASTRESULTTXT"] = substr($this -> Hline, 0, 1024); 
		if($this -> Hstatus["LASTRESULT"] !=  "+") return false;
		return true; 
	} 

	public function pop3_user($user){
		//设置用户名
		fputs($this -> Hsocket,"USER ".$user."\r\n"); 
		$this -> Hline = fgets($this -> Hsocket, 1024); 
		$this -> Hstatus["LASTRESULT"] = substr($this -> Hline, 0, 1); 
		$this -> Hstatus["LASTRESULTTXT"] = substr($this -> Hline, 0, 1024); 
		if ($this -> Hstatus["LASTRESULT"] !=  "+") return false; 
		return true; 
	} 

	public function pop3_pass($pass){
    	//设置密码
        fputs($this -> Hsocket,"PASS ".$pass."\r\n"); 
        $this -> Hline = fgets($this -> Hsocket, 1024); 
        $this -> Hstatus["LASTRESULT"] = substr($this -> Hline, 0, 1); 
        $this -> Hstatus["LASTRESULTTXT"] = substr($this -> Hline, 0, 1024);
        if ($this -> Hstatus["LASTRESULT"] !=  "+") return false;
        return true; 
    }
    
    public function pop3_uidl($nr=0){
    	//返回邮件唯一id
        if($nr > 0) fputs($this -> Hsocket,"UIDL ".$nr."\r\n"); 
        else fputs($this -> Hsocket,"UIDL\r\n"); 
        $this -> Hline = fgets($this -> Hsocket, 1024); 
        $this -> Hstatus["LASTRESULT"] = substr($this -> Hline, 0, 1); 
        $this -> Hstatus["LASTRESULTTXT"] = substr($this -> Hline, 0, 1024); 
        if ($this -> Hstatus["LASTRESULT"] !=  "+") return false;
        if($nr > 0){
        	if (!eregi("\+OK (.*) (.*)", $this -> Hline, $regs)) return false;
    	}else{
    		$i = 0; 
	        while(trim($this -> Hline = fgets($this -> Hsocket, 4096)) != "."){
	        	$regs[$i] = explode(" ",trim($this -> Hline));
	            $i++; 
	        }
    	}
    	return $regs;
    }
    
    public function pop3_stat(){
    	//返回邮箱的统计资料
        fputs($this -> Hsocket,"STAT\r\n"); 
        $this -> Hline = fgets($this -> Hsocket, 1024); 
        $this -> Hstatus["LASTRESULT"] = substr($this -> Hline, 0, 1); 
        $this -> Hstatus["LASTRESULTTXT"] = substr($this -> Hline, 0, 1024); 
        if ($this -> Hstatus["LASTRESULT"] !=  "+") return false;
        if (!eregi("\+OK (.*) (.*)", $this -> Hline, $regs)) return false;
        return $regs; 
    }
    
    public function pop3_noop(){
    	//返回一个肯定的响应
        fputs($this -> Hsocket,"NOOP\r\n"); 
        $this -> Hline = fgets($this -> Hsocket, 1024); 
        $this -> Hstatus["LASTRESULT"] = substr($this -> Hline, 0, 1); 
        $this -> Hstatus["LASTRESULTTXT"] = substr($this -> Hline, 0, 1024); 
        if ($this -> Hstatus["LASTRESULT"] !=  "+") return false;
        if (!eregi("\+OK (.*) (.*)", $this -> Hline, $regs)) return false;
        return $regs; 
    }
    
    public function pop3_list($nr=0){
    	//返回邮件数量和每个邮件的大小
        if($nr > 0) fputs($this -> Hsocket,"LIST ".$nr."\r\n"); 
        else fputs($this -> Hsocket,"LIST\r\n"); 
        $this -> Hline = fgets($this -> Hsocket, 1024); 
        $this -> Hstatus["LASTRESULT"] = substr($this -> Hline, 0, 1); 
        $this -> Hstatus["LASTRESULTTXT"] = substr($this -> Hline, 0, 1024);
        if ($this -> Hstatus["LASTRESULT"] !=  "+") return false;
        $i = 0; 
        while(trim($this -> Hline = fgets($this -> Hsocket, 4096)) != "."){
            $H_list[$i] = $this -> Hline;
            $i++; 
        }
        return $H_list;
    }
    
    public function pop3_top($n=1,$m=0){
    	//返回 n 号邮件的前 m 行内容,m必须是自然数
    	$this -> H_data = array();
    	$this -> H_head = array();
    	$this -> H_body = array();
    	$this -> H_headf = false;
    	
    	$H_stafg = false;
        if($m > 0) fputs($this -> Hsocket,"TOP ".$n." ".$m."\r\n"); 
        else fputs($this -> Hsocket,"TOP ".$n." 0\r\n"); 
        $this -> Hline = fgets($this -> Hsocket, 1024); 
        $this -> Hstatus["LASTRESULT"] = substr($this -> Hline, 0, 1); 
        $this -> Hstatus["LASTRESULTTXT"] = substr($this -> Hline, 0, 1024);
        if($this -> Hstatus["LASTRESULT"] !=  "+") return false;
        $H_i = -1;
        $H_j = -1;
        while(trim($this -> Hline = fgets($this -> Hsocket, 4096)) != "."){
            //每次读取一行存储
            $H_tems = trim($this -> Hline);
            if($H_tems == '' && !$this -> H_headf) $this -> H_headf = true;
            if(!$this -> H_headf) $this -> H_head[++$H_i] = $H_tems;
            else $this -> H_body[++$H_j] = $H_tems;
        }
        return true;
    }
    
    public function pop3_retr($nr){
    	//返回由参数标识的邮件的全部文本
        $this -> H_data = array();
    	$this -> H_head = array();
    	$this -> H_body = array();
    	$this -> H_headf = false;
    	fputs($this -> Hsocket,  "RETR ".$nr."\r\n"); 
        $this -> Hline = fgets($this -> Hsocket, 1024); 
        $this -> Hstatus["LASTRESULT"] = substr($this -> Hline, 0, 1); 
        $this -> Hstatus["LASTRESULTTXT"] = substr($this -> Hline, 0, 1024); 
        if($this -> Hstatus["LASTRESULT"] !=  "+") return false;
        $H_i = -1;
        $H_j = -1;
         while(trim($this -> Hline = fgets($this -> Hsocket, 4096)) != "."){ //每次读取一行存储
           	$H_tems = trim($this -> Hline);
            if($H_tems == '' && !$this -> H_headf) $this -> H_headf = true;
            if(!$this -> H_headf) $this -> H_head[++$H_i] = $H_tems;
             else $this -> H_body[++$H_j] = $H_tems;
        }
       return true;
    }
    
    public function pop3_dele($nr){ 
		//将邮件标记为删除,由quit命令执行
        fputs($this -> Hsocket,  "DELE ".$nr."\r\n"); 
        $this -> Hline = fgets($this -> Hsocket, 1024); 
        $this -> Hstatus["LASTRESULT"] = substr($this -> Hline, 0, 1); 
        $this -> Hstatus["LASTRESULTTXT"] = substr($this -> Hline, 0, 1024);
        if($this -> Hstatus["LASTRESULT"] !=  "+") return false;
        return true; 
    }
    
    public function pop3_quit(){ 
		//更新并退出
        fputs($this -> Hsocket,  "QUIT\r\n"); 
        $this -> Hline = fgets($this -> Hsocket, 1024); 
        $this -> Hstatus["LASTRESULT"] = substr($this -> Hline, 0, 1); 
        $this -> Hstatus["LASTRESULTTXT"] = substr($this -> Hline, 0, 1024);
        if($this -> Hstatus["LASTRESULT"] <>  "+") return false;
        return true;
    }
    public function get_heads(){
    	//获得邮件头信息
    	$H_data = array();
    	if(strtolower(gettype($this -> H_head)) == 'array'){
    		foreach($this -> H_head as $H_val){
	    		$H_temp = explode(":",$H_val);
	        	$H_tems = strtolower(trim(count($H_temp) > 1 ? $H_temp[0] : $H_tems));
	        	if(count($H_temp) > 1) unset($H_temp[0]);
	        	$H_tstr = trim(implode(":",$H_temp));
	    		switch($H_tems){
	        		case "date" : {				//发件日期(Sat, 1 Mar 2008 18:00:44 +0800 (CST))
	        			$H_data["date"] .= $H_tstr;
	        			break;
	        		}
	        		case "from" : {				//发件编码和人=?GBK?B?u8azrMi6?= <cnhcq@126.com>
	        			$H_data["from"] .= $H_tstr;
	        			break;
	        		}
	        		case "to" : {				//接收人
	        			$H_data["to"] .= $H_tstr;
	        			break;
	        		}
	        		case "message-id" : {		//唯一id
	        			$H_data["message-id"] .= $H_tstr;
	        			break;
	        		}
	        		case "subject" : {			//邮件主题
	        			$H_data["subject"] .= $H_tstr;
	        			break;
	        		}
	        		case "mime-version" : {		//MIME的版本
	        			$H_data["mime-version"] .= $H_tstr;
	        			break;
	        		}
	        		case "content-type" : {		//内容类型
	        			$H_data["content-type"] .= $H_tstr;
	        			break;
	        		}
	        		case "content-transfer-encoding" : {		//编码
	        			$H_data["content-transfer-encoding"] .= $H_tstr;
	        			break;
	        		}
	        		case "x-originating-ip" : {	//发送者和服务器ip
	        			$H_data["x-originating-ip"] .= $H_tstr;
	        			break;
	        		}
	        		case "x-priority" : {		//优先级
	        			$H_data["x-priority"] .= $H_tstr;
	        			break;
	        		}
	        		case "x-mailer" : {			//邮件服务器版本
	        			$H_data["x-mailer"] .= $H_tstr;
	        			break;
	        		}
	        		case "x-coremail-antispam" : {	//反垃圾邮件
	        			$H_data["x-coremail-antispam"] .= $H_tstr;
	        			break;
	        		}
	        	}//end switch
	    	}//end foreach
	    	$this -> H_head = array();
	    	//发件日期(Sat, 1 Mar 2008 18:00:44 +0800 (CST))
	    	$H_data["date"] = $this -> get_date($H_data["date"]);
	    	//发件编码和人=?GBK?B?u8azrMi6?= <cnhcq@126.com>
        	$H_data["from"] = explode(" ",preg_replace(array("'\"'","'\<'","'\>'"),array("","",""),$this -> get_encode($H_data["from"])));
        	//接收人
        	$H_data["to"] = explode(" ",preg_replace(array("'\"'","'\<'","'\>'"),array("","",""),$this -> get_encode($H_data["to"])));
        	//邮件主题
        	$H_data["subject"] = $this -> get_encode($H_data["subject"],"gb2312");
        	//内容类型
        	$H_temp = explode(";",trim($H_data["content-type"]));
        	$H_tempa["type"] = $H_temp[0];	//类型(multipart/mixed|multipart/alternative|text/html)
        	if(count($H_temp) > 1){	//标示符
        		$H_temt = explode("=",trim($H_temp[1]));
        		$H_annx = strtolower(trim($H_temt[0]));
        		if(count($H_temt) > 1) unset($H_temt[0]);
        		if(ereg("^\"(.*)\"$",implode("=",$H_temt),$H_regs)){
        			$H_tempa[$H_annx] = $H_regs[1];
        		}else $H_tempa[trim($H_tems[0])] = trim($H_temt[1]);
        	}
        	$H_data["content-type"] = $H_tempa;
        	$this -> H_data["head"] = $H_data;
	    	return true;
    	}else return false;
    }
    public function get_bodys(){
    	//处理内容正文与附件
    	$this -> H_data["body"] = array();
    	$this -> H_data["attc"] = array();
    	$H_allba = array();
    	$H_stafg = false;
    	$H_attfg = false;
    	$H_boday = '';
    	//检测是否是混合类型
    	if(!eregi("multipart",$this -> H_data["head"]["content-type"]["type"]) && !preg_match("/^--[\S]*[^--]$/",$this -> H_body[1])){
    		$H_cont = implode("\r\n",$this -> H_body);
    		$H_body = array(array("cont" => $H_cont,"size" => strlen($H_cont)));
		}else foreach($this -> H_body as $H_val){
    		if(preg_match("/^--[\S]*--$/",$H_val)){	//结束标记
    			if($H_tempa != "") $H_allba[] = $H_tempa;
    			$H_tempa = array();
	    		$H_temfg = false;
	    		$H_stafg = false;
	    		if($H_attfg){
	    			if(('--'.$H_boday.'--') == trim($H_val)) $H_body = $H_allba;
	    			else $H_attc = $H_allba;
	    		}else $H_body = $H_allba;
	    		unset($H_allba);
    		}else if(preg_match("/^--[\S]*[^--]$/",$H_val)){	//开始标记
    			if($H_tempa != "") $H_allba[] = $H_tempa;
    			$H_tempa = array();
	    		$H_temfg = false;
	    		$H_stafg = true;
    		}else{
    			if($H_stafg){
    				if(eregi('boundary=\"([^\"]*)\"',$H_val,$H_regs)){	//有附件
    					$H_tempa["boundary"] = $H_regs[1];
    					$H_boday = $H_regs[1];
    					$H_attfg = true;
    				}else if($H_temfg){	//内容
    					//处理每行最后的=
    					if(ereg("=$",$H_val,$H_tregs) && ($H_tempa["content-transfer-encoding"] == 'quoted-printable')){
    						$H_val = substr($H_val,0,strlen($H_val)-1);
    					}
    					$H_tempa["cont"] .= $H_val;
    				}else{
    					if($H_vlstr == ''){ $H_vlstr = $H_val; continue;}
    					if($H_val != ''){
	    					$H_temp = explode(":",$H_val);
							if(count($H_temp) < 2){
								$H_vlstr .= $H_val;
								continue;
							}
						}
						$H_temp = explode(":",$H_vlstr);
						$H_vlstr = $H_val;
						$H_temps = explode(";",trim($H_temp[1]));
						$H_annex = strtolower(trim($H_temp[0]));
						$H_tempa[$H_annex] = trim($H_temps[0]);
						if(count($H_temps) > 1) foreach($H_temps as $H_valst){
							if($H_valst != '') $H_tempb = explode("=\"",preg_replace("'\"$'","",trim($H_valst)));
				    		if(count($H_tempb) > 1) $H_tempa[strtolower($H_tempb[0])] = preg_replace("'\"'","",trim($H_tempb[1]));
				    	}
			    	}
			    	if($H_val == '') $H_temfg = true;
		    	}
	    	}
		}
		$this -> H_body = array();
		//内容解码添加size属性
		$H_i = 0;
		if($H_body != '') foreach($H_body as $H_val){
			$H_encod = $H_val["content-transfer-encoding"] == '' ? $this -> H_data["head"]["content-transfer-encoding"] : $H_val["content-transfer-encoding"];
			if($H_encod != ''){
				switch(strtolower($H_encod)){
					case "base64" : 	//将 BASE64 编码字符串解码
						$H_body[$H_i]["cont"] = base64_decode($H_val["cont"]);
						break;
					case "quoted-printable" :	//将 qp 编码字符串转成 8 位字符串
						$H_body[$H_i]["cont"] = quoted_printable_decode($H_val["cont"]);
						break;
				}
				$H_body[$H_i]["cont"] = mb_convert_encoding($H_body[$H_i]["cont"],"gb2312","ucs-bom,utf-8,gb2312,cp936,big5,euc-jp,euc-kr,latin1");
				$H_body[$H_i]["charset"] = 'gb2312';
				$H_body[$H_i]["cont"] = preg_replace("'\.\.'",".",$H_body[$H_i]["cont"]);
			}
			$H_body[$H_i]["size"] = strlen($H_body[$H_i]["cont"]);
			++$H_i;
		}
		//附件解码
		$H_i = 0;
		if($H_attc != '') foreach($H_attc as $H_val){
			if(count($H_val) > 1){
				$H_attc[$H_i]["name"] = $this -> get_encode($H_val["name"]);
				$H_attc[$H_i]["filename"] = $this -> get_encode($H_val["filename"]);
				$H_encod = $H_val["content-transfer-encoding"] == '' ? $this -> H_data["head"]["content-transfer-encoding"] : $H_val["content-transfer-encoding"];
				if($H_encod != ''){
					switch(strtolower($H_encod)){
						case "base64" : 	//将 BASE64 编码字符串解码
							$H_attc[$H_i]["cont"] = base64_decode($H_val["cont"]);
							break;
						case "quoted-printable" :	//将 qp 编码字符串转成 8 位字符串
							$H_attc[$H_i]["cont"] = quoted_printable_decode($H_val["cont"]);
							break;
					}
				}
				$H_attc[$H_i]["size"] = strlen($H_attc[$H_i]["cont"]);
			}
			++$H_i;
		}
		$this -> H_data["body"] = $H_body;
		$this -> H_data["attc"] = $H_attc;
		unset($H_body,$H_attc);
		return true;
    }
    public function get_encode($data,$H_bm="gb2312", $encode="ucs-bom,utf-8,gb2312,cp936,big5,euc-jp,euc-kr,latin1") { 
		//收发件人-解码
	    $data = mb_convert_encoding($data, $H_bm, $encode); 
	    $data = preg_replace_callback("/(=\?(.*?)\?B\?(.*?)\?=)/i", create_function('$matches', 'return mb_convert_encoding(base64_decode($matches[3]), '.$H_bm.', $matches[2]);'), $data);
	    $data = preg_replace_callback("/(=\?(.*?)\?Q\?(.*?)\?=)/i", create_function('$matches', 'return mb_convert_encoding(quoted_printable_decode($matches[3]), '.$H_bm.', $matches[2]);'), $data);
	    //$data = preg_replace_callback("/(=\?(.*?)\?Q\?(.*?)\?=)/i", create_function('$matches', 'return mb_convert_encoding(imap_qprint($matches[3]), '.$H_bm.', $matches[2]);'), $data);
	    return $data; 
	}
	public function get_date($H_date){
		//处理时间
		$H_temp = explode("+",$H_date);
		$H_tem1 = explode(",",trim($H_temp[0]));
		if(count($H_tem1) > 1){
			$H_tems = trim($H_tem1[1]);
			switch(trim(strtolower($H_tem1[0]))){
				case "mon" : $H_week = "星期一"; break;
				case "tue" : $H_week = "星期二"; break;
				case "wed" : $H_week = "星期三"; break;
				case "thu" : $H_week = "星期四"; break;
				case "fri" : $H_week = "星期五"; break;
				case "sat" : $H_week = "星期六"; break;
				case "sun" : $H_week = "星期日"; break;
			}
		}else{
			$H_tems = trim($H_tem1[0]);
		}
		$H_tem2 = explode(" ",trim($H_tems));
		switch(trim(strtolower($H_tem2[1]))){
			case "jan" : $H_moth = array(1,"一月"); break;
			case "feb" : $H_moth = array(2,"二月"); break;
			case "mar" : $H_moth = array(3,"三月"); break;
			case "apr" : $H_moth = array(4,"四月"); break;
			case "may" : $H_moth = array(5,"五月"); break;
			case "jun" : $H_moth = array(6,"六月"); break;
			case "jul" : $H_moth = array(7,"七月"); break;
			case "aug" : $H_moth = array(8,"八月"); break;
			case "stp" : $H_moth = array(9,"九月"); break;
			case "oct" : $H_moth = array(10,"十月"); break;
			case "nov" : $H_moth = array(11,"十一月"); break;
			case "dec" : $H_moth = array(12,"十二月"); break;
		}
		$H_days = trim($H_tem2[0]);		//日
		$H_year = trim($H_tem2[2]);		//年
		$H_tem3 = explode(":",trim($H_tem2[3]));
		$H_hous = trim($H_tem3[0]);		//时
		$H_mins = trim($H_tem3[1]);		//分
		$H_sect = trim($H_tem3[2]) == '' ? '00':trim($H_tem3[2]);		//秒
		if($H_week == ''&& $H_moth[0]!=''&&$H_days!=''&&$H_year!=''){
			switch(trim(strtolower(date("D",mktime($H_moth[0],$H_days,$H_year))))){
				case "mon" : $H_week = "星期一"; break;
				case "tue" : $H_week = "星期二"; break;
				case "wed" : $H_week = "星期三"; break;
				case "thu" : $H_week = "星期四"; break;
				case "fri" : $H_week = "星期五"; break;
				case "sat" : $H_week = "星期六"; break;
				case "sun" : $H_week = "星期日"; break;
			}
		}
		return array("week" => $H_week,"days" => $H_days,"moth" => $H_moth,"year" => $H_year,"hous" => $H_hous,"mins" => $H_mins,"sect" => $H_sect);
	}
	public function get_attc($H_num=1,$H_name=''){
		//下载附件
		$H_enum = count($this -> H_data["attc"]);
		if($H_num < 1 || $H_num > $H_enum) return 'ERROR';
		$H_ctype = $this -> H_data["attc"][$H_num]["content-type"];
		$H_fsize = $this -> H_data["attc"][$H_num]["size"];
		$H_temp = explode(".",$this -> H_data["attc"][$H_num]["filename"]);
		$H_fname = ($H_name == '' ? $H_temp[0] : $H_name).".".$H_temp[1];
		//设置头信息
		Header('Content-type: '.$H_ctype);
		Header('Accept-Ranges: bytes');
		Header('Accept-Length: '.$H_fsize);
		Header('Content-Disposition: attachment; filename='.$H_fname);
		echo $this -> H_data["attc"][$H_num]["cont"];	//输出
		flush();
	}
}//End Class
?>

 

posted @ 2012-01-17 15:32  祥辉  阅读(361)  评论(0编辑  收藏  举报