From: Michael M Slusarz Date: Sat, 18 Sep 2010 05:54:35 +0000 (-0600) Subject: Fix deletion of messages in virtual folders. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=9351a5d5f564df97d6bc2ed4ce1fa00665e5d5be;p=horde.git Fix deletion of messages in virtual folders. Can't rely on global IMP_Mailbox instances, since the master mailbox is instead the search mailbox. Need to explicitly pass in the mailbox object to be updated. --- diff --git a/imp/lib/Message.php b/imp/lib/Message.php index 2028963b8..5fd262edc 100644 --- a/imp/lib/Message.php +++ b/imp/lib/Message.php @@ -50,6 +50,8 @@ class IMP_Message *
      * 'create' - (boolean) Should the target mailbox be created?
      *            DEFAULT: false
+     * 'mailboxob' - (IMP_Mailbox) Update this mailbox object.
+     *               DEFAULT: No update.
      * 
* * @return boolean True if successful, false if not. @@ -131,9 +133,10 @@ class IMP_Message try { $imp_imap->copy($mbox, $targetMbox, array('ids' => $msgIndices, 'move' => $imap_move)); - $imp_mailbox = $GLOBALS['injector']->getInstance('IMP_Mailbox')->getOb($mbox); - if (($action == 'move') && $imp_mailbox->isBuilt()) { - $imp_mailbox->removeMsgs(new IMP_Indices($mbox, $msgIndices)); + if (($action == 'move') && + !empty($opts['mailboxob']) && + $opts['mailboxob']->isBuilt()) { + $opts['mailboxob']->removeMsgs(new IMP_Indices($mbox, $msgIndices)); } if ($spam_report) { @@ -164,6 +167,8 @@ class IMP_Message *
      * 'keeplog' - (boolean) Should any history information of the message be
      *             kept?
+     * 'mailboxob' - (IMP_Mailbox) Update this mailbox object.
+     *               DEFAULT: No update.
      * 'nuke' - (boolean) Override user preferences and nuke (i.e. permanently
      *          delete) the messages instead?
      * 
@@ -232,9 +237,9 @@ class IMP_Message try { $imp_imap->copy($mbox, $trash, array('ids' => $msgIndices, 'move' => true)); - $imp_mailbox = $GLOBALS['injector']->getInstance('IMP_Mailbox')->getOb($mbox); - if ($imp_mailbox->isBuilt()) { - $imp_mailbox->removeMsgs($imp_indices); + if (!empty($options['mailboxob']) && + $options['mailboxob']->isBuilt()) { + $options['mailboxob']->removeMsgs($imp_indices); } } catch (Horde_Imap_Client_Exception $e) { // @todo Check for overquota error. @@ -272,7 +277,12 @@ class IMP_Message try { $imp_imap->store($mbox, array('add' => array('\\deleted'), 'ids' => $msgIndices)); if ($expunge_now) { - $this->expungeMailbox($imp_indices->indices()); + $this->expungeMailbox( + $imp_indices->indices(), + array( + 'mailboxob' => empty($opts['mailboxob']) ? null : $opts['mailboxob'] + ) + ); } } catch (Horde_Imap_Client_Exception $e) {} @@ -457,11 +467,16 @@ class IMP_Message * @param IMP_Indices $indices An indices object. * @param string $partid The MIME ID of the part to strip. All * parts are stripped if null. + * @param array $opts Additional options: + *
+     * 'mailboxob' - (IMP_Mailbox) Update this mailbox object.
+     *               DEFAULT: No update.
+     * 
* * @return IMP_Indices Returns the new indices object. * @throws IMP_Exception */ - public function stripPart($indices, $partid = null) + public function stripPart($indices, $partid = null, array $opts = array()) { list($mbox, $uid) = $indices->getSingle(); if (!$uid) { @@ -566,15 +581,23 @@ class IMP_Message throw new IMP_Exception(_("An error occured while attempting to strip the attachment.")); } - $this->delete($indices, array('nuke' => true, 'keeplog' => true)); + $this->delete($indices, array( + 'keeplog' => true, + 'mailboxob' => empty($opts['mailboxob']) ? null : $opts['mailboxob'], + 'nuke' => true + )); - $GLOBALS['injector']->getInstance('IMP_Mailbox')->getOb($mbox, new IMP_Indices($mbox, $new_uid)); + $indices_ob = new IMP_Indices($mbox, $new_uid); + + if (!empty($opts['mailboxob'])) { + $opts['mailboxob']->setIndex($indices_ob); + } /* We need to replace the old index in the query string with the * new index. */ $_SERVER['QUERY_STRING'] = str_replace($uid, $new_uid, $_SERVER['QUERY_STRING']); - return new IMP_Indices($mbox, $new_uid); + return $indices_ob; } /** @@ -678,12 +701,14 @@ class IMP_Message *
      * 'list' - (boolean) Return a list of messages expunged.
      *          DEFAULT: false
+     * 'mailboxob' - (IMP_Mailbox) Update this mailbox object.
+     *               DEFAULT: No update.
      * 
* * @return IMP_Indices If 'list' option is true, an indices object * containing the messages that have been expunged. */ - public function expungeMailbox($mbox_list, $options = array()) + public function expungeMailbox($mbox_list, array $options = array()) { $msg_list = !empty($options['list']); @@ -721,9 +746,9 @@ class IMP_Message try { $update_list[$key] = $imp_imap->expunge($key, array('ids' => is_array($val) ? $val : array(), 'list' => $msg_list)); - $imp_mailbox = $GLOBALS['injector']->getInstance('IMP_Mailbox')->getOb($key); - if ($imp_mailbox->isBuilt()) { - $imp_mailbox->removeMsgs(is_array($val) ? new IMP_Indices($key, $val) : true); + if (!empty($opts['mailboxob']) && + $opts['mailboxob']->isBuilt()) { + $opts['mailboxob']->removeMsgs(is_array($val) ? new IMP_Indices($key, $val) : true); } } catch (Horde_Imap_Client_Exception $e) {} } diff --git a/imp/message.php b/imp/message.php index 54998c270..0e1890b09 100644 --- a/imp/message.php +++ b/imp/message.php @@ -90,7 +90,12 @@ case 'undelete_message': if ($vars->actionID == 'undelete_message') { $imp_message->undelete($indices); } else { - $imp_message->delete($indices); + $imp_message->delete( + $indices, + array( + 'mailboxob' => $imp_mailbox + ) + ); if ($prefs->getValue('mailbox_return')) { _returnToMailbox($imp_mailbox->getMessageIndex()); require IMP_BASE . '/mailbox.php'; @@ -112,7 +117,15 @@ case 'copy_message': } else { $newMbox = false; } - $imp_message->copy($targetMbox, ($vars->actionID == 'move_message') ? 'move' : 'copy', $indices, array('create' => $newMbox)); + $imp_message->copy( + $targetMbox, + ($vars->actionID == 'move_message') ? 'move' : 'copy', + $indices, + array( + 'create' => $newMbox, + 'mailboxob' => $imp_mailbox + ) + ); if ($prefs->getValue('mailbox_return')) { _returnToMailbox($imp_mailbox->getMessageIndex()); require IMP_BASE . '/mailbox.php'; @@ -163,7 +176,13 @@ case 'add_address': case 'strip_all': case 'strip_attachment': try { - $imp_message->stripPart($indices, ($vars->actionID == 'strip_all') ? null : $vars->imapid); + $imp_message->stripPart( + $indices, + ($vars->actionID == 'strip_all') ? null : $vars->imapid, + array( + 'mailboxob' => $imp_mailbox + ) + ); $notification->push(_("Attachment successfully stripped."), 'horde.success'); } catch (Horde_Exception $e) { $notification->push($e);