- Improved _listMailboxes() performance and small parseResponse() improvement (#1488134)

pull/1/head
alecpl 13 years ago
parent 5e9065284e
commit 9230525d98

@ -2242,12 +2242,29 @@ class rcube_imap_generic
list($code, $response) = $this->execute($subscribed ? 'LSUB' : 'LIST', $args); list($code, $response) = $this->execute($subscribed ? 'LSUB' : 'LIST', $args);
if ($code == self::ERROR_OK) { if ($code == self::ERROR_OK) {
$folders = array(); $folders = array();
while ($this->tokenizeResponse($response, 1) == '*') { $last = 0;
$cmd = strtoupper($this->tokenizeResponse($response, 1)); $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> // * LIST (<options>) <delimiter> <mailbox>
if ($cmd == 'LIST' || $cmd == 'LSUB') { 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 // Add to result array
if (!$lstatus) { if (!$lstatus) {
@ -2266,21 +2283,13 @@ class rcube_imap_generic
} }
// * STATUS <mailbox> (<result>) // * STATUS <mailbox> (<result>)
else if ($cmd == 'STATUS') { 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) { for ($i=0, $len=count($status); $i<$len; $i += 2) {
list($name, $value) = $this->tokenizeResponse($status, 2); list($name, $value) = $this->tokenizeResponse($status, 2);
$folders[$mailbox][$name] = $value; $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; return $folders;
@ -3390,15 +3399,10 @@ class rcube_imap_generic
// String atom, number, NIL, *, % // String atom, number, NIL, *, %
default: default:
// empty or one character // empty string
if ($str === '') { if ($str === '' || $str === null) {
break 2; break 2;
} }
if (strlen($str) < 2) {
$result[] = $str;
$str = '';
break;
}
// excluded chars: SP, CTL, ), [, ] // excluded chars: SP, CTL, ), [, ]
if (preg_match('/^([^\x00-\x20\x29\x5B\x5D\x7F]+)/', $str, $m)) { if (preg_match('/^([^\x00-\x20\x29\x5B\x5D\x7F]+)/', $str, $m)) {

Loading…
Cancel
Save