From 50a2358d457a16490bb36b977fe532a59a886602 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 5 May 2015 18:57:26 -0600 Subject: [PATCH] Tweak: determine whether to not store small literals in streams at read time also --- .../Imap/Client/Socket/Connection/Socket.php | 9 ++++- .../lib/Horde/Imap/Client/Tokenize.php | 36 +++++++++---------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/framework/Imap_Client/lib/Horde/Imap/Client/Socket/Connection/Socket.php b/framework/Imap_Client/lib/Horde/Imap/Client/Socket/Connection/Socket.php index b700fd2ffbf..4c7d45cf9bc 100644 --- a/framework/Imap_Client/lib/Horde/Imap/Client/Socket/Connection/Socket.php +++ b/framework/Imap_Client/lib/Horde/Imap/Client/Socket/Connection/Socket.php @@ -185,7 +185,14 @@ public function read($size = null) while (($literal_len > 0) && !feof($this->_stream)) { $in = fread($this->_stream, min($literal_len, 8192)); - $token->addLiteralStream($in); + /* Only store in stream if this is something more than a + * nominal number of bytes. */ + if ($old_len > 256) { + $token->addLiteralStream($in); + } else { + $token->add($in); + } + if (!empty($this->_params['debugliteral'])) { $this->_params['debug']->raw($in); } diff --git a/framework/Imap_Client/lib/Horde/Imap/Client/Tokenize.php b/framework/Imap_Client/lib/Horde/Imap/Client/Tokenize.php index 4600c36fc1f..6a64010ed58 100644 --- a/framework/Imap_Client/lib/Horde/Imap/Client/Tokenize.php +++ b/framework/Imap_Client/lib/Horde/Imap/Client/Tokenize.php @@ -301,26 +301,24 @@ public function next() case '{': $literal_len = intval($this->_stream->getToChar('}')); - if ($this->literalStream) { - $pos = $this->_stream->pos(); - if (isset($this->_literals[$pos])) { - $text = $this->_literals[$pos]; - } elseif ($literal_len > self::MIN_LITERAL_STREAM) { - $text = new Horde_Stream_Temp(); - while (($literal_len > 0) && !feof($stream)) { - $part = $this->_stream->substring( - 0, - min($literal_len, 8192) - ); - $text->add($part); - $literal_len -= strlen($part); - } - } else { - $text = false; + $pos = $this->_stream->pos(); + if (isset($this->_literals[$pos])) { + $text = $this->_literals[$pos]; + if (!$this->literalStream) { + $text = strval($text); } - } - - if ($text === false) { + } elseif ($this->literalStream && + ($literal_len > self::MIN_LITERAL_STREAM)) { + $text = new Horde_Stream_Temp(); + while (($literal_len > 0) && !feof($stream)) { + $part = $this->_stream->substring( + 0, + min($literal_len, 8192) + ); + $text->add($part); + $literal_len -= strlen($part); + } + } else { $text = $this->_stream->substring(0, $literal_len); } $check_len = false;