Skip to content

Commit

Permalink
Better debugging/cleanup debug output
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Feb 24, 2014
1 parent 67911c0 commit 3d716f1
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 17 deletions.
35 changes: 29 additions & 6 deletions framework/Imap_Client/lib/Horde/Imap/Client/Base.php
Expand Up @@ -401,7 +401,10 @@ public function _setInit($key = null, $val = null)
if ($ci = $this->getParam('capability_ignore')) {
if ($this->_debug->debug &&
($ignored = array_intersect_key($val, array_flip($ci)))) {
$this->_debug->info(sprintf("CONFIG: IGNORING these IMAP capabilities: %s", implode(', ', array_keys($ignored))));
$this->_debug->info(sprintf(
'CONFIG: IGNORING these IMAP capabilities: %s',
implode(', ', array_keys($ignored))
));
}

$val = array_diff_key($val, array_flip($ci));
Expand Down Expand Up @@ -3802,7 +3805,10 @@ protected function _updateCache(Horde_Imap_Client_Fetch_Results $data)

$c = $this->getParam('cache');
if (in_array(strval($this->_selected), $c['fetch_ignore'])) {
$this->_debug->info(sprintf("CACHE: Ignoring FETCH data (mailbox: %s)", $this->_selected));
$this->_debug->info(sprintf(
'CACHE: Ignoring FETCH data [%s]',
$this->_selected
));
return;
}

Expand Down Expand Up @@ -3908,7 +3914,11 @@ protected function _moveCache(Horde_Imap_Client_Mailbox $to, $map,

$c = $this->getParam('cache');
if (in_array(strval($to), $c['fetch_ignore'])) {
$this->_debug->info(sprintf("CACHE: Ignoring moving FETCH data (%s => %s)", $this->_selected, $to));
$this->_debug->info(sprintf(
'CACHE: Ignoring moving FETCH data (%s => %s)',
$this->_selected,
$to
));
return;
}

Expand Down Expand Up @@ -3995,11 +4005,19 @@ protected function _getSearchCache($type, $options)
$md[self::CACHE_SEARCHID] = $cacheid;
if ($this->_debug->debug &&
!isset($this->_temp['searchcacheexpire'][strval($this->_selected)])) {
$this->_debug->info(sprintf("SEARCH: Expired from cache (mailbox: %s)", $this->_selected));
$this->_debug->info(sprintf(
'SEARCH: Expired from cache [%s]',
$this->_selected
));
$this->_temp['searchcacheexpire'][strval($this->_selected)] = true;
}
} elseif (isset($md[self::CACHE_SEARCH][$cache])) {
$this->_debug->info(sprintf("SEARCH: Retrieved %s from cache (mailbox: %s; id: %s)", $type, $this->_selected, $cache));
$this->_debug->info(sprintf(
'SEARCH: Retrieved %s from cache (%s [%s])',
$type,
$cache,
$this->_selected
));
$ret['data'] = $md[self::CACHE_SEARCH][$cache];
unset($md[self::CACHE_SEARCHID]);
}
Expand All @@ -4024,7 +4042,12 @@ protected function _setSearchCache($data, $sdata)
$this->_cache->setMetaData($this->_selected, null, $sdata['metadata']);

if ($this->_debug->debug) {
$this->_debug->info(sprintf("SEARCH: Saved %s to cache (mailbox: %s; id: %s)", $sdata['type'], $this->_selected, $sdata['id']));
$this->_debug->info(sprintf(
'SEARCH: Saved %s to cache (%s [%s])',
$sdata['type'],
$sdata['id'],
$this->_selected
));
unset($this->_temp['searchcacheexpire'][strval($this->_selected)]);
}
}
Expand Down
12 changes: 9 additions & 3 deletions framework/Imap_Client/lib/Horde/Imap/Client/Socket.php
Expand Up @@ -3877,7 +3877,9 @@ protected function _sendCmd($cmd)
* cache any data and immediately close the mailbox. */
foreach ($pipeline->data['modseqs_nouid'] as $val) {
if (!$pipeline->fetch[$val]->getUid()) {
$this->_debug->info('Server provided FLAGS MODSEQ without providing UID.');
$this->_debug->info(
'Server provided FLAGS MODSEQ without providing UID.'
);
$this->close();
return $pipeline;
}
Expand Down Expand Up @@ -4080,7 +4082,9 @@ protected function _processCmdContinuation($pipeline, $noexception = false)
return false;
}

$this->_debug->info("ERROR: Unexpected response from server while waiting for a continuation request.");
$this->_debug->info(
'ERROR: Unexpected response from server while waiting for a continuation request.'
);
$e = new Horde_Imap_Client_Exception(
Horde_Imap_Client_Translation::r("Error when communicating with the mail server."),
Horde_Imap_Client_Exception::SERVER_READERROR
Expand Down Expand Up @@ -4685,7 +4689,9 @@ protected function _responseCode(
case 'CLIENTBUG':
case 'CANNOT':
// Defined by RFC 5530 [3]
$this->_debug->info("ERROR: mail server explicitly reporting an error.");
$this->_debug->info(
'ERROR: mail server explicitly reporting an error.'
);
break;

case 'LIMIT':
Expand Down
Expand Up @@ -41,9 +41,10 @@ protected function _connect($host, $port, $timeout, $secure, $retries = 0)
parent::_connect($host, $port, $timeout, $secure, $retries);

if ($timer) {
$this->_params['debug']->info(
sprintf('Server connection took %s seconds.', round($timer->pop(), 4))
);
$this->_params['debug']->info(sprintf(
'Server connection took %s seconds.',
round($timer->pop(), 4)
));
}
}

Expand Down
Expand Up @@ -58,15 +58,17 @@ public function read()
{
if (feof($this->_stream)) {
$this->close();
$this->_params['debug']->info("ERROR: Server closed the connection.");
$this->_params['debug']->info(
'ERROR: Server closed the connection.'
);
throw new Horde_Imap_Client_Exception(
Horde_Imap_Client_Translation::r("Server closed the connection unexpectedly."),
Horde_Imap_Client_Exception::DISCONNECT
);
}

if (($read = fgets($this->_stream)) === false) {
$this->_params['debug']->info("ERROR: read/timeout error.");
$this->_params['debug']->info('ERROR: read/timeout error.');
throw new Horde_Imap_Client_Exception(
Horde_Imap_Client_Translation::r("Error when communicating with the mail server."),
Horde_Imap_Client_Exception::SERVER_READERROR
Expand Down
Expand Up @@ -116,7 +116,9 @@ public function read()
do {
if (feof($this->_stream)) {
$this->close();
$this->_params['debug']->info("ERROR: Server closed the connection.");
$this->_params['debug']->info(
'ERROR: Server closed the connection.'
);
throw new Horde_Imap_Client_Exception(
Horde_Imap_Client_Translation::r("Mail server closed the connection unexpectedly."),
Horde_Imap_Client_Exception::DISCONNECT
Expand Down Expand Up @@ -175,7 +177,7 @@ public function read()
} while (true);

if (!$got_data) {
$this->_params['debug']->info("ERROR: read/timeout error.");
$this->_params['debug']->info('ERROR: read/timeout error.');
throw new Horde_Imap_Client_Exception(
Horde_Imap_Client_Translation::r("Error when communicating with the mail server."),
Horde_Imap_Client_Exception::SERVER_READERROR
Expand Down
Expand Up @@ -1188,7 +1188,7 @@ protected function _getResponse($multiline = false)

$read = explode(' ', rtrim($this->_connection->read(), "\r\n"), 2);
if (!in_array($read[0], array('+OK', '-ERR', '+'))) {
$this->_debug->info("ERROR: IMAP read/timeout error.");
$this->_debug->info('ERROR: IMAP read/timeout error.');
throw new Horde_Imap_Client_Exception(
Horde_Imap_Client_Translation::r("Error when communicating with the mail server."),
Horde_Imap_Client_Exception::SERVER_READERROR
Expand Down

0 comments on commit 3d716f1

Please sign in to comment.