ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Mail_RFC822 Class Reference
+ Collaboration diagram for Mail_RFC822:

Public Member Functions

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

Data Fields

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

Detailed Description

Definition at line 70 of file RFC822.php.

Constructor & Destructor Documentation

◆ __construct()

Mail_RFC822::__construct (   $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 154 of file RFC822.php.

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

155  {
156  if (isset($address)) {
157  $this->address = $address;
158  }
159  if (isset($default_domain)) {
160  $this->default_domain = $default_domain;
161  }
162  if (isset($nest_groups)) {
163  $this->nestGroups = $nest_groups;
164  }
165  if (isset($validate)) {
166  $this->validate = $validate;
167  }
168  if (isset($limit)) {
169  $this->limit = $limit;
170  }
171  }
$validate
Whether or not to validate atoms for non-ascii characters.
Definition: RFC822.php:95
$default_domain
The default domain to use for unqualified addresses.
Definition: RFC822.php:83
$limit
A limit after which processing stops.
Definition: RFC822.php:139
$address
The address being parsed by the RFC822 object.
Definition: RFC822.php:77

Member Function Documentation

◆ _hasUnclosedBrackets()

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 425 of file RFC822.php.

References _hasUnclosedBracketsSub().

Referenced by _splitCheck().

426  {
427  $num_angle_start = substr_count($string, $chars[0]);
428  $num_angle_end = substr_count($string, $chars[1]);
429 
430  $this->_hasUnclosedBracketsSub($string, $num_angle_start, $chars[0]);
431  $this->_hasUnclosedBracketsSub($string, $num_angle_end, $chars[1]);
432 
433  if ($num_angle_start < $num_angle_end) {
434  $this->error = 'Invalid address spec. Unmatched quote or bracket (' . $chars . ')';
435  return false;
436  } else {
437  return ($num_angle_start > $num_angle_end);
438  }
439  }
_hasUnclosedBracketsSub($string, &$num, $char)
Sub function that is used only by hasUnclosedBrackets().
Definition: RFC822.php:450
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _hasUnclosedBracketsSub()

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 450 of file RFC822.php.

References $i, and _hasUnclosedQuotes().

Referenced by _hasUnclosedBrackets().

451  {
452  $parts = explode($char, $string);
453  for ($i = 0; $i < count($parts); $i++) {
454  if (substr($parts[$i], -1) == '\\' || $this->_hasUnclosedQuotes($parts[$i])) {
455  $num--;
456  }
457  if (isset($parts[$i + 1])) {
458  $parts[$i + 1] = $parts[$i] . $char . $parts[$i + 1];
459  }
460  }
461 
462  return $num;
463  }
_hasUnclosedQuotes($string)
Checks if a string has unclosed quotes or not.
Definition: RFC822.php:387
$i
Definition: disco.tpl.php:19
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _hasUnclosedQuotes()

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 387 of file RFC822.php.

References $i.

Referenced by _hasUnclosedBracketsSub(), and _splitCheck().

388  {
389  $string = trim($string);
390  $iMax = strlen($string);
391  $in_quote = false;
392  $i = $slashes = 0;
393 
394  for (; $i < $iMax; ++$i) {
395  switch ($string[$i]) {
396  case '\\':
397  ++$slashes;
398  break;
399 
400  case '"':
401  if ($slashes % 2 == 0) {
402  $in_quote = !$in_quote;
403  }
404  // Fall through to default action below.
405 
406  // no break
407  default:
408  $slashes = 0;
409  break;
410  }
411  }
412 
413  return $in_quote;
414  }
$i
Definition: disco.tpl.php:19
+ Here is the caller graph for this function:

◆ _isGroup()

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 329 of file RFC822.php.

References $address, and _splitCheck().

Referenced by _splitAddresses().

330  {
331  // First comma not in quotes, angles or escaped:
332  $parts = explode(',', $address);
333  $string = $this->_splitCheck($parts, ',');
334 
335  // Now we have the first address, we can reliably check for a
336  // group by searching for a colon that's not escaped or in
337  // quotes or angle brackets.
338  if (count($parts = explode(':', $string)) > 1) {
339  $string2 = $this->_splitCheck($parts, ':');
340  return ($string2 !== $string);
341  } else {
342  return false;
343  }
344  }
_splitCheck($parts, $char)
A common function that will check an exploded string.
Definition: RFC822.php:354
$address
The address being parsed by the RFC822 object.
Definition: RFC822.php:77
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _splitAddresses()

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 255 of file RFC822.php.

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

Referenced by parseAddressList().

256  {
257  if (!empty($this->limit) && count($this->addresses) == $this->limit) {
258  return '';
259  }
260 
261  if ($this->_isGroup($address) && !isset($this->error)) {
262  $split_char = ';';
263  $is_group = true;
264  } elseif (!isset($this->error)) {
265  $split_char = ',';
266  $is_group = false;
267  } elseif (isset($this->error)) {
268  return false;
269  }
270 
271  // Split the string based on the above ten or so lines.
272  $parts = explode($split_char, $address);
273  $string = $this->_splitCheck($parts, $split_char);
274 
275  // If a group...
276  if ($is_group) {
277  // If $string does not contain a colon outside of
278  // brackets/quotes etc then something's fubar.
279 
280  // First check there's a colon at all:
281  if (strpos($string, ':') === false) {
282  $this->error = 'Invalid address: ' . $string;
283  return false;
284  }
285 
286  // Now check it's outside of brackets/quotes:
287  if (!$this->_splitCheck(explode(':', $string), ':')) {
288  return false;
289  }
290 
291  // We must have a group at this point, so increase the counter:
292  $this->num_groups++;
293  }
294 
295  // $string now contains the first full address/group.
296  // Add to the addresses array.
297  $this->addresses[] = array(
298  'address' => trim($string),
299  'group' => $is_group
300  );
301 
302  // Remove the now stored address from the initial line, the +1
303  // is to account for the explode character.
304  $address = trim(substr($address, strlen($string) + 1));
305 
306  // If the next char is a comma and this was a group, then
307  // there are more addresses, otherwise, if there are any more
308  // chars, then there is another address.
309  if ($is_group && substr($address, 0, 1) == ',') {
310  $address = trim(substr($address, 1));
311  return $address;
312  } elseif (strlen($address) > 0) {
313  return $address;
314  } else {
315  return '';
316  }
317 
318  // If you got here then something's off
319  return false;
320  }
_splitCheck($parts, $char)
A common function that will check an exploded string.
Definition: RFC822.php:354
Create styles array
The data for the language used.
$address
The address being parsed by the RFC822 object.
Definition: RFC822.php:77
_isGroup($address)
Checks for a group at the start of the string.
Definition: RFC822.php:329
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _splitCheck()

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 354 of file RFC822.php.

References $i, _hasUnclosedBrackets(), and _hasUnclosedQuotes().

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

355  {
356  $string = $parts[0];
357 
358  for ($i = 0; $i < count($parts); $i++) {
359  if ($this->_hasUnclosedQuotes($string)
360  || $this->_hasUnclosedBrackets($string, '<>')
361  || $this->_hasUnclosedBrackets($string, '[]')
362  || $this->_hasUnclosedBrackets($string, '()')
363  || substr($string, -1) == '\\') {
364  if (isset($parts[$i + 1])) {
365  $string = $string . $char . $parts[$i + 1];
366  } else {
367  $this->error = 'Invalid address spec. Unclosed bracket or quotes';
368  return false;
369  }
370  } else {
371  $this->index = $i;
372  break;
373  }
374  }
375 
376  return $string;
377  }
_hasUnclosedBrackets($string, $chars)
Checks if a string has an unclosed brackets or not.
Definition: RFC822.php:425
_hasUnclosedQuotes($string)
Checks if a string has unclosed quotes or not.
Definition: RFC822.php:387
$i
Definition: disco.tpl.php:19
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _validateAddress()

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 472 of file RFC822.php.

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

Referenced by parseAddressList().

473  {
474  $is_group = false;
475  $addresses = array();
476 
477  if ($address['group']) {
478  $is_group = true;
479 
480  // Get the group part of the name
481  $parts = explode(':', $address['address']);
482  $groupname = $this->_splitCheck($parts, ':');
483  $structure = array();
484 
485  // And validate the group part of the name.
486  if (!$this->_validatePhrase($groupname)) {
487  $this->error = 'Group name did not validate.';
488  return false;
489  } else {
490  // Don't include groups if we are not nesting
491  // them. This avoids returning invalid addresses.
492  if ($this->nestGroups) {
493  $structure = new stdClass;
494  $structure->groupname = $groupname;
495  }
496  }
497 
498  $address['address'] = ltrim(substr($address['address'], strlen($groupname . ':')));
499  }
500 
501  // If a group then split on comma and put into an array.
502  // Otherwise, Just put the whole address in an array.
503  if ($is_group) {
504  while (strlen($address['address']) > 0) {
505  $parts = explode(',', $address['address']);
506  $addresses[] = $this->_splitCheck($parts, ',');
507  $address['address'] = trim(substr($address['address'], strlen(end($addresses) . ',')));
508  }
509  } else {
510  $addresses[] = $address['address'];
511  }
512 
513  // Check that $addresses is set, if address like this:
514  // Groupname:;
515  // Then errors were appearing.
516  if (!count($addresses)) {
517  $this->error = 'Empty group.';
518  return false;
519  }
520 
521  // Trim the whitespace from all of the address strings.
522  array_map('trim', $addresses);
523 
524  // Validate each mailbox.
525  // Format could be one of: name <geezer@domain.com>
526  // geezer@domain.com
527  // geezer
528  // ... or any other format valid by RFC 822.
529  for ($i = 0; $i < count($addresses); $i++) {
530  if (!$this->validateMailbox($addresses[$i])) {
531  if (empty($this->error)) {
532  $this->error = 'Validation failed for: ' . $addresses[$i];
533  }
534  return false;
535  }
536  }
537 
538  // Nested format
539  if ($this->nestGroups) {
540  if ($is_group) {
541  $structure->addresses = $addresses;
542  } else {
543  $structure = $addresses[0];
544  }
545 
546  // Flat format
547  } else {
548  if ($is_group) {
549  $structure = array_merge($structure, $addresses);
550  } else {
552  }
553  }
554 
555  return $structure;
556  }
$structure
The final array of parsed address information that we build up.
Definition: RFC822.php:107
_splitCheck($parts, $char)
A common function that will check an exploded string.
Definition: RFC822.php:354
_validatePhrase($phrase)
Function to validate a phrase.
Definition: RFC822.php:565
validateMailbox(&$mailbox)
Function to validate a mailbox, which is: mailbox = addr-spec ; simple address / phrase route-addr ; ...
Definition: RFC822.php:663
Create styles array
The data for the language used.
$address
The address being parsed by the RFC822 object.
Definition: RFC822.php:77
$i
Definition: disco.tpl.php:19
$addresses
The array of raw addresses built up as we parse.
Definition: RFC822.php:101
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _validateAddrSpec()

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 895 of file RFC822.php.

References $default_domain, $domain, $validate, _splitCheck(), _validateDomain(), _validateLocalPart(), and array.

Referenced by _validateRouteAddr(), and validateMailbox().

896  {
897  $addr_spec = trim($addr_spec);
898 
899  // mjansen patch 16 Sep 2016 start
900  $validateState = $this->validate;
901  // mjansen patch 16 Sep 2016 end
902  // Split on @ sign if there is one.
903  if (strpos($addr_spec, '@') !== false) {
904  $parts = explode('@', $addr_spec);
905  $local_part = $this->_splitCheck($parts, '@');
906  $domain = substr($addr_spec, strlen($local_part . '@'));
907  // mjansen patch 16 Sep 2016 start
908  if (substr_count($addr_spec, '@') != 1 && $local_part == '') {
909  $this->validate = false;
910  $local_part = $addr_spec;
912  }
913  // mjansen patch 16 Sep 2016 end
914  // No @ sign so assume the default domain.
915  } else {
916  $local_part = $addr_spec;
918  }
919 
920  if (($local_part = $this->_validateLocalPart($local_part)) === false) {
921  return false;
922  }
923  // mjansen patch 16 Sep 2016 start
924  if ($validateState != $this->validate) {
925  $this->validate = $validateState;
926  }
927  // mjansen patch 16 Sep 2016 end
928  if (($domain = $this->_validateDomain($domain)) === false) {
929  return false;
930  }
931 
932  // Got here so return successful.
933  return array('local_part' => $local_part, 'domain' => $domain);
934  }
$validate
Whether or not to validate atoms for non-ascii characters.
Definition: RFC822.php:95
$default_domain
The default domain to use for unqualified addresses.
Definition: RFC822.php:83
_validateDomain($domain)
Function to validate a domain, though this is not quite what you expect of a strict internet domain...
Definition: RFC822.php:827
_splitCheck($parts, $char)
A common function that will check an exploded string.
Definition: RFC822.php:354
Create styles array
The data for the language used.
_validateLocalPart($local_part)
Function to validate the local part of an address: local-part = word *("." word)
Definition: RFC822.php:944
if(!array_key_exists('domain', $_REQUEST)) $domain
Definition: resume.php:8
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _validateAtom()

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 609 of file RFC822.php.

Referenced by _validatePhrase(), and _validateSubdomain().

610  {
611  if (!$this->validate) {
612  // Validation has been turned off; assume the atom is okay.
613  return true;
614  }
615 
616  // Check for any char from ASCII 0 - ASCII 127
617  // mjansen patch 16 Sep 2015 start
618  // Check for specials:
619  if (preg_match('/[][()<>@,;\\:". ]/', $atom)) {
620  return false;
621  }
622 
623  // Check for control characters (ASCII 0-31):
624  if (preg_match('/[\\x00-\\x1F]+/', $atom)) {
625  return false;
626  }
627  #16291
628  #17618
629  if (!(bool) preg_match('//u', $atom)) {
630  return false;
631  }
632  // mjansen patch 16 Sep 2015 end
633 
634  return true;
635  }
+ Here is the caller graph for this function:

◆ _validateDliteral()

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 881 of file RFC822.php.

Referenced by _validateSubdomain().

882  {
883  return !preg_match('/(.)[][\x0D\\\\]/', $dliteral, $matches) && $matches[1] != '\\';
884  }
+ Here is the caller graph for this function:

◆ _validateDomain()

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 827 of file RFC822.php.

References $domain, $i, _splitCheck(), and _validateSubdomain().

Referenced by _validateAddrSpec(), and _validateRoute().

828  {
829  // Note the different use of $subdomains and $sub_domains
830  $subdomains = explode('.', $domain);
831 
832  while (count($subdomains) > 0) {
833  $sub_domains[] = $this->_splitCheck($subdomains, '.');
834  for ($i = 0; $i < $this->index + 1; $i++) {
835  array_shift($subdomains);
836  }
837  }
838 
839  foreach ($sub_domains as $sub_domain) {
840  if (!$this->_validateSubdomain(trim($sub_domain))) {
841  return false;
842  }
843  }
844 
845  // Managed to get here, so return input.
846  return $domain;
847  }
_splitCheck($parts, $char)
A common function that will check an exploded string.
Definition: RFC822.php:354
$i
Definition: disco.tpl.php:19
if(!array_key_exists('domain', $_REQUEST)) $domain
Definition: resume.php:8
_validateSubdomain($subdomain)
Function to validate a subdomain: subdomain = domain-ref / domain-literal.
Definition: RFC822.php:857
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _validateLocalPart()

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 944 of file RFC822.php.

References $i, _splitCheck(), _validatePhrase(), and array.

Referenced by _validateAddrSpec().

945  {
946  $parts = explode('.', $local_part);
947  $words = array();
948 
949  // Split the local_part into words.
950  while (count($parts) > 0) {
951  $words[] = $this->_splitCheck($parts, '.');
952  for ($i = 0; $i < $this->index + 1; $i++) {
953  array_shift($parts);
954  }
955  }
956 
957  // Validate each word.
958  foreach ($words as $word) {
959  // If this word contains an unquoted space, it is invalid. (6.2.4)
960  if (strpos($word, ' ') && $word[0] !== '"') {
961  // mjansen patch 24 Feb 2016 start
962  // Mantis issue #18018
963  // # http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx/
964  //return false;
965  // mjansen patch 24 Feb 2016 end
966  }
967 
968  if ($this->_validatePhrase(trim($word)) === false) {
969  return false;
970  }
971  }
972 
973  // Managed to get here, so return the input.
974  return $local_part;
975  }
_splitCheck($parts, $char)
A common function that will check an exploded string.
Definition: RFC822.php:354
_validatePhrase($phrase)
Function to validate a phrase.
Definition: RFC822.php:565
Create styles array
The data for the language used.
$i
Definition: disco.tpl.php:19
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _validatePhrase()

Mail_RFC822::_validatePhrase (   $phrase)

Function to validate a phrase.

private

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

Definition at line 565 of file RFC822.php.

References $i, _splitCheck(), _validateAtom(), _validateQuotedString(), and array.

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

566  {
567  // Splits on one or more Tab or space.
568  $parts = preg_split('/[ \\x09]+/', $phrase, -1, PREG_SPLIT_NO_EMPTY);
569 
570  $phrase_parts = array();
571  while (count($parts) > 0) {
572  $phrase_parts[] = $this->_splitCheck($parts, ' ');
573  for ($i = 0; $i < $this->index + 1; $i++) {
574  array_shift($parts);
575  }
576  }
577 
578  foreach ($phrase_parts as $part) {
579  // If quoted string:
580  if (substr($part, 0, 1) == '"') {
581  if (!$this->_validateQuotedString($part)) {
582  return false;
583  }
584  continue;
585  }
586 
587  // Otherwise it's an atom:
588  if (!$this->_validateAtom($part)) {
589  return false;
590  }
591  }
592 
593  return true;
594  }
_splitCheck($parts, $char)
A common function that will check an exploded string.
Definition: RFC822.php:354
_validateQuotedString($qstring)
Function to validate quoted string, which is: quoted-string = <"> *(qtext/quoted-pair) <"> ...
Definition: RFC822.php:645
Create styles array
The data for the language used.
$i
Definition: disco.tpl.php:19
_validateAtom($atom)
Function to validate an atom which from rfc822 is: atom = 1*<any CHAR except specials, SPACE and CTLs>
Definition: RFC822.php:609
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _validateQuotedString()

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 645 of file RFC822.php.

Referenced by _validatePhrase().

646  {
647  // Leading and trailing "
648  $qstring = substr($qstring, 1, -1);
649 
650  // Perform check, removing quoted characters first.
651  return !preg_match('/[\x0D\\\\"]/', preg_replace('/\\\\./', '', $qstring));
652  }
+ Here is the caller graph for this function:

◆ _validateRoute()

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 802 of file RFC822.php.

References $domain, and _validateDomain().

Referenced by _validateRouteAddr().

803  {
804  // Split on comma.
805  $domains = explode(',', trim($route));
806 
807  foreach ($domains as $domain) {
808  $domain = str_replace('@', '', trim($domain));
809  if (!$this->_validateDomain($domain)) {
810  return false;
811  }
812  }
813 
814  return $route;
815  }
_validateDomain($domain)
Function to validate a domain, though this is not quite what you expect of a strict internet domain...
Definition: RFC822.php:827
if(!array_key_exists('domain', $_REQUEST)) $domain
Definition: resume.php:8
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _validateRouteAddr()

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 752 of file RFC822.php.

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

Referenced by validateMailbox().

753  {
754  // Check for colon.
755  if (strpos($route_addr, ':') !== false) {
756  $parts = explode(':', $route_addr);
757  $route = $this->_splitCheck($parts, ':');
758  } else {
759  $route = $route_addr;
760  }
761 
762  // If $route is same as $route_addr then the colon was in
763  // quotes or brackets or, of course, non existent.
764  if ($route === $route_addr) {
765  unset($route);
766  $addr_spec = $route_addr;
767  if (($addr_spec = $this->_validateAddrSpec($addr_spec)) === false) {
768  return false;
769  }
770  } else {
771  // Validate route part.
772  if (($route = $this->_validateRoute($route)) === false) {
773  return false;
774  }
775 
776  $addr_spec = substr($route_addr, strlen($route . ':'));
777 
778  // Validate addr-spec part.
779  if (($addr_spec = $this->_validateAddrSpec($addr_spec)) === false) {
780  return false;
781  }
782  }
783 
784  if (isset($route)) {
785  $return['adl'] = $route;
786  } else {
787  $return['adl'] = '';
788  }
789 
790  $return = array_merge($return, $addr_spec);
791  return $return;
792  }
_validateRoute($route)
Function to validate a route, which is: route = 1#("@" domain) ":".
Definition: RFC822.php:802
_validateAddrSpec($addr_spec)
Function to validate an addr-spec.
Definition: RFC822.php:895
_splitCheck($parts, $char)
A common function that will check an exploded string.
Definition: RFC822.php:354
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _validateSubdomain()

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 857 of file RFC822.php.

References _validateAtom(), and _validateDliteral().

Referenced by _validateDomain().

858  {
859  if (preg_match('|^\[(.*)]$|', $subdomain, $arr)) {
860  if (!$this->_validateDliteral($arr[1])) {
861  return false;
862  }
863  } else {
864  if (!$this->_validateAtom($subdomain)) {
865  return false;
866  }
867  }
868 
869  // Got here, so return successful.
870  return true;
871  }
_validateDliteral($dliteral)
Function to validate a domain literal: domain-literal = "[" *(dtext / quoted-pair) "]"...
Definition: RFC822.php:881
_validateAtom($atom)
Function to validate an atom which from rfc822 is: atom = 1*<any CHAR except specials, SPACE and CTLs>
Definition: RFC822.php:609
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ approximateCount()

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 987 of file RFC822.php.

References $data.

988  {
989  return count(preg_split('/(?<!\\\\),/', $data));
990  }

◆ isValidInetAddress()

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 1005 of file RFC822.php.

References $data, and array.

1006  {
1007  $regex = $strict ? '/^([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})$/i' : '/^([*+!.&#$|\'\\%\/0-9a-z^_`{}=?~:-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})$/i';
1008  if (preg_match($regex, trim($data), $matches)) {
1009  return array($matches[1], $matches[2]);
1010  } else {
1011  return false;
1012  }
1013  }
Create styles array
The data for the language used.

◆ parseAddressList()

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 185 of file RFC822.php.

References $address, $default_domain, $limit, $structure, $valid, $validate, _splitAddresses(), _validateAddress(), and array.

186  {
187  if (!isset($this) || !isset($this->mailRFC822)) {
188  $obj = new Mail_RFC822($address, $default_domain, $nest_groups, $validate, $limit);
189  return $obj->parseAddressList();
190  }
191 
192  if (isset($address)) {
193  $this->address = $address;
194  }
195  if (isset($default_domain)) {
196  $this->default_domain = $default_domain;
197  }
198  if (isset($nest_groups)) {
199  $this->nestGroups = $nest_groups;
200  }
201  if (isset($validate)) {
202  $this->validate = $validate;
203  }
204  if (isset($limit)) {
205  $this->limit = $limit;
206  }
207 
208  $this->structure = array();
209  $this->addresses = array();
210  $this->error = null;
211  $this->index = null;
212 
213  // Unfold any long lines in $this->address.
214  $this->address = preg_replace('/\r?\n/', "\r\n", $this->address);
215  $this->address = preg_replace('/\r\n(\t| )+/', ' ', $this->address);
216 
217  while ($this->address = $this->_splitAddresses($this->address));
218 
219  if ($this->address === false || isset($this->error)) {
220  // mjansen patch 14 Ap 2016 start
221  require_once 'Services/Mail/exceptions/class.ilMailException.php';
222  throw new ilMailException($this->error);
223  // mjansen patch 14 Ap 2016 end
224  }
225 
226  // Validate each address individually. If we encounter an invalid
227  // address, stop iterating and return an error immediately.
228  foreach ($this->addresses as $address) {
229  $valid = $this->_validateAddress($address);
230 
231  if ($valid === false || isset($this->error)) {
232  // mjansen patch 14 Ap 2016 start
233  require_once 'Services/Mail/exceptions/class.ilMailException.php';
234  throw new ilMailException($this->error);
235  // mjansen patch 14 Ap 2016 end
236  }
237 
238  if (!$this->nestGroups) {
239  $this->structure = array_merge($this->structure, $valid);
240  } else {
241  $this->structure[] = $valid;
242  }
243  }
244 
245  return $this->structure;
246  }
$validate
Whether or not to validate atoms for non-ascii characters.
Definition: RFC822.php:95
$valid
$default_domain
The default domain to use for unqualified addresses.
Definition: RFC822.php:83
Class ilMailException.
_validateAddress($address)
Function to begin checking the address.
Definition: RFC822.php:472
$structure
The final array of parsed address information that we build up.
Definition: RFC822.php:107
$limit
A limit after which processing stops.
Definition: RFC822.php:139
_splitAddresses($address)
Splits an address into separate addresses.
Definition: RFC822.php:255
Create styles array
The data for the language used.
$address
The address being parsed by the RFC822 object.
Definition: RFC822.php:77
+ Here is the call graph for this function:

◆ validateMailbox()

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 663 of file RFC822.php.

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

Referenced by _validateAddress().

664  {
665  // A couple of defaults.
666  $phrase = '';
667  $comment = '';
668  $comments = array();
669 
670  // Catch any RFC822 comments and store them separately.
671  $_mailbox = $mailbox;
672  while (strlen(trim($_mailbox)) > 0) {
673  $parts = explode('(', $_mailbox);
674  $before_comment = $this->_splitCheck($parts, '(');
675  if ($before_comment != $_mailbox) {
676  // First char should be a (.
677  $comment = substr(str_replace($before_comment, '', $_mailbox), 1);
678  $parts = explode(')', $comment);
679  $comment = $this->_splitCheck($parts, ')');
680  $comments[] = $comment;
681 
682  // +2 is for the brackets
683  $_mailbox = substr($_mailbox, strpos($_mailbox, '(' . $comment)+strlen($comment)+2);
684  } else {
685  break;
686  }
687  }
688 
689  foreach ($comments as $comment) {
690  $mailbox = str_replace("($comment)", '', $mailbox);
691  }
692 
693  $mailbox = trim($mailbox);
694 
695  // Check for name + route-addr
696  if (substr($mailbox, -1) == '>' && substr($mailbox, 0, 1) != '<') {
697  $parts = explode('<', $mailbox);
698  $name = $this->_splitCheck($parts, '<');
699 
700  $phrase = trim($name);
701  $route_addr = trim(substr($mailbox, strlen($name . '<'), -1));
702 
703  if ($this->_validatePhrase($phrase) === false || ($route_addr = $this->_validateRouteAddr($route_addr)) === false) {
704  return false;
705  }
706 
707  // Only got addr-spec
708  } else {
709  // First snip angle brackets if present.
710  if (substr($mailbox, 0, 1) == '<' && substr($mailbox, -1) == '>') {
711  $addr_spec = substr($mailbox, 1, -1);
712  } else {
713  $addr_spec = $mailbox;
714  }
715 
716  if (($addr_spec = $this->_validateAddrSpec($addr_spec)) === false) {
717  return false;
718  }
719  }
720 
721  // Construct the object that will be returned.
722  $mbox = new stdClass();
723 
724  // Add the phrase (even if empty) and comments
725  $mbox->personal = $phrase;
726  $mbox->comment = isset($comments) ? $comments : array();
727 
728  if (isset($route_addr)) {
729  $mbox->mailbox = $route_addr['local_part'];
730  $mbox->host = $route_addr['domain'];
731  $route_addr['adl'] !== '' ? $mbox->adl = $route_addr['adl'] : '';
732  } else {
733  $mbox->mailbox = $addr_spec['local_part'];
734  $mbox->host = $addr_spec['domain'];
735  }
736 
737  $mailbox = $mbox;
738  return true;
739  }
_validateAddrSpec($addr_spec)
Function to validate an addr-spec.
Definition: RFC822.php:895
_splitCheck($parts, $char)
A common function that will check an exploded string.
Definition: RFC822.php:354
if($format !==null) $name
Definition: metadata.php:146
_validatePhrase($phrase)
Function to validate a phrase.
Definition: RFC822.php:565
_validateRouteAddr($route_addr)
This function validates a route-addr which is: route-addr = "<" [route] addr-spec ">"...
Definition: RFC822.php:752
$comment
Definition: buildRTE.php:83
Create styles array
The data for the language used.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $address

string Mail_RFC822::$address = ''

The address being parsed by the RFC822 object.

Definition at line 77 of file RFC822.php.

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

◆ $addresses

array Mail_RFC822::$addresses = array()

The array of raw addresses built up as we parse.

Definition at line 101 of file RFC822.php.

Referenced by _validateAddress().

◆ $default_domain

string Mail_RFC822::$default_domain = 'localhost'

The default domain to use for unqualified addresses.

Definition at line 83 of file RFC822.php.

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

◆ $error

string Mail_RFC822::$error = null

The current error message, if any.

Definition at line 113 of file RFC822.php.

◆ $index

integer Mail_RFC822::$index = null

An internal counter/pointer.

Definition at line 119 of file RFC822.php.

◆ $limit

int Mail_RFC822::$limit = null

A limit after which processing stops.

Definition at line 139 of file RFC822.php.

Referenced by __construct(), and parseAddressList().

◆ $mailRFC822

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 133 of file RFC822.php.

◆ $nestGroups

boolean Mail_RFC822::$nestGroups = true

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

Definition at line 89 of file RFC822.php.

◆ $num_groups

integer Mail_RFC822::$num_groups = 0

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

public

Definition at line 126 of file RFC822.php.

◆ $structure

array Mail_RFC822::$structure = array()

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

Definition at line 107 of file RFC822.php.

Referenced by _validateAddress(), and parseAddressList().

◆ $validate

boolean Mail_RFC822::$validate = true

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

Definition at line 95 of file RFC822.php.

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


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