public function fetchFlags($messages)
{
$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 fetchFlags() on the IMAP transport when a mailbox is not selected.");
}
$flags = array();
$ids = implode($messages, ',');
$tag = $this->getNextTag();
$this->connection->sendData("{$tag} {$uid}FETCH {$ids} (FLAGS)");
$response = trim($this->connection->getLine());
while (strpos($response, $tag) === false) {
if (strpos($response, ' FETCH (') !== false) {
if ($this->options->uidReferencing) {
if (preg_match('/\\*\\s.*\\sFETCH\\s\\(FLAGS \\((.*)\\)\\sUID\\s(.*)\\)/U', $response, $matches)) {
$parts = explode(' ', $matches[1]);
$flags[intval($matches[2])] = $parts;
} else {
preg_match('/\\*\\s.*\\sFETCH\\s\\(UID\\s(.*)\\sFLAGS \\((.*)\\)\\)/U', $response, $matches);
$parts = explode(' ', $matches[2]);
$flags[intval($matches[1])] = $parts;
}
} else {
preg_match('/\\*\\s(.*)\\sFETCH\\s\\(FLAGS \\((.*)\\)/U', $response, $matches);
$parts = explode(' ', $matches[2]);
$flags[intval($matches[1])] = $parts;
}
}
$response = trim($this->connection->getLine());
}
if ($this->responseType($response) != self::RESPONSE_OK) {
throw new ezcMailTransportException("The IMAP server could not fetch flags for the messages '{$messages}': {$response}.");
}
return $flags;
}