Improvements to IMP_Mailbox updates.
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 9 Dec 2008 06:44:19 +0000 (23:44 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 9 Dec 2008 06:49:56 +0000 (23:49 -0700)
Have IMP_Message:: always update IMP_Mailbox object if it exists and the
mailbox data has already been built.

imp/lib/Mailbox.php
imp/lib/Message.php
imp/message-mimp.php
imp/message.php

index bbdc9fb..2ee0903 100644 (file)
@@ -229,11 +229,21 @@ class IMP_Mailbox
     }
 
     /**
+     * Returns true if the mailbox data has been built.
+     *
+     * @return boolean  True if the mailbox has been built.
+     */
+    public function isBuilt()
+    {
+        return !is_null($this->_sorted);
+    }
+
+    /**
      * Builds the sorted list of messages in the mailbox.
      */
     protected function _buildMailbox()
     {
-        if (!is_null($this->_sorted)) {
+        if ($this->isBuilt()) {
             return;
         }
 
index 1b89a10..7a5c196 100644 (file)
@@ -30,13 +30,6 @@ class IMP_Message
     protected $_usepop = false;
 
     /**
-     * An IMP_Mailbox object to update on message actions.
-     *
-     * @var IMP_Mailbox
-     */
-    protected $_mailboxOb = null;
-
-    /**
      * Returns a reference to the global IMP_Message object, only creating it
      * if it doesn't already exist. This ensures that only one IMP_Message
      * instance is instantiated for any given session.
@@ -69,16 +62,6 @@ class IMP_Message
     }
 
     /**
-     * Set the IMP_Mailbox object to update on message actions.
-     *
-     * @param IMP_Mailbox &$ob  An IMP_Mailbox object.
-     */
-    public function updateMailboxOb(&$ob)
-    {
-        $this->_mailboxOb = $ob;
-    }
-
-    /**
      * Copies or moves a list of messages to a new mailbox.
      * Handles use of the IMP::SEARCH_MBOX mailbox and the Trash mailbox.
      *
@@ -148,8 +131,10 @@ class IMP_Message
             /* Attempt to copy/move messages to new mailbox. */
             try {
                 $imp_imap->ob->copy($mbox, $targetMbox, array('ids' => $msgIndices, 'move' => $imap_move));
-                if (!is_null($this->_mailboxOb)) {
-                    $this->_mailboxOb->removeMsgs(array($mbox => $msgIndices));
+
+                $imp_mailbox = &IMP_Mailbox::singleton($mbox);
+                if ($imp_mailbox->isBuilt()) {
+                    $imp_mailbox->removeMsgs(array($mbox => $msgIndices));
                 }
             } catch (Horde_Imap_Client_Exception $e) {
                 $notification->push(sprintf($message, IMP::displayFolder($mbox), IMP::displayFolder($targetMbox)) . ': ' . imap_last_error(), 'horde.error');
@@ -219,8 +204,10 @@ class IMP_Message
             if ($use_trash_folder && ($mbox != $trash)) {
                 try {
                     $imp_imap->ob->copy($mbox, $trash, array('ids' => $msgIndices, 'move' => true));
-                    if (!is_null($this->_mailboxOb)) {
-                        $this->_mailboxOb->removeMsgs(array($mbox => $msgIndices));
+
+                    $imp_mailbox = &IMP_Mailbox::singleton($mbox);
+                    if ($imp_mailbox->isBuilt()) {
+                        $imp_mailbox->removeMsgs(array($mbox => $msgIndices));
                     }
                 } catch (Horde_Imap_Client_Exception $e) {
                     // @todo Check for overquota error.
@@ -648,8 +635,10 @@ class IMP_Message
         foreach ($process_list as $key => $val) {
             try {
                 $imp_imap->ob->expunge($key, array('ids' => is_array($val) ? $val : array()));
-                if (!is_null($this->_mailboxOb)) {
-                    $this->_mailboxOb->removeMsgs(is_array($val) ? array($key => $val) : true);
+
+                $imp_mailbox = &IMP_Mailbox::singleton($mbox);
+                if ($imp_mailbox->isBuilt()) {
+                    $imp_mailbox->removeMsgs(is_array($val) ? array($key => $val) : true);
                 }
                 $update_list[$key] = $val;
             } catch (Horde_Imap_Client_Exception $e) {}
index e701f0b..f27d0ae 100644 (file)
@@ -26,9 +26,8 @@ if (!$imp_mailbox->isValidIndex()) {
     exit;
 }
 
-/* Update IMP_Mailbox on message actions. */
+/* Initialize IMP_Message object. */
 $imp_message = &IMP_Message::singleton();
-$imp_message->updateMailboxOb($imp_mailbox);
 
 /* Determine if mailbox is readonly. */
 $readonly = $imp_imap->isReadOnly($imp_mbox['mailbox']);
index 21d5c14..800c052 100644 (file)
@@ -44,9 +44,8 @@ if (!$imp_mailbox->isValidIndex()) {
     exit;
 }
 
-/* Update IMP_Mailbox on message actions. */
+/* Initialize IMP_Message object. */
 $imp_message = &IMP_Message::singleton();
-$imp_message->updateMailboxOb($imp_mailbox);
 
 /* Set the current time zone. */
 NLS::setTimeZone();