diff --git a/CHANGELOG b/CHANGELOG index 00e65ce36..94930bc83 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ CHANGELOG Roundcube Webmail =========================== +- Fix parsing of square bracket characters in IMAP response strings (#1489223) - Don't clear References and in-Reply-To when a message is "edited as new" (#1489216) - Make possible to disable some (broken) IMAP extensions with imap_disable_caps option (#1489184) - Contacts drag-n-drop default action is to move contacts (#1488751) diff --git a/program/lib/Roundcube/rcube_imap_generic.php b/program/lib/Roundcube/rcube_imap_generic.php index ae390a0ee..9b11624a7 100644 --- a/program/lib/Roundcube/rcube_imap_generic.php +++ b/program/lib/Roundcube/rcube_imap_generic.php @@ -2163,14 +2163,18 @@ class rcube_imap_generic else if ($name == 'RFC822') { $result[$id]->body = $value; } - else if ($name == 'BODY') { - $body = $this->tokenizeResponse($line, 1); - if ($value[0] == 'HEADER.FIELDS') - $headers = $body; - else if (!empty($value)) - $result[$id]->bodypart[$value[0]] = $body; + else if (stripos($name, 'BODY[') === 0) { + $name = str_replace(']', '', substr($name, 5)); + + if ($name == 'HEADER.FIELDS') { + // skip ']' after headers list + $this->tokenizeResponse($line, 1); + $headers = $this->tokenizeResponse($line, 1); + } + else if (strlen($name)) + $result[$id]->bodypart[$name] = $value; else - $result[$id]->body = $body; + $result[$id]->body = $value; } } @@ -2515,8 +2519,7 @@ class rcube_imap_generic for ($i=0; $iassertSame(array(1, 2, 3), $result); $this->assertCount(3, $result); } + + /** + * Test for tokenizeResponse + */ + function test_tokenizeResponse() + { + $response = "test brack[et] {1}\r\na {0}\r\n (item1 item2)"; + + $result = rcube_imap_generic::tokenizeResponse($response, 1); + $this->assertSame("test", $result); + + $result = rcube_imap_generic::tokenizeResponse($response, 1); + $this->assertSame("brack[et]", $result); + + $result = rcube_imap_generic::tokenizeResponse($response, 1); + $this->assertSame("a", $result); + + $result = rcube_imap_generic::tokenizeResponse($response, 1); + $this->assertSame("", $result); + + $result = rcube_imap_generic::tokenizeResponse($response, 1); + $this->assertSame(array('item1', 'item2'), $result); + } }