Fix mailbox list generation in IMP
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 24 Nov 2010 18:50:23 +0000 (11:50 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 24 Nov 2010 18:50:23 +0000 (11:50 -0700)
In [M]IMP message mode, we want to use a cached version of the mailbox
list in order to prevent wild index swings when deleting messages.
However, we also need to make sure that we correctly rebuild the mailbox
once we return to the mailbox view since things may have changed in the
meantime.

imp/lib/Injector/Factory/MailboxList.php
imp/lib/Mailbox/List/Track.php

index bb1cc33..406db46 100644 (file)
@@ -88,6 +88,7 @@ class IMP_Injector_Factory_MailboxList
         case 'imp':
         case 'mimp':
             $this->_instances[$mailbox]->setIndex($indices);
+            $this->_instance[$mailbox]->checkcache = is_null($indices);
             break;
         }
 
index 5d3561a..192323b 100644 (file)
 class IMP_Mailbox_List_Track extends IMP_Mailbox_List
 {
     /**
+     * Check the IMAP cache ID?
+     *
+     * @var boolean
+     */
+    public $checkcache = true;
+
+    /**
+     * The IMAP cache ID of the mailbox.
+     *
+     * @var string
+     */
+    protected $_cacheid = null;
+
+    /**
      * The location in the sorted array we are at.
      *
      * @var integer
@@ -28,7 +42,7 @@ class IMP_Mailbox_List_Track extends IMP_Mailbox_List
      *
      * @var array
      */
-    protected $_slist = array('_index');
+    protected $_slist = array('_cacheid', '_index');
 
     /**
      * Returns the current message array index. If the array index has
@@ -126,6 +140,22 @@ class IMP_Mailbox_List_Track extends IMP_Mailbox_List
 
     /**
      */
+    protected function _buildMailbox()
+    {
+        $cacheid = $this->getCacheID();
+
+        /* Check cache ID: will catch changes to the mailbox after coming out
+         * of message view mode. */
+        if (!$this->isBuilt() ||
+            ($this->checkcache && ($this->_cacheid != $cacheid))) {
+            $this->_sorted = null;
+            $this->_cacheid = $cacheid;
+            parent::_buildMailbox();
+        }
+    }
+
+    /**
+     */
     protected function _rebuild($force = false)
     {
         if ($force ||