Skip to content

Commit

Permalink
Reset client_debug correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Jul 17, 2014
1 parent 196643c commit c0447e9
Showing 1 changed file with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,20 @@ public function write($data, $eol = false)
{
if ($eol) {
$buffer = $this->_buffer;
$debug = $this->client_debug;
$this->_buffer = '';

$this->client_debug = true;

if (fwrite($this->_stream, $buffer . $data . ($eol ? "\r\n" : '')) === false) {
throw new Horde_Imap_Client_Exception(
Horde_Imap_Client_Translation::r("Server write error."),
Horde_Imap_Client_Exception::SERVER_WRITEERROR
);
}

if ($this->client_debug) {
if ($debug) {
$this->_params['debug']->client($buffer . $data);
} else {
$this->client_debug = true;
}
} else {
$this->_buffer .= $data;
Expand All @@ -86,28 +87,31 @@ public function write($data, $eol = false)
public function writeLiteral($data, $length, $binary = false)
{
$this->_buffer = '';
$success = false;

if ($data instanceof Horde_Stream) {
$data = $data->stream;
}

if (!rewind($data)) {
if (rewind($data)) {
$success = true;
while (!feof($data)) {
if ((($read_data = fread($data, 8192)) === false) ||
(fwrite($this->_stream, $read_data) === false)) {
$success = false;
break;
}
}
}

if (!$success) {
$this->client_debug = true;
throw new Horde_Imap_Client_Exception(
Horde_Imap_Client_Translation::r("Server write error."),
Horde_Imap_Client_Exception::SERVER_WRITEERROR
);
}

while (!feof($data)) {
if ((($read_data = fread($data, 8192)) === false) ||
(fwrite($this->_stream, $read_data) === false)) {
throw new Horde_Imap_Client_Exception(
Horde_Imap_Client_Translation::r("Server write error."),
Horde_Imap_Client_Exception::SERVER_WRITEERROR
);
}
}

if ($this->client_debug && !empty($this->_params['debugliteral'])) {
rewind($data);
while (!feof($data)) {
Expand Down

0 comments on commit c0447e9

Please sign in to comment.