[Svn] r4117 - in trunk/roundcubemail: . program/include

trac at roundcube.net trac at roundcube.net
Wed Oct 20 15:33:28 CEST 2010


Author: alec
Date: 2010-10-20 08:33:27 -0500 (Wed, 20 Oct 2010)
New Revision: 4117

Modified:
   trunk/roundcubemail/CHANGELOG
   trunk/roundcubemail/program/include/rcube_imap_generic.php
Log:
- Improve performance of unseen messages counting, use STATUS instead of SELECT+SEARCH (#1487058)


Modified: trunk/roundcubemail/CHANGELOG
===================================================================
--- trunk/roundcubemail/CHANGELOG	2010-10-20 12:24:21 UTC (rev 4116)
+++ trunk/roundcubemail/CHANGELOG	2010-10-20 13:33:27 UTC (rev 4117)
@@ -37,6 +37,7 @@
 - Add METADATA extension support into IMAP classes (RFC5464)
 - Fix decoding of e-mail address strings in message headers (#1487068)
 - Fix handling of attachments when Content-Disposition is not inline nor attachment (#1487051)
+- Improve performance of unseen messages counting (#1487058)
 
 RELEASE 0.4.2
 -------------

Modified: trunk/roundcubemail/program/include/rcube_imap_generic.php
===================================================================
--- trunk/roundcubemail/program/include/rcube_imap_generic.php	2010-10-20 12:24:21 UTC (rev 4116)
+++ trunk/roundcubemail/program/include/rcube_imap_generic.php	2010-10-20 13:33:27 UTC (rev 4117)
@@ -733,6 +733,41 @@
         return false;
     }
 
+    /**
+     * Executes STATUS comand
+     *
+     * @param string $mailbox Mailbox name
+     * @param array  $items   Requested item names
+     *
+     * @return array Status item-value hash
+     * @access public
+     * @since 0.5-beta
+     */
+    function status($mailbox, $items)
+    {
+	    if (empty($mailbox) || empty($items)) {
+		    return false;
+	    }
+
+        list($code, $response) = $this->execute('STATUS', array($this->escape($mailbox),
+            '(' . implode(' ', (array) $items) . ')'));
+
+        if ($code == self::ERROR_OK && preg_match('/\* STATUS /i', $response)) {
+            $result   = array();
+            $response = substr($response, 9); // remove prefix "* STATUS "
+
+            list($mbox, $items) = $this->tokenizeResponse($response, 2);
+
+            for ($i=0, $len=count($items); $i<$len; $i += 2) {
+                $result[$items[$i]] = (int) $items[$i+1];
+            }
+
+			return $result;
+		}
+
+        return false;
+    }
+
     function checkForRecent($mailbox)
     {
 	    if (empty($mailbox)) {
@@ -761,6 +796,32 @@
         return false;
     }
 
+    /**
+     * Returns count of messages without \Seen flag in a specified folder
+     *
+     * @param string $mailbox Mailbox name
+     *
+     * @return int Number of messages, False on error
+     * @access public
+     */
+    function countUnseen($mailbox)
+    {
+        // Try STATUS, should be faster
+        $counts = $this->status($mailbox, array('UNSEEN'));
+        if (is_array($counts)) {
+            return (int) $counts['UNSEEN'];
+        }
+
+        // Invoke SEARCH as a fallback
+        // @TODO: ESEARCH support
+        $index = $this->search($mailbox, 'ALL UNSEEN');
+        if (is_array($index)) {
+            return count($index);
+        }
+
+        return false;
+    }
+
     function sort($mailbox, $field, $add='', $is_uid=FALSE, $encoding = 'US-ASCII')
     {
 	    $field = strtoupper($field);
@@ -1413,14 +1474,6 @@
 	    return $result;
     }
 
-    function countUnseen($folder)
-    {
-        $index = $this->search($folder, 'ALL UNSEEN');
-        if (is_array($index))
-            return count($index);
-        return false;
-    }
-
     // Don't be tempted to change $str to pass by reference to speed this up - it will slow it down by about
     // 7 times instead :-) See comments on http://uk2.php.net/references and this article:
     // http://derickrethans.nl/files/phparch-php-variables-article.pdf

_______________________________________________
http://lists.roundcube.net/mailman/listinfo/svn



More information about the Svn mailing list