From 2061e1638f4f8e98eebc43c220ec3c3a152eb44d Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 10 Aug 2010 16:38:35 -0600 Subject: [PATCH] Request #6455: Spam reporting on mailbox move. Add preference to allow for automatic spam reporting when explicitly moving messages to the Spam mailbox. --- imp/config/prefs.php.dist | 11 ++++++++++- imp/docs/CHANGES | 2 ++ imp/lib/Api.php | 4 ++-- imp/lib/Message.php | 20 ++++++++++++++++---- imp/lib/Prefs/Ui.php | 15 +++++++++++---- imp/lib/Spam.php | 15 +++++++++++---- imp/mailbox.php | 2 +- imp/message.php | 2 +- 8 files changed, 54 insertions(+), 17 deletions(-) diff --git a/imp/config/prefs.php.dist b/imp/config/prefs.php.dist index a09f33594..db69d526b 100644 --- a/imp/config/prefs.php.dist +++ b/imp/config/prefs.php.dist @@ -867,7 +867,8 @@ $prefGroups['delmove'] = array( 'desc' => _("Set preferences for what happens when you move and delete messages."), 'members' => array( 'mailbox_return', 'delete_spam_after_report', 'move_ham_after_report', - 'empty_spam_menu', 'use_trash', 'trashselect', 'empty_trash_menu' + 'move_spam_report', 'empty_spam_menu', 'use_trash', 'trashselect', + 'empty_trash_menu' ) ); @@ -903,6 +904,14 @@ $_prefs['move_ham_after_report'] = array( 'help' => 'prefs-move_ham_after_report' ); +// If moving a message to the Spam mailbox, should they be reported as spam? +$_prefs['move_spam_report'] = array( + 'value' => 0, + 'advanced' => true, + 'type' => 'checkbox', + 'desc' => _("If moving a message to the Spam mailbox, should those messages be reported as spam?") +); + // should we move messages to a trash folder instead of just marking // them as deleted? $_prefs['use_trash'] = array( diff --git a/imp/docs/CHANGES b/imp/docs/CHANGES index d94895e57..a508339ea 100644 --- a/imp/docs/CHANGES +++ b/imp/docs/CHANGES @@ -2,6 +2,8 @@ v5.0-git -------- +[mms] Add preference to allow for automatic spam reporting when explicitly + moving messages to the Spam mailbox (Request #6455). [mms] Automatically determine view based on browser and 'dynamic_view' preference (Request #9159). [mms] Add preference to define default font family/size for the HTML compose diff --git a/imp/lib/Api.php b/imp/lib/Api.php index e69f22e7c..c90a9aab4 100644 --- a/imp/lib/Api.php +++ b/imp/lib/Api.php @@ -117,7 +117,7 @@ class IMP_Api extends Horde_Registry_Api */ public function copyMessages($mailbox, $indices, $target) { - return $GLOBALS['injector']->getInstance('IMP_Message')->copy($target, 'copy', new IMP_Indices($mailbox, $indices), true); + return $GLOBALS['injector']->getInstance('IMP_Message')->copy($target, 'copy', new IMP_Indices($mailbox, $indices), array('create' => true)); } /** @@ -131,7 +131,7 @@ class IMP_Api extends Horde_Registry_Api */ public function moveMessages($mailbox, $indices, $target) { - return $GLOBALS['injector']->getInstance('IMP_Message')->copy($target, 'move', new IMP_Indices($mailbox, $indices), true); + return $GLOBALS['injector']->getInstance('IMP_Message')->copy($target, 'move', new IMP_Indices($mailbox, $indices), array('create' => true)); } /** diff --git a/imp/lib/Message.php b/imp/lib/Message.php index 5241763bb..bcfc5fded 100644 --- a/imp/lib/Message.php +++ b/imp/lib/Message.php @@ -46,12 +46,15 @@ class IMP_Message * (UTF7-IMAP). * @param string $action Either 'copy' or 'move'. * @param IMP_Indices $indices An indices object. - * @param boolean $new Whether the target mailbox has to be - * created. + * @param array $opts Additional options: + *
+     * 'create' - (boolean) Should the target mailbox be created?
+     *            DEFAULT: false
+     * 
* * @return boolean True if successful, false if not. */ - public function copy($targetMbox, $action, $indices, $new = false) + public function copy($targetMbox, $action, $indices, array $opts = array()) { global $conf, $notification, $prefs; @@ -73,7 +76,7 @@ class IMP_Message return true; } - if ($new) { + if (!empty($opts['create'])) { $imp_folder = $GLOBALS['injector']->getInstance('IMP_Folder'); if (!$imp_folder->exists($targetMbox) && !$imp_folder->create($targetMbox, $prefs->getValue('subscribe'))) { @@ -81,6 +84,11 @@ class IMP_Message } } + /* Determine if report on move to Spam mailbox is active. */ + $spam_report = + $prefs->getValue('move_spam_report') && + ($targetMbox == IMP::folderPref($prefs->getValue('spam_folder'), true)); + $imap_move = false; $return_value = true; @@ -127,6 +135,10 @@ class IMP_Message if (($action == 'move') && $imp_mailbox->isBuilt()) { $imp_mailbox->removeMsgs(new IMP_Indices($mbox, $msgIndices)); } + + if ($spam_report) { + IMP_Spam::reportSpam(new IMP_Indices($mbox, $msgIndices), 'spam', array('noaction' => true)); + } } catch (Horde_Imap_Client_Exception $e) { $error = $e->getMessage(); } diff --git a/imp/lib/Prefs/Ui.php b/imp/lib/Prefs/Ui.php index aed3c7a70..d019ee570 100644 --- a/imp/lib/Prefs/Ui.php +++ b/imp/lib/Prefs/Ui.php @@ -101,14 +101,21 @@ class IMP_Prefs_Ui case 'delmove': if ($pop3) { $ui->suppress[] = 'move_ham_after_report'; + $ui->suppress[] = 'move_spam_report'; $ui->suppress[] = 'empty_spam_menu'; $ui->suppress[] = 'use_trash'; $ui->suppress[] = 'trashselect'; $ui->suppress[] = 'empty_trash_menu'; - } elseif ($prefs->isLocked('use_trash') || - !$prefs->getValue('use_trash')) { - $ui->suppress[] = 'trashselect'; - $ui->suppress[] = 'empty_trash_menu'; + } else { + if ($prefs->isLocked('use_trash') || + !$prefs->getValue('use_trash')) { + $ui->suppress[] = 'trashselect'; + $ui->suppress[] = 'empty_trash_menu'; + } + + if (!$prefs->getValue('spam_folder')) { + $ui->suppress[] = 'move_spam_report'; + } } break; diff --git a/imp/lib/Spam.php b/imp/lib/Spam.php index b9ad898dd..bb0c904d8 100644 --- a/imp/lib/Spam.php +++ b/imp/lib/Spam.php @@ -21,11 +21,16 @@ class IMP_Spam * * @param IMP_Indices $indices An indices object. * @param string $action Either 'spam' or 'notspam'. + * @param array $opts Additional options: + *
+     * 'noaction' - (boolean) Don't perform any action after reporting?
+     *              DEFAULT: false
+     * 
* * @return integer 1 if messages have been deleted, 2 if messages have * been moved. */ - static public function reportSpam($indices, $action) + static public function reportSpam($indices, $action, array $opts = array()) { global $notification; @@ -181,7 +186,8 @@ class IMP_Spam /* Delete/move message after report. */ switch ($action) { case 'spam': - if ($result = $GLOBALS['prefs']->getValue('delete_spam_after_report')) { + if (empty($opts['noaction']) && + ($result = $GLOBALS['prefs']->getValue('delete_spam_after_report'))) { $imp_message = $GLOBALS['injector']->getInstance('IMP_Message'); switch ($result) { case 1: @@ -200,7 +206,7 @@ class IMP_Spam case 2: $targetMbox = IMP::folderPref($GLOBALS['prefs']->getValue('spam_folder'), true); if ($targetMbox) { - if (!$imp_message->copy($targetMbox, 'move', $indices, true)) { + if (!$imp_message->copy($targetMbox, 'move', $indices, array('create' => true))) { $result = 0; } } else { @@ -213,7 +219,8 @@ class IMP_Spam break; case 'notspam': - if ($result = $GLOBALS['prefs']->getValue('move_ham_after_report')) { + 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)) { $result = 0; diff --git a/imp/mailbox.php b/imp/mailbox.php index 33a0a39b8..31f4f815f 100644 --- a/imp/mailbox.php +++ b/imp/mailbox.php @@ -157,7 +157,7 @@ case 'copy_messages': $targetMbox = $vars->targetMbox; $newMbox = false; } - $injector->getInstance('IMP_Message')->copy($targetMbox, ($actionID == 'move_messages') ? 'move' : 'copy', $indices, $newMbox); + $injector->getInstance('IMP_Message')->copy($targetMbox, ($actionID == 'move_messages') ? 'move' : 'copy', $indices, array('create' => $newMbox)); } break; diff --git a/imp/message.php b/imp/message.php index 06cb4157a..2ff20135e 100644 --- a/imp/message.php +++ b/imp/message.php @@ -112,7 +112,7 @@ case 'copy_message': } else { $newMbox = false; } - $imp_message->copy($vars->targetMbox, ($vars->actionID == 'move_message') ? 'move' : 'copy', $indices, $vars->newMbox); + $imp_message->copy($vars->targetMbox, ($vars->actionID == 'move_message') ? 'move' : 'copy', $indices, array('create' => $newMbox)); if ($prefs->getValue('mailbox_return')) { _returnToMailbox($imp_mailbox->getMessageIndex()); require IMP_BASE . '/mailbox.php'; -- 2.11.0