How to search inbox using zend mail
The following is a function from zend_mail_protocol_imap. i read that to search emails, I would want to override it using zend_mail_storage_imap (which is what I'm using now to grab email from gmail). I copy and pasted the following function into zend_mail_storage_imap, but I'm having issues with the params. I can't find documentation on what to use for the array $params. I initially thought it was the search term before reading it more thoroughly. I'm out of ideas. Here's the function...
/**
* do a search request
*
* This method is currently marked as internal as the API might change and is not
* safe if you don't take precautions.
*
* @internal
* @return array message ids
*/
public function search(array $params)
{
$response = $this->requestAndResponse('SEARCH', $params);
if (!$response) {
return $response;
}
foreach ($response as $ids) {
if ($ids[0] == 'SE开发者_运维技巧ARCH') {
array_shift($ids);
return $ids;
}
}
return array();
}
Initially I thought this would do the trick...
$storage = new Zend_Mail_Storage_Imap($imap);
$searchresults = $storage->search('search term');
Here's the error message:
Catchable fatal error: Argument 1 passed to Zend_Mail_Storage_Imap::search() must be an array, string given, called in...
But nope, I need to send the info in an array. Any ideas?
How about
$searchresults = $storage->search(array('search term'));
this is how i did it
$searchTerm = 'TEXT ' . $searchTerm ;
$searchresults = $storage->search(array($searchTerm));
Search parameter for zend is same as of imap_search . Use http://php.net/manual/en/function.imap-search.php for further reference .
there is (still) no search function in storage\imap, that function is actually in the protocol class.
to have a search in storage\imap add this function:
public function search($params = null) {
return $this->protocol->search($params);
}
now you should be able to call like this
$storage->search(array('SUBJECT "test","UNSEEN",'FROM "santa@northpole.org"'));
and the result should be a list of ids/uids of the messages, just like imap_search. imho this function or a getter for protocol should be in the storage class, but it isnt.
精彩评论