From ce032286c01df2bf45f7656325ad42f961f0109b Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Thu, 4 Dec 2008 01:04:02 -0700 Subject: [PATCH] Re-add mailbox list caching to DIMP. --- imp/imp-dimp.php | 7 +++---- imp/lib/Mailbox.php | 21 +++++++++++++++++++++ imp/lib/Views/ListMessages.php | 3 +-- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/imp/imp-dimp.php b/imp/imp-dimp.php index 1150010e6..e86c257de 100644 --- a/imp/imp-dimp.php +++ b/imp/imp-dimp.php @@ -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) diff --git a/imp/lib/Mailbox.php b/imp/lib/Mailbox.php index f9c9f7c6e..bbdc9fb0c 100644 --- a/imp/lib/Mailbox.php +++ b/imp/lib/Mailbox.php @@ -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(); + } + } diff --git a/imp/lib/Views/ListMessages.php b/imp/lib/Views/ListMessages.php index 28515b898..298bee7b9 100644 --- a/imp/lib/Views/ListMessages.php +++ b/imp/lib/Views/ListMessages.php @@ -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'])) { -- 2.11.0