Source for file rfc822address.php
Documentation is available at rfc822address.php
* Contains rfc822 email address function parsing functions.
* @copyright © 2004-2006 The SquirrelMail Project Team
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id: rfc822address.php,v 1.11 2006/07/15 12:00:45 tokul Exp $
* parseRFC822Address: function for parsing RFC822 email address strings and store
* them in an address array
* @param string $address The email address string to parse
* @param integer $iLimit stop on $iLimit parsed addresses
* @author Marc Groot Koerkamp
$sPersonal =
$sEmail =
$sComment =
$sGroup =
'';
$aStack =
$aComment =
$aAddress =
array();
foreach ($aTokens as $sToken) {
if ($iLimit &&
$iLimit ==
count($aAddress)) {
$aComment[] =
substr($sToken,1,-
1);
$sEmail =
$sGroup .
':;';
$aStack =
$aComment =
array();
default:
$aStack[] =
$sToken; break;
/* now do the action again for the last address */
* Do the address array to string translation
* @param array $aAddressList list with email address arrays
* @param array $aProps associative array with properties
* @see parseRFC822Address
* @author Marc Groot Koerkamp
'separator' =>
',', // address separator
'limit' =>
0, // limits returned addresses
'personal' =>
true, // show persnal part
'email' =>
true, // show email part
'best' =>
false, // show personal if available
'encode' =>
false, // encode the personal part
'unique' =>
false, // make email addresses unique.
'exclude' =>
array() // array with exclude addresses
// format of address: mailbox@host
$aNewAddressList =
array();
foreach ($aAddressList as $aAddr) {
if ($aProps['limit'] &&
count($aNewAddressList) ==
$aProps['limit']) {
$sEmail =
($sHost) ?
"$sMailbox@$sHost":
$sMailbox;
if (in_array($sEmail,$aProps['exclude'],true)) {
if (in_array($sEmail,$aEmailUnique,true)) {
$aEmailUnique[] =
$sEmail;
$s .=
($sPersonal) ?
$sPersonal :
$sEmail;
if ($aProps['personal'] &&
$sPersonal) {
if ($aProps['email'] &&
$sEmail) {
$s.=
($s) ?
' <'.
$sEmail.
'>':
'<'.
$sEmail.
'>';
return implode($aProps['separator'],$aNewAddressList);
* Do after address parsing handling. This is used by compose.php and should
* be moved to compose.php.
* The AddressStructure objetc is now obsolete and dependent parts of that will
* be adapted so that it can make use of this function
* After that we can remove the parseAddress method from the Rfc822Header class completely
* so we achieved 1 single instance of parseAddress instead of two like we have now.
* @param array $aAddressList list with email address arrays
* @param array $aProps associative array with properties
* @see parseRFC822Address
* @author Marc Groot Koerkamp
$aProcessedAddress =
array();
foreach ($aAddresses as $aEntry) {
* if the emailaddress does not contain the domainpart it can concern
* an alias or local (in the same domain as the user is) email
* address. In that case we try to look it up in the addressbook or add
if (isset
($aAddr['email'])) {
* if the returned email address concerns multiple email
* addresses we have to process those as well
if (strpos($aAddr['email'],',')) { /* multiple addresses */
/* add the parsed addresses to the processed address array */
/* skip to next address, all processing is done */
} else { /* single address */
$iPosAt =
strpos($aAddr['email'], '@');
if (isset
($aAddr['name'])) {
$aProcessedAddress[] =
$aEntry;
return $aProcessedAddress;
* Internal function for creating an address array
* @return array $aAddr array with personal (0), adl(1), mailbox(2) and host(3) info
* @author Marc Groot Koerkamp
while (count($aStack) &&
!$sEmail) {
if (!$sPersonal &&
count($aComment)) {
// if ($sPersonal && substr($sPersonal,0,2) == '=?') {
// $aAddr[SQM_ADDR_PERSONAL] = encodeHeader($sPersonal);
$iPosAt =
strpos($sEmail,'@');
$aStack =
$aComment =
array();
* Tokenizer function for parsing the RFC822 email address string
* @param string $address The email address string to parse
* @author Marc Groot Koerkamp
$aSpecials =
array('(' ,'<' ,',' ,';' ,':');
$aReplace =
array(' (',' <',' ,',' ;',' :');
$iEnd =
strpos($address,'>',$i+
1);
$sToken =
substr($address,$i);
$sToken =
substr($address,$i,$iEnd -
$i +
1);
if ($sToken) $aTokens[] =
$sToken;
$iEnd =
strpos($address,$cChar,$i+
1);
$prev_char =
$address{$iEnd-
1};
while ($prev_char ===
'\\' &&
substr($address,$iEnd-
2,2) !==
'\\\\') {
$iEnd =
strpos($address,$cChar,$iEnd+
1);
$prev_char =
$address{$iEnd-
1};
$sToken =
substr($address,$i);
// also remove the surrounding quotes
$sToken =
substr($address,$i+
1,$iEnd -
$i -
1);
if ($sToken) $aTokens[] =
$sToken;
$iEnd =
strpos($address,')',$i);
$sToken =
substr($address,$i);
while (($iDepth >
0) &&
(++
$iComment <
$iCnt)) {
$cCharComment =
$address{$iComment};
$sToken =
substr($address,$i,$iComment -
$i +
1);
$sToken =
substr($address,$i,$iEnd -
$i +
1);
// check the next token in case comments appear in the middle of email addresses
$prevToken =
end($aTokens);
if (!in_array($prevToken,$aSpecials,true)) {
if ($i+
1<
strlen($address) &&
!in_array($address{$i+
1},$aSpecials,true)) {
$iEnd =
strpos($address,' ',$i+
1);
$sNextToken =
trim(substr($address,$i+
1,$iEnd -
$i -
1));
// create token and add it again
$sNewToken =
$prevToken .
$sNextToken;
if($sNewToken) $aTokens[] =
$sNewToken;
if ($sToken) $aTokens[] =
$sToken;
$iEnd =
strpos($address,' ',$i+
1);
if ($sToken) $aTokens[] =
$sToken;
Documentation generated on Sat, 07 Oct 2006 16:13:17 +0300 by phpDocumentor 1.3.0RC6