From 4f599be8fe37e6ac0926dd003b7d12dffea44074 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Mon, 8 Nov 2010 19:55:30 -0700 Subject: [PATCH] Bug #6455: Add post_spam hook Partial revert of 2061e1638f4f8e98eebc43c220ec3c3a152eb44d Previous applied code was not the subject of the ticket. Cleanest to provide a post_spam hook and have the admin perform the necessary actions. Provide the copy-to-mailbox scenario as the hook example. --- imp/config/hooks.php.dist | 17 +++++++++++++++++ imp/config/prefs.php.dist | 11 +---------- imp/docs/CHANGES | 3 +-- imp/lib/Message.php | 9 --------- imp/lib/Prefs/Ui.php | 15 ++++----------- imp/lib/Spam.php | 5 +++++ 6 files changed, 28 insertions(+), 32 deletions(-) diff --git a/imp/config/hooks.php.dist b/imp/config/hooks.php.dist index f32d855bc..1c165f723 100644 --- a/imp/config/hooks.php.dist +++ b/imp/config/hooks.php.dist @@ -592,6 +592,23 @@ class IMP_Hooks /** + * Perform an action after messages have been reported as spam/ham. + * + * @param string $action Either 'spam' or 'ham'. + * @param IMP_Indices $indices The list of indices that have been + reported as spam/ham. + */ +// public function post_spam($action, $indices) +// { +// // Example #1: Copy messages to a (not)spam mailbox. +// $targetMbox = 'foo'; +// +// $imp_message = $GLOBALS['injector']->getInstance('IMP_Message'); +// $imp_message->copy($targetMbox, 'copy', $indices, array('create' => true)); +// } + + + /** * Determine quota for a user. * * @param array $params Parameters for the function, set in backends.php. diff --git a/imp/config/prefs.php.dist b/imp/config/prefs.php.dist index c5f9f4059..a67d89573 100644 --- a/imp/config/prefs.php.dist +++ b/imp/config/prefs.php.dist @@ -879,8 +879,7 @@ $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', - 'move_spam_report', 'empty_spam_menu', 'use_trash', 'trashselect', - 'empty_trash_menu' + 'empty_spam_menu', 'use_trash', 'trashselect', 'empty_trash_menu' ) ); @@ -916,14 +915,6 @@ $_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 b3a9e21d9..62f7b4bdf 100644 --- a/imp/docs/CHANGES +++ b/imp/docs/CHANGES @@ -2,6 +2,7 @@ v5.0-git -------- +[mms] Add post_spam hook called after reporting spam/ham (Request #6455). [mms] Implement stationery support in DIMP. [mms] Add preference to control displayed content for multipart/alternative parts (Request #6711). @@ -25,8 +26,6 @@ v5.0-git server. [mms] Add preference to control if we check for recipient PGP public keys when replying (Request #7962). -[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/Message.php b/imp/lib/Message.php index e7701fd87..344434222 100644 --- a/imp/lib/Message.php +++ b/imp/lib/Message.php @@ -86,11 +86,6 @@ 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; @@ -138,10 +133,6 @@ class IMP_Message $opts['mailboxob']->isBuilt()) { $opts['mailboxob']->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 788566698..0d3928233 100644 --- a/imp/lib/Prefs/Ui.php +++ b/imp/lib/Prefs/Ui.php @@ -107,21 +107,14 @@ 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'; - } 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'; - } + } elseif ($prefs->isLocked('use_trash') || + !$prefs->getValue('use_trash')) { + $ui->suppress[] = 'trashselect'; + $ui->suppress[] = 'empty_trash_menu'; } break; diff --git a/imp/lib/Spam.php b/imp/lib/Spam.php index 11af755bd..d00bcce84 100644 --- a/imp/lib/Spam.php +++ b/imp/lib/Spam.php @@ -200,6 +200,11 @@ class IMP_Spam $mbox_args['mailboxob'] = $opts['mailboxob']; } + /* Run post-reporting hook. */ + try { + Horde::callHook('post_spam', array($action, $indices), 'imp'); + } catch (Horde_Exception_HookNotSet $e) {} + /* Delete/move message after report. */ switch ($action) { case 'spam': -- 2.11.0