summaryrefslogtreecommitdiff
path: root/program/include/rcube_imap_generic.php
diff options
context:
space:
mode:
authoralecpl <alec@alec.pl>2011-11-09 10:03:54 +0000
committeralecpl <alec@alec.pl>2011-11-09 10:03:54 +0000
commit51f7a5b2a09777d3a279757af620e42985ff9a86 (patch)
tree1b4700d4e4f3e5277dcb9877118acc1ee9098b74 /program/include/rcube_imap_generic.php
parent69cb80b0594add4d18f8de6b5c676f1dc4d0a835 (diff)
- Apply fixes from trunk up to r5401
Diffstat (limited to 'program/include/rcube_imap_generic.php')
-rw-r--r--program/include/rcube_imap_generic.php56
1 files changed, 29 insertions, 27 deletions
diff --git a/program/include/rcube_imap_generic.php b/program/include/rcube_imap_generic.php
index 5c7a41c73..a4e921fe6 100644
--- a/program/include/rcube_imap_generic.php
+++ b/program/include/rcube_imap_generic.php
@@ -2242,12 +2242,29 @@ class rcube_imap_generic
list($code, $response) = $this->execute($subscribed ? 'LSUB' : 'LIST', $args);
if ($code == self::ERROR_OK) {
- $folders = array();
- while ($this->tokenizeResponse($response, 1) == '*') {
- $cmd = strtoupper($this->tokenizeResponse($response, 1));
+ $folders = array();
+ $last = 0;
+ $pos = 0;
+ $response .= "\r\n";
+
+ while ($pos = strpos($response, "\r\n", $pos+1)) {
+ // literal string, not real end-of-command-line
+ if ($response[$pos-1] == '}') {
+ continue;
+ }
+
+ $line = substr($response, $last, $pos - $last);
+ $last = $pos + 2;
+
+ if (!preg_match('/^\* (LIST|LSUB|STATUS) /i', $line, $m)) {
+ continue;
+ }
+ $cmd = strtoupper($m[1]);
+ $line = substr($line, strlen($m[0]));
+
// * LIST (<options>) <delimiter> <mailbox>
if ($cmd == 'LIST' || $cmd == 'LSUB') {
- list($opts, $delim, $mailbox) = $this->tokenizeResponse($response, 3);
+ list($opts, $delim, $mailbox) = $this->tokenizeResponse($line, 3);
// Add to result array
if (!$lstatus) {
@@ -2258,31 +2275,21 @@ class rcube_imap_generic
}
// Add to options array
- if (!empty($opts)) {
- if (empty($this->data['LIST'][$mailbox]))
- $this->data['LIST'][$mailbox] = $opts;
- else
- $this->data['LIST'][$mailbox] = array_unique(array_merge(
- $this->data['LIST'][$mailbox], $opts));
- }
+ if (empty($this->data['LIST'][$mailbox]))
+ $this->data['LIST'][$mailbox] = $opts;
+ else if (!empty($opts))
+ $this->data['LIST'][$mailbox] = array_unique(array_merge(
+ $this->data['LIST'][$mailbox], $opts));
}
// * STATUS <mailbox> (<result>)
else if ($cmd == 'STATUS') {
- list($mailbox, $status) = $this->tokenizeResponse($response, 2);
+ list($mailbox, $status) = $this->tokenizeResponse($line, 2);
for ($i=0, $len=count($status); $i<$len; $i += 2) {
list($name, $value) = $this->tokenizeResponse($status, 2);
$folders[$mailbox][$name] = $value;
}
}
- // other untagged response line, skip it
- else {
- $response = ltrim($response);
- if (($position = strpos($response, "\n")) !== false)
- $response = substr($response, $position+1);
- else
- $response = '';
- }
}
return $folders;
@@ -3392,15 +3399,10 @@ class rcube_imap_generic
// String atom, number, NIL, *, %
default:
- // empty or one character
- if ($str === '') {
+ // empty string
+ if ($str === '' || $str === null) {
break 2;
}
- if (strlen($str) < 2) {
- $result[] = $str;
- $str = '';
- break;
- }
// excluded chars: SP, CTL, ), [, ]
if (preg_match('/^([^\x00-\x20\x29\x5B\x5D\x7F]+)/', $str, $m)) {