Fix updating mailbox after reporting as spam
authorMichael M Slusarz <slusarz@curecanti.org>
Mon, 27 Sep 2010 05:51:05 +0000 (23:51 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Mon, 27 Sep 2010 17:25:01 +0000 (11:25 -0600)
imp/lib/Spam.php
imp/message-mimp.php
imp/message.php

index 8dc29c8..545ec1f 100644 (file)
@@ -23,6 +23,8 @@ class IMP_Spam
      * @param string $action        Either 'spam' or 'notspam'.
      * @param array $opts           Additional options:
      * <pre>
+     * 'mailboxob' - (IMP_Mailbox) Update this mailbox object.
+     *               DEFAULT: No update.
      * 'noaction' - (boolean) Don't perform any action after reporting?
      *              DEFAULT: false
      * </pre>
@@ -183,6 +185,11 @@ class IMP_Spam
         }
         $notification->push($msg, 'horde.message');
 
+        $mbox_args = array();
+        if (isset($opts['mailboxob'])) {
+            $mbox_args['mailboxob'] = $opts['mailboxob'];
+        }
+
         /* Delete/move message after report. */
         switch ($action) {
         case 'spam':
@@ -191,7 +198,7 @@ class IMP_Spam
                 $imp_message = $GLOBALS['injector']->getInstance('IMP_Message');
                 switch ($result) {
                 case 1:
-                    $msg_count = $imp_message->delete($indices);
+                    $msg_count = $imp_message->delete($indices, $mbox_args);
                     if ($msg_count === false) {
                         $result = 0;
                     } else {
@@ -206,7 +213,7 @@ class IMP_Spam
                 case 2:
                     $targetMbox = $GLOBALS['prefs']->getValue('spam_folder');
                     if ($targetMbox) {
-                        if (!$imp_message->copy(IMP::folderPref($targetMbox, true), 'move', $indices, array('create' => true))) {
+                        if (!$imp_message->copy(IMP::folderPref($targetMbox, true), 'move', $indices, array_merge($mbox_args, array('create' => true)))) {
                             $result = 0;
                         }
                     } else {
@@ -222,7 +229,7 @@ class IMP_Spam
             if (empty($opts['noaction']) &&
                 ($result = $GLOBALS['prefs']->getValue('move_ham_after_report'))) {
                 $imp_message = $GLOBALS['injector']->getInstance('IMP_Message');
-                if (!$imp_message->copy('INBOX', 'move', $indices)) {
+                if (!$imp_message->copy('INBOX', 'move', $indices, $mbox_args)) {
                     $result = 0;
                 }
             }
index eb83382..328857a 100644 (file)
@@ -50,9 +50,8 @@ case 'u':
     if ($readonly) {
         break;
     }
-    $index_ob = $imp_mailbox->getIMAPIndex();
     $msg_index = $imp_mailbox->getMessageIndex();
-    $imp_indices = new IMP_Indices($index_ob['mailbox'], $index_ob['uid']);
+    $imp_indices = new IMP_Indices($imp_mailbox);
     $imp_message = $injector->getInstance('IMP_Message');
 
     if ($vars->a == 'd') {
@@ -71,10 +70,8 @@ case 'u':
 // 'ri' = report innocent
 case 'rs':
 case 'ri':
-    $index_ob = $imp_mailbox->getIMAPIndex();
     $msg_index = $imp_mailbox->getMessageIndex();
-
-    $msg_delete = (IMP_Spam::reportSpam(new IMP_Indices($index_ob['mailbox'], $index_ob['uid']), $vars->a == 'rs' ? 'spam' : 'innocent') === 1);
+    $msg_delete = (IMP_Spam::reportSpam(new IMP_Indices($imp_mailbox), $vars->a == 'rs' ? 'spam' : 'innocent', array('mailboxob' => $imp_mailbox)) === 1);
     break;
 
 // 'pa' = part action
index 0e1890b..dba6e69 100644 (file)
@@ -137,7 +137,7 @@ case 'copy_message':
 case 'spam_report':
 case 'notspam_report':
     $action = str_replace('_report', '', $vars->actionID);
-    switch (IMP_Spam::reportSpam($indices, $action)) {
+    switch (IMP_Spam::reportSpam($indices, $action, array('mailboxob' => $imp_mailbox))) {
     case 1:
         if ($imp_ui->moveAfterAction()) {
             $imp_mailbox->setIndex(1);