Added address lookup callback function argument for parseAddress.
authorstekkel <stekkel@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Fri, 27 Dec 2002 12:24:12 +0000 (12:24 +0000)
committerstekkel <stekkel@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Fri, 27 Dec 2002 12:24:12 +0000 (12:24 +0000)
In stable we verified addresses against the addressbook. In devel this
functionality was forgotten.
Note: Required php version 4.0.4 due to the use of call_user_func_array.

git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@4313 7612ce4b-ef26-0410-bec9-ea0150e637f0

class/mime/Rfc822Header.class.php

index 913fcf1fbaa753fc18f64ed9bdcc0849b080fdbc..f4db5a0294d3dd4e6c03dce8228928de7f80db60 100644 (file)
@@ -195,9 +195,24 @@ class Rfc822Header {
                 break;
         }
     }
-
+    /*
+     * parseAddress: recursive function for parsing address strings and store 
+     *               them in an address stucture object.
+     *               input: $address = string
+     *                      $ar      = boolean (return array instead of only the
+     *                                 first element)
+     *                      $addr_ar = array with parsed addresses
+     *                      $group   = string
+     *                      $host    = string (default domainname in case of 
+     *                                 addresses without a domainname)
+     *                      $lookup  = callback function (for lookup address
+     *                                 strings which are probably nicks
+     *                                 (without @ ) ) 
+     *               output: array with addressstructure objects or only one
+     *                       address_structure object.
+     */
     function parseAddress
-    ($address, $ar=false, $addr_ar = array(), $group = '', $host='') {
+    ($address, $ar=false, $addr_ar = array(), $group = '', $host='',$lookup=false) {
         $pos = 0;
         $j = strlen($address);
         $name = '';
@@ -237,7 +252,6 @@ class Rfc822Header {
                     $pos = $addr_start + 1;
                     break;
                 case ',':  /* we reached a delimiter */
-//case ';':
                     if ($addr == '') {
                         $addr = substr($address, 0, $pos);
                     } else if ($name == '') {
@@ -252,9 +266,23 @@ class Rfc822Header {
                         $addr_structure->mailbox = substr($addr, 0, $at);
                         $addr_structure->host = substr($addr, $at+1);
                     } else {
-                        $addr_structure->mailbox = $addr;
-                       if ($host) {
-                          $addr_structure->host = $host;
+                       /* if lookup function */
+                       if ($lookup) {
+                           $aAddr = call_user_func_array($lookup,array($addr));
+                           if (isset($aAddr['email'])) {
+                               $at = strpos($aAddr['email'], '@');
+                               $addr_structure->mailbox = substr($aAddr['email'], 0, $at);
+                               $addr_structure->host = substr($aAddr['email'], $at+1);
+                               if (isset($aAddr['name'])) {
+                                   $addr_structure->personal = $aAddr['name'];
+                               }
+                           }
+                       }
+                       if (!isset($addr_structure->mailbox)) {
+                           $addr_structure->mailbox = trim($addr);
+                           if ($host) {
+                               $addr_structure->host = $host;
+                           }
                        }
                     }
                     $address = trim(substr($address, $pos+1));
@@ -298,9 +326,23 @@ class Rfc822Header {
             $addr_structure->mailbox = trim(substr($addr, 0, $at));
             $addr_structure->host = trim(substr($addr, $at+1));
         } else {
-            $addr_structure->mailbox = trim($addr);
-            if ($host) {
-              $addr_structure->host = $host;
+           /* if lookup function */
+           if ($lookup) {
+               $aAddr = call_user_func_array($lookup,array($addr));
+               if (isset($aAddr['email'])) {
+                   $at = strpos($aAddr['email'], '@');
+                    $addr_structure->mailbox = substr($aAddr['email'], 0, $at);
+                    $addr_structure->host = substr($aAddr['email'], $at+1);
+                   if (isset($aAddr['name'])) {
+                       $addr_structure->personal = $aAddr['name'];
+                   }
+               }
+           }
+           if (!isset($addr_structure->mailbox)) {
+                $addr_structure->mailbox = trim($addr);
+               if ($host) {
+                   $addr_structure->host = $host;
+               }
            }
         }
         if ($group && $addr == '') { /* no addresses found in group */