Do array filtering on store, not retrieve
authorMichael Slusarz <slusarz@curecanti.org>
Sun, 14 Feb 2010 21:42:41 +0000 (14:42 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Mon, 15 Feb 2010 20:29:38 +0000 (13:29 -0700)
ingo/lib/Api.php
ingo/lib/Storage/Blacklist.php
ingo/lib/Storage/Whitelist.php

index 0b3596b..17b9a3d 100644 (file)
@@ -29,18 +29,13 @@ class Ingo_Api extends Horde_Registry_Api
      */
     public function blacklistFrom($addresses)
     {
-        /* Check for '@' entries in $addresses - this would call all mail to
-         * be blacklisted which is most likely not what is desired. */
-        $addresses = array_flip($addresses);
-        unset($addresses['@']);
-
         if (!empty($addresses)) {
             try {
                 $blacklist = $GLOBALS['ingo_storage']->retrieve(Ingo_Storage::ACTION_BLACKLIST);
-                $blacklist->setBlacklist(array_merge($blacklist->getBlacklist(), array_keys($addresses)));
+                $blacklist->setBlacklist(array_merge($blacklist->getBlacklist(), $addresses));
                 $GLOBALS['ingo_storage']->store($blacklist);
                 Ingo::updateScript();
-                foreach (array_keys($addresses) as $from) {
+                foreach ($addresses as $from) {
                     $GLOBALS['notification']->push(sprintf(_("The address \"%s\" has been added to your blacklist."), $from));
                 }
             } catch (Ingo_Exception $e) {
index faf7fe8..912338d 100644 (file)
@@ -26,7 +26,7 @@ class Ingo_Storage_Blacklist extends Ingo_Storage_Rule
      */
     public function setBlacklist($data, $sort = true)
     {
-        $addr = $this->_addressList($data, $sort);
+        $addr = array_filter($this->_addressList($data, $sort), array('Ingo', 'filterEmptyAddress'));
         if (!empty($GLOBALS['conf']['storage']['maxblacklist'])) {
             $addr_count = count($addr);
             if ($addr_count > $GLOBALS['conf']['storage']['maxblacklist']) {
@@ -49,9 +49,7 @@ class Ingo_Storage_Blacklist extends Ingo_Storage_Rule
      */
     public function getBlacklist()
     {
-        return empty($this->_addr)
-            ? array()
-            : array_filter($this->_addr, array('Ingo', 'filterEmptyAddress'));
+        return $this->_addr;
     }
 
     /**
index 6d32181..9194afc 100644 (file)
@@ -30,8 +30,7 @@ class Ingo_Storage_Whitelist extends Ingo_Storage_Rule
      */
     public function setWhitelist($data, $sort = true)
     {
-        $addr = $this->_addressList($data, $sort);
-        $addr = array_filter($addr, array('Ingo', 'filterEmptyAddress'));
+        $addr = array_filter($this->_addressList($data, $sort), array('Ingo', 'filterEmptyAddress'));
         if (!empty($GLOBALS['conf']['storage']['maxwhitelist'])) {
             $addr_count = count($addr);
             if ($addr_count > $GLOBALS['conf']['storage']['maxwhitelist']) {
@@ -47,9 +46,7 @@ class Ingo_Storage_Whitelist extends Ingo_Storage_Rule
      */
     public function getWhitelist()
     {
-        return empty($this->_addr)
-            ? array()
-            : array_filter($this->_addr, array('Ingo', 'filterEmptyAddress'));
+        return $this->_addr;
     }
 
 }