protected function _processCmd($pipeline, $cmd, $data)
{
if ($this->_debug->debug && $data instanceof Horde_Imap_Client_Interaction_Command) {
$data->startTimer();
}
foreach ($data as $key => $val) {
if ($val instanceof Horde_Imap_Client_Interaction_Command_Continuation) {
$this->_connection->write('', true);
/* Check for optional continuation responses when the command
* has already finished. */
if (!($cmd_continuation = $this->_processCmdContinuation($pipeline, $val->optional))) {
return false;
}
$this->_processCmd($pipeline, $cmd, $val->getCommands($cmd_continuation));
continue;
}
if (!is_null($debug_msg = array_shift($cmd->debug))) {
$this->_debug->client(($cmd == $data ? $cmd->tag . ' ' : '') . $debug_msg);
$this->_connection->client_debug = false;
}
if ($key) {
$this->_connection->write(' ');
}
if ($val instanceof Horde_Imap_Client_Data_Format_List) {
$this->_connection->write('(');
$this->_processCmd($pipeline, $cmd, $val);
$this->_connection->write(')');
} elseif ($val instanceof Horde_Imap_Client_Data_Format_String && $val->literal()) {
$c = $this->_capability();
/* RFC 6855: If UTF8 extension is available, quote short
* strings instead of sending as literal. */
if ($c->isEnabled('UTF8=ACCEPT') && $val->length() < 100) {
$val->forceQuoted();
$this->_connection->write($val->escape());
} else {
/* RFC 3516/4466: Send literal8 if we have binary data. */
if ($cmd->literal8 && $val->binary() && ($c->query('BINARY') || $c->isEnabled('UTF8=ACCEPT'))) {
$binary = true;
$this->_connection->write('~');
} else {
$binary = false;
}
$literal_len = $val->length();
$this->_connection->write('{' . $literal_len);
/* RFC 2088 - If LITERAL+ is available, saves a roundtrip
* from the server. */
if ($cmd->literalplus && $c->query('LITERAL+')) {
$this->_connection->write('+}', true);
} else {
$this->_connection->write('}', true);
$this->_processCmdContinuation($pipeline);
}
if ($debug_msg) {
$this->_connection->client_debug = false;
}
$this->_connection->writeLiteral($val->getStream(), $literal_len, $binary);
}
} else {
$this->_connection->write($val->escape());
}
}
return true;
}