protected function _fetch(Horde_Imap_Client_Fetch_Results $results, $queries)
{
$pipeline = $this->_pipeline();
$pipeline->data['fetch_lookup'] = array();
$pipeline->data['fetch_followup'] = array();
foreach ($queries as $options) {
$this->_fetchCmd($pipeline, $options);
$sequence = $options['ids']->sequence;
}
try {
$resp = $this->_sendCmd($pipeline);
/* Check for EXPUNGEISSUED (RFC 2180 [4.1]/RFC 5530 [3]). */
if (!empty($resp->data['expungeissued'])) {
$this->noop();
}
foreach ($resp->fetch as $k => $v) {
$results->get($sequence ? $k : $v->getUid())->merge($v);
}
} catch (Horde_Imap_Client_Exception_ServerResponse $e) {
if ($e->status === Horde_Imap_Client_Interaction_Server::NO) {
if ($e->getCode() === $e::UNKNOWNCTE) {
/* UNKNOWN-CTE error. Redo the query without the BINARY
* elements. */
$bq = $pipeline->data['binaryquery'];
foreach ($queries as $val) {
foreach ($bq as $key2 => $val2) {
unset($val2['decode']);
$val['_query']->bodyPart($key2, $val2);
$val['_query']->remove(Horde_Imap_Client::FETCH_BODYPARTSIZE, $key2);
}
$pipeline->data['fetch_followup'][] = $val;
}
} elseif ($sequence) {
/* A NO response, when coupled with a sequence FETCH, most
* likely means that messages were expunged. (RFC 2180
* [4.1]) */
$this->noop();
}
}
} catch (Exception $e) {
// For any other error, ignore the Exception - fetch() is nice in
// that the return value explicitly handles missing data for any
// given message.
}
if (!empty($pipeline->data['fetch_followup'])) {
$this->_fetch($results, $pipeline->data['fetch_followup']);
}
}