public function searchMailbox($criteria = null)
{
$uid = $this->options->uidReferencing ? self::UID : self::NO_UID;
if ($this->state != self::STATE_SELECTED && $this->state != self::STATE_SELECTED_READONLY) {
throw new ezcMailTransportException("Can't call searchMailbox() on the IMAP transport when a mailbox is not selected.");
}
$criteria = trim($criteria);
if (empty($criteria)) {
$criteria = 'ALL';
}
$matchingMessages = array();
$tag = $this->getNextTag();
$this->connection->sendData("{$tag} {$uid}SEARCH {$criteria}");
$response = $this->getResponse('* SEARCH');
if (strpos($response, '* SEARCH') !== false) {
$ids = substr(trim($response), 9);
if (trim($ids) !== "") {
$matchingMessages = explode(' ', $ids);
}
}
$response = trim($this->getResponse($tag, $response));
if ($this->responseType($response) != self::RESPONSE_OK) {
throw new ezcMailTransportException("The IMAP server could not search the messages by the specified criteria: {$response}.");
}
return new ezcMailImapSet($this->connection, array_values($matchingMessages), false, array('uidReferencing' => $this->options->uidReferencing));
}