ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
Mail_RFC822 Class Reference
+ Collaboration diagram for Mail_RFC822:

Public Member Functions

 Mail_RFC822 ($address=null, $default_domain=null, $nest_groups=null, $validate=null, $limit=null)
 Sets up the object.
 parseAddressList ($address=null, $default_domain=null, $nest_groups=null, $validate=null, $limit=null)
 Starts the whole process.
 _splitAddresses ($address)
 Splits an address into separate addresses.
 _isGroup ($address)
 Checks for a group at the start of the string.
 _splitCheck ($parts, $char)
 A common function that will check an exploded string.
 _hasUnclosedQuotes ($string)
 Checks if a string has unclosed quotes or not.
 _hasUnclosedBrackets ($string, $chars)
 Checks if a string has an unclosed brackets or not.
 _hasUnclosedBracketsSub ($string, &$num, $char)
 Sub function that is used only by hasUnclosedBrackets().
 _validateAddress ($address)
 Function to begin checking the address.
 _validatePhrase ($phrase)
 Function to validate a phrase.
 _validateAtom ($atom)
 Function to validate an atom which from rfc822 is: atom = 1*<any CHAR except specials, SPACE and CTLs>
 _validateQuotedString ($qstring)
 Function to validate quoted string, which is: quoted-string = <"> *(qtext/quoted-pair) <">
 validateMailbox (&$mailbox)
 Function to validate a mailbox, which is: mailbox = addr-spec ; simple address / phrase route-addr ; name and route-addr.
 _validateRouteAddr ($route_addr)
 This function validates a route-addr which is: route-addr = "<" [route] addr-spec ">".
 _validateRoute ($route)
 Function to validate a route, which is: route = 1#("@" domain) ":".
 _validateDomain ($domain)
 Function to validate a domain, though this is not quite what you expect of a strict internet domain.
 _validateSubdomain ($subdomain)
 Function to validate a subdomain: subdomain = domain-ref / domain-literal.
 _validateDliteral ($dliteral)
 Function to validate a domain literal: domain-literal = "[" *(dtext / quoted-pair) "]".
 _validateAddrSpec ($addr_spec)
 Function to validate an addr-spec.
 _validateLocalPart ($local_part)
 Function to validate the local part of an address: local-part = word *("." word)
 approximateCount ($data)
 Returns an approximate count of how many addresses are in the given string.
 isValidInetAddress ($data, $strict=false)
 This is a email validating function separate to the rest of the class.

Data Fields

 $address = ''
 The address being parsed by the RFC822 object.
 $default_domain = 'localhost'
 The default domain to use for unqualified addresses.
 $nestGroups = true
 Should we return a nested array showing groups, or flatten everything?
 $validate = true
 Whether or not to validate atoms for non-ascii characters.
 $addresses = array()
 The array of raw addresses built up as we parse.
 $structure = array()
 The final array of parsed address information that we build up.
 $error = null
 The current error message, if any.
 $index = null
 An internal counter/pointer.
 $num_groups = 0
 The number of groups that have been found in the address list.
 $mailRFC822 = true
 A variable so that we can tell whether or not we're inside a Mail_RFC822 object.
 $limit = null
 A limit after which processing stops.

Detailed Description

Definition at line 70 of file RFC822.php.

Member Function Documentation

Mail_RFC822::_hasUnclosedBrackets (   $string,
  $chars 
)

Checks if a string has an unclosed brackets or not.

IMPORTANT: This function handles both angle brackets and square brackets;

private

Parameters
string$stringThe string to check.
string$charsThe characters to check for.
Returns
boolean True if there are unclosed brackets inside the string, false otherwise.

Definition at line 400 of file RFC822.php.

References _hasUnclosedBracketsSub().

Referenced by _splitCheck().

{
$num_angle_start = substr_count($string, $chars[0]);
$num_angle_end = substr_count($string, $chars[1]);
$this->_hasUnclosedBracketsSub($string, $num_angle_start, $chars[0]);
$this->_hasUnclosedBracketsSub($string, $num_angle_end, $chars[1]);
if ($num_angle_start < $num_angle_end) {
$this->error = 'Invalid address spec. Unmatched quote or bracket (' . $chars . ')';
return false;
} else {
return ($num_angle_start > $num_angle_end);
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Mail_RFC822::_hasUnclosedBracketsSub (   $string,
$num,
  $char 
)

Sub function that is used only by hasUnclosedBrackets().

private

Parameters
string$stringThe string to check.
integer&$numThe number of occurences.
string$charThe character to count.
Returns
integer The number of occurences of $char in $string, adjusted for backslashes.

Definition at line 425 of file RFC822.php.

References _hasUnclosedQuotes().

Referenced by _hasUnclosedBrackets().

{
$parts = explode($char, $string);
for ($i = 0; $i < count($parts); $i++){
if (substr($parts[$i], -1) == '\\' || $this->_hasUnclosedQuotes($parts[$i]))
$num--;
if (isset($parts[$i + 1]))
$parts[$i + 1] = $parts[$i] . $char . $parts[$i + 1];
}
return $num;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Mail_RFC822::_hasUnclosedQuotes (   $string)

Checks if a string has unclosed quotes or not.

private

Parameters
string$stringThe string to check.
Returns
boolean True if there are unclosed quotes inside the string, false otherwise.

Definition at line 363 of file RFC822.php.

Referenced by _hasUnclosedBracketsSub(), and _splitCheck().

{
$string = trim($string);
$iMax = strlen($string);
$in_quote = false;
$i = $slashes = 0;
for (; $i < $iMax; ++$i) {
switch ($string[$i]) {
case '\\':
++$slashes;
break;
case '"':
if ($slashes % 2 == 0) {
$in_quote = !$in_quote;
}
// Fall through to default action below.
default:
$slashes = 0;
break;
}
}
return $in_quote;
}

+ Here is the caller graph for this function:

Mail_RFC822::_isGroup (   $address)

Checks for a group at the start of the string.

private

Parameters
string$addressThe address to check.
Returns
boolean Whether or not there is a group at the start of the string.

Definition at line 305 of file RFC822.php.

References $address, and _splitCheck().

Referenced by _splitAddresses().

{
// First comma not in quotes, angles or escaped:
$parts = explode(',', $address);
$string = $this->_splitCheck($parts, ',');
// Now we have the first address, we can reliably check for a
// group by searching for a colon that's not escaped or in
// quotes or angle brackets.
if (count($parts = explode(':', $string)) > 1) {
$string2 = $this->_splitCheck($parts, ':');
return ($string2 !== $string);
} else {
return false;
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Mail_RFC822::_splitAddresses (   $address)

Splits an address into separate addresses.

private

Parameters
string$addressThe addresses to split.
Returns
boolean Success or failure.

Definition at line 229 of file RFC822.php.

References $address, _isGroup(), and _splitCheck().

Referenced by parseAddressList().

{
if (!empty($this->limit) && count($this->addresses) == $this->limit) {
return '';
}
if ($this->_isGroup($address) && !isset($this->error)) {
$split_char = ';';
$is_group = true;
} elseif (!isset($this->error)) {
$split_char = ',';
$is_group = false;
} elseif (isset($this->error)) {
return false;
}
// Split the string based on the above ten or so lines.
$parts = explode($split_char, $address);
$string = $this->_splitCheck($parts, $split_char);
// If a group...
if ($is_group) {
// If $string does not contain a colon outside of
// brackets/quotes etc then something's fubar.
// First check there's a colon at all:
if (strpos($string, ':') === false) {
$this->error = 'Invalid address: ' . $string;
return false;
}
// Now check it's outside of brackets/quotes:
if (!$this->_splitCheck(explode(':', $string), ':')) {
return false;
}
// We must have a group at this point, so increase the counter:
$this->num_groups++;
}
// $string now contains the first full address/group.
// Add to the addresses array.
$this->addresses[] = array(
'address' => trim($string),
'group' => $is_group
);
// Remove the now stored address from the initial line, the +1
// is to account for the explode character.
$address = trim(substr($address, strlen($string) + 1));
// If the next char is a comma and this was a group, then
// there are more addresses, otherwise, if there are any more
// chars, then there is another address.
if ($is_group && substr($address, 0, 1) == ','){
$address = trim(substr($address, 1));
return $address;
} elseif (strlen($address) > 0) {
return $address;
} else {
return '';
}
// If you got here then something's off
return false;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Mail_RFC822::_splitCheck (   $parts,
  $char 
)

A common function that will check an exploded string.

private

Parameters
array$partsThe exloded string.
string$charThe char that was exploded on.
Returns
mixed False if the string contains unclosed quotes/brackets, or the string on success.

Definition at line 330 of file RFC822.php.

References _hasUnclosedBrackets(), and _hasUnclosedQuotes().

Referenced by _isGroup(), _splitAddresses(), _validateAddress(), _validateAddrSpec(), _validateDomain(), _validateLocalPart(), _validatePhrase(), _validateRouteAddr(), and validateMailbox().

{
$string = $parts[0];
for ($i = 0; $i < count($parts); $i++) {
if ($this->_hasUnclosedQuotes($string)
|| $this->_hasUnclosedBrackets($string, '<>')
|| $this->_hasUnclosedBrackets($string, '[]')
|| $this->_hasUnclosedBrackets($string, '()')
|| substr($string, -1) == '\\') {
if (isset($parts[$i + 1])) {
$string = $string . $char . $parts[$i + 1];
} else {
$this->error = 'Invalid address spec. Unclosed bracket or quotes';
return false;
}
} else {
$this->index = $i;
break;
}
}
return $string;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Mail_RFC822::_validateAddress (   $address)

Function to begin checking the address.

private

Parameters
string$addressThe address to validate.
Returns
mixed False on failure, or a structured array of address information on success.

Definition at line 445 of file RFC822.php.

References $address, $addresses, $structure, _splitCheck(), _validatePhrase(), and validateMailbox().

Referenced by parseAddressList().

{
$is_group = false;
$addresses = array();
if ($address['group']) {
$is_group = true;
// Get the group part of the name
$parts = explode(':', $address['address']);
$groupname = $this->_splitCheck($parts, ':');
$structure = array();
// And validate the group part of the name.
if (!$this->_validatePhrase($groupname)){
$this->error = 'Group name did not validate.';
return false;
} else {
// Don't include groups if we are not nesting
// them. This avoids returning invalid addresses.
if ($this->nestGroups) {
$structure = new stdClass;
$structure->groupname = $groupname;
}
}
$address['address'] = ltrim(substr($address['address'], strlen($groupname . ':')));
}
// If a group then split on comma and put into an array.
// Otherwise, Just put the whole address in an array.
if ($is_group) {
while (strlen($address['address']) > 0) {
$parts = explode(',', $address['address']);
$addresses[] = $this->_splitCheck($parts, ',');
$address['address'] = trim(substr($address['address'], strlen(end($addresses) . ',')));
}
} else {
$addresses[] = $address['address'];
}
// Check that $addresses is set, if address like this:
// Groupname:;
// Then errors were appearing.
if (!count($addresses)){
$this->error = 'Empty group.';
return false;
}
// Trim the whitespace from all of the address strings.
array_map('trim', $addresses);
// Validate each mailbox.
// Format could be one of: name <geezer@domain.com>
// geezer@domain.com
// geezer
// ... or any other format valid by RFC 822.
for ($i = 0; $i < count($addresses); $i++) {
if (!$this->validateMailbox($addresses[$i])) {
if (empty($this->error)) {
$this->error = 'Validation failed for: ' . $addresses[$i];
}
return false;
}
}
// Nested format
if ($this->nestGroups) {
if ($is_group) {
$structure->addresses = $addresses;
} else {
}
// Flat format
} else {
if ($is_group) {
$structure = array_merge($structure, $addresses);
} else {
}
}
return $structure;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Mail_RFC822::_validateAddrSpec (   $addr_spec)

Function to validate an addr-spec.

addr-spec = local-part "@" domain

private

Parameters
string$addr_specThe string to check.
Returns
mixed False on failure, or the validated addr-spec on success.

Definition at line 857 of file RFC822.php.

References $default_domain, _splitCheck(), _validateDomain(), and _validateLocalPart().

Referenced by _validateRouteAddr(), and validateMailbox().

{
$addr_spec = trim($addr_spec);
// Split on @ sign if there is one.
if (strpos($addr_spec, '@') !== false) {
$parts = explode('@', $addr_spec);
$local_part = $this->_splitCheck($parts, '@');
$domain = substr($addr_spec, strlen($local_part . '@'));
// No @ sign so assume the default domain.
} else {
$local_part = $addr_spec;
}
if (($local_part = $this->_validateLocalPart($local_part)) === false) return false;
if (($domain = $this->_validateDomain($domain)) === false) return false;
// Got here so return successful.
return array('local_part' => $local_part, 'domain' => $domain);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Mail_RFC822::_validateAtom (   $atom)

Function to validate an atom which from rfc822 is: atom = 1*<any CHAR except specials, SPACE and CTLs>

If validation ($this->validate) has been turned off, then validateAtom() doesn't actually check anything. This is so that you can split a list of addresses up before encoding personal names (umlauts, etc.), for example.

private

Parameters
string$atomThe string to check.
Returns
boolean Success or failure.

Definition at line 579 of file RFC822.php.

Referenced by _validatePhrase(), and _validateSubdomain().

{
if (!$this->validate) {
// Validation has been turned off; assume the atom is okay.
return true;
}
// Check for any char from ASCII 0 - ASCII 127
// mjansen patch 16 Sep 2015 start
// Check for specials:
if (preg_match('/[][()<>@,;\\:". ]/', $atom)) {
return false;
}
// Check for control characters (ASCII 0-31):
if (preg_match('/[\\x00-\\x1F]+/', $atom)) {
return false;
}
#16291
#17618
if (!(bool)preg_match('//u', $atom)) {
return false;
}
// mjansen patch 16 Sep 2015 end
return true;
}

+ Here is the caller graph for this function:

Mail_RFC822::_validateDliteral (   $dliteral)

Function to validate a domain literal: domain-literal = "[" *(dtext / quoted-pair) "]".

private

Parameters
string$dliteralThe string to check.
Returns
boolean Success or failure.

Definition at line 843 of file RFC822.php.

Referenced by _validateSubdomain().

{
return !preg_match('/(.)[][\x0D\\\\]/', $dliteral, $matches) && $matches[1] != '\\';
}

+ Here is the caller graph for this function:

Mail_RFC822::_validateDomain (   $domain)

Function to validate a domain, though this is not quite what you expect of a strict internet domain.

domain = sub-domain *("." sub-domain)

private

Parameters
string$domainThe string to check.
Returns
mixed False on failure, or the validated domain on success.

Definition at line 795 of file RFC822.php.

References _splitCheck(), and _validateSubdomain().

Referenced by _validateAddrSpec(), and _validateRoute().

{
// Note the different use of $subdomains and $sub_domains
$subdomains = explode('.', $domain);
while (count($subdomains) > 0) {
$sub_domains[] = $this->_splitCheck($subdomains, '.');
for ($i = 0; $i < $this->index + 1; $i++)
array_shift($subdomains);
}
foreach ($sub_domains as $sub_domain) {
if (!$this->_validateSubdomain(trim($sub_domain)))
return false;
}
// Managed to get here, so return input.
return $domain;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Mail_RFC822::_validateLocalPart (   $local_part)

Function to validate the local part of an address: local-part = word *("." word)

private

Parameters
string$local_part
Returns
mixed False on failure, or the validated local part on success.

Definition at line 888 of file RFC822.php.

References _splitCheck(), and _validatePhrase().

Referenced by _validateAddrSpec().

{
$parts = explode('.', $local_part);
$words = array();
// Split the local_part into words.
while (count($parts) > 0){
$words[] = $this->_splitCheck($parts, '.');
for ($i = 0; $i < $this->index + 1; $i++) {
array_shift($parts);
}
}
// Validate each word.
foreach ($words as $word) {
// If this word contains an unquoted space, it is invalid. (6.2.4)
if (strpos($word, ' ') && $word[0] !== '"')
{
return false;
}
if ($this->_validatePhrase(trim($word)) === false) return false;
}
// Managed to get here, so return the input.
return $local_part;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Mail_RFC822::_validatePhrase (   $phrase)

Function to validate a phrase.

private

Parameters
string$phraseThe phrase to check.
Returns
boolean Success or failure.

Definition at line 538 of file RFC822.php.

References _splitCheck(), _validateAtom(), and _validateQuotedString().

Referenced by _validateAddress(), _validateLocalPart(), and validateMailbox().

{
// Splits on one or more Tab or space.
$parts = preg_split('/[ \\x09]+/', $phrase, -1, PREG_SPLIT_NO_EMPTY);
$phrase_parts = array();
while (count($parts) > 0){
$phrase_parts[] = $this->_splitCheck($parts, ' ');
for ($i = 0; $i < $this->index + 1; $i++)
array_shift($parts);
}
foreach ($phrase_parts as $part) {
// If quoted string:
if (substr($part, 0, 1) == '"') {
if (!$this->_validateQuotedString($part)) {
return false;
}
continue;
}
// Otherwise it's an atom:
if (!$this->_validateAtom($part)) return false;
}
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Mail_RFC822::_validateQuotedString (   $qstring)

Function to validate quoted string, which is: quoted-string = <"> *(qtext/quoted-pair) <">

private

Parameters
string$qstringThe string to check
Returns
boolean Success or failure.

Definition at line 615 of file RFC822.php.

Referenced by _validatePhrase().

{
// Leading and trailing "
$qstring = substr($qstring, 1, -1);
// Perform check, removing quoted characters first.
return !preg_match('/[\x0D\\\\"]/', preg_replace('/\\\\./', '', $qstring));
}

+ Here is the caller graph for this function:

Mail_RFC822::_validateRoute (   $route)

Function to validate a route, which is: route = 1#("@" domain) ":".

private

Parameters
string$routeThe string to check.
Returns
mixed False on failure, or the validated $route on success.

Definition at line 772 of file RFC822.php.

References _validateDomain().

Referenced by _validateRouteAddr().

{
// Split on comma.
$domains = explode(',', trim($route));
foreach ($domains as $domain) {
$domain = str_replace('@', '', trim($domain));
if (!$this->_validateDomain($domain)) return false;
}
return $route;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Mail_RFC822::_validateRouteAddr (   $route_addr)

This function validates a route-addr which is: route-addr = "<" [route] addr-spec ">".

Angle brackets have already been removed at the point of getting to this function.

private

Parameters
string$route_addrThe string to check.
Returns
mixed False on failure, or an array containing validated address/route information on success.

Definition at line 722 of file RFC822.php.

References _splitCheck(), _validateAddrSpec(), and _validateRoute().

Referenced by validateMailbox().

{
// Check for colon.
if (strpos($route_addr, ':') !== false) {
$parts = explode(':', $route_addr);
$route = $this->_splitCheck($parts, ':');
} else {
$route = $route_addr;
}
// If $route is same as $route_addr then the colon was in
// quotes or brackets or, of course, non existent.
if ($route === $route_addr){
unset($route);
$addr_spec = $route_addr;
if (($addr_spec = $this->_validateAddrSpec($addr_spec)) === false) {
return false;
}
} else {
// Validate route part.
if (($route = $this->_validateRoute($route)) === false) {
return false;
}
$addr_spec = substr($route_addr, strlen($route . ':'));
// Validate addr-spec part.
if (($addr_spec = $this->_validateAddrSpec($addr_spec)) === false) {
return false;
}
}
if (isset($route)) {
$return['adl'] = $route;
} else {
$return['adl'] = '';
}
$return = array_merge($return, $addr_spec);
return $return;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Mail_RFC822::_validateSubdomain (   $subdomain)

Function to validate a subdomain: subdomain = domain-ref / domain-literal.

private

Parameters
string$subdomainThe string to check.
Returns
boolean Success or failure.

Definition at line 823 of file RFC822.php.

References _validateAtom(), and _validateDliteral().

Referenced by _validateDomain().

{
if (preg_match('|^\[(.*)]$|', $subdomain, $arr)){
if (!$this->_validateDliteral($arr[1])) return false;
} else {
if (!$this->_validateAtom($subdomain)) return false;
}
// Got here, so return successful.
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Mail_RFC822::approximateCount (   $data)

Returns an approximate count of how many addresses are in the given string.

This is APPROXIMATE as it only splits based on a comma which has no preceding backslash. Could be useful as large amounts of addresses will end up producing large structures when used with parseAddressList().

Parameters
string$dataAddresses to count
Returns
int Approximate count

Definition at line 926 of file RFC822.php.

{
return count(preg_split('/(?<!\\\\),/', $data));
}
Mail_RFC822::isValidInetAddress (   $data,
  $strict = false 
)

This is a email validating function separate to the rest of the class.

It simply validates whether an email is of the common internet form: <user><domain>. This can be sufficient for most people. Optional stricter mode can be utilised which restricts mailbox characters allowed to alphanumeric, full stop, hyphen and underscore.

Parameters
string$dataAddress to check
boolean$strictOptional stricter mode
Returns
mixed False if it fails, an indexed array username/domain if it matches

Definition at line 944 of file RFC822.php.

{
$regex = $strict ? '/^([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})$/i' : '/^([*+!.&#$|\'\\%\/0-9a-z^_`{}=?~:-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})$/i';
if (preg_match($regex, trim($data), $matches)) {
return array($matches[1], $matches[2]);
} else {
return false;
}
}
Mail_RFC822::Mail_RFC822 (   $address = null,
  $default_domain = null,
  $nest_groups = null,
  $validate = null,
  $limit = null 
)

Sets up the object.

The address must either be set here or when calling parseAddressList(). One or the other.

public

Parameters
string$addressThe address(es) to validate.
string$default_domainDefault domain/host etc. If not supplied, will be set to localhost.
boolean$nest_groupsWhether to return the structure with groups nested for easier viewing.
boolean$validateWhether to validate atoms. Turn this off if you need to run addresses through before encoding the personal names, for instance.
Returns
object Mail_RFC822 A new Mail_RFC822 object.

Definition at line 152 of file RFC822.php.

References $address, $default_domain, $limit, and $validate.

Referenced by parseAddressList().

{
if (isset($address)) $this->address = $address;
if (isset($default_domain)) $this->default_domain = $default_domain;
if (isset($nest_groups)) $this->nestGroups = $nest_groups;
if (isset($validate)) $this->validate = $validate;
if (isset($limit)) $this->limit = $limit;
}

+ Here is the caller graph for this function:

Mail_RFC822::parseAddressList (   $address = null,
  $default_domain = null,
  $nest_groups = null,
  $validate = null,
  $limit = null 
)

Starts the whole process.

The address must either be set here or when creating the object. One or the other.

public

Parameters
string$addressThe address(es) to validate.
string$default_domainDefault domain/host etc.
boolean$nest_groupsWhether to return the structure with groups nested for easier viewing.
boolean$validateWhether to validate atoms. Turn this off if you need to run addresses through before encoding the personal names, for instance.
Returns
array A structured array of addresses.

Definition at line 173 of file RFC822.php.

References $address, $default_domain, $limit, $structure, $valid, $validate, _splitAddresses(), _validateAddress(), Mail_RFC822(), and PEAR\raiseError().

Referenced by Mail\parseRecipients().

{
if (!isset($this) || !isset($this->mailRFC822)) {
$obj = new Mail_RFC822($address, $default_domain, $nest_groups, $validate, $limit);
return $obj->parseAddressList();
}
if (isset($address)) $this->address = $address;
if (isset($default_domain)) $this->default_domain = $default_domain;
if (isset($nest_groups)) $this->nestGroups = $nest_groups;
if (isset($validate)) $this->validate = $validate;
if (isset($limit)) $this->limit = $limit;
$this->structure = array();
$this->addresses = array();
$this->error = null;
$this->index = null;
// Unfold any long lines in $this->address.
$this->address = preg_replace('/\r?\n/', "\r\n", $this->address);
$this->address = preg_replace('/\r\n(\t| )+/', ' ', $this->address);
while ($this->address = $this->_splitAddresses($this->address));
if ($this->address === false || isset($this->error)) {
require_once 'PEAR.php';
return PEAR::raiseError($this->error);
}
// Validate each address individually. If we encounter an invalid
// address, stop iterating and return an error immediately.
foreach ($this->addresses as $address) {
$valid = $this->_validateAddress($address);
if ($valid === false || isset($this->error)) {
require_once 'PEAR.php';
return PEAR::raiseError($this->error);
}
if (!$this->nestGroups) {
$this->structure = array_merge($this->structure, $valid);
} else {
$this->structure[] = $valid;
}
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Mail_RFC822::validateMailbox ( $mailbox)

Function to validate a mailbox, which is: mailbox = addr-spec ; simple address / phrase route-addr ; name and route-addr.

public

Parameters
string&$mailboxThe string to check.
Returns
boolean Success or failure.

Definition at line 633 of file RFC822.php.

References $comment, _splitCheck(), _validateAddrSpec(), _validatePhrase(), and _validateRouteAddr().

Referenced by _validateAddress().

{
// A couple of defaults.
$phrase = '';
$comment = '';
$comments = array();
// Catch any RFC822 comments and store them separately.
$_mailbox = $mailbox;
while (strlen(trim($_mailbox)) > 0) {
$parts = explode('(', $_mailbox);
$before_comment = $this->_splitCheck($parts, '(');
if ($before_comment != $_mailbox) {
// First char should be a (.
$comment = substr(str_replace($before_comment, '', $_mailbox), 1);
$parts = explode(')', $comment);
$comment = $this->_splitCheck($parts, ')');
$comments[] = $comment;
// +2 is for the brackets
$_mailbox = substr($_mailbox, strpos($_mailbox, '('.$comment)+strlen($comment)+2);
} else {
break;
}
}
foreach ($comments as $comment) {
$mailbox = str_replace("($comment)", '', $mailbox);
}
$mailbox = trim($mailbox);
// Check for name + route-addr
if (substr($mailbox, -1) == '>' && substr($mailbox, 0, 1) != '<') {
$parts = explode('<', $mailbox);
$name = $this->_splitCheck($parts, '<');
$phrase = trim($name);
$route_addr = trim(substr($mailbox, strlen($name.'<'), -1));
if ($this->_validatePhrase($phrase) === false || ($route_addr = $this->_validateRouteAddr($route_addr)) === false) {
return false;
}
// Only got addr-spec
} else {
// First snip angle brackets if present.
if (substr($mailbox, 0, 1) == '<' && substr($mailbox, -1) == '>') {
$addr_spec = substr($mailbox, 1, -1);
} else {
$addr_spec = $mailbox;
}
if (($addr_spec = $this->_validateAddrSpec($addr_spec)) === false) {
return false;
}
}
// Construct the object that will be returned.
$mbox = new stdClass();
// Add the phrase (even if empty) and comments
$mbox->personal = $phrase;
$mbox->comment = isset($comments) ? $comments : array();
if (isset($route_addr)) {
$mbox->mailbox = $route_addr['local_part'];
$mbox->host = $route_addr['domain'];
$route_addr['adl'] !== '' ? $mbox->adl = $route_addr['adl'] : '';
} else {
$mbox->mailbox = $addr_spec['local_part'];
$mbox->host = $addr_spec['domain'];
}
$mailbox = $mbox;
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

string Mail_RFC822::$address = ''

The address being parsed by the RFC822 object.

Definition at line 76 of file RFC822.php.

Referenced by _isGroup(), _splitAddresses(), _validateAddress(), Mail_RFC822(), and parseAddressList().

array Mail_RFC822::$addresses = array()

The array of raw addresses built up as we parse.

Definition at line 100 of file RFC822.php.

Referenced by _validateAddress().

string Mail_RFC822::$default_domain = 'localhost'

The default domain to use for unqualified addresses.

Definition at line 82 of file RFC822.php.

Referenced by _validateAddrSpec(), Mail_RFC822(), and parseAddressList().

string Mail_RFC822::$error = null

The current error message, if any.

Definition at line 112 of file RFC822.php.

integer Mail_RFC822::$index = null

An internal counter/pointer.

Definition at line 118 of file RFC822.php.

int Mail_RFC822::$limit = null

A limit after which processing stops.

Definition at line 138 of file RFC822.php.

Referenced by Mail_RFC822(), and parseAddressList().

boolean Mail_RFC822::$mailRFC822 = true

A variable so that we can tell whether or not we're inside a Mail_RFC822 object.

Definition at line 132 of file RFC822.php.

boolean Mail_RFC822::$nestGroups = true

Should we return a nested array showing groups, or flatten everything?

Definition at line 88 of file RFC822.php.

integer Mail_RFC822::$num_groups = 0

The number of groups that have been found in the address list.

public

Definition at line 125 of file RFC822.php.

array Mail_RFC822::$structure = array()

The final array of parsed address information that we build up.

Definition at line 106 of file RFC822.php.

Referenced by _validateAddress(), and parseAddressList().

boolean Mail_RFC822::$validate = true

Whether or not to validate atoms for non-ascii characters.

Definition at line 94 of file RFC822.php.

Referenced by Mail_RFC822(), and parseAddressList().


The documentation for this class was generated from the following file: