From e74ba3787a01c5b03e16999475e4fdd2401e38d0 Mon Sep 17 00:00:00 2001 From: stekkel Date: Fri, 27 Dec 2002 12:24:12 +0000 Subject: [PATCH] Added address lookup callback function argument for parseAddress. 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 | 60 ++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 9 deletions(-) diff --git a/class/mime/Rfc822Header.class.php b/class/mime/Rfc822Header.class.php index 913fcf1f..f4db5a02 100644 --- a/class/mime/Rfc822Header.class.php +++ b/class/mime/Rfc822Header.class.php @@ -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 */ -- 2.25.1