<?php
+
/**
* rfc822address.php
*
- * Copyright (c) 2004 The SquirrelMail Project Team
- * Licensed under the GNU GPL. For full terms see the file COPYING.
- *
* Contains rfc822 email address function parsing functions.
*
- *
+ * @copyright 2004-2021 The SquirrelMail Project Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id$
* @package squirrelmail
*/
-/**
- * Undocumented defines
- */
-if (!defined('SQM_ADDR_PERSONAL')) define('SQM_ADDR_PERSONAL', 0);
-if (!defined('SQM_ADDR_ADLL')) define('SQM_ADDR_ADL', 1);
-if (!defined('SQM_ADDR_MAILBOX')) define('SQM_ADDR_MAILBOX', 2);
-if (!defined('SQM_ADDR_HOST')) define('SQM_ADDR_HOST', 3);
/**
* 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 array $aProps associative array with properties
+ * @param string $address The email address string to parse
+ * @param integer $iLimit stop on $iLimit parsed addresses
* @public
* @author Marc Groot Koerkamp
*
**/
-
-function parseRFC822Address($sAddress,$aProps) {
-// $aPropsDefault = array (
-// 'domain' => '', //
-// 'limit' => 0, // limits returned addresses
-// 'abooklookup' => false); // callback function for addressbook lookup
-//
-// $aProps = is_array($aProps) ? array_merge($aPropsDefault,$aProps) : $aPropsDefault;
-
-// $cbLookup = $aProps['abooklookup'];
-// $sDomain = $aProps['domain'];
- $iLimit = $aProps['limit'];
+function parseRFC822Address($sAddress,$iLimit = 0) {
$aTokens = _getAddressTokens($sAddress);
- $sEmail = $sGroup = '';
+ $sPersonal = $sEmail = $sComment = $sGroup = '';
$aStack = $aComment = $aAddress = array();
foreach ($aTokens as $sToken) {
if ($iLimit && $iLimit == count($aAddress)) {
return $aAddress;
}
- $cChar = $sToken{0};
+ $cChar = $sToken[0];
switch ($cChar)
{
case '=':
case ';':
if ($sGroup) {
$aAddress[] = _createAddressElement($aStack,$aComment,$sEmail);
- $oAddr = end($aAddress);
- if(!$oAddr || ((isset($oAddr)) && !$oAddr->mailbox && !$oAddr->personal)) {
+ $aAddr = end($aAddress);
+ if(!$aAddr || ((isset($aAddr)) && !$aAddr[SQM_ADDR_MAILBOX] && !$aAddr[SQM_ADDR_PERSONAL])) {
$sEmail = $sGroup . ':;';
}
$aAddress[] = _createAddressElement($aStack,$aComment,$sEmail);
return $aAddress;
}
+
/**
* Do the address array to string translation
*
**/
function getAddressString($aAddressList,$aProps) {
$aPropsDefault = array (
- 'separator' => ',', // address separator
+ 'separator' => ', ', // address separator
'limit' => 0, // limits returned addresses
'personal' => true, // show persnal part
'email' => true, // show email part
$aNewAddressList[] = $s;
}
}
- return explode($aProps['seperator'],$aNewAddressList);
+ return implode($aProps['separator'],$aNewAddressList);
}
* @return string
* @public
* @see parseRFC822Address
- * $see Rfc822Header
+ * @see Rfc822Header
* @author Marc Groot Koerkamp
*
**/
$iCnt = strlen($address);
$i = 0;
while ($i < $iCnt) {
- $cChar = $address{$i};
+ $cChar = $address[$i];
switch($cChar)
{
case '<':
$iEnd = strpos($address,$cChar,$i+1);
if ($iEnd) {
// skip escaped quotes
- $prev_char = $address{$iEnd-1};
+ $prev_char = $address[$iEnd-1];
while ($prev_char === '\\' && substr($address,$iEnd-2,2) !== '\\\\') {
$iEnd = strpos($address,$cChar,$iEnd+1);
if ($iEnd) {
- $prev_char = $address{$iEnd-1};
+ $prev_char = $address[$iEnd-1];
} else {
$prev_char = false;
}
$iDepth = 1;
$iComment = $i;
while (($iDepth > 0) && (++$iComment < $iCnt)) {
- $cCharComment = $address{$iComment};
+ $cCharComment = $address[$iComment];
switch($cCharComment) {
case '\\':
++$iComment;
// 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)) {
+ if ($i+1<strlen($address) && !in_array($address[$i+1],$aSpecials,true)) {
$iEnd = strpos($address,' ',$i+1);
if ($iEnd) {
$sNextToken = trim(substr($address,$i+1,$iEnd - $i -1));
}
return $aTokens;
}
-?>
\ No newline at end of file