如何使用Zend_Mail_Protocol_Imap或Zend_Mail_Storage_Imap批量检索电子邮件


How to do batch retreival of email using Zend_Mail_Protocol_Imap or Zend_Mail_Storage_Imap

我正在使用Zend_Mail_Storage_Imap访问电子邮件,但使用以下代码

$storage = new Zend_Mail_Storage_Imap($imap);
$allIds = $storage->getUniqueId(); // i get all key value pair of meesageid and uniqueid
foreach ($allIds as $k => $v) 
{
    echo '<li>' . htmlentities($storage->getMessage($v)->subject) . "</li>'n";
}

我的问题是它循环并一次接收一封电子邮件,这很慢,就像每秒收到两封电子邮件一样,这非常慢。我正在寻找这些邮件的批量检索方法,但找不到任何.以前有人做过吗

终于明白了。

其中$imap是Zend_Mail_Protocol_Imap的实例化和连接版本:

  1. $imap->select(); // or $imap->select('FOLDER_NAME');

  2. $imap->requestAndResponse('SEARCH UNSEEN', $imap->escapeString('*'))//all unread email ids

  3. $imap->requestAndResponse('SEARCH UNSEEN FROM "someEmail@gmail.com"', $imap->escapeString('*'))//all unread email id's from someEmail@gmail.com

  4. $imap->requestAndResponse('SEARCH UNSEEN SUBJECT "test" FROM "someEmail@gmail.com"', $imap->escapeString('*'))//all unread email id's from someEmail@gmail.com with the subject of test

*您必须先执行上面的#1,否则您将获得类似于以下内容:"现在不允许标记#错误搜索。

以上所有内容都将返回一个类似于以下数组的数组:

//C: TAG3 SEARCH UNSEEN
//S: * SEARCH 321 323 362 371 377 384 386 387 388 389 416 417 418 
//S: TAG3 OK SEARCH completed (Success) 
//The above lines are in the format of RFC 1730 to show what was actually sent/received.
array (size=1)
  0 => 
    array (size=14)
      0 => string 'SEARCH' (length=6)
      1 => string '321' (length=3)
      2 => string '323' (length=3)
      3 => string '362' (length=3)
      4 => string '371' (length=3)
      5 => string '377' (length=3)
      6 => string '384' (length=3)
      7 => string '386' (length=3)
      8 => string '387' (length=3)
      9 => string '388' (length=3)
      10 => string '389' (length=3)
      11 => string '416' (length=3)
      12 => string '417' (length=3)
      13 => string '418' (length=3)