protected function _sendCmdChunk($pipeline, $chunk)
{
if (empty($chunk)) {
return;
}
$cmd_count = count($chunk);
$exception = null;
foreach ($chunk as $val) {
$val->pipeline = $pipeline;
try {
if ($this->_processCmd($pipeline, $val, $val)) {
$this->_connection->write('', true);
} else {
$cmd_count = 0;
}
} catch (Horde_Imap_Client_Exception $e) {
switch ($e->getCode()) {
case Horde_Imap_Client_Exception::SERVER_WRITEERROR:
$this->_temp['logout'] = true;
$this->logout();
break;
}
throw $e;
}
}
while ($cmd_count) {
try {
if ($this->_getLine($pipeline) instanceof Horde_Imap_Client_Interaction_Server_Tagged) {
--$cmd_count;
}
} catch (Horde_Imap_Client_Exception $e) {
switch ($e->getCode()) {
case $e::DISCONNECT:
/* Guaranteed to have no more data incoming, so we can
* immediately logout. */
$this->_temp['logout'] = true;
$this->logout();
throw $e;
}
/* For all other issues, catch and store exception; don't
* throw until all input is read since we need to clear
* incoming queue. (For now, only store first exception.) */
if (is_null($exception)) {
$exception = $e;
}
if ($e instanceof Horde_Imap_Client_Exception_ServerResponse && $e->command) {
--$cmd_count;
}
}
}
if (!is_null($exception)) {
throw $exception;
}
}