一个简单的(也可以说是不完全的)IMAP类和应用_PHP
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:
}
}
}
};
?>

熱AI工具

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

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

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

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

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

在C語言中,if語句通常用於基於單一條件執行特定程式碼區塊。但是,透過使用邏輯運算子(如 &&、|| 和 !),可以組合多個條件來進行判斷。包括使用邏輯與(&&)判斷多個條件、使用邏輯或(||)判斷至少一個條件、使用邏輯非(!)判斷單一條件的否定,以及嵌套if語句和使用括號明確優先權。

從主畫面中刪除了重要內容並試圖將其取回?您可以透過多種方式將應用程式圖示放回螢幕。我們已經討論了您可以遵循的所有方法,並將應用程式圖示放回主畫面如何在iPhone中撤消從主畫面中刪除正如我們之前提到的,有幾種方法可以在iPhone上恢復此變更。方法1–替換應用程式庫中的應用程式圖示您可以直接從應用程式庫將應用程式圖示放置在主畫面上。步驟1–橫向滑動以尋找應用程式庫中的所有應用程式。步驟2–找到您先前刪除的應用程式圖示。步驟3–只需將應用程式圖示從主庫拖曳到主畫面上的正確位置即可。這是將應用程式圖

PHP中箭頭符號的作用及實踐應用在PHP中,箭頭符號(->)通常用於存取物件的屬性和方法。物件是PHP中物件導向程式設計(OOP)的基本概念之一,在實際開發中,箭頭符號在操作物件時發揮重要作用。本文將介紹箭頭符號的作用以及實踐應用,並提供具體的程式碼範例來幫助讀者更好地理解。一、箭頭符號的作用存取物件的屬性箭頭符號可以用來存取物件的屬性。當我們實例化一個對

Linuxtee命令是一個非常有用的命令列工具,它可以在不影響已有輸出的情況下,將輸出寫入檔案或將輸出送到另一個命令。在本文中,我們將深入探索Linuxtee命令的各種應用場景,從入門到精通。 1.基本用法首先,我們來看看tee指令的基本用法。 tee指令的語法如下:tee[OPTION]...[FILE]...該指令會從標準輸入讀取數據,並將數據

Go語言是一種由Google開發的開源程式語言,於2007年首次發布。它被設計成一種簡單易學、高效、並發性強的語言,受到越來越多開發者的青睞。本文將探討Go語言的優勢,並介紹一些適合Go語言的應用場景,同時給出具體的程式碼範例。優勢並發性強:Go語言內建支援輕量級執行緒-goroutine,能夠輕鬆實現並發程式設計。透過使用go關鍵字就可以啟動goroutin

Linux在雲端運算領域的廣泛應用隨著雲端運算技術的不斷發展和普及,Linux作為一種開源作業系統在雲端運算領域中發揮重要作用。由於其穩定性、安全性和靈活性,Linux系統被廣泛應用於各種雲端運算平台和服務中,為雲端運算技術的發展提供了堅實的基礎。本文將介紹Linux在雲端運算領域的廣泛應用,並給出具體的程式碼範例。一、Linux在雲端運算平台中的應用虛擬化技術虛擬化技術

MySQL時間戳記是十分重要的資料類型,它可以儲存日期、時間或日期加時間。在實際的開發過程中,合理地使用時間戳記可以提高資料庫操作的效率,並且方便進行時間相關的查詢和計算。本文將從MySQL時間戳記的功能、功能和應用場景等面向展開探討,並結合具體的程式碼範例來講解。一、MySQL時間戳記的功能與特性MySQL中有兩種類型的時間戳,一種是TIMESTAMP

目前最受歡迎的Go框架有:Gin:輕量級、高效能的Web框架,簡潔易用。 Echo:快速、高度可自訂的網路框架,提供高效能路由和中介軟體。 GorillaMux:快速、靈活的多工器,提供進階路由設定選項。 Fiber:效能最佳化的高效能Web框架,處理高並發請求。 Martini:物件導向設計的模組化網路框架,提供豐富的功能集。
