Update IMP_Filter::
authorMichael M Slusarz <slusarz@curecanti.org>
Mon, 10 Nov 2008 19:10:44 +0000 (12:10 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Mon, 10 Nov 2008 19:10:44 +0000 (12:10 -0700)
imp/lib/Filter.php

index 27ff871..7d5f170 100644 (file)
@@ -13,8 +13,6 @@
  *   mail/whitelistFrom
  *   mail/showWhitelist
  *
- * $Horde: imp/lib/Filter.php,v 1.80 2008/10/13 20:51:51 slusarz Exp $
- *
  * Copyright 2002-2008 The Horde Project (http://www.horde.org/)
  *
  * See the enclosed file COPYING for license information (GPL). If you
  * @author  Michael Slusarz <slusarz@horde.org>
  * @package IMP
  */
-class IMP_Filter {
-
+class IMP_Filter
+{
     /**
      * Runs the filters if they are able to be applied manually.
      *
      * @param string $mbox  The mailbox to apply the filters to.
      */
-    function filter($mbox)
+    public function filter($mbox)
     {
-        if (!empty($_SESSION['imp']['filteravail'])) {
-            if (isset($GLOBALS['imp_search']) &&
-                $GLOBALS['imp_search']->isSearchMbox($mbox)) {
-                $mbox_list = $GLOBALS['imp_search']->getSearchFolders($mbox);
-            } else {
-                $mbox_list = array($mbox);
-            }
+        if (empty($_SESSION['imp']['filteravail'])) {
+            return;
+        }
 
-            foreach ($mbox_list as $val) {
-                // @todo ingo needs to be rewritten to use non-stream access
-                $GLOBALS['registry']->call('mail/applyFilters', array(array('mailbox' => $val)));
-            }
+        $mbox_list = $GLOBALS['imp_search']->isSearchMbox($mbox)
+            ? $GLOBALS['imp_search']->getSearchFolders($mbox)
+            : array($mbox);
+
+        foreach ($mbox_list as $val) {
+            // @todo ingo needs to be rewritten to use non-stream access
+            $GLOBALS['registry']->call('mail/applyFilters', array(array('mailbox' => $val)));
         }
     }
 
@@ -55,21 +52,21 @@ class IMP_Filter {
      * @param boolean $show_link  Show link to the blacklist management in the
      *                            notification message?
      *
-     * @return boolean  True if the messages(s) were delete.
+     * @return boolean  True if the messages(s) were deleted.
      */
-    function blacklistMessage($indices, $show_link = true)
+    public function blacklistMessage($indices, $show_link = true)
     {
-        $this->_processBWlist($indices, _("your blacklist"), 'blacklistFrom', 'showBlacklist', $show_link);
+        if ($this->_processBWlist($indices, _("your blacklist"), 'blacklistFrom', 'showBlacklist', $show_link)) {
+            $imp_message = &IMP_Message::singleton();
 
-        $imp_message = &IMP_Message::singleton();
-        $msg_count = $imp_message->delete($indices);
-        if ($msg_count) {
-            if ($msg_count == 1) {
-                $GLOBALS['notification']->push(_("The message has been deleted."), 'horde.message');
-            } else {
-                $GLOBALS['notification']->push(_("The messages have been deleted."), 'horde.message');
+            if (($msg_count = $imp_message->delete($indices))) {
+                if ($msg_count == 1) {
+                    $GLOBALS['notification']->push(_("The message has been deleted."), 'horde.message');
+                } else {
+                    $GLOBALS['notification']->push(_("The messages have been deleted."), 'horde.message');
+                }
+                return true;
             }
-            return true;
         }
 
         return false;
@@ -81,39 +78,41 @@ class IMP_Filter {
      * @param array $indices      See IMP::parseIndicesList().
      * @param boolean $show_link  Show link to the whitelist management in the
      *                            notification message?
+     *
+     * @return boolean  True if the messages(s) were whitelisted.
      */
-    function whitelistMessage($indices, $show_link = true)
+    public function whitelistMessage($indices, $show_link = true)
     {
-        $this->_processBWlist($indices, _("your whitelist"), 'whitelistFrom', 'showWhitelist', $show_link);
+        return $this->_processBWlist($indices, _("your whitelist"), 'whitelistFrom', 'showWhitelist', $show_link);
     }
 
     /**
      * Internal function to handle adding addresses to [black|white]list.
      *
-     * @access private
-     *
-     * @param array  $indices  See IMP::parseIndicesList().
+     * @param array $indices   See IMP::parseIndicesList().
      * @param string $descrip  The textual description to use.
      * @param string $reg1     The name of the mail/ registry call to use for
      *                         adding the addresses.
      * @param string $reg2     The name of the mail/ registry call to use for
      *                         linking to the filter management page.
-     * @param boolean link     Show link to the whitelist management in the
+     * @param boolean $link    Show link to the whitelist management in the
      *                         notification message?
+     *
+     * @return boolean  True on success.
      */
-    function _processBWlist($indices, $descrip, $reg1, $reg2, $link)
+    protected function _processBWlist($indices, $descrip, $reg1, $reg2, $link)
     {
         if (!($msgList = IMP::parseIndicesList($indices))) {
             return false;
         }
 
         /* Get the list of from addresses. */
-        // TODO
         $addr = array();
-        foreach ($msgList as $folder => $msgIndices) {
-            $ob = $msg_cache->retrieve($folder, $msgIndices, 32);
-            foreach ($msgIndices as $msg) {
-                $addr[] = $ob[$msg]->header->getFromAddress();
+        foreach ($msgList as $mbox => $msgIndices) {
+            foreach ($msgIndices as $idx) {
+                $contents = &IMP_Contents::singleton($idx . IMP::IDX_SEP . $mbox);
+                $hdr = $contents->getHeaderOb();
+                $addr[] = Horde_Mime_Address::bareAddress($hdr->getValue('from'));
             }
         }
 
@@ -124,6 +123,7 @@ class IMP_Filter {
             $manage_link = Horde::link(Horde::url($GLOBALS['registry']->link('mail/' . $reg2)), sprintf(_("Filters: %s management page"), $descrip)) . _("HERE") . '</a>';
             $GLOBALS['notification']->push(sprintf(_("Click %s to go to %s management page."), $manage_link, $descrip), 'horde.message', array('content.raw'));
         }
-    }
 
+        return true;
+    }
 }