Hul*_*ner 0 php imap zend-framework zend-mail
我正在尝试编写一个脚本,在没有自定义标志的情况下下载某个文件夹中的所有邮件,现在让我们调用标志$ aNiceFlag; 在我收到邮件后,我想用$ aNiceFlag标记它.然而,在解决标志问题之前,我有一个问题是立即从邮件中提取我需要的内容.
这是我需要的信息:
我可以通过使用轻松获得主题$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());
}
Run Code Online (Sandbox Code Playgroud)
我正在使用谷歌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";
}
}
Run Code Online (Sandbox Code Playgroud)