PHP操作IMAP服务器的类
服务器
我认为是相当经典的,帮过我大忙,可以实现很多PHP的IMAP函数不能实现的功能。以前在广州站贴过,那时北京站还没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 "
ERRORNO: ($errno)
ERRSTR: ($errstr)
\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
"); */
$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
"); */
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 "
UNEXPECTED IMAP-SERVER-ERROR
SENT COMMAND: | $line |
SERVER RETURNED: | |
$result[$i] |
";
}
}
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];
}
return $ret;
}
// SETTING QUOTA
function setmbquota($mb_name, $quota) {
$this->command(". setquota \"$mb_name\" (STORAGE $quota)");
}
/*
#
# MAILBOX Functions
#
*/
function createmb($mb_name, $mb_partition="") {
$this->command(". create \"$mb_name\" $mb_partition");
}
function deletemb($mb_name) {
$this->command(". setacl \"$mb_name\" $this->admin d");
$this->command(". delete \"$mb_name\"");
}
function renamemb($mb_name, $newmbname) {
$all="lrswipcda";
$this->setacl($mb_name, $this->admin,$all);
$this->command(". rename \"$mb_name\" \"$newmbname\"");
$this->deleteacl($newmbname, $this->admin);
}
function renameuser($from_mb_name, $to_mb_name) {
$all="lrswipcda"; $find_out=array(); $split_res=array(); $owner=""; $oldowner="";
/* Anlegen und Kopieren der INBOX */
$this->createmb($to_mb_name);
$this->setacl($to_mb_name, $this->admin,$all);
$this->copymailsfromfolder($from_mb_name, $to_mb_name);
/* Quotas uebernehmen */
$quota=$this->getquota($from_mb_name);
$oldquota=trim($quota["qmax"]);
if (strcmp($oldquota,"NOT-SET")!=0) {
$this->setmbquota($to_mb_name, $oldquota);
}
/* Den Rest Umbenennen */
$username=str_replace(".","/",$from_mb_name);
$split_res=explode(".", $to_mb_name);
if (strcmp($split_res[0],"user")==0) {
$owner=$split_res[1];
}
$split_res=explode(".", $from_mb_name);
if (strcmp($split_res[0],"user")==0) {
$oldowner=$split_res[1];
}
$find_out=$this->GetFolders($username);
for ($i=0; $i
if (strcmp($find_out[$i],$username)!=0) {
$split_res=split("$username",$find_out[$i]);
$split_res[1]=str_replace("/",".",$split_res[1]);
$this->renamemb((str_replace("/",".",$find_out[$i])), ("$to_mb_name"."$split_res[1]"));
if ($owner) {
$this->setacl(("$to_mb_name"."$split_res[1]"),$owner,$all);
}
if ($oldowner) {
$this->deleteacl(("$to_mb_name"."$split_res[1]"),$oldowner);
}
};
}
$this->deleteacl($to_mb_name, $this->admin);
$this->imap_logout();
$this->imap_login();
$this->deletemb($from_mb_name);
}
function copymailsfromfolder($from_mb_name, $to_mb_name) {
$com_ret=array();
$find_out=array();
$all="lrswipcda";
$mails=0;
$this->setacl($from_mb_name, $this->admin,$all);
$com_ret=$this->command(". select $from_mb_name");
for ($i=0; $i if (strstr( $com_ret[$i], "EXISTS"))
{
$findout=explode(" ", $com_ret[$i]);
$mails=$findout[1];
}
}
if ( $mails != 0 ) {
$com_ret=$this->command(". copy 1:$mails $to_mb_name");
for ($i=0; $i print "$com_ret[$i]
";
}
}
$this->deleteacl($from_mb_name, $this->admin);
}
/*
#
# ACL Functions
#
*/
function setacl($mb_name, $user, $acl) {
$this->command(". setacl \"$mb_name\" \"$user\" $acl");
}
function deleteacl($mb_name, $user) {
$result=$this->command(". deleteacl \"$mb_name\" \"$user\"");
}
function getacl($mb_name) {
$aclflag=1; $tmp_pos=0;
$output = $this->command(". getacl \"$mb_name\"");
$output = explode(" ", $output[0]);
$i=count($output)-1;
while ($i>3) {
if (strstr($output[$i],'"')) {
$i++;
}
if (strstr($output[$i-1],'"')) {
$aclflag=1;
$lauf=$i-1;
$spacestring=$output[$lauf];
$tmp_pos=$i;
$i=$i-2;
while ($aclflag!=0)
{
$spacestring=$output[$i]." ".$spacestring;
if (strstr($output[$i],'"')) { $aclflag=0; }
$i--;
}
$spacestring=str_replace("\"","",$spacestring);
if ($i>2) {
$ret[$spacestring] = $output[$tmp_pos];
}
}
else
{
$ret[$output[$i-1]] = $output[$i];
$i = $i - 2;
}
}
return $ret;
}
/*
#
# Folder Functions
#
*/
function GetFolders($username){
$username=str_replace("/",".",$username);
$output = $this->command(". list \"$username\" *");
for ($i=0; $i $splitfolder=split("\"",$output[$i]);
$output[$i]=str_replace(".","/",$splitfolder[3]);
}
return $output;
}
function EGetFolders($username){
$lastfolder=split("/",$username);
$position=count($lastfolder)-1;
$last=$lastfolder[$position];
$username=str_replace("/",".",$username);
$output = $this->command(". list \"$username\" *");
for ($i=0; $i $splitfolder=split("\"",$output[$i]);
$currentfolder=split("\.",$splitfolder[3]);
$current=$currentfolder[$position];
// echo "
FOLDER:($) CURRENTFOLDER:($splitfolder[3]) CURRENT:($current) LAST:($last) POSITION:($position)
";
if (strcmp($current,$last)==0){
$newoutput[$i]=str_replace(".","/",$splitfolder[3]);
}
}
return $newoutput;
}
/*
#
# Folder-Output Functions
#
*/
function GenerateFolderList($folder_array, $username)
{
print "
urlencode($username), "&folder=", urlencode($folder_array[$l]), "\">/$folder_array[$l] |
}
function GetUsers($char) {
$users = array();
$this->imap_login();
$output=$this->GetFolders("user.$char");
$this->imap_logout();
$j = 0;
$prev = 0;
for ($i=0; $i $username = split("/", $output[$i],-1);
$this->debug("($username[1]),
$users[$prev])");
if ((isset($username)) && (isset($users))) {
if (strcmp($username[1], $users[$prev])) {
$users[$j] = $username[1];
$j++;
}
}
if ($j != 0) { $prev = $j - 1; }
}
return $users;
}
function debug($message) {
// echo "
$message
";
}
} //KLASSEN ENDE
?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

Part 1: Initial Troubleshooting Steps Checking Apple’s System Status: Before delving into complex solutions, let’s start with the basics. The problem may not lie with your device; Apple's servers may be down. Visit Apple's System Status page to see if the AppStore is working properly. If there's a problem, all you can do is wait for Apple to fix it. Check your internet connection: Make sure you have a stable internet connection as the "Unable to connect to AppStore" issue can sometimes be attributed to a poor connection. Try switching between Wi-Fi and mobile data or resetting network settings (General > Reset > Reset Network Settings > Settings). Update your iOS version:

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

A colleague got stuck due to a bug pointed by this. Vue2’s this pointing problem caused an arrow function to be used, resulting in the inability to get the corresponding props. He didn't know it when I introduced it to him, and then I deliberately looked at the front-end communication group. So far, at least 70% of front-end programmers still don't understand it. Today I will share with you this link. If everything is wrong If you haven’t learned it yet, please give me a big mouth.

Front-end output configuration requires specific code examples. In front-end development, output configuration is a very important configuration. It is used to define the file path, file name and related resource paths generated after the project is packaged. This article will introduce the role of front-end output configuration, common configuration options, and give specific code examples. The role of output configuration: The output configuration item is used to specify the file path and file name generated after the project is packaged. It determines the final output of the project. Packaged in webpack etc.

This article will help you interpret the vue source code and introduce why you can use this to access properties in various options in Vue2. I hope it will be helpful to everyone!

Watch4pro and gt each have different features and applicable scenarios. If you focus on comprehensive functions, high performance and stylish appearance, and are willing to bear a higher price, then Watch 4 Pro may be more suitable. If you don’t have high functional requirements and pay more attention to battery life and reasonable price, then the GT series may be more suitable. The final choice should be decided based on personal needs, budget and preferences. It is recommended to carefully consider your own needs before purchasing and refer to the reviews and comparisons of various products to make a more informed choice.
