summaryrefslogtreecommitdiff
path: root/program/include/rcube_imap_generic.php
diff options
context:
space:
mode:
authoralecpl <alec@alec.pl>2010-10-29 18:02:19 +0000
committeralecpl <alec@alec.pl>2010-10-29 18:02:19 +0000
commit9ae29c9525dbd878cff63d691625bb0c6f6cbf5c (patch)
treee4ad1075261213bfd929d84e3470051f0d9b79ea /program/include/rcube_imap_generic.php
parent93272ea91b3263acd883cac77986125e9a2ad8c6 (diff)
- Improve performance of message cache status checking when skip_disabled=true
Diffstat (limited to 'program/include/rcube_imap_generic.php')
-rw-r--r--program/include/rcube_imap_generic.php32
1 files changed, 23 insertions, 9 deletions
diff --git a/program/include/rcube_imap_generic.php b/program/include/rcube_imap_generic.php
index 5d16dc0c1..a7bfe05ad 100644
--- a/program/include/rcube_imap_generic.php
+++ b/program/include/rcube_imap_generic.php
@@ -1008,8 +1008,8 @@ class rcube_imap_generic
}
// message IDs
- if (is_array($add))
- $add = $this->compressMessageSet(join(',', $add));
+ if (!empty($add))
+ $add = $this->compressMessageSet($add);
list($code, $response) = $this->execute($is_uid ? 'UID SORT' : 'SORT',
array("($field)", $encoding, 'ALL' . (!empty($add) ? ' '.$add : '')));
@@ -1026,7 +1026,7 @@ class rcube_imap_generic
function fetchHeaderIndex($mailbox, $message_set, $index_field='', $skip_deleted=true, $uidfetch=false)
{
if (is_array($message_set)) {
- if (!($message_set = $this->compressMessageSet(join(',', $message_set))))
+ if (!($message_set = $this->compressMessageSet($message_set)))
return false;
} else {
list($from_idx, $to_idx) = explode(':', $message_set);
@@ -1150,12 +1150,12 @@ class rcube_imap_generic
return $result;
}
- private function compressMessageSet($messages, $force=false)
+ static function compressMessageSet($messages, $force=false)
{
// given a comma delimited list of independent mid's,
// compresses by grouping sequences together
- if (!is_array($message_set)) {
+ if (!is_array($messages)) {
// if less than 255 bytes long, let's not bother
if (!$force && strlen($messages)<255) {
return $messages;
@@ -1199,6 +1199,23 @@ class rcube_imap_generic
return implode(',', $result);
}
+ static function uncompressMessageSet($messages)
+ {
+ $result = array();
+ $messages = explode(',', $messages);
+
+ foreach ($messages as $part) {
+ $items = explode(':', $part);
+ $max = max($items[0], $items[1]);
+
+ for ($x=$items[0]; $x<=$max; $x++) {
+ $result[] = $x;
+ }
+ }
+
+ return $result;
+ }
+
/**
* Returns message sequence identifier
*
@@ -1265,9 +1282,6 @@ class rcube_imap_generic
return false;
}
- if (is_array($message_set))
- $message_set = join(',', $message_set);
-
$message_set = $this->compressMessageSet($message_set);
if ($add)
@@ -1824,7 +1838,7 @@ class rcube_imap_generic
if (in_array('MAX', $items))
$result['MAX'] = !empty($response) ? max($response) : 0;
if (in_array('ALL', $items))
- $result['ALL'] = $this->compressMessageSet(implode(',', $response), true);
+ $result['ALL'] = $this->compressMessageSet($response, true);
return $result;
}