class myimap { var $username=""; var $userpwd=""; var $hostname=""; var $port=0; var $connection=0; //是否连接 var $state="DISCONNECTED"; //连接状态 var $greeting=""; var $must_update=0; var $inStream=0;
Function open() { if ($this->port==110) $this->inStream=imap_open("{$this->hostname/pop3:110}inbox",$this->username,$this->userpwd); else $this->inStream=imap_open("{$this->hostname/imap:143}inbox",$this->username,$this->userpwd);
Function decode_mime_string ($string) { $pos = strpos($string, '=?'); if (!is_int($pos)) { return $string; }
$preceding = substr($string, 0, $pos); // save any preceding text
$search = substr($string, $pos+2, 75); // the mime header spec says this is the longest a single encoded word can be $d1 = strpos($search, '?'); if (!is_int($d1)) { return $string; }
Function get_barefrom($user, $server) { $barefrom = "$user@$real_server";
return $barefrom; }
Function get_structure($msg_num) { $structure=imap_fetchstructure($this->inStream,$msg_num); //echo gettype($structure); return $structure; }
Function proc_structure($msg_part, $part_no, $msg_num) { if ($msg_part->ifdisposition) { // See if it has a disposition // The only thing I know of that this // would be used for would be an attachment // Lets check anyway if ($msg_part->disposition == "ATTACHMENT") { // If it is an attachment, then we let people download it // First see if they sent a filename $att_name = "unknown"; for ($lcv = 0; $lcv parameters); $lcv++) { $param = $msg_part->parameters[$lcv];
// You could give a link to download the attachment here.... echo ''.$att_name.' '; $fp=fopen(".\\$att_name","w+"); fputs($fp,imap_base64(imap_fetchbody($this->inStream,$msg_num,$part_no))); fclose($fp); } else { // I guess it is used for something besides attachments???? } } else { // Not an attachment, lets see what this part is... switch ($msg_part->type) { case TYPETEXT: $mime_type = "text"; break; case TYPEMULTIPART: $mime_type = "multipart"; // Hey, why not use this function to deal with all the parts // of this multipart part :) for ($i = 0; $i parts); $i++) { if ($part_no != "") { $part_no = $part_no."."; } for ($i = 0; $i parts); $i++) { $this->proc_structure($msg_part->parts[$i], $part_no.($i + 1), $msg_num); } } break; case TYPEMESSAGE: $mime_type = "message"; break; case TYPEAPPLICATION: $mime_type = "application"; break; case TYPEAUDIO: $mime_type = "audio"; break; case TYPEIMAGE: $mime_type = "image"; break; case TYPEVIDEO: $mime_type = "video"; break; case TYPEMODEL: $mime_type = "model"; break; default: $mime_type = "unknown"; // hmmm.... }
// Decide what you what to do with this part // If you want to show it, figure out the encoding and echo away switch ($msg_part->encoding) { case ENCBASE64: // use imap_base64 to decode $fp=fopen(".\\$att_name","w+"); fputs($fp,imap_base64(imap_fetchbody($this->inStream,$msg_num,$part_no))); fclose($fp); break; case ENCQUOTEDPRINTABLE: // use imap_qprint to decode //echo ereg_replace("\n"," ",imap_qprint(imap_fetchbody($this->inStream,$msg_num,$part_no))); echo '
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn