[英]How do I extract the content from zend mail imap?
我正在嘗試編寫一個腳本,該腳本可以在沒有自定義標志的情況下將所有郵件下載到某個文件夾中,現在我們將其稱為標志$ aNiceFlag; 提取郵件后,我想用$ aNiceFlag標記它。 但是,在解決標志問題之前,我現在有一個問題要從郵件中提取我需要的內容。
這是我需要的信息:
我可以通過使用$mailObject->subject
輕松獲得$mailObject->subject
。 我正在查看Zend文檔,但對我來說有點混亂。
現在是我的代碼,我不應該回顯內容,但這只是在測試時:
$this->gOauth = new GoogleOauth();
$this->gOauth->connect_imap();
$storage = new Zend_Mail_Storage_Imap(&$this->gOauth->gImap);
$storage->selectFolder($this->label);
foreach($storage as $mail){
echo $mail->subject();
echo strip_tags($mail->getContent());
}
我正在使用google oAuth訪問郵件。 $this->label
是我想要的文件夾。 現在這很簡單,但是在變得復雜之前,我想弄清楚基礎知識,例如將上面列出的所有數據提取到數組中單獨鍵中的合適方法。
您可以使用與主題相同的技術來輕松獲取發送者,接收者和日期的標頭,但是實際的純文本主體比較棘手,下面的示例代碼可以完成您想要的操作
$this->gOauth = new GoogleOauth();
$this->gOauth->connect_imap();
$storage = new Zend_Mail_Storage_Imap(&$this->gOauth->gImap);
$storage->selectFolder($this->label);
// output first text/plain part
$foundPart = null;
foreach($storage as $mail){
echo '----------------------<br />'."\n";
echo "From: ".utf8_encode($mail->from)."<br />\n";
echo "To: ".utf8_encode(htmlentities($mail->to))."<br />\n";
echo "Time: ".utf8_encode(htmlentities(date("Y-m-d H:s" ,strtotime($mail->date))))."<br />\n";
echo "Subject: ".utf8_encode($mail->subject)."<br />\n";
foreach (new RecursiveIteratorIterator($mail) as $part) {
try {
if (strtok($part->contentType, ';') == 'text/plain') {
$foundPart = $part;
break;
}
} catch (Zend_Mail_Exception $e) {
// ignore
}
}
if (!$foundPart) {
echo "no plain text part found <br /><br /><br /><br />\n\n\n";
} else {
echo "plain text part: <br />" .
str_replace("\n", "\n<br />", trim(utf8_encode(quoted_printable_decode(strip_tags($foundPart)))))
." <br /><br /><br /><br />\n\n\n";
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.