From 85f4209074aab255dacd766109af5092017606ae Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Fri, 2 Oct 2015 10:56:35 +0200 Subject: [PATCH] Code improvements: CS fixes, improved internal cache cleanup on folder selection, removed redundant cache --- program/lib/Roundcube/rcube_imap.php | 15 +------- program/lib/Roundcube/rcube_imap_cache.php | 2 +- program/lib/Roundcube/rcube_imap_generic.php | 39 ++++++++++++++++---- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/program/lib/Roundcube/rcube_imap.php b/program/lib/Roundcube/rcube_imap.php index d73623541..dfcfb5122 100644 --- a/program/lib/Roundcube/rcube_imap.php +++ b/program/lib/Roundcube/rcube_imap.php @@ -62,7 +62,6 @@ class rcube_imap extends rcube_storage protected $sort_field = ''; protected $sort_order = 'DESC'; protected $struct_charset; - protected $uid_id_map = array(); protected $msg_headers = array(); protected $search_set; protected $search_string = ''; @@ -2682,7 +2681,6 @@ class rcube_imap extends rcube_storage // really deleted from the folder $this->expunge_message($uids, $folder, false); $this->clear_messagecount($folder); - unset($this->uid_id_map[$folder]); // unset threads internal cache unset($this->icache['threads']); @@ -3963,8 +3961,6 @@ class rcube_imap extends rcube_storage return $res; } - - return null; } /** @@ -3985,7 +3981,6 @@ class rcube_imap extends rcube_storage } // @TODO: log error - return null; } @@ -4254,19 +4249,11 @@ class rcube_imap extends rcube_storage $folder = $this->folder; } - if ($uid = array_search($id, (array)$this->uid_id_map[$folder])) { - return $uid; - } - if (!$this->check_connection()) { return null; } - $uid = $this->conn->ID2UID($folder, $id); - - $this->uid_id_map[$folder][$uid] = $id; - - return $uid; + return $this->conn->ID2UID($folder, $id); } /** diff --git a/program/lib/Roundcube/rcube_imap_cache.php b/program/lib/Roundcube/rcube_imap_cache.php index ef284d353..a402c1800 100644 --- a/program/lib/Roundcube/rcube_imap_cache.php +++ b/program/lib/Roundcube/rcube_imap_cache.php @@ -986,7 +986,7 @@ class rcube_imap_cache return false; } // ... and max UID - if ($object->max() != $this->imap->id2uid($mbox_data['EXISTS'], $mailbox, true)) { + if ($object->max() != $this->imap->id2uid($mbox_data['EXISTS'], $mailbox)) { return false; } } diff --git a/program/lib/Roundcube/rcube_imap_generic.php b/program/lib/Roundcube/rcube_imap_generic.php index 54edad257..85cbfa91e 100644 --- a/program/lib/Roundcube/rcube_imap_generic.php +++ b/program/lib/Roundcube/rcube_imap_generic.php @@ -1095,6 +1095,8 @@ class rcube_imap_generic list($code, $response) = $this->execute('SELECT', $params); if ($code == self::ERROR_OK) { + $this->clear_mailbox_cache(); + $response = explode("\r\n", $response); foreach ($response as $line) { if (preg_match('/^\* ([0-9]+) (EXISTS|RECENT)$/i', $line, $m)) { @@ -2034,7 +2036,6 @@ class rcube_imap_generic return (int) $arr[0]; } } - return null; } /** @@ -2055,14 +2056,20 @@ class rcube_imap_generic return null; } + if ($uid = $this->data['UID-MAP'][$id]) { + return $uid; + } + + if (isset($this->data['EXISTS']) && $id > $this->data['EXISTS']) { + return null; + } + $index = $this->search($mailbox, $id, true); if ($index->count() == 1) { $arr = $index->get(); - return (int) $arr[0]; + return $this->data['UID-MAP'][$id] = (int) $arr[0]; } - - return null; } /** @@ -3849,9 +3856,27 @@ class rcube_imap_generic protected function clear_status_cache($mailbox) { unset($this->data['STATUS:' . $mailbox]); - unset($this->data['EXISTS']); - unset($this->data['RECENT']); - unset($this->data['UNSEEN']); + + $keys = array('EXISTS', 'RECENT', 'UNSEEN', 'UID-MAP'); + + foreach ($keys as $key) { + unset($this->data[$key]); + } + } + + /** + * Clear internal cache of the current mailbox + */ + protected function clear_mailbox_cache() + { + $this->clear_status_cache($this->selected); + + $keys = array('UIDNEXT', 'UIDVALIDITY', 'HIGHESTMODSEQ', 'NOMODSEQ', + 'PERMANENTFLAGS', 'QRESYNC', 'VANISHED', 'READ-WRITE'); + + foreach ($keys as $key) { + unset($this->data[$key]); + } } /**