public function __construct(Horde_Imap_Client_Tokenize $token)
{
$this->token = $token;
/* Check for response status. */
$status = $token->current();
$valid = array('BAD', 'BYE', 'NO', 'OK', 'PREAUTH');
if (in_array($status, $valid)) {
$this->status = constant(__CLASS__ . '::' . $status);
$resp_text = $token->next();
/* Check for response code. Only occurs if there is a response
* status. */
if (is_string($resp_text) && $resp_text[0] === '[') {
$resp = new stdClass();
$resp->data = array();
if ($resp_text[strlen($resp_text) - 1] === ']') {
$resp->code = substr($resp_text, 1, -1);
} else {
$resp->code = substr($resp_text, 1);
while (($elt = $token->next()) !== false) {
if (is_string($elt) && $elt[strlen($elt) - 1] === ']') {
$resp->data[] = substr($elt, 0, -1);
break;
}
$resp->data[] = is_string($elt) ? $elt : $token->flushIterator();
}
}
$token->next();
$this->responseCode = $resp;
}
}
}