日期:2011-06-10  浏览次数:20535 次

我认为是相当经典的,帮过我大忙,可以实现很多PHP的IMAP函数不能实现的功能。以前在广州站贴过,那时北京站还没PHP版,现在再贴一个吧。:)

<?php
/*************************************************************

File: cyradm.inc.php
Author: 忘了,嘻嘻
Date: 2000-11-01

This is a completely new implementation of the IMAP Access for
PHP. It is based on a socket connection to the server an is
independent from the imap-Functions of PHP

***************************************************************/

class cyradm {

var $host;
var $port;
var $mbox;
var $list;

var $admin;
var $pass;
var $fp;
var $line;
var $error_msg;

/*
#
#Konstruktor
#
*/
function cyradm($IMAP_HOST="localhost", $IMAP_ADMIN="", $IMAP_PW="", $IMAP_PORT="143"){
$this->host = $IMAP_HOST;
$this->port = $IMAP_PORT;
$this->mbox = "";
$this->list = array();

$this->admin = $IMAP_ADMIN;
$this->pass = $IMAP_PW;
$this->fp = 0;
$this->line = "";
$this->error_msg = "";
}


/*
#
# SOCKETLOGIN on Server via Telnet-Connection!
#
*/
function imap_login() {
$this->fp = fsockopen($this->host, $this->port, &$errno, &$errstr);
$this->error_msg=$errstr;
if(!$this->fp) {
echo "<br>ERRORNO: ($errno) <br>ERRSTR: ($errstr)<br><hr>\n";
} else {
$this->command(". login \"$this->admin\" \"$this->pass\"");
}
return $errno;
}


/*
#
# SOCKETLOGOUT from Server via Telnet-Connection!
#
*/
function imap_logout() {
$this->command(". logout");
fclose($this->fp);
}


/*
#
# SENDING COMMAND to Server via Telnet-Connection!
#
*/
function command($line) {
/* print ("$line <br>"); */
$result = array();
$i=0; $f=0;
$returntext="";
$r = fputs($this->fp,"$line\n");
while (!((strstr($returntext,". OK")||(strstr($returntext,". NO"))||(strstr($returntext,". BAD")))))
{
$returntext=$this->getline();
/* print ("$returntext <br>"); */
if ($returntext)
{
if (!((strstr($returntext,". OK")||(strstr($returntext,". NO"))||(strstr($returntext,". BAD")))))
{
$result[$i]=$returntext;
}
$i++;
}
}

if (strstr($returntext,". BAD")||(strstr($returntext,". NO")))
{
$result[0]="$returntext";
$this->error_msg = $returntext;

if (( strstr($returntext,". NO Quota") ))
{

}
else
{
print "<br><hr><H1><center><blink>ERROR: </blink>UNEXPECTED IMAP-SERVER-ERROR</center></H1><hr><br>
<table color=red border=0 align=center cellpadding=5 callspacing=3>
<tr><td>SENT COMMAND: </td><td>$line</td></tr>
<tr><td>SERVER RETURNED:</td><td></td></tr>
";
for ($i=0; $i < count($result); $i++) {
print "<tr><td></td><td>$result[$i]</td></tr>";
}
print "</table><hr><br><br>";
}
}
return $result;
}


/*
#
# READING from Server via Telnet-Connection!
#
*/

function getline() {
$this->line = fgets($this->fp, 256);
return $this->line;
}

/*
#
# QUOTA Functions
#
*/

// GETTING QUOTA

function getquota($mb_name) {
$output=$this->command(". getquota \"$mb_name\"");
if (strstr($output[0],". NO"))
{
$ret["used"] = "NOT-SET";
$ret["qmax"] = "NOT-SET";
}
else
{
$realoutput = str_replace(")", "", $output[0]);
$tok_list = split(" ",$realoutput);
$si_used=sizeof($tok_list)-2;
$si_max=sizeof($tok_list)-1;
$ret["used"] = str_replace(")","",$tok_list[$si_used]);
$ret["qmax"] = $tok_list[$si_max];
}
ret