Skip to content

Commit

Permalink
Improved POP3 logging
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Jul 17, 2014
1 parent c0447e9 commit 7a7fb10
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ class Horde_Imap_Client_Socket_Connection_Pop3
/**
* Writes data to the POP3 output stream.
*
* @param string $data String data.
* @param string $data String data.
* @param boolean $debug Output line to debug?
*
* @throws Horde_Imap_Client_Exception
*/
public function write($data)
public function write($data, $debug = true)
{
if (fwrite($this->_stream, $data . "\r\n") === false) {
throw new Horde_Imap_Client_Exception(
Expand All @@ -48,7 +49,9 @@ public function write($data)
);
}

$this->_params['debug']->client($data);
if ($debug) {
$this->_params['debug']->client($data);
}
}

/**
Expand Down
27 changes: 10 additions & 17 deletions framework/Imap_Client/lib/Horde/Imap/Client/Socket/Pop3.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ protected function _tryLogin($method)
$challenge = $this->_sendLine('AUTH ' . $method);
$response = base64_encode($username . ' ' . hash_hmac(strtolower(substr($method, 5)), base64_decode(substr($challenge['resp'], 2)), $password, true));
$this->_sendLine($response, array(
'debug' => sprintf('[%s Response - username: %s]', $method, $username)
'debug' => sprintf('[AUTH Response (username: %s)]', $username)
));
break;

Expand All @@ -346,7 +346,7 @@ protected function _tryLogin($method)
'pop3'
));
$sresponse = $this->_sendLine($response, array(
'debug' => sprintf('[%s Response - username: %s]', $method, $username)
'debug' => sprintf('[AUTH Response (username: %s)]', $username)
));
if (stripos(base64_decode(substr($sresponse['resp'], 2)), 'rspauth=') === false) {
throw new Horde_Imap_Client_Exception(
Expand All @@ -362,11 +362,9 @@ protected function _tryLogin($method)
case 'LOGIN':
// RFC 4616 (AUTH=PLAIN) & 5034 (POP3 SASL)
$this->_sendLine('AUTH LOGIN');
$this->_sendLine(base64_encode($username), array(
'debug' => sprintf('[AUTH LOGIN Command - username: %s]', $username)
));
$this->_sendLine(base64_encode($username));
$this->_sendLine(base64_encode($password), array(
'debug' => '[AUTH LOGIN Command - password]'
'debug' => sprintf('[AUTH Password (username: %s)]', $username)
));
break;

Expand All @@ -377,7 +375,7 @@ protected function _tryLogin($method)
$username,
$password
))), array(
'debug' => sprintf('[AUTH PLAIN Command - username: %s]', $username)
'debug' => sprintf('AUTH PLAIN [Auth Response (username: %s)]', $username)
));
break;

Expand All @@ -390,7 +388,7 @@ protected function _tryLogin($method)
// RFC 1939 [7]
$this->_sendLine('USER ' . $username);
$this->_sendLine('PASS ' . $password, array(
'debug' => '[USER Command - password]'
'debug' => 'PASS [Password]'
));
break;

Expand Down Expand Up @@ -1151,31 +1149,26 @@ public function resolveIds(Horde_Imap_Client_Mailbox $mailbox,
*/
protected function _sendLine($cmd, $options = array())
{
$old_debug = $this->_debug->debug;
if (!empty($options['debug'])) {
$this->_debug->raw($options['debug'] . "\n");
$this->_debug->debug = false;
$this->_debug->client($options['debug']);
}

if ($old_debug) {
if ($this->_debug->debug) {
$timer = new Horde_Support_Timer();
$timer->push();
}

try {
$this->_connection->write($cmd);
$this->_connection->write($cmd, empty($options['debug']));
} catch (Horde_Imap_Client_Exception $e) {
$this->_debug->debug = $old_debug;
throw $e;
}

$this->_debug->debug = $old_debug;

$resp = $this->_getResponse(
empty($options['multiline']) ? false : $options['multiline']
);

if ($old_debug) {
if ($this->_debug->debug) {
$this->_debug->info(sprintf(
'Command took %s seconds.',
round($timer->pop(), 4)
Expand Down

0 comments on commit 7a7fb10

Please sign in to comment.