您现在的位置: 军旅同心-旅游自驾-军旅文学 >> 读书赏析 >> 学习园地 >> 电脑网络 >> 技术文章 >> 正文
pop3邮件收取一例
作者:采集员 文章来源:来源于网络 点击数: 更新时间:2005-9-10 14:34:49
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 &quot;$pop3_connection->hostname&quot;.</PRE> ";
   if(($error=$pop3_connection->Login($user,$password,$apop))=="")
   {
      echo "<PRE>User &quot;$user&quot; logged in.</PRE> ";
      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> ";
         $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> ";
             if($messages>0)
            {
                if(($error=$pop3_connection->RetrieveMessage(1,&$headers,&$body,-1))=="")
                {
                  echo "<PRE>Message 1: ---Message headers starts below---</PRE> ";
                  for($line=0;$line<count($headers);$line++)
                     echo "<PRE>",HtmlSpecialChars($headers[$line]),"</PRE> ";
                  echo "<PRE>---Message headers ends above--- ---Message body starts below---</PRE> ";
                  for($line=0;$line<count($body);$line++)
                     echo "<PRE>",HtmlSpecialChars($body[$line]),"</PRE> ";
                  echo "<PRE>---Message body ends above---</PRE> ";
                     
                  }
               }
             if($error==""&&($error=$pop3_connection->Close())=="")
                  echo "<PRE>Disconnected from the POP3 server &quot;$pop3_connection->hostname&quot;.</PRE> ";
         }
        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> ";
        }

        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)==" ")
                        {
                                $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 "));
        }

        Function OpenConnection()
        {
                if($this->hostname=="")
                        return("2 it was not specified a valid hostname");
                switch(($this->connection=fsockopen($this->hostname,$this->port)))
                {
            &nb

[1] [2] [3] [4] [5] 下一页


更多
免责声明:作品版权归所属媒体与作者所有!!本站刊载此文不代表同意其说法或描述,仅为提供更多信息。如果您认为我们侵犯了您的版权,请告知!本站立即删除。有异议请联系我们。
文章录入:烟灰缸    责任编辑:烟灰缸 
网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
| 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 网站地图 | 版权申明 | 网站公告 | 管理登录 |