‪TYPO3CMS  ‪main
TYPO3\CMS\Core\Mail\Rfc822AddressesParser Class Reference

Public Member Functions

 __construct ($address=null, $default_domain=null, $validate=null, $limit=null)
 
array parseAddressList ($address=null, $default_domain=null, $validate=null, $limit=null)
 

Protected Member Functions

string false _splitAddresses ($address)
 
bool _isGroup ($address)
 
mixed _splitCheck ($parts, $char)
 
bool _hasUnclosedQuotes ($string)
 
bool _hasUnclosedBrackets ($string, $chars)
 
int _hasUnclosedBracketsSub ($string, &$num, $char)
 
mixed _validateAddress ($address)
 
bool _validatePhrase ($phrase)
 
bool _validateAtom ($atom)
 
bool _validateQuotedString ($qstring)
 
bool validateMailbox (&$mailbox)
 
mixed _validateRouteAddr ($route_addr)
 
string bool _validateRoute ($route)
 
mixed _validateDomain ($domain)
 
bool _validateSubdomain ($subdomain)
 
bool _validateDliteral ($dliteral)
 
mixed _validateAddrSpec ($addr_spec)
 
mixed _validateLocalPart ($local_part)
 

Private Attributes

string false $address = ''
 
string $default_domain = 'localhost'
 
bool $validate = true
 
array $addresses = array( )
 
array $structure = array( )
 
string null $error
 
int null $index
 
int $num_groups = 0
 
int $limit
 

Detailed Description

RFC 822 Email address list validation Utility

What is it?

This class will take an address string, and parse it into it's constituent parts, be that either addresses, groups, or combinations. Nested groups are not supported. The structure it returns is pretty straight forward, and is similar to that provided by the imap_rfc822_parse_adrlist(). Use print_r() to view the structure.

How do I use it?

$address_string = 'My Group: "Richard" <richard@localhost> (A comment), ted@example.com (Ted Bloggs), Barney;';
‪$structure = Mail_RFC822::parseAddressList($address_string, 'example.com', TRUE)
print_r(‪$structure);
Version
Revision
294749

@license BSD

Definition at line 66 of file Rfc822AddressesParser.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Core\Mail\Rfc822AddressesParser::__construct (   $address = null,
  $default_domain = null,
  $validate = null,
  $limit = null 
)

Sets up the object.

Parameters
string$address‪The address(es) to validate.
string$default_domain‪Default domain/host etc. If not supplied, will be set to localhost.
bool$validate‪Whether to validate atoms. Turn this off if you need to run addresses through before encoding the personal names, for instance.
int$limit

Definition at line 130 of file Rfc822AddressesParser.php.

References TYPO3\CMS\Core\Mail\Rfc822AddressesParser\$address, TYPO3\CMS\Core\Mail\Rfc822AddressesParser\$default_domain, TYPO3\CMS\Core\Mail\Rfc822AddressesParser\$limit, and TYPO3\CMS\Core\Mail\Rfc822AddressesParser\$validate.

Member Function Documentation

◆ _hasUnclosedBrackets()

bool TYPO3\CMS\Core\Mail\Rfc822AddressesParser::_hasUnclosedBrackets (   $string,
  $chars 
)
protected

Checks if a string has an unclosed brackets or not. IMPORTANT: This function handles both angle brackets and square brackets;

Parameters
string$string‪The string to check.
string$chars‪The characters to check for.
Returns
‪bool TRUE if there are unclosed brackets inside the string, FALSE otherwise.

Definition at line 357 of file Rfc822AddressesParser.php.

References TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_hasUnclosedBracketsSub().

Referenced by TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_splitCheck().

◆ _hasUnclosedBracketsSub()

int TYPO3\CMS\Core\Mail\Rfc822AddressesParser::_hasUnclosedBracketsSub (   $string,
$num,
  $char 
)
protected

Sub function that is used only by hasUnclosedBrackets().

Parameters
string$string‪The string to check.
int$num‪The number of occurrences.
string$char‪The character to count.
Returns
‪int The number of occurrences of $char in $string, adjusted for backslashes.

Definition at line 379 of file Rfc822AddressesParser.php.

References TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_hasUnclosedQuotes().

Referenced by TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_hasUnclosedBrackets().

◆ _hasUnclosedQuotes()

bool TYPO3\CMS\Core\Mail\Rfc822AddressesParser::_hasUnclosedQuotes (   $string)
protected

Checks if a string has unclosed quotes or not.

Parameters
string$string‪The string to check.
Returns
‪bool TRUE if there are unclosed quotes inside the string,

Definition at line 325 of file Rfc822AddressesParser.php.

Referenced by TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_hasUnclosedBracketsSub(), and TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_splitCheck().

◆ _isGroup()

bool TYPO3\CMS\Core\Mail\Rfc822AddressesParser::_isGroup (   $address)
protected

Checks for a group at the start of the string.

Parameters
string | false$address‪The address to check.
Returns
‪bool Whether or not there is a group at the start of the string.

Definition at line 272 of file Rfc822AddressesParser.php.

References TYPO3\CMS\Core\Mail\Rfc822AddressesParser\$address, and TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_splitCheck().

Referenced by TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_splitAddresses().

◆ _splitAddresses()

string false TYPO3\CMS\Core\Mail\Rfc822AddressesParser::_splitAddresses (   $address)
protected

Splits an address into separate addresses.

Parameters
string | false$address‪The addresses to split.
Returns
‪string|false False on failure.

Definition at line 202 of file Rfc822AddressesParser.php.

References TYPO3\CMS\Core\Mail\Rfc822AddressesParser\$address, TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_isGroup(), and TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_splitCheck().

Referenced by TYPO3\CMS\Core\Mail\Rfc822AddressesParser\parseAddressList().

◆ _splitCheck()

◆ _validateAddress()

mixed TYPO3\CMS\Core\Mail\Rfc822AddressesParser::_validateAddress (   $address)
protected

◆ _validateAddrSpec()

mixed TYPO3\CMS\Core\Mail\Rfc822AddressesParser::_validateAddrSpec (   $addr_spec)
protected

Function to validate an addr-spec.

addr-spec = local-part "@" domain

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

Definition at line 762 of file Rfc822AddressesParser.php.

References TYPO3\CMS\Core\Mail\Rfc822AddressesParser\$default_domain, TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_splitCheck(), TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_validateDomain(), and TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_validateLocalPart().

Referenced by TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_validateRouteAddr(), and TYPO3\CMS\Core\Mail\Rfc822AddressesParser\validateMailbox().

◆ _validateAtom()

bool TYPO3\CMS\Core\Mail\Rfc822AddressesParser::_validateAtom (   $atom)
protected

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.

Parameters
string$atom‪The string to check.
Returns
‪bool Success or failure.

Definition at line 511 of file Rfc822AddressesParser.php.

Referenced by TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_validatePhrase(), and TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_validateSubdomain().

◆ _validateDliteral()

bool TYPO3\CMS\Core\Mail\Rfc822AddressesParser::_validateDliteral (   $dliteral)
protected

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

Parameters
string$dliteral‪The string to check.
Returns
‪bool Success or failure.

Definition at line 748 of file Rfc822AddressesParser.php.

Referenced by TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_validateSubdomain().

◆ _validateDomain()

mixed TYPO3\CMS\Core\Mail\Rfc822AddressesParser::_validateDomain (   $domain)
protected

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

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

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

Definition at line 697 of file Rfc822AddressesParser.php.

References TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_splitCheck(), and TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_validateSubdomain().

Referenced by TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_validateAddrSpec(), and TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_validateRoute().

◆ _validateLocalPart()

mixed TYPO3\CMS\Core\Mail\Rfc822AddressesParser::_validateLocalPart (   $local_part)
protected

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

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

Definition at line 792 of file Rfc822AddressesParser.php.

References TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_splitCheck(), and TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_validatePhrase().

Referenced by TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_validateAddrSpec().

◆ _validatePhrase()

bool TYPO3\CMS\Core\Mail\Rfc822AddressesParser::_validatePhrase (   $phrase)
protected

◆ _validateQuotedString()

bool TYPO3\CMS\Core\Mail\Rfc822AddressesParser::_validateQuotedString (   $qstring)
protected

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

Parameters
string$qstring‪The string to check
Returns
‪bool Success or failure.

Definition at line 540 of file Rfc822AddressesParser.php.

Referenced by TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_validatePhrase().

◆ _validateRoute()

string bool TYPO3\CMS\Core\Mail\Rfc822AddressesParser::_validateRoute (   $route)
protected

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

Parameters
string$route‪The string to check.
Returns
‪string|bool False on failure, or the validated $route on success.

Definition at line 674 of file Rfc822AddressesParser.php.

References TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_validateDomain().

Referenced by TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_validateRouteAddr().

◆ _validateRouteAddr()

mixed TYPO3\CMS\Core\Mail\Rfc822AddressesParser::_validateRouteAddr (   $route_addr)
protected

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.

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

Definition at line 632 of file Rfc822AddressesParser.php.

References TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_splitCheck(), TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_validateAddrSpec(), and TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_validateRoute().

Referenced by TYPO3\CMS\Core\Mail\Rfc822AddressesParser\validateMailbox().

◆ _validateSubdomain()

bool TYPO3\CMS\Core\Mail\Rfc822AddressesParser::_validateSubdomain (   $subdomain)
protected

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

Parameters
string$subdomain‪The string to check.
Returns
‪bool Success or failure.

Definition at line 725 of file Rfc822AddressesParser.php.

References TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_validateAtom(), and TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_validateDliteral().

Referenced by TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_validateDomain().

◆ parseAddressList()

array TYPO3\CMS\Core\Mail\Rfc822AddressesParser::parseAddressList (   $address = null,
  $default_domain = 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.

Parameters
string$address‪The address(es) to validate.
string$default_domain‪Default domain/host etc.
bool$validate‪Whether to validate atoms. Turn this off if you need to run addresses through before encoding the personal names, for instance.
int$limit
Returns
‪array A structured array of addresses.

Definition at line 156 of file Rfc822AddressesParser.php.

References TYPO3\CMS\Core\Mail\Rfc822AddressesParser\$address, TYPO3\CMS\Core\Mail\Rfc822AddressesParser\$default_domain, TYPO3\CMS\Core\Mail\Rfc822AddressesParser\$limit, TYPO3\CMS\Core\Mail\Rfc822AddressesParser\$structure, TYPO3\CMS\Core\Mail\Rfc822AddressesParser\$validate, TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_splitAddresses(), and TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_validateAddress().

◆ validateMailbox()

bool TYPO3\CMS\Core\Mail\Rfc822AddressesParser::validateMailbox ( $mailbox)
protected

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

Parameters
string$mailbox‪The string to check.
Returns
‪bool Success or failure.

Definition at line 556 of file Rfc822AddressesParser.php.

References TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_splitCheck(), TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_validateAddrSpec(), TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_validatePhrase(), and TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_validateRouteAddr().

Referenced by TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_validateAddress().

Member Data Documentation

◆ $address

◆ $addresses

array TYPO3\CMS\Core\Mail\Rfc822AddressesParser::$addresses = array( )
private

The array of raw addresses built up as we parse.

Definition at line 90 of file Rfc822AddressesParser.php.

Referenced by TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_validateAddress().

◆ $default_domain

string TYPO3\CMS\Core\Mail\Rfc822AddressesParser::$default_domain = 'localhost'
private

◆ $error

string null TYPO3\CMS\Core\Mail\Rfc822AddressesParser::$error
private

The current error message, if any.

Definition at line 102 of file Rfc822AddressesParser.php.

◆ $index

int null TYPO3\CMS\Core\Mail\Rfc822AddressesParser::$index
private

An internal counter/pointer.

Definition at line 108 of file Rfc822AddressesParser.php.

◆ $limit

int TYPO3\CMS\Core\Mail\Rfc822AddressesParser::$limit
private

◆ $num_groups

int TYPO3\CMS\Core\Mail\Rfc822AddressesParser::$num_groups = 0
private

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

Definition at line 114 of file Rfc822AddressesParser.php.

◆ $structure

array TYPO3\CMS\Core\Mail\Rfc822AddressesParser::$structure = array( )
private

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

Definition at line 96 of file Rfc822AddressesParser.php.

Referenced by TYPO3\CMS\Core\Mail\Rfc822AddressesParser\_validateAddress(), and TYPO3\CMS\Core\Mail\Rfc822AddressesParser\parseAddressList().

◆ $validate

bool TYPO3\CMS\Core\Mail\Rfc822AddressesParser::$validate = true
private

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

Definition at line 84 of file Rfc822AddressesParser.php.

Referenced by TYPO3\CMS\Core\Mail\Rfc822AddressesParser\__construct(), and TYPO3\CMS\Core\Mail\Rfc822AddressesParser\parseAddressList().

‪TYPO3\CMS\Core\Mail\Rfc822AddressesParser\$structure
‪array $structure
Definition: Rfc822AddressesParser.php:96