From 7ab9c1775243217f3f6cb0717b1894a98303d04e Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Tue, 26 Jun 2012 05:11:53 -0400
Subject: [PATCH] Improve performance by skipping redundant ENABLE commands

---
 program/include/rcube_imap_cache.php |   13 ++++++-------
 1 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/program/include/rcube_imap_cache.php b/program/include/rcube_imap_cache.php
index eb2df16..fec6510 100644
--- a/program/include/rcube_imap_cache.php
+++ b/program/include/rcube_imap_cache.php
@@ -917,18 +917,17 @@
             return;
         }
 
-        // NOTE: make sure the mailbox isn't selected, before
-        // enabling QRESYNC and invoking SELECT
-        if ($this->imap->conn->selected !== null) {
-            $this->imap->conn->close();
-        }
-
         // Enable QRESYNC
         $res = $this->imap->conn->enable($qresync ? 'QRESYNC' : 'CONDSTORE');
-        if (!is_array($res)) {
+        if ($res === false) {
             return;
         }
 
+        // Close mailbox if already selected to get most recent data
+        if ($this->imap->conn->selected == $mailbox) {
+            $this->imap->conn->close();
+        }
+
         // Get mailbox data (UIDVALIDITY, HIGHESTMODSEQ, counters, etc.)
         $mbox_data = $this->imap->folder_data($mailbox);
 

--
Gitblit v1.9.1