public function selectMailbox($mailbox, $readOnly = false)
{
if ($this->state != self::STATE_AUTHENTICATED && $this->state != self::STATE_SELECTED && $this->state != self::STATE_SELECTED_READONLY) {
throw new ezcMailTransportException("Can't call selectMailbox() when not successfully logged in.");
}
$tag = $this->getNextTag();
// if the mailbox selection will be successful, $state will be STATE_SELECTED
// or STATE_SELECTED_READONLY, depending on the $readOnly parameter
if ($readOnly !== true) {
$this->connection->sendData("{$tag} SELECT \"{$mailbox}\"");
$state = self::STATE_SELECTED;
} else {
$this->connection->sendData("{$tag} EXAMINE \"{$mailbox}\"");
$state = self::STATE_SELECTED_READONLY;
}
// if the selecting of the mailbox fails (with "NO" or "BAD" response
// from the server), $state reverts to STATE_AUTHENTICATED
$response = trim($this->getResponse($tag));
if ($this->responseType($response) == self::RESPONSE_OK) {
$this->state = $state;
$this->selectedMailbox = $mailbox;
} else {
$this->state = self::STATE_AUTHENTICATED;
$this->selectedMailbox = null;
throw new ezcMailTransportException("Could not select mailbox '{$mailbox}': {$response}.");
}
}