Re-add mailbox list caching to DIMP.
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 4 Dec 2008 08:04:02 +0000 (01:04 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 4 Dec 2008 08:05:05 +0000 (01:05 -0700)
imp/imp-dimp.php
imp/lib/Mailbox.php
imp/lib/Views/ListMessages.php

index 1150010..e86c257 100644 (file)
@@ -32,11 +32,10 @@ function _generateDeleteResult($folder, $indices, $change)
     return $result;
 }
 
-function _cacheID($folder)
+function _cacheID($mbox)
 {
-//    $imp_mailbox = &IMP_Mailbox::singleton($folder);
-//    return $imp_mailbox->getCacheId();
-    return false;
+    $imp_mailbox = &IMP_Mailbox::singleton($mbox);
+    return $imp_mailbox->getCacheID();
 }
 
 function _changed($folder, $compare, $indices = array(), $nothread = false)
index f9c9f7c..bbdc9fb 100644 (file)
@@ -710,4 +710,25 @@ class IMP_Mailbox
         }
     }
 
+    /**
+     * Returns a unique identifier for the current mailbox status.
+     *
+     * @return string  The cache ID string, which will change when the
+     *                 composition of the mailbox changes.
+     */
+    public function getCacheID()
+    {
+        if (!$this->_searchmbox) {
+            $sortpref = IMP::getSort($this->_mailbox);
+
+            try {
+                $status = $GLOBALS['imp_imap']->ob->status($this->_mailbox, Horde_Imap_Client::STATUS_MESSAGES | Horde_Imap_Client::STATUS_UIDNEXT | Horde_Imap_Client::STATUS_UIDVALIDITY);
+                return implode('|', array($status['messages'], $status['uidnext'], $status['uidvalidity'], $sortpref['by'], $sortpref['dir']));
+            } catch (Horde_Imap_Client_Exception $e) {}
+        }
+
+        /* This should generate a sufficiently random #. */
+        return time() . mt_rand();
+    }
+
 }
index 28515b8..298bee7 100644 (file)
@@ -95,8 +95,7 @@ class IMP_Views_ListMessages
         $result->id = $folder;
         $result->totalrows = $msgcount;
         $result->label = $label;
-        // @todo
-        $result->cacheid = time();
+        $result->cacheid = $imp_mailbox->getCacheID();
 
         /* Determine the row slice to process. */
         if (isset($args['slice_rownum'])) {