[dev] Re: [imp] whitelist patch...

Amith Varghese amith at xalan.com
Wed Mar 5 00:14:13 PST 2003


> No, no constants. The error code would be a Notification class -
> 'horde.success', 'horde.error', 'horde.message', or 'horde.warning'.

I've fixed it so that sam uses Notification objects to report success or
failure.  The code now returns a horde.warning if the user is already in the
blacklist/whitelist.  The code also prevents duplicates from being added (if you
select more than one message with the same sender from the mailbox view and add
that to a blacklist/whitelist it will add the first occurrence and warn on the
others).

Ingo should be updated to do the same thing as sam because IMP no longer reports
that the address was added to the blacklist (not that it was working correctly
in the first place)

If there are any questions please let me know

Amith
-------------- next part --------------
Index: sam/lib/api.php
===================================================================
RCS file: /repository/sam/lib/api.php,v
retrieving revision 1.2
diff -u -r1.2 api.php
--- sam/lib/api.php	26 Feb 2003 17:37:30 -0000	1.2
+++ sam/lib/api.php	5 Mar 2003 05:00:30 -0000
@@ -1,6 +1,6 @@
 <?php
 /**
- * Whups external API interface.
+ * Sam external API interface.
  *
  * $Horde: sam/lib/api.php,v 1.2 2003/02/26 17:37:30 jan Exp $
  *
@@ -31,28 +31,47 @@
 {
     require_once dirname(__FILE__) . '/../lib/base.php';
 
-    global $sam;
+    global $sam, $notification;
     $sam->retrieve();
 
     $blacklist_from = $sam->getListOption('blacklist_from');
     $blacklist_from = preg_split('|\s|', trim($blacklist_from));
 
+    // keep track of the original blacklist so we can do error checking later
+    $original_blacklist = $blacklist_from;
+
     if (is_array($addresses)) {
         foreach ($addresses as $address) {
-            if (in_array($address, $blacklist_from)) {
-                return PEAR::raiseError(sprintf(_("%s is already in your blacklist filter.")));
+            if (!in_array($address, $blacklist_from)) {
+                $blacklist_from[] = $address;
             }
-            $blacklist_from[] = $address;
         }
     } else {
-        if (in_array($addresses, $blacklist_from)) {
-            return PEAR::raiseError(sprintf(_("%s is already in your blacklist filter.")));
+        if (!in_array($addresses, $blacklist_from)) {
+            $blacklist_from[] = $addresses;
         }
-        $blacklist_from[] = $addresses;
     }
 
     $sam->setListOption('blacklist_from', implode(' ', $blacklist_from));
-    $sam->store();
+    $result = $sam->store();
+
+    if (is_a($result, 'PEAR_Error')) {
+       foreach (array_merge(array(), $addresses) as $address) {
+           $notification->push(sprintf(_("%s was not added to your blacklist because of a storage error."), $address), 'horde.error');
+       }
+    } else {
+       foreach (array_merge(array(), $addresses) as $address) {
+           if (in_array($address, $original_blacklist)) {
+               $notification->push(sprintf(_("%s is already in your blacklist filter."), $address), 'horde.warning');
+           } else {
+               $notification->push(sprintf(_("The address %s has been added to your blacklist."), $address), 'horde.success');
+
+               // add the address to the list so that if we see it again we
+               // can inform the user that address has already been added 
+               $original_blacklist[] = $address;
+           }
+       }
+    }
 
     return true;
 }
@@ -61,28 +80,47 @@
 {
     require_once dirname(__FILE__) . '/../lib/base.php';
 
-    global $sam;
+    global $sam, $notification;
     $sam->retrieve();
 
     $whitelist_from = $sam->getListOption('whitelist_from');
     $whitelist_from = preg_split('|\s|', trim($whitelist_from));
 
+    // keep track of the original blacklist so we can do error checking later
+    $original_whitelist = $whitelist_from;
+
     if (is_array($addresses)) {
         foreach ($addresses as $address) {
-            if (in_array($address, $whitelist_from)) {
-                return PEAR::raiseError(sprintf(_("%s is already in your whitelist filter.")));
+            if (!in_array($address, $whitelist_from)) {
+                $whitelist_from[] = $address;
             }
-            $whitelist_from[] = $address;
         }
     } else {
-        if (in_array($addresses, $whitelist_from)) {
-            return PEAR::raiseError(sprintf(_("%s is already in your whitelist filter.")));
+        if (!in_array($addresses, $whitelist_from)) {
+            $whitelist_from[] = $addresses;
         }
-        $whitelist_from[] = $addresses;
     }
 
     $sam->setListOption('whitelist_from', implode(' ', $whitelist_from));
-    $sam->store();
+    $result = $sam->store();
+
+    if (is_a($result, 'PEAR_Error')) {
+       foreach (array_merge(array(), $addresses) as $address) {
+           $notification->push(sprintf(_("%s was not added to your whitelist because of a storage error."), $address), 'horde.error');
+       }
+    } else {
+       foreach (array_merge(array(), $addresses) as $address) {
+           if (in_array($address, $original_whitelist)) {
+               $notification->push(sprintf(_("%s is already in your whitelist filter."), $address), 'horde.warning');
+           } else {
+               $notification->push(sprintf(_("The address %s has been added to your whitelist."), $address), 'horde.success');
+               
+               // add the address to the list so that if we see it again we
+               // can inform the user that address has already been added
+               $original_whitelist[] = $address;
+           }
+       }
+    }
 
     return true;
 }
Index: imp/lib/IMP.php
===================================================================
RCS file: /repository/imp/lib/IMP.php,v
retrieving revision 1.370
diff -u -r1.370 IMP.php
--- imp/lib/IMP.php	4 Mar 2003 19:59:26 -0000	1.370
+++ imp/lib/IMP.php	5 Mar 2003 05:03:35 -0000
@@ -431,7 +431,6 @@
         foreach ($indices as $msgnum) {
             $imp_headers = new IMP_Headers($msgnum);
             $from = $imp_headers->getFromAddress();
-            $notification->push(sprintf(_("The address %s has been added to your blacklist."), $from));
             $addr[] = $from;
         }
 
@@ -460,7 +459,6 @@
         foreach ($indices as $msgnum) {
             $imp_headers = new IMP_Headers($msgnum);
             $from = $imp_headers->getFromAddress();
-            $notification->push(sprintf(_("The address %s has been added to your whitelist."), $from));
             $addr[] = $from;
         }
 


More information about the dev mailing list