Skip to content

Commit

Permalink
[jan] Fix parsing IMAP responses with tilde characters.
Browse files Browse the repository at this point in the history
  • Loading branch information
yunosh committed Nov 19, 2015
1 parent 88c5e20 commit 2cc3963
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
13 changes: 10 additions & 3 deletions framework/Imap_Client/lib/Horde/Imap/Client/Tokenize.php
Expand Up @@ -247,7 +247,7 @@ public function next()

do {
$check_len = true;
$in_quote = $text = false;
$in_quote = $text = $binary = false;

while (($c = fgetc($stream)) !== false) {
switch ($c) {
Expand Down Expand Up @@ -291,10 +291,16 @@ public function next()

case '~':
// Ignore binary string identifier. PHP strings are
// binary-safe.
break;
// binary-safe. But keep it is not used as string
// identifier.
$binary = true;
$text .= $c;
continue;

case '{':
if ($binary) {
$text = substr($text, 0, -1);
}
$literal_len = intval($this->_stream->getToChar('}'));
$pos = $this->_stream->pos();
if (isset($this->_literals[$pos])) {
Expand Down Expand Up @@ -330,6 +336,7 @@ public function next()
}
break;
}
$binary = false;
}

if ($check_len) {
Expand Down
4 changes: 2 additions & 2 deletions framework/Imap_Client/package.xml
Expand Up @@ -21,7 +21,7 @@
</stability>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
*
* [jan] Fix parsing IMAP responses with tilde characters.
</notes>
<contents>
<dir baseinstalldir="/" name="/">
Expand Down Expand Up @@ -2958,7 +2958,7 @@
<date>2015-09-07</date>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
*
* [jan] Fix parsing IMAP responses with tilde characters.
</notes>
</release>
</changelog>
Expand Down
24 changes: 24 additions & 0 deletions framework/Imap_Client/test/Horde/Imap/Client/TokenizeTest.php
Expand Up @@ -464,6 +464,30 @@ public function testLiteralLength()
100,
$len['length']
);

// Test non-binary-marker tilde.
$test = '* LIST () "" ~foo';
$token = new Horde_Imap_Client_Tokenize($test);
$token->rewind();

$this->assertEquals(
'*',
$token->next()
);
$this->assertEquals(
'LIST',
$token->next()
);
$this->assertTrue($token->next());
$this->assertFalse($token->next());
$this->assertEquals(
'',
$token->next()
);
$this->assertEquals(
'~foo',
$token->next()
);
}

public function testLiteralStream()
Expand Down

0 comments on commit 2cc3963

Please sign in to comment.