How to perform bulk email recovery using Zend_Mail_Protocol_Imap or Zend_Mail_Storage_Imap

I am using Zend_Mail_Storage_Imap to access my email, but using the following code

$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"; } 

My problem is that it loops and receives one email at a time, which is slow, like receiving two emails per second, which is very slow. I am looking for a method for batch recovery of these letters, but could not find. Has anyone done this before

+7
source share
1 answer

Finally got it.

Where $ imap is the instantiated and connected version of Zend_Mail_Protocol_Imap:

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

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

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

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

* First you must do # 1, otherwise you will get something similar: "TAG # BAD SEARCH is not allowed now."

All of the above will return an array similar to the following array:

 //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) 
+2
source

All Articles