IMAP
//by Alpha.Z//05/21/2000
class myimap
{
var $username="";
var $userpwd="";
var $hostname="";
var $port=0;
var $connection=0; //是否连接
var $state="DISCONNECTED"; //连接状态
var $greeting="";
var $must_update=0;
var $inStream=0;
Function open()
{
if ($this->port==110)
$this->inStream=imap_open("{$this->hostname/pop3:110}inbox",$this->username,$this->userpwd);
else
$this->inStream=imap_open("{$this->hostname/imap:143}inbox",$this->username,$this->userpwd);
if ($this->inStream)
{
echo "用户:$this->username 的信箱连接成功。
";
return $inStream;
}
else
{
echo "用户:$this->username 的信箱连接失败。
";
return 0;
}
}
Function close()
{
if(imap_close($this->inStream))
{
echo "
已经与服务器 $this->hostname 断开连接。";
return 1;
}
else
{
echo "
与服务器 $this->hostname 断开连接失败。";
return 0;
}
}
Function CheckMailbox()
{
$mboxinfo=@imap_mailboxmsginfo($this->inStream);
//$mboxinfo=imap_check($this->inStream);
if ($mboxinfo)
if ($mboxinfo->Nmsgs>0)
{
echo "您的收件箱里共有邮件数:".$mboxinfo->Nmsgs."
";
echo "未读邮件数:".$mboxinfo->Unread."
";
//echo "新邮件数:".$mboxinfo->Rescent."
";
echo "总共占用空间:".$mboxinfo->Size."字节
";
echo "最新邮件日期:".$mboxinfo->Date."
";
}
else
{
echo "您的信箱里没有邮件。
";
}
else
{
echo '错误:无法获取收件箱的信息。';
}
echo '
'.$frm.' | '.$sub.' | '.$date.' | '.$msg_size.' | ';
}
Function decode_mime_string ($string)
{
$pos = strpos($string, '=?');
if (!is_int($pos))
{
return $string;
}
$preceding = substr($string, 0, $pos); // save any preceding text
$search = substr($string, $pos+2, 75); // the mime header spec says this is the longest a single encoded word can be
$d1 = strpos($search, '?');
if (!is_int($d1))
{
return $string;
}
$charset = substr($string, $pos+2, $d1);
$search = substr($search, $d1+1);
$d2 = strpos($search, '?');
if (!is_int($d2))
{
return $string;
}
$encoding = substr($search, 0, $d2);
$search = substr($search, $d2+1);
$end = strpos($search, '?=');
if (!is_int($end))
{
return $string;
}
$encoded_text = substr($search, 0, $end);
$rest = substr($string, (strlen($preceding . $charset . $encoding . $encoded_text)+6));
switch ($encoding)
{
case 'Q':
case 'q':
$encoded_text = str_replace('_', '%20', $encoded_text);
$encoded_text = str_replace('=', '%', $encoded_text);
$decoded = urldecode($encoded_text);
break;
case 'B':
case 'b':
$decoded = urldecode(base64_decode($encoded_text));
break;
default:
$decoded = '=?' . $charset . '?' . $encoding . '?' . $encoded_text . '?=';
break;
}
return $preceding . $decoded . decode_mime_string($rest);
}
Function display_toaddress ($user, $server, $from)
{
return is_int(strpos($from, $this->get_barefrom($user, $server)));
}
Function get_barefrom($user, $server)
{
$barefrom = "$user@$real_server";
return $barefrom;
}
Function get_structure($msg_num)
{
$structure=imap_fetchstructure($this->inStream,$msg_num);
//echo gettype($structure);
return $structure;
}
Function proc_structure($msg_part, $part_no, $msg_num)
{
if ($msg_part->ifdisposition)
{
// See if it has a disposition
// The only thing I know of that this
// would be used for would be an attachment
// Lets check anyway
if ($msg_part->disposition == "ATTACHMENT")
{
// If it is an attachment, then we let people download it
// First see if they sent a filename
$att_name = "unknown";
for ($lcv = 0; $lcv parameters); $lcv++)
{
$param = $msg_part->parameters[$lcv];
if ($param->attribute == "NAME")
{
$att_name = $param->value;
break;
}
}
// You could give a link to download the attachment here....
echo ''.$att_name.'
';
$fp=fopen(".\\$att_name","w+");
fputs($fp,imap_base64(imap_fetchbody($this->inStream,$msg_num,$part_no)));
fclose($fp);
}
else
{
// I guess it is used for something besides attachments????
}
}
else
{
// Not an attachment, lets see what this part is...
switch ($msg_part->type)
{
case TYPETEXT:
$mime_type = "text";
break;
case TYPEMULTIPART:
$mime_type = "multipart";
// Hey, why not use this function to deal with all the parts
// of this multipart part :)
for ($i = 0; $i parts); $i++)
{
if ($part_no != "")
{
$part_no = $part_no.".";
}
for ($i = 0; $i parts); $i++)
{
$this->proc_structure($msg_part->parts[$i], $part_no.($i + 1), $msg_num);
}
}
break;
case TYPEMESSAGE:
$mime_type = "message";
break;
case TYPEAPPLICATION:
$mime_type = "application";
break;
case TYPEAUDIO:
$mime_type = "audio";
break;
case TYPEIMAGE:
$mime_type = "image";
break;
case TYPEVIDEO:
$mime_type = "video";
break;
case TYPEMODEL:
$mime_type = "model";
break;
default:
$mime_type = "unknown";
// hmmm....
}
$full_mime_type = $mime_type."/".$msg_part->subtype;
//echo $full_mime_type.'
';
// Decide what you what to do with this part
// If you want to show it, figure out the encoding and echo away
switch ($msg_part->encoding)
{
case ENCBASE64:
// use imap_base64 to decode
$fp=fopen(".\\$att_name","w+");
fputs($fp,imap_base64(imap_fetchbody($this->inStream,$msg_num,$part_no)));
fclose($fp);
break;
case ENCQUOTEDPRINTABLE:
// use imap_qprint to decode
//echo ereg_replace("\n","
",imap_qprint(imap_fetchbody($this->inStream,$msg_num,$part_no)));
echo '
'.imap_qprint(imap_fetchbody($this->inStream,$msg_num,$part_no)).'';
break;
case ENCOTHER:
// not sure if this needs decoding at all
break;
default:
}
}
}
};
?>

PHP和Python各有優勢,選擇應基於項目需求。 1.PHP適合web開發,語法簡單,執行效率高。 2.Python適用於數據科學和機器學習,語法簡潔,庫豐富。

PHP不是在消亡,而是在不斷適應和進化。 1)PHP從1994年起經歷多次版本迭代,適應新技術趨勢。 2)目前廣泛應用於電子商務、內容管理系統等領域。 3)PHP8引入JIT編譯器等功能,提升性能和現代化。 4)使用OPcache和遵循PSR-12標準可優化性能和代碼質量。

PHP的未來將通過適應新技術趨勢和引入創新特性來實現:1)適應云計算、容器化和微服務架構,支持Docker和Kubernetes;2)引入JIT編譯器和枚舉類型,提升性能和數據處理效率;3)持續優化性能和推廣最佳實踐。

在PHP中,trait適用於需要方法復用但不適合使用繼承的情況。 1)trait允許在類中復用方法,避免多重繼承複雜性。 2)使用trait時需注意方法衝突,可通過insteadof和as關鍵字解決。 3)應避免過度使用trait,保持其單一職責,以優化性能和提高代碼可維護性。

依賴注入容器(DIC)是一種管理和提供對象依賴關係的工具,用於PHP項目中。 DIC的主要好處包括:1.解耦,使組件獨立,代碼易維護和測試;2.靈活性,易替換或修改依賴關係;3.可測試性,方便注入mock對象進行單元測試。

SplFixedArray在PHP中是一種固定大小的數組,適用於需要高性能和低內存使用量的場景。 1)它在創建時需指定大小,避免動態調整帶來的開銷。 2)基於C語言數組,直接操作內存,訪問速度快。 3)適合大規模數據處理和內存敏感環境,但需謹慎使用,因其大小固定。

PHP通過$\_FILES變量處理文件上傳,確保安全性的方法包括:1.檢查上傳錯誤,2.驗證文件類型和大小,3.防止文件覆蓋,4.移動文件到永久存儲位置。

JavaScript中處理空值可以使用NullCoalescingOperator(??)和NullCoalescingAssignmentOperator(??=)。 1.??返回第一個非null或非undefined的操作數。 2.??=將變量賦值為右操作數的值,但前提是該變量為null或undefined。這些操作符簡化了代碼邏輯,提高了可讀性和性能。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

記事本++7.3.1
好用且免費的程式碼編輯器

Dreamweaver CS6
視覺化網頁開發工具

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具