0

Maildir 和 PHP 的一个小问题让我发疯了。我需要检查APACHE_RUN_USER's 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;
}

我怎样才能用手去除它?一些解决方法?

谢谢。

4

2 回答 2

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 。

于 2010-12-10T11:57:54.123 回答
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);
    }
于 2010-12-10T13:29:24.753 回答