Add filter option to getAddressesFromObject
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 12 Dec 2008 20:09:23 +0000 (13:09 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 12 Dec 2008 20:10:15 +0000 (13:10 -0700)
framework/Mime/lib/Horde/Mime/Address.php

index d524155..a107384 100644 (file)
@@ -192,8 +192,8 @@ class Horde_Mime_Address
      *
      * @param array $addresses  The array of address objects.
      * @param mixed $filter     A user@example.com style bare address to
-     *                          ignore.  If any address matches $filter, it
-     *                          will not be included in the final string.
+     *                          ignore. Either single string or an array of
+     *                          strings.
      *
      * @return string  All of the addresses in a comma-delimited string.
      *                 Returns the empty string on error/no addresses found.
@@ -219,7 +219,9 @@ class Horde_Mime_Address
     /**
      * Return the list of addresses for a header object.
      *
-     * @param array $obs  An array of header objects.
+     * @param array $obs     An array of header objects.
+     * @param mixed $filter  A user@example.com style bare address to ignore.
+     *                       Either single string or an array of strings.
      *
      * @return array  An array of address information. Array elements:
      * <pre>
@@ -231,7 +233,7 @@ class Horde_Mime_Address
      * 'personal' - (string) Personal string
      * </pre>
      */
-    static public function getAddressesFromObject($obs)
+    static public function getAddressesFromObject($obs, $filter = '')
     {
         $ret = array();
 
@@ -261,14 +263,17 @@ class Horde_Mime_Address
 
             $inner = self::writeAddress($ob['mailbox'], $ob['host']);
 
-            /* Generate the new object. */
-            $ret[] = array(
-                'address' => self::addrObject2String($ob),
-                'display' => (empty($ob['personal']) ? '' : $ob['personal'] . ' <') . $inner . (empty($ob['personal']) ? '' : '>'),
-                'host' => $ob['host'],
-                'inner' => $inner,
-                'personal' => $ob['personal']
-            );
+            $addr_string = self::addrObject2String($ob, $filter);
+            if (!empty($addr_string)) {
+                /* Generate the new object. */
+                $ret[] = array(
+                    'address' => $addr_string,
+                    'display' => (empty($ob['personal']) ? '' : $ob['personal'] . ' <') . $inner . (empty($ob['personal']) ? '' : '>'),
+                    'host' => $ob['host'],
+                    'inner' => $inner,
+                    'personal' => $ob['personal']
+                );
+            }
         }
 
         return $ret;