Skip to content

Commit

Permalink
[mms] Directly store literal data in a separate stream when parsing I…
Browse files Browse the repository at this point in the history
…MAP tokens, so we don't have to duplicate the stream later when processing it.
  • Loading branch information
slusarz committed May 6, 2015
1 parent 85f7506 commit 35e5ad4
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 12 deletions.
Expand Up @@ -185,7 +185,7 @@ public function read($size = null)

while (($literal_len > 0) && !feof($this->_stream)) {
$in = fread($this->_stream, min($literal_len, 8192));
$token->add($in);
$token->addLiteralStream($in);
if (!empty($this->_params['debugliteral'])) {
$this->_params['debug']->raw($in);
}
Expand Down
52 changes: 41 additions & 11 deletions framework/Imap_Client/lib/Horde/Imap/Client/Tokenize.php
Expand Up @@ -62,6 +62,13 @@ class Horde_Imap_Client_Tokenize implements Iterator
*/
protected $_level = false;

/**
* Array of literal stream objects.
*
* @var array
*/
protected $_literals = array();

/**
* next() modifiers.
*
Expand Down Expand Up @@ -136,6 +143,21 @@ public function add($data)
$this->_stream->add($data);
}

/**
* Add data to literal stream at the current position.
*
* @param mixed $data Data to add (string, resource, or Horde_Stream
* object).
*/
public function addLiteralStream($data)
{
$pos = $this->_stream->pos();
if (!isset($this->_literals[$pos])) {
$this->_literals[$pos] = new Horde_Stream_Temp();
}
$this->_literals[$pos]->add($data);
}

/**
* Flush the remaining entries left in the iterator.
*
Expand Down Expand Up @@ -279,18 +301,26 @@ public function next()

case '{':
$literal_len = intval($this->_stream->getToChar('}'));
if ($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);
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;
}
} else {
}

if ($text === false) {
$text = $this->_stream->substring(0, $literal_len);
}
$check_len = false;
Expand Down
2 changes: 2 additions & 0 deletions framework/Imap_Client/package.xml
Expand Up @@ -21,6 +21,7 @@
</stability>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
* [mms] Directly store literal data in a separate stream when parsing IMAP tokens, so we don&apos;t have to duplicate the stream later when processing it.
* [mms] Don&apos;t load literal IMAP data into a string variable when tokenizing IMAP input.
* [mms] Fix search queries where ID list given is explicitly empty, indicating that a match can never be successful (Bug #13971).
* [mms] Fix expunging in certain cases when UIDPLUS is not available (Bug #13970; Robin McCorkell &lt;rmccorkell@karoshi.org.uk&gt;).
Expand Down Expand Up @@ -2876,6 +2877,7 @@
<date>2015-04-27</date>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
* [mms] Directly store literal data in a separate stream when parsing IMAP tokens, so we don&apos;t have to duplicate the stream later when processing it.
* [mms] Don&apos;t load literal IMAP data into a string variable when tokenizing IMAP input.
* [mms] Fix search queries where ID list given is explicitly empty, indicating that a match can never be successful (Bug #13971).
* [mms] Fix expunging in certain cases when UIDPLUS is not available (Bug #13970; Robin McCorkell &lt;rmccorkell@karoshi.org.uk&gt;).
Expand Down

0 comments on commit 35e5ad4

Please sign in to comment.