public function listUniqueIdentifiers($msgNum = null)
{
if ($this->state != self::STATE_SELECTED && $this->state != self::STATE_SELECTED_READONLY) {
throw new ezcMailTransportException("Can't call listUniqueIdentifiers() on the IMAP transport when a mailbox is not selected.");
}
$result = array();
if ($msgNum !== null) {
$tag = $this->getNextTag();
$this->connection->sendData("{$tag} UID SEARCH {$msgNum}");
$response = $this->getResponse('* SEARCH');
if (strpos($response, '* SEARCH') !== false) {
$result[(int) $msgNum] = trim(substr($response, 9));
}
$response = trim($this->getResponse($tag, $response));
} else {
$uids = array();
$messages = array_keys($this->listMessages());
$tag = $this->getNextTag();
$this->connection->sendData("{$tag} UID SEARCH UNDELETED");
$response = $this->getResponse('* SEARCH');
if (strpos($response, '* SEARCH') !== false) {
$response = trim(substr($response, 9));
if ($response !== "") {
$uids = explode(' ', $response);
}
for ($i = 0; $i < count($messages); $i++) {
$result[trim($messages[$i])] = $uids[$i];
}
}
$response = trim($this->getResponse($tag));
}
if ($this->responseType($response) != self::RESPONSE_OK) {
throw new ezcMailTransportException("The IMAP server could not fetch the unique identifiers: {$response}.");
}
return $result;
}