TYPO3 CMS  TYPO3_7-6
TYPO3\CMS\Core\Mail\Rfc822AddressesParser Class Reference

Public Member Functions

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

Protected Member Functions

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

Private Attributes

 $address = ''
 
 $default_domain = 'localhost'
 
 $validate = true
 
 $addresses = []
 
 $structure = []
 
 $error = null
 
 $index = null
 
 $num_groups = 0
 
 $limit = null
 

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 consituent 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> (A comment), ted@e.nosp@m.xamp.nosp@m.le.co.nosp@m.m (Ted Bloggs), Barney;'; $structure = Mail_RFC822::parseAddressList($address_string, 'example.com', TRUE) print_r($structure);

Version
Revision
294749

BSD

Definition at line 63 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.

public

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

Definition at line 137 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()

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;

private

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

Definition at line 354 of file Rfc822AddressesParser.php.

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

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

◆ _hasUnclosedBracketsSub()

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

Sub function that is used only by hasUnclosedBrackets().

private

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

Definition at line 377 of file Rfc822AddressesParser.php.

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

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

◆ _hasUnclosedQuotes()

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

Checks if a string has unclosed quotes or not.

private

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

Definition at line 323 of file Rfc822AddressesParser.php.

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

◆ _isGroup()

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

Checks for a group at the start of the string.

private

Parameters
string$addressThe 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()

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

Splits an address into separate addresses.

private

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

Definition at line 210 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()

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

◆ _validateAddrSpec()

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

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 758 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()

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.

private

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

Definition at line 505 of file Rfc822AddressesParser.php.

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

◆ _validateDliteral()

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

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

private

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

Definition at line 744 of file Rfc822AddressesParser.php.

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

◆ _validateDomain()

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)

private

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

Definition at line 694 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()

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

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 788 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()

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

◆ _validateQuotedString()

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

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

private

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

Definition at line 534 of file Rfc822AddressesParser.php.

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

◆ _validateRoute()

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

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 671 of file Rfc822AddressesParser.php.

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

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

◆ _validateRouteAddr()

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.

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 626 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()

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

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

private

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

Definition at line 721 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()

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.

public

Parameters
string$addressThe address(es) to validate.
string$default_domainDefault domain/host etc.
bool$nest_groupsWhether to return the structure with groups nested for easier viewing.
bool$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 164 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()

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

public

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

Definition at line 551 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 = []
private

The array of raw addresses built up as we parse.

Definition at line 91 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 TYPO3\CMS\Core\Mail\Rfc822AddressesParser::$error = null
private

The current error message, if any.

Definition at line 105 of file Rfc822AddressesParser.php.

◆ $index

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

An internal counter/pointer.

Definition at line 112 of file Rfc822AddressesParser.php.

◆ $limit

int TYPO3\CMS\Core\Mail\Rfc822AddressesParser::$limit = null
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.

public

Definition at line 120 of file Rfc822AddressesParser.php.

◆ $structure

array TYPO3\CMS\Core\Mail\Rfc822AddressesParser::$structure = []
private

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

Definition at line 98 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().