Skip to content

Commit

Permalink
Revert "Use new Horde_Stream methods"
Browse files Browse the repository at this point in the history
This reverts commit fe19a38.
  • Loading branch information
slusarz committed Oct 1, 2013
1 parent 4bf89cf commit cd44606
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 34 deletions.
Expand Up @@ -107,7 +107,7 @@ public function escapeStream()
throw new Horde_Imap_Client_Data_Format_Exception('String requires literal to output.');
}

$this->_data->rewind();
rewind($this->_data->stream);

$stream = new Horde_Stream_Temp();
$stream->add($this->_data, true);
Expand Down
4 changes: 2 additions & 2 deletions framework/Imap_Client/lib/Horde/Imap/Client/Ids.php
Expand Up @@ -234,8 +234,8 @@ public function split($length)
$out = array();

do {
$out[] = $id->getString(null, $length + $id->pos()) . $id->getToChar(',');
} while (!$id->eof());
$out[] = stream_get_contents($id->stream, $length) . $id->getToChar(',');
} while (!feof($id->stream));

return $out;
}
Expand Down
8 changes: 4 additions & 4 deletions framework/Imap_Client/lib/Horde/Imap/Client/Socket.php
Expand Up @@ -1648,7 +1648,7 @@ protected function _append(Horde_Imap_Client_Mailbox $mailbox, $data,
if ($catenate) {
$cmd->add($tmp);
} else {
$cmd->add($this->_appendData($data_stream, $asize));
$cmd->add($this->_appendData($data_stream->stream, $asize));
}
} else {
$cmd->add($this->_appendData($data[$key]['data'], $asize));
Expand Down Expand Up @@ -1728,15 +1728,15 @@ protected function _append(Horde_Imap_Client_Mailbox $mailbox, $data,
* Prepares append message data for insertion into the IMAP command
* string.
*
* @param mixed $data Either a Horde_Stream object or a string.
* @param mixed $data Either a resource or a string.
* @param integer &$asize Total append size.
*
* @return Horde_Imap_Client_Data_Format_String The data object.
*/
protected function _appendData($data, &$asize)
{
if ($data instanceof Horde_Stream) {
$data->rewind();
if (is_resource($data)) {
rewind($data);
}

$ob = new Horde_Imap_Client_Data_Format_String($data, array(
Expand Down
Expand Up @@ -98,15 +98,13 @@ public function writeLiteral($data, $length, $binary = false)
{
$this->_buffer = '';

if (is_resource($data)) {
$data = new Horde_Stream_Existing(array(
'stream' => $data
));
if ($data instanceof Horde_Stream) {
$data = $data->stream;
}

$data->rewind();
while ($data->eof()) {
if (fwrite($this->_stream, $data->getString(null, 8192)) === false) {
rewind($data);
while (!feof($data)) {
if (fwrite($this->_stream, fread($data, 8192)) === false) {
throw new Horde_Imap_Client_Exception(
Horde_Imap_Client_Translation::t("Server write error."),
Horde_Imap_Client_Exception::SERVER_WRITEERROR
Expand All @@ -115,9 +113,9 @@ public function writeLiteral($data, $length, $binary = false)
}

if ($this->_debugliteral) {
$data->rewind();
while (!$data->eof()) {
$this->_debug->raw($data->getString(null, 8192));
rewind($data);
while (!feof($data)) {
$this->_debug->raw(fread($data, 8192));
}
} else {
$this->_debug->client('[' . ($binary ? 'BINARY' : 'LITERAL') . ' DATA: ' . $length . ' bytes]');
Expand Down
27 changes: 12 additions & 15 deletions framework/Imap_Client/lib/Horde/Imap/Client/Tokenize.php
Expand Up @@ -78,7 +78,7 @@ public function __get($name)
{
switch ($name) {
case 'eos':
return $this->_stream->eof();
return feof($this->_stream->stream);
}
}

Expand All @@ -93,9 +93,9 @@ public function __sleep()
*/
public function __toString()
{
$pos = $this->_stream->pos();
$pos = ftell($this->_stream->stream);
$out = $this->_current . ' ' . $this->_stream->getString();
$this->_stream->seek($pos, false);
fseek($this->_stream->stream, $pos);
return $out;
}

Expand Down Expand Up @@ -141,8 +141,8 @@ public function flushIterator($return = true, $sublevel = true)
$this->next();
}
} else {
$this->_stream->end();
$this->_stream->getChar();
fseek($this->_stream->stream, 0, SEEK_END);
fgetc($this->_stream->stream);
$this->_current = $this->_key = $this->_level = false;
}

Expand All @@ -159,7 +159,7 @@ public function flushIterator($return = true, $sublevel = true)
*/
public function getLiteralLength()
{
$this->_stream->end(-1);
fseek($this->_stream->stream, -1, SEEK_END);
if ($this->_stream->peek() == '}') {
$literal_data = $this->_stream->getString($this->_stream->search('{', true) - 1);
$literal_len = substr($literal_data, 2, -1);
Expand Down Expand Up @@ -211,7 +211,7 @@ public function next()
*/
public function rewind()
{
$this->_stream->rewind();
fseek($this->_stream->stream, 0);
$this->_current = false;
$this->_key = -1;
$this->_level = 0;
Expand All @@ -232,13 +232,14 @@ public function valid()
protected function _parseStream()
{
$in_quote = false;
$stream = $this->_stream->stream;
$text = '';

while (($c = $this->_stream->getChar()) !== false) {
while (($c = fgetc($stream)) !== false) {
switch ($c) {
case '\\':
$text .= $in_quote
? $this->_stream->getChar()
? fgetc($stream)
: $c;
break;

Expand All @@ -263,7 +264,7 @@ protected function _parseStream()

case ')':
if (strlen($text)) {
$this->_stream->seek(-1);
fseek($stream, -1, SEEK_CUR);
break 3;
}
--$this->_level;
Expand All @@ -275,11 +276,7 @@ protected function _parseStream()
break;

case '{':
$length = $this->_stream->getToChar('}');
return $this->_stream->getString(
null,
$this->_stream->pos() + $length - 1
);
return stream_get_contents($stream, $this->_stream->getToChar('}'));

case ' ':
if (strlen($text)) {
Expand Down
2 changes: 1 addition & 1 deletion framework/Imap_Client/package.xml
Expand Up @@ -289,7 +289,7 @@
<package>
<name>Horde_Stream</name>
<channel>pear.horde.org</channel>
<min>1.4.0</min>
<min>1.0.0</min>
<max>2.0.0alpha1</max>
<exclude>2.0.0alpha1</exclude>
</package>
Expand Down
2 changes: 1 addition & 1 deletion framework/Stream/lib/Horde/Stream.php
Expand Up @@ -168,7 +168,7 @@ public function length($utf8 = false)
*
* @return string The string up to $end (stream is positioned after the
* end character(s), all of which are stripped from the
* return data).
return data).
*/
public function getToChar($end)
{
Expand Down

0 comments on commit cd44606

Please sign in to comment.