我对Maildir和PHP的一个小问题感到很疯狂。
我需要查看APACHE_RUN_USER
的 Maildir 并解析delivery-status
条消息。
阅读后删除消息的问题;我注意到Zend_Mail_Storage_Maildir->removeMessage()
仍然是一个存根。
try {
$mailbox = new Zend_Mail_Storage_Maildir( array('dirname' => '/home/' . $_ENV['APACHE_RUN_USER'] . '/Maildir/') );
foreach ($mailbox as $id => $message) {
// seen flag
if ($message->hasFlag(Zend_Mail_Storage::FLAG_SEEN)) { continue; }
//get the unique id
$uniqueid = $mailbox->getUniqueId($id);
//obtain message headers
$headers = $message->getHeaders();
//check if the original message was sent from this app and is a delivery-status
$result = strpos($message, $id_header);
if($result === false) { echo '1 mail skipped: ' . $uniqueid . '. <br />'; continue; }
$result = strpos($headers['content-type'], 'delivery-status');
//if no skip to the next mail
if($result === false) { echo '1 mail skipped: ' . $uniqueid . '. <br />'; continue; }
// if everything it's ok process it.
// clear results
$data = array();
// foreach line of message
foreach( preg_split('/(\r?\n)/', $message) as $line ){
//clear results
$matches = array();
//perform matches on textlines
if( preg_match('/^(.+)\:\s{0,1}(.+)$/', $line, $matches) ) {
//grab intrested headers
foreach( array('Action', 'Status', 'Remote-MTA', 'Diagnostic-Code', $id_header) as $header) {
if($matches[1] == $header) $data[$header] = $matches[2];
}
}
}
// *** I NEED TO DROP THE MESSAGE HERE ***
// not working code ***
$currentmessageid = $mailbox->getNumberByUniqueId($uniqueid);
$mailbox->removeMessage($currentmessageid);
// *** I NEED TO DROP THE MESSAGE HERE ***
// print out results
echo '<pre class="email">';
print_r( $data );
echo '</pre>';
}
} catch (Exception $e) {
echo $e;
}
如何手动将其取出?一些解决方法?
感谢。
答案 0 :(得分:1)
抱歉,尚未实施!
查看问题跟踪器http://framework.zend.com/issues/browse/ZF-9574
它的公开问题直到今天,但有些评论可能会有所帮助:
要从中删除电子邮件 maildir或mbox存储必须使用: Zend_Mail_Storage_Writable_Maildir或 Zend_Mail_Storage_Writable_Mbox
这有历史原因 他们应该得到解决 标准化。就目前而言 必须使用类或例外 将被抛出一条消息 有点误导。
请参阅: http://framework.zend.com/issues/browse/ZF-9574 了解更多详情。
答案 1 :(得分:1)
按照 tawfekov 的回答,我解决了以下问题:
打开邮箱:
$mailbox = new Zend_Mail_Storage_Writable_Maildir( array('dirname' => '/home/' . $_ENV['APACHE_RUN_USER'] . '/Maildir/') );
处理邮件代码:
foreach ($mailbox as $id => $message) {
$uniqueid = $mailbox->getUniqueId($id);
/* ... mail processing code ... */
// mark as read
$currentmessageid = $mailbox->getNumberByUniqueId($uniqueid);
$mailbox->setFlags($currentmessageid, array(Zend_Mail_Storage::FLAG_SEEN));
// or uncomment to delete it
//$mailbox->removeMessage($currentmessageid);
}