2010-12-10 148 views
0

我在Maildir和PHP的一个小问题上疯了。 我需要检查APACHE_RUN_USERMaildir并解析delivery-status消息。如何从PHP中删除Maildir中的电子邮件?

阅读后删除信息的问题;我注意到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; 
} 

如何手动将其取出?一些解决方法?

感谢。

回答

1

tawfekov答案的顺序我解决如下:

开幕邮箱:

$mailbox = new Zend_Mail_Storage_Writable_Maildir(array('dirname' => '/home/' . $_ENV['APACHE_RUN_USER'] . '/Maildir/')); 

处理邮件代码:

1

对不起,它还没有实现!

退房问题跟踪http://framework.zend.com/issues/browse/ZF-9574

其开放式的问题,直到今天,但有些评论可能会有所帮助:

为了从 邮件目录或MBOX存储删除电子邮件必须使用: Zend_Mail_Storage_Writable_Maildir或 Zend_Mail_Storage_Writable_Mbox

这个 有一些历史原因,他们应该解决一个d 标准化。目前,必须使用上述 类别,否则将引发 的异常,并显示消息 有点误导。

请参阅: http://framework.zend.com/issues/browse/ZF-9574 了解更多详情。

+0

谢谢,我解决了Zend_Mail_Storage_Writable_Maildir类取代。 – 2010-12-10 13:24:47

相关问题