diff options
author | alecpl <alec@alec.pl> | 2010-12-22 18:11:29 +0000 |
---|---|---|
committer | alecpl <alec@alec.pl> | 2010-12-22 18:11:29 +0000 |
commit | ab1bea48436be72d0d6009e187c56cfdbcfc6445 (patch) | |
tree | 0499867c426e6344ed0c9dce3461ed0129b69627 | |
parent | fbaaae0098be39da7dd61275d26f55d8b366ea6c (diff) |
- Fix handling (skipping) of unilateral untagged server responses (in THREAD/SORT/SEARCH commands)
-rw-r--r-- | program/include/rcube_imap_generic.php | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/program/include/rcube_imap_generic.php b/program/include/rcube_imap_generic.php index e5e06c440..512e7e44e 100644 --- a/program/include/rcube_imap_generic.php +++ b/program/include/rcube_imap_generic.php @@ -1150,9 +1150,12 @@ class rcube_imap_generic array("($field)", $encoding, 'ALL' . (!empty($add) ? ' '.$add : ''))); if ($code == self::ERROR_OK) { - // remove prefix and \r\n from raw response - $response = str_replace("\r\n", '', substr($response, 7)); - return preg_split('/\s+/', $response, -1, PREG_SPLIT_NO_EMPTY); + // remove prefix and unilateral untagged server responses + $response = substr($response, stripos($response, '* SORT') + 7); + if ($pos = strpos($response, '*')) { + $response = substr($response, 0, $pos); + } + return preg_split('/[\s\r\n]+/', $response, -1, PREG_SPLIT_NO_EMPTY); } return false; @@ -1889,9 +1892,15 @@ class rcube_imap_generic list($code, $response) = $this->execute('THREAD', array( $algorithm, $encoding, $criteria)); - if ($code == self::ERROR_OK && preg_match('/^\* THREAD /i', $response)) { - // remove prefix and \r\n from raw response - $response = str_replace("\r\n", '', substr($response, 9)); + if ($code == self::ERROR_OK) { + // remove prefix... + $response = substr($response, stripos($response, '* THREAD') + 9); + // ...unilateral untagged server responses + if ($pos = strpos($response, '*')) { + $response = substr($response, 0, $pos); + } + + $response = str_replace("\r\n", '', $response); $depthmap = array(); $haschildren = array(); @@ -1949,9 +1958,13 @@ class rcube_imap_generic array($params)); if ($code == self::ERROR_OK) { - // remove prefix and \r\n from raw response - $response = substr($response, $esearch ? 10 : 9); - $response = str_replace("\r\n", '', $response); + // remove prefix... + $response = substr($response, stripos($response, + $esearch ? '* ESEARCH' : '* SEARCH') + ($esearch ? 10 : 9)); + // ...and unilateral untagged server responses + if ($pos = strpos($response, '*')) { + $response = rtrim(substr($response, 0, $pos)); + } if ($esearch) { // Skip prefix: ... (TAG "A285") UID ... @@ -1970,7 +1983,7 @@ class rcube_imap_generic return $result; } else { - $response = preg_split('/\s+/', $response, -1, PREG_SPLIT_NO_EMPTY); + $response = preg_split('/[\s\r\n]+/', $response, -1, PREG_SPLIT_NO_EMPTY); if (!empty($items)) { $result = array(); |