162 if (isset($nest_groups)) {
163 $this->nestGroups = $nest_groups;
186 if (!isset($this) || !isset($this->mailRFC822)) {
188 return $obj->parseAddressList();
197 if (isset($nest_groups)) {
198 $this->nestGroups = $nest_groups;
207 $this->structure = array();
208 $this->addresses = array();
213 $this->address = preg_replace(
'/\r?\n/',
"\r\n", $this->address);
214 $this->address = preg_replace(
'/\r\n(\t| )+/',
' ', $this->address);
218 if ($this->address ===
false || isset($this->error)) {
220 throw new \ilMailException($this->error);
226 foreach ($this->addresses as
$address) {
229 if (
$valid ===
false || isset($this->error)) {
231 throw new \ilMailException($this->error);
235 if (!$this->nestGroups) {
236 $this->structure = array_merge($this->structure,
$valid);
238 $this->structure[] =
$valid;
253 if (!empty($this->limit) && count($this->addresses) == $this->limit) {
260 } elseif (!isset($this->error)) {
263 } elseif (isset($this->error)) {
268 $parts = explode($split_char,
$address);
277 if (strpos($string,
':') ===
false) {
278 $this->error =
'Invalid address: ' . $string;
283 if (!$this->
_splitCheck(explode(
':', $string),
':')) {
293 $this->addresses[] = array(
294 'address' => trim($string),
305 if ($is_group && substr(
$address, 0, 1) ==
',') {
333 if (count($parts = explode(
':', $string)) > 1) {
335 return ($string2 !== $string);
352 for (
$i = 0;
$i < count($parts);
$i++) {
357 || substr($string, -1) ==
'\\') {
358 if (isset($parts[
$i + 1])) {
359 $string = $string . $char . $parts[
$i + 1];
361 $this->error =
'Invalid address spec. Unclosed bracket or quotes';
382 $string = trim($string);
383 $iMax = strlen($string);
387 for (;
$i < $iMax; ++
$i) {
388 switch ($string[
$i]) {
394 if ($slashes % 2 == 0) {
395 $in_quote = !$in_quote;
419 $num_angle_start = substr_count($string, $chars[0]);
420 $num_angle_end = substr_count($string, $chars[1]);
425 if ($num_angle_start < $num_angle_end) {
426 $this->error =
'Invalid address spec. Unmatched quote or bracket (' . $chars .
')';
429 return ($num_angle_start > $num_angle_end);
443 $parts = explode($char, $string);
444 for (
$i = 0;
$i < count($parts);
$i++) {
448 if (isset($parts[$i + 1])) {
449 $parts[$i + 1] = $parts[
$i] . $char . $parts[$i + 1];
471 $parts = explode(
':',
$address[
'address']);
477 $this->error =
'Group name did not validate.';
482 if ($this->nestGroups) {
488 $address[
'address'] = ltrim(substr(
$address[
'address'], strlen($groupname .
':')));
494 while (strlen(
$address[
'address']) > 0) {
495 $parts = explode(
',',
$address[
'address']);
513 if (empty($this->error)) {
514 $this->error =
'Validation failed for: ' .
$addresses[
$i];
521 if ($this->nestGroups) {
549 $parts = preg_split(
'/[ \\x09]+/', $phrase, -1, PREG_SPLIT_NO_EMPTY);
551 $phrase_parts = array();
552 while (count($parts) > 0) {
554 for (
$i = 0;
$i < $this->index + 1;
$i++) {
559 foreach ($phrase_parts as $part) {
561 if (substr($part, 0, 1) ==
'"') {
591 if (!$this->validate) {
599 if (preg_match(
'/[][()<>@,;\\:". ]/', $atom)) {
604 if (preg_match(
'/[\\x00-\\x1F]+/', $atom)) {
609 if (!(
bool) preg_match(
'//u', $atom)) {
627 $qstring = substr($qstring, 1, -1);
630 return !preg_match(
'/[\x0D\\\\"]/', preg_replace(
'/\\\\./',
'', $qstring));
649 $_mailbox = $mailbox;
650 while (strlen(trim($_mailbox)) > 0) {
651 $parts = explode(
'(', $_mailbox);
653 if ($before_comment != $_mailbox) {
655 $comment = substr(str_replace($before_comment,
'', $_mailbox), 1);
661 $_mailbox = substr($_mailbox, strpos($_mailbox,
'(' .
$comment) + strlen(
$comment) + 2);
668 $mailbox = str_replace(
"($comment)",
'', $mailbox);
671 $mailbox = trim($mailbox);
674 if (substr($mailbox, -1) ==
'>' && substr($mailbox, 0, 1) !=
'<') {
675 $parts = explode(
'<', $mailbox);
678 $phrase = trim(
$name);
679 $route_addr = trim(substr($mailbox, strlen(
$name .
'<'), -1));
688 if (substr($mailbox, 0, 1) ==
'<' && substr($mailbox, -1) ==
'>') {
689 $addr_spec = substr($mailbox, 1, -1);
691 $addr_spec = $mailbox;
703 $mbox->personal = $phrase;
704 $mbox->comment = isset($comments) ? $comments : array();
706 if (isset($route_addr)) {
707 $mbox->mailbox = $route_addr[
'local_part'];
708 $mbox->host = $route_addr[
'domain'];
709 $route_addr[
'adl'] !==
'' ? $mbox->adl = $route_addr[
'adl'] :
'';
711 $mbox->mailbox = $addr_spec[
'local_part'];
712 $mbox->host = $addr_spec[
'domain'];
732 if (strpos($route_addr,
':') !==
false) {
733 $parts = explode(
':', $route_addr);
736 $route = $route_addr;
741 if ($route === $route_addr) {
743 $addr_spec = $route_addr;
753 $addr_spec = substr($route_addr, strlen($route .
':'));
762 $return[
'adl'] = $route;
767 $return = array_merge($return, $addr_spec);
781 $domains = explode(
',', trim($route));
783 foreach ($domains as
$domain) {
784 $domain = str_replace(
'@',
'', trim($domain));
805 $subdomains = explode(
'.',
$domain);
807 while (count($subdomains) > 0) {
808 $sub_domains[] = $this->
_splitCheck($subdomains,
'.');
809 for (
$i = 0;
$i < $this->index + 1;
$i++) {
810 array_shift($subdomains);
814 foreach ($sub_domains as $sub_domain) {
833 if (preg_match(
'|^\[(.*)]$|', $subdomain, $arr)) {
856 return !preg_match(
'/(.)[][\x0D\\\\]/', $dliteral, $matches) && ((!isset($matches[1])) || $matches[1] !=
'\\');
869 $addr_spec = trim($addr_spec);
875 if (strpos($addr_spec,
'@') !==
false) {
876 $parts = explode(
'@', $addr_spec);
878 $domain = substr($addr_spec, strlen($local_part .
'@'));
880 if (substr_count($addr_spec,
'@') != 1 && $local_part ==
'') {
881 $this->validate =
false;
882 $local_part = $addr_spec;
888 $local_part = $addr_spec;
896 if ($validateState != $this->validate) {
897 $this->validate = $validateState;
905 return array(
'local_part' => $local_part,
'domain' =>
$domain);
918 $parts = explode(
'.', $local_part);
922 while (count($parts) > 0) {
924 for (
$i = 0;
$i < $this->index + 1;
$i++) {
930 foreach ($words as $word) {
938 if (strpos($word,
' ') && $word[0] !==
'"') {
967 return count(preg_split(
'/(?<!\\\\),/',
$data));
985 $regex = $strict ?
'/^([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})$/i' :
'/^([*+!.&#$|\'\\%\/0-9a-z^_`{}=?~:-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})$/i';
986 if (preg_match($regex, trim(
$data), $matches)) {
987 return array($matches[1], $matches[2]);
$index
An internal counter/pointer.
_validateDliteral($dliteral)
Function to validate a domain literal: domain-literal = "[" *(dtext / quoted-pair) "]"...
$validate
Whether or not to validate atoms for non-ascii characters.
_hasUnclosedBrackets($string, $chars)
Checks if a string has an unclosed brackets or not.
_validateRoute($route)
Function to validate a route, which is: route = 1#("@" domain) ":".
_validateAddrSpec($addr_spec)
Function to validate an addr-spec.
$default_domain
The default domain to use for unqualified addresses.
_hasUnclosedBracketsSub($string, &$num, $char)
Sub function that is used only by hasUnclosedBrackets().
parseAddressList($address=null, $default_domain=null, $nest_groups=null, $validate=null, $limit=null)
Starts the whole process.
_validateAddress($address)
Function to begin checking the address.
_validateDomain($domain)
Function to validate a domain, though this is not quite what you expect of a strict internet domain...
$structure
The final array of parsed address information that we build up.
_splitCheck($parts, $char)
A common function that will check an exploded string.
_validatePhrase($phrase)
Function to validate a phrase.
$limit
A limit after which processing stops.
$error
The current error message, if any.
_splitAddresses($address)
Splits an address into separate addresses.
_validateRouteAddr($route_addr)
This function validates a route-addr which is: route-addr = "<" [route] addr-spec ">"...
_validateQuotedString($qstring)
Function to validate quoted string, which is: quoted-string = <"> *(qtext/quoted-pair) <"> ...
$num_groups
The number of groups that have been found in the address list.
approximateCount($data)
Returns an approximate count of how many addresses are in the given string.
_hasUnclosedQuotes($string)
Checks if a string has unclosed quotes or not.
validateMailbox(&$mailbox)
Function to validate a mailbox, which is: mailbox = addr-spec ; simple address / phrase route-addr ; ...
_validateLocalPart($local_part)
Function to validate the local part of an address: local-part = word *("." word)
$mailRFC822
A variable so that we can tell whether or not we're inside a Mail_RFC822 object.
$address
The address being parsed by the RFC822 object.
isValidInetAddress($data, $strict=false)
This is a email validating function separate to the rest of the class.
$nestGroups
Should we return a nested array showing groups, or flatten everything?
_isGroup($address)
Checks for a group at the start of the string.
if(!array_key_exists('domain', $_REQUEST)) $domain
__construct($address=null, $default_domain=null, $nest_groups=null, $validate=null, $limit=null)
Sets up the object.
_validateSubdomain($subdomain)
Function to validate a subdomain: subdomain = domain-ref / domain-literal.
$addresses
The array of raw addresses built up as we parse.
_validateAtom($atom)
Function to validate an atom which from rfc822 is: atom = 1*<any CHAR except specials, SPACE and CTLs>