From 6a1bb00ff93708dc69202cf5f7bee5bbaf6d6d55 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Mon, 8 Dec 2008 23:44:19 -0700 Subject: [PATCH] Improvements to IMP_Mailbox updates. Have IMP_Message:: always update IMP_Mailbox object if it exists and the mailbox data has already been built. --- imp/lib/Mailbox.php | 12 +++++++++++- imp/lib/Message.php | 35 ++++++++++++----------------------- imp/message-mimp.php | 3 +-- imp/message.php | 3 +-- 4 files changed, 25 insertions(+), 28 deletions(-) diff --git a/imp/lib/Mailbox.php b/imp/lib/Mailbox.php index bbdc9fb0c..2ee0903ff 100644 --- a/imp/lib/Mailbox.php +++ b/imp/lib/Mailbox.php @@ -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; } diff --git a/imp/lib/Message.php b/imp/lib/Message.php index 1b89a1033..7a5c196ef 100644 --- a/imp/lib/Message.php +++ b/imp/lib/Message.php @@ -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) {} diff --git a/imp/message-mimp.php b/imp/message-mimp.php index e701f0b81..f27d0ae46 100644 --- a/imp/message-mimp.php +++ b/imp/message-mimp.php @@ -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']); diff --git a/imp/message.php b/imp/message.php index 21d5c140d..800c052d6 100644 --- a/imp/message.php +++ b/imp/message.php @@ -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(); -- 2.11.0