ZF-8858: Add search() to Zend_Mail_Storage_Imap

Description

There already is a search() function in Zend_Mail_Protocol_Imap, but it is only used for countMessages() at the moment.

It would be nice to have a search() function in Zend_Mail_Storage_Imap, so we can search the current folder for mails.

Should be very easy, for example this does the job:


/**
 * get IDs by full body search on IMAP server
 *
 * @param string $searchterm
 * @return array
 */
public function search($searchterm)
{
    $params = array('BODY ' . $searchterm);
    return $this->_protocol->search($params);
}

It would be cool to not only do a full BODY search but also search in specific parts, for example build a complex filter (see RFC 3501 http://tools.ietf.org/html/rfc3501#page-49 ). Then building a filter similar to Zend_Ldap_Filter would be perfect.

But in the first version just a simple full BODY search would be a beginning.

Comments

My idea was to have a class, let's call it Zend_Mail_Storage_Set, supporting UIDs, ranges, search, sort, ... An instance of a storage class would have a method set(), which returns a set instance (common or specialized for this storage). A couple of features are not IMAP specific and it wouldn't make sense to just add a new method for one storage.

Zend_Mail_Storage_Set would implement an iterator interface and instead of getting just an id or UID you could also fetch the corresponding message. I have an old mail with a couple of use cases.

Sounds good as long as it is fast. For example if you want to retrieve messages with UID 1-5, it should only call one IMAP command and not 5. The same for moving messages, deleting messages and so on. See also my other issues ZF-9138 ZF-8513 ZF-8488