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>
";
if(($error=$pop3_connection->Login($user,$password,$apop))=="")
{
echo "<PRE>User "$user" 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 "$pop3_connection->hostname".</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] 下一页