首页 >> 读书频道 >> 电脑 >> pop3邮件收取一例
 
· smtp邮件发送一例
· 采用行写方式的聊天程序(
· 采用行写方式的聊天程序(
· 采用行写方式的聊天程序(
· PHP对象编程实现3D饼
· 用PHP开发GUI
· 基于PHP与XML的PD
· 用PHP实现通过Web执
· 如何把PHP转成EXE文
· web方式ftp
· 用PHP动态创建Flas
· 用PHP读取IMAP邮件
 
· 美容养颜手册
· 加油金顺剧情分集介绍完整
· 红楼梦:120回全本[清
· 素质教育在美国
· 全唐诗卷四十六
· 韩剧《布拉格恋人》剧情介
· 夜航船[作者:明·张岱]
· 局外人[作者:韩·可爱淘
· 现场流行病学
· 源氏物语[日本:紫式部]
· 武林寓言故事
· 2006高考录取规则
 
· (出租)中动商场部分及写
· (出租)中动动漫基地&#
· 喜剧学院
· 《善德女王》剧情介绍
· 魔女18号 剧情
· 丑女无敌剧情介绍
· 魔女幼熙剧情介绍
· 龙游天下剧情介绍
· 震撼世界的七日剧情介绍
· 静静的白桦林剧情介绍
· 心情日记—老公今天我想对
· 旗舰剧情介绍
欢迎来到月影社区!如果您觉得这里不错,请推荐给您的朋友们。月影社区:http://wf66.com/

pop3邮件收取一例


查看有无更新版本

关键字:PHP 2006-9-4

 

test_pop3.php
<HTML>
<HEAD>
<TITLE>Test for Manuel Lemos's PHP POP3 class</TITLE>
</HEAD>
<BODY>
<?
require("pop3.php");
$user="user";
$password="passwd";
$apop=0;
$pop3_connection=new pop3_class;
$pop3_connection->hostname="mail.xiaocui.com";
if(($error=$pop3_connection->Open())=="")
{
   echo "<PRE>Connected to the POP3 server "$pop3_connection->hostname".</PRE>\n";
   if(($error=$pop3_connection->Login($user,$password,$apop))=="")
   {
      echo "<PRE>User "$user" logged in.</PRE>\n";
      if(($error=$pop3_connection->Statistics(&$messages,&$size))=="")
      {
         echo "<PRE>There are <b>$messages</b> messages in the mail box with a total of <b>$size</b> bytes.</PRE>\n";
         $result=$pop3_connection->ListMessages("",0);
         if(GetType($result)=="array")
         {
            for(Reset($result),$message=0;$message<count($result);Next($result),$message++)
               echo "<PRE>Message ",Key($result)," - ",$result[Key($result)]," bytes.</PRE>\n";
             if($messages>0)
            {
                if(($error=$pop3_connection->RetrieveMessage(1,&$headers,&$body,-1))=="")
                {
                  echo "<PRE>Message 1:\n---Message headers starts below---</PRE>\n";
                  for($line=0;$line<count($headers);$line++)
                     echo "<PRE>",HtmlSpecialChars($headers[$line]),"</PRE>\n";
                  echo "<PRE>---Message headers ends above---\n---Message body starts below---</PRE>\n";
                  for($line=0;$line<count($body);$line++)
                     echo "<PRE>",HtmlSpecialChars($body[$line]),"</PRE>\n";
                  echo "<PRE>---Message body ends above---</PRE>\n";
                    
                  }
               }
             if($error==""&&($error=$pop3_connection->Close())=="")
                  echo "<PRE>Disconnected from the POP3 server "$pop3_connection->hostname".</PRE>\n";
         }
        else
           $error=$result;
      }
   }
}
if($error!="")
   echo "<H2>Error: ",HtmlSpecialChars($error),"</H2>";
?>
</BODY>
</HTML>

pop3.php
<?
class pop3_class
{
        var $hostname="";
        var $port=110;
        var $connection=0;
        var $state="DISCONNECTED";
        var $greeting="";
        var $must_update=0;
        var $debug=0;
        Function OutputDebug($message)
        {
                echo $message,"<br>\n";
        }
        Function GetLine()
        {
                for($line="";;)
                {
                        if(feof($this->connection))
                                return(0);
                        $line.=fgets($this->connection,100);
                        $length=strlen($line);
                        if($length>=2 && substr($line,$length-2,2)=="\r\n")
                        {
                                $line=substr($line,0,$length-2);
                                if($this->debug)
                                        $this->OutputDebug("< $line");
                                return($line);
                        }
                }
        }
        Function PutLine($line)
        {
                if($this->debug)
                        $this->OutputDebug("> $line");
                return(fputs($this->connection,"$line\r\n"));
        }
        Function OpenConnection()
        {
                if($this->hostname=="")
                        return("2 it was not specified a valid hostname");
                switch(($this->connection=fsockopen($this->hostname,$this->port)))
                {
                        case -3:
                                return("-3 socket could not be created");
                        case -4:
                                return("-4 dns lookup on hostname \"$hostname\" failed");
                        case -5:
                                return("-5 connection refused or timed out");
                        case -6:
                                return("-6 fdopen() call failed");
                        case -7:
                                return("-7 setvbuf() call failed");
                        default:
                                return("");
                }
        }
        Function CloseConnection()
        {
                if($this->connection!=0)
                {
                        fclose($this->connection);
                        $this->connection=0;
                }
        }
        Function Open()
        {
                if($this->state!="DISCONNECTED")
                        return("1 a connection is already opened");
                if(($error=$this->OpenConnection())!="")
                        return($error);
                $this->greeting=$this->GetLine();
                if(GetType($this->greeting)!="string"
                || strtok($this->greeting," ")!="+OK")
                {
                        $this->CloseConnection();
                        return("3 POP3 server greeting was not found");
                }
                $this->greeting=strtok("\r\n");
                $this->must_update=0;
                $this->state="AUTHORIZATION";
                return("");
        }
       
        Function Close()
        {
                if($this->state=="DISCONNECTED")
                        return("no connection was opened");
                if($this->must_update)
                {
                        if($this->PutLine("QUIT")==0)
                                return("Could not send the QUIT command");
                        $response=$this->GetLine();
                        if(GetType($response)!="string")
                                return("Could not get quit command response");
                        if(strtok($response," ")!="+OK")
                                return("Could not quit the connection: ".strtok("\r\n"));
                }
                $this->CloseConnection();
                $this->state="DISCONNECTED";
                return("");
        }
        Function Login($user,$password,$apop)
        {
                if($this->state!="AUTHORIZATION")
                        return("connection is not in AUTHORIZATION state");
                if($apop)
                {
                        if($this->PutLine("APOP $user ".md5($this->greeting.$password))==0)
                                return("Could not send the APOP command");
                        $response=$this->GetLine();
                        if(GetType($response)!="string")
                                return("Could not get APOP login command response");
                        if(strtok($response," ")!="+OK")
                                return("APOP login failed: ".strtok("\r\n"));
                }
                else
                {
                        if($this->PutLine("USER $user")==0)
                                return("Could not send the USER command");
                        $response=$this->GetLine();
                        if(GetType($response)!="string")
                                return("Could not get user login entry response");
                        if(strtok($response," ")!="+OK")
                                return("User error: ".strtok("\r\n"));
                        if($this->PutLine("PASS $password")==0)
                                return("Could not send the PASS command");
                        $response=$this->GetLine();
                        if(GetType($response)!="string")
                                return("Could not get login password entry response");
                        if(strtok($response," ")!="+OK")
                                return("Password error: ".strtok("\r\n"));
                }
                $this->state="TRANSACTION";
                return("");
        }
        /* Statistics method - pass references to variables to hold the number of
     messages in the mail box and the size that they take in bytes.  */
        Function Statistics($messages,$size)
        {
                if($this->state!="TRANSACTION")
                        return("connection is not in TRANSACTION state");
                if($this->PutLine("STAT")==0)
                        return("Could not send the STAT command");
                $response=$this->GetLine();
                if(GetType($response)!="string")
                        return("Could not get the statistics command response");
                if(strtok($response," ")!="+OK")
                        return("Could not get the statistics: ".strtok("\r\n"));
                $messages=strtok(" ");
                $size=strtok(" ");
                return("");
        }
        Function ListMessages($message,$unique_id)
        {
                if($this->state!="TRANSACTION")
                        return("connection is not in TRANSACTION state");
                if($unique_id)
                        $list_command="UIDL";
                else
                        $list_command="LIST";
                if($this->PutLine("$list_command $message")==0)
                        return("Could not send the $list_command command");
                $response=$this->GetLine();
                if(GetType($response)!="string")
                        return("Could not get message list command response");
                if(strtok($response," ")!="+OK")
                        return("Could not get the message listing: ".strtok("\r\n"));
                if($message=="")
                {
                        for($messages=array();;)
                        {
                                $response=$this->GetLine();
                                if(GetType($response)!="string")
                                        return("Could not get message list response");
                                if($response==".")
                                        break;
                                $message=intval(strtok($response," "));
                                if($unique_id)
                                        $messages[$message]=strtok(" ");
                                else
                                        $messages[$message]=intval(strtok(" "));
                        }
                        return($messages);
                }
                else
                {
                        $message=intval(strtok(" "));
                        return(intval(strtok(" ")));
                }
        }
        Function RetrieveMessage($message,$headers,$body,$lines)
        {
                if($this->state!="TRANSACTION")
                        return("connection is not in TRANSACTION state");
                if($lines<0)
                {
                        $command="RETR";
                        $arguments="$message";
                }
                else
                {
                        $command="TOP";
                        $arguments="$message $lines";
                }
                if($this->PutLine("$command $arguments")==0)
                        return("Could not send the $command command");
                $response=$this->GetLine();
                if(GetType($response)!="string")
                        return("Could not get message retrieval command response");
                if(strtok($response," ")!="+OK")
                        return("Could not retrieve the message: ".strtok("\r\n"));
                for($headers=$body=array(),$line=0;;$line++)
                {
                        $response=$this->GetLine();
                        if(GetType($response)!="string")
                                return("Could not retrieve the message");
                        switch($response)
                        {
                                case ".":
                                        return("");
                                case "":
                                        break 2;
                                default:
                                        if(substr($response,0,1)==".")
                                                $response=substr($response,1,strlen($response)-1);
                                        break;
                        }
                        $headers[$line]=$response;
                }
                for($line=0;;$line++)
                {
                        $response=$this->GetLine();
                        if(GetType($response)!="string")
                                return("Could not retrieve the message");
                        switch($response)
                        {
                                case ".":
                                        return("");
                                default:
                                        if(substr($response,0,1)==".")
                                                $response=substr($response,1,strlen($response)-1);
                                        break;
                        }
                        $body[$line]=$response;
                }
                return("");
        }
};
?>

pop3邮件收取一例

[ 1 ]
pop3邮件收取一例 num

打印本页 关闭

关于我们版权声明本站导航友情连结作品演示 TOP↑