⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imap.class.inc

📁 groupoffice
💻 INC
📖 第 1 页 / 共 3 页
字号:
	/**	* Get one message with the structure	*	* @param int $uid The unique identifier of the	* @param string $preferred_type Preferred body type to get html or text	* @param string $part Get a specific part of a message	* @access public	* @return array The E-mail message elements	*/	function get_message($uid, $preferred_type = "html", $part = "") {		if ($this->conn) {			unset ($this->message);									//determine next and previous message			if (!isset ($this->sort)) {				$this->sort();			}			$this->message['uid'] = $uid;			$this->message['number'] = imap_msgno($this->conn, $uid);						if(!@$headerinfo = imap_headerinfo($this->conn, $this->message['number']))			{				//message doesn't exist				return false;			}			for ($i = 0; $i < sizeof($this->sort); $i ++) {				if ($this->message['uid'] == $this->sort[$i]) {					$this->message["next"] = ($i -1 >= 0) ? $this->sort[$i -1] : 0;					$this->message["previous"] = ($i +1 < sizeof($this->sort)) ? $this->sort[$i +1] : 0;					break;				}			}															$this->message['udate'] = $headerinfo->udate;			//$this->message["udate"] = strtotime(str_replace('CEST', '', $headerinfo->date));			$this->message['new'] = ($headerinfo->Unseen == 'U' && $this->is_imap()) ? true : false;			$tmp = $headerinfo->from;			$this->message["sender"] = $tmp[0]->mailbox.'@'.$tmp[0]->host;			$this->message["from"] = isset ($tmp[0]->personal) ? enc_utf8($tmp[0]->personal) : $this->message["sender"];			$this->message["reply_to"] = $this->RFC822->write_address($this->message['from'], $this->message["sender"]);			if (isset ($headerinfo->reply_to)) {				$tmp = $headerinfo->reply_to;				$this->message["reply_to"] = $this->RFC822->write_address($this->message['from'], $tmp[0]->mailbox.'@'.$tmp[0]->host);			}			$this->message["subject"] = isset ($headerinfo->Subject) ? enc_utf8($headerinfo->Subject) : '';			$this->message["to"] = array();			if (isset($headerinfo->to) && is_array ($headerinfo->to)) {				$tmp = $headerinfo->to;				for ($x = 0; $x < sizeof($tmp); $x ++) {					$email = '';					if (isset ($tmp[$x]->mailbox)) {						$host = isset ($tmp[$x]->host) ? '@'.$tmp[$x]->host : '';						$email = $tmp[$x]->mailbox.$host;					}					$personal = isset ($tmp[$x]->personal) ? enc_utf8($tmp[$x]->personal) : '';					$this->message["to"][$x] = $this->RFC822->write_address($personal, $email);				}			}						$this->message["cc"] = array();			if (isset($headerinfo->cc) && is_array ($headerinfo->cc)) {				$tmp = $headerinfo->cc;				for ($x = 0; $x < sizeof($tmp); $x ++) {					$email = '';					if (isset ($tmp[$x]->mailbox)) {						$host = isset ($tmp[$x]->host) ? '@'.$tmp[$x]->host : '';						$email = $tmp[$x]->mailbox.$host;					}					$personal = isset ($tmp[$x]->personal) ? enc_utf8($tmp[$x]->personal) : '';					$this->message["cc"][$x] = $this->RFC822->write_address($personal, $email);				}			}			$this->message["bcc"] = array();			if (isset($headerinfo->bcc) && is_array ($headerinfo->bcc)) {				$tmp = $headerinfo->bcc;				for ($x = 0; $x < sizeof($tmp); $x ++) {					$email = '';					if (isset ($tmp[$x]->mailbox)) {						$host = isset ($tmp[$x]->host) ? '@'.$tmp[$x]->host : '';						$email = $tmp[$x]->mailbox.$host;					}					$personal = isset ($tmp[$x]->personal) ? enc_utf8($tmp[$x]->personal) : '';					$this->message["bcc"][$x] = $this->RFC822->write_address($personal, $email);				}			}									$this->message["parts"] = array ();			if ($part == '') {				$structure = imap_fetchstructure($this->conn, $uid, FT_UID);			} else {				$structure = imap_bodystruct($this->conn, $this->message['number'], $part);			}			$this->mail["parts"] = array ();			$this->get_parts($structure, $preferred_type);			// $this->print_structure($structure);			$header = imap_fetchheader($this->conn, $uid, FT_UID);			$this->message["priority"] = $this->get_header_value("X-Priority:", $header);			$this->message["notification"] = $this->get_header_value("Disposition-Notification-To:", $header);			$this->message["header"] = $header;			$overview = imap_fetch_overview($this->conn, $uid, FT_UID);			$this->message["flagged"] = $overview[0]->flagged;			$this->message["size"] = $overview[0]->size;			$this->message["answered"] = $overview[0]->answered;			return $this->message;		} else {			return false;		}	}	/**	* Get structured parts of a message	*	* @param array $mimeobj An array returned by imap_fetch_structure()	* @param string $preferred_type Preferred body type to get html or text	* @param string $section The current section of the message	* @access private	* @return void	*/	function get_parts($mimeobj, $preferred_type = "html", $section = 0) {		if (isset ($mimeobj->type)) {			$type = $this->get_mime_type($mimeobj->type);		} else {			$type = 'text';		}		$full_mime_type = $type."/".$mimeobj->subtype;		$encoding = $this->get_encoding($mimeobj->encoding);		if (isset ($mimeobj->parameters)) {			$params = $mimeobj->parameters;			for ($x = 0; $x < count($params); $x ++) {				if(is_object($params) && isset($params->$x))				{					$param = $params->$x;				}elseif(is_array($params) && isset($params[$x]))				{					$param = $params[$x];				}else				{					$param = null;				}								if(isset($param))				{					if ((strtolower($param->attribute) == 'name' || strtolower($param->attribute) == 'name*') && $param->value != '') {						$name = enc_utf8($param->value);						break;					}				}			}		}		$name = isset ($name) ? $name : '';		if ((!isset ($name) || $name == "") && isset ($mimeobj->dparameters)) {			$params = $mimeobj->dparameters;			for ($x = 0; $x < count($params); $x ++) {				if(is_object($params) && isset($params->$x))				{					$param = $params->$x;				}elseif(is_array($params) && isset($params[$x]))				{					$param = $params[$x];				}else				{					$param = null;				}								if(isset($param))				{					if ((strtolower($param->attribute) == 'filename' || strtolower($param->attribute) == 'filename*') && $param->value != '') {						//$name = enc_utf8(quoted_printable_decode($param->value));						$name = enc_utf8($param->value);						break;					}				}			}		}		$x = 0;		if (isset ($mimeobj->parts)) {			for ($x = 0; $x < count($mimeobj->parts); $x ++) {				if ($mimeobj->subtype == "ALTERNATIVE" && $preferred_type == "html") {					if (isset ($mimeobj->parts[$x +1]) && eregi('html', $mimeobj->parts[$x +1]->subtype)) {						$x ++;					} else {						$preferred_type = 'text';					}				}				// If we are in the root of the object increment by whole integers				if ($section == 0) {					$nsection = $x +1;				} else					if (($pos = strrpos($section, ".")) && ($mimeobj->parts[0]->type != TYPEMULTIPART || $mimeobj->parts[0]->subtype != 'RELATED')) {						$subsection = (int) substr($section, $pos +1) + $x;						if ($subsection == '') {							$subsection = '0';						}						$nsection = substr($section, 0, $pos).".". ($subsection +1);					} else {						$nsection = $section;					}				// If there are more parts to the part about to be processed reference it as a header with ".0"				// but only if the child of this child isn't MULTIPART				if (isset ($mimeobj->parts[$x]->parts) && count($mimeobj->parts[$x]->parts)) {					// Funny really, if a mime section is a inline message that has a multipart body you reference the message					// mime section with "2" the inline message header with "2.0" and the subsections with	"2.x"					// However if the mime section is a inline message with only 1 part then you reference the					// mime section in the message with 2.0 and the	inline message body with 2.1					if (!($mimeobj->parts[$x]->type == TYPEMESSAGE && $mimeobj->parts[$x]->parts[0]->type == TYPEMULTIPART)) {						$nsection .= ".0";					} else {						$nsection .= "";					}				}				$this->get_parts($mimeobj->parts[$x], $preferred_type, $nsection);				if ($mimeobj->subtype == "ALTERNATIVE" && $preferred_type == "plain")					$x ++;			}		}		// If after processing the entire MIME object the $x variable is still zero then we didn't		// process a multipart mime message.		if ($x == 0 && $section == 0) {			$section = "1";		}		if ($type != "multipart" && $full_mime_type) {			if (eregi('message', $full_mime_type)) {				$section ++;			}			$part_charset = 'ISO-8859-15';			if ($mimeobj->ifparameters) {				for ($x = 0; $x < count($mimeobj->parameters); $x ++) {					$param = $mimeobj->parameters[$x];					if ((strtolower($param->attribute) == 'charset') && ($param->value != '')) {						$part_charset = $param->value;						break;					}				}			}			$bytes = isset ($mimeobj->bytes) ? $mimeobj->bytes : 0;			$tmp = Array ('number' => $section, 'id' => $mimeobj->ifid ? $mimeobj->id : 0, 'name' => $name, 'mime' => $full_mime_type, 'transfer' => $encoding, 'charset' => $part_charset, 'disposition' => $mimeobj->ifdisposition ? $mimeobj->disposition : '', 'size' => $bytes);			array_unshift($this->message["parts"], $tmp);		}	}	/*		function print_structure($mimeobj, $depth = 0, $section = 0)		{			for($y = 0; $y < $depth; $y++)			{				echo("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");			}			echo($this->get_mime_type($mimeobj->type) . "/{$mimeobj->subtype},");			echo($this->get_encoding($mimeobj->encoding) . "(<B>$section</B>)<br>");				$x=0;			if (isset($mimeobj->parts))			{					for($x = 0; $x < count($mimeobj->parts); $x++)				{					// If we are in the root of the object increment by whole	integers						if($section == 0)					{						$nsection = $x + 1;						$subsection = 0;						// If we are in the object and the first sub-object of our	object isn't multipart						// then increment the postfix by ".1" otherwise	we are multipart or a message						// and leave the section id alone to be handled by the next	code block							//else if(($pos = strrpos($section, ".")) && sizeof($mimeobj->parts) > 1)					}else if(($pos = strrpos($section, ".")) && ($mimeobj->parts[0]->type != TYPEMULTIPART || $mimeobj->parts[0]->subtype != 'RELATED'))						//}elseif($pos = strrpos($section, "."))					{						$subsection = (int) substr($section, $pos+1)+$x;						if ($subsection == '')						{							$subsection = '0';						}						$nsection = substr($section, 0, $pos) .	"." . ($subsection + 1);					}else					{						$nsection = $section;						}						// If there are more parts to the part about to be processed reference it as a header with ".0"					// but only if the child of this child isn't MULTIPART						if(isset($mimeobj->parts[$x]->parts) && count($mimeobj->parts[$x]->parts))					{						// Funny really, if a mime section is a inline message that has a multipart body you reference the message						// mime section with "2" the inline	message header with "2.0" and the subsections with	"2.x"						// However if the mime section is a inline message with only 1 part then you reference the						// mime section in the message with 2.0 and the	inline message body with 2.1							if(!($mimeobj->parts[$x]->type == TYPEMESSAGE && $mimeobj->parts[$x]->parts[0]->type ==	TYPEMULTIPART))						{							$nsection .= ".0";						}else						{							$nsection .= "";						}					}						$this->print_structure($mimeobj->parts[$x], $depth + 1, $nsection);			}		}			// If after processing the entire MIME object the $x variable is still zero then we didn't		// process a multipart mime message, it's just normal email so say so here.			if($x == 0 && $section == 0)		{			echo($this->get_mime_type($mimeobj->type) . "/{$mimeobj->subtype}, ");			echo($this->get_encoding($mimeobj->encoding) . "(<B>1</B>) (<B>NOT MIME MULTIPART</B>)<br>");		}	}	*/	/**		* Get the encoding of a message part in text		*		* @param int $encoding The encoding type as ut comes from imap_fetch_structure()		* @access private		* @return String The Encoding		*/	function get_encoding($encoding) {		switch ($encoding) {			case 0 :				$encoding = '7BIT';				break;			case 1 :				$encoding = '8BIT';				break;			case 2 :				$encoding = 'BINARY';				break;			case 3 :				$encoding = 'BASE64';				break;			case 4 :				$encoding = 'QUOTED-PRINTABLE';				break;			case 5 :				$encoding = 'OTHER';				break;			default :				$encoding = 'none';				break;		}		return $encoding;	}	/**		* Get the mime type of a message part in text		*		* @param int $type The mime type as ut comes from imap_fetch_structure()		* @access private		* @return String The mime type		*/	function get_mime_type($type) {		switch ($type) {			case 0 :				$mime_type = 'text';				break;			case 1 :				$mime_type = 'multipart';				break;			case 2 :				$mime_type = 'message';				break;			case 3 :				$mime_type = 'application';				break;			case 4 :				$mime_type = 'audio';				break;			case 5 :				$mime_type = 'image';				break;			case 6 :				$mime_type = 'video';				break;			case 7 :				$mime_type = 'model';				break;			default :				$mime_type = 'unknown';		}		return $mime_type;	}	/**		* Search a plain text header for a value		*		* @param String $fieldname The name of the field

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -