162        if (isset($nest_groups)) {
 
  163            $this->nestGroups     = $nest_groups;
 
  187        if (!isset($this) || !isset($this->mailRFC822)) {
 
  189            return $obj->parseAddressList();
 
  198        if (isset($nest_groups)) {
 
  199            $this->nestGroups     = $nest_groups;
 
  208        $this->structure  = array();
 
  209        $this->addresses  = array();
 
  214        $this->address = preg_replace(
'/\r?\n/', 
"\r\n", $this->address);
 
  215        $this->address = preg_replace(
'/\r\n(\t| )+/', 
' ', $this->address);
 
  219        if ($this->address === 
false || isset($this->
error)) {
 
  221            require_once 
'Services/Mail/exceptions/class.ilMailException.php';
 
  228        foreach ($this->addresses as 
$address) {
 
  233                require_once 
'Services/Mail/exceptions/class.ilMailException.php';
 
  238            if (!$this->nestGroups) {
 
  239                $this->structure = array_merge($this->structure, 
$valid);
 
  241                $this->structure[] = 
$valid;
 
  257        if (!empty($this->limit) && count($this->addresses) == $this->limit) {
 
  264        } elseif (!isset($this->
error)) {
 
  267        } elseif (isset($this->
error)) {
 
  272        $parts  = explode($split_char, 
$address);
 
  281            if (strpos($string, 
':') === 
false) {
 
  282                $this->
error = 
'Invalid address: ' . $string;
 
  287            if (!$this->
_splitCheck(explode(
':', $string), 
':')) {
 
  297        $this->addresses[] = array(
 
  298                                   'address' => trim($string),
 
  309        if ($is_group && substr(
$address, 0, 1) == 
',') {
 
  338        if (count($parts = explode(
':', $string)) > 1) {
 
  340            return ($string2 !== $string);
 
  358        for (
$i = 0; 
$i < count($parts); 
$i++) {
 
  363                || substr($string, -1) == 
'\\') {
 
  364                if (isset($parts[
$i + 1])) {
 
  365                    $string = $string . $char . $parts[
$i + 1];
 
  367                    $this->
error = 
'Invalid address spec. Unclosed bracket or quotes';
 
  389        $string = trim($string);
 
  390        $iMax = strlen($string);
 
  394        for (; 
$i < $iMax; ++
$i) {
 
  395            switch ($string[
$i]) {
 
  401                if ($slashes % 2 == 0) {
 
  402                    $in_quote = !$in_quote;
 
  427        $num_angle_start = substr_count($string, $chars[0]);
 
  428        $num_angle_end   = substr_count($string, $chars[1]);
 
  433        if ($num_angle_start < $num_angle_end) {
 
  434            $this->
error = 
'Invalid address spec. Unmatched quote or bracket (' . $chars . 
')';
 
  437            return ($num_angle_start > $num_angle_end);
 
  452        $parts = explode($char, $string);
 
  453        for (
$i = 0; 
$i < count($parts); 
$i++) {
 
  457            if (isset($parts[
$i + 1])) {
 
  458                $parts[
$i + 1] = $parts[
$i] . $char . $parts[
$i + 1];
 
  481            $parts     = explode(
':', 
$address[
'address']);
 
  487                $this->
error = 
'Group name did not validate.';
 
  492                if ($this->nestGroups) {
 
  498            $address[
'address'] = ltrim(substr(
$address[
'address'], strlen($groupname . 
':')));
 
  504            while (strlen(
$address[
'address']) > 0) {
 
  505                $parts       = explode(
',', 
$address[
'address']);
 
  517            $this->
error = 
'Empty group.';
 
  531                if (empty($this->
error)) {
 
  539        if ($this->nestGroups) {
 
  568        $parts = preg_split(
'/[ \\x09]+/', $phrase, -1, PREG_SPLIT_NO_EMPTY);
 
  570        $phrase_parts = array();
 
  571        while (count($parts) > 0) {
 
  573            for (
$i = 0; 
$i < $this->index + 1; 
$i++) {
 
  578        foreach ($phrase_parts as $part) {
 
  580            if (substr($part, 0, 1) == 
'"') {
 
  611        if (!$this->validate) {
 
  619        if (preg_match(
'/[][()<>@,;\\:". ]/', $atom)) {
 
  624        if (preg_match(
'/[\\x00-\\x1F]+/', $atom)) {
 
  629        if (!(
bool) preg_match(
'//u', $atom)) {
 
  648        $qstring = substr($qstring, 1, -1);
 
  651        return !preg_match(
'/[\x0D\\\\"]/', preg_replace(
'/\\\\./', 
'', $qstring));
 
  671        $_mailbox = $mailbox;
 
  672        while (strlen(trim($_mailbox)) > 0) {
 
  673            $parts = explode(
'(', $_mailbox);
 
  675            if ($before_comment != $_mailbox) {
 
  677                $comment    = substr(str_replace($before_comment, 
'', $_mailbox), 1);
 
  683                $_mailbox = substr($_mailbox, strpos($_mailbox, 
'(' . 
$comment)+strlen(
$comment)+2);
 
  690            $mailbox = str_replace(
"($comment)", 
'', $mailbox);
 
  693        $mailbox = trim($mailbox);
 
  696        if (substr($mailbox, -1) == 
'>' && substr($mailbox, 0, 1) != 
'<') {
 
  697            $parts  = explode(
'<', $mailbox);
 
  700            $phrase     = trim(
$name);
 
  701            $route_addr = trim(substr($mailbox, strlen(
$name . 
'<'), -1));
 
  710            if (substr($mailbox, 0, 1) == 
'<' && substr($mailbox, -1) == 
'>') {
 
  711                $addr_spec = substr($mailbox, 1, -1);
 
  713                $addr_spec = $mailbox;
 
  722        $mbox = 
new stdClass();
 
  725        $mbox->personal = $phrase;
 
  726        $mbox->comment  = isset($comments) ? $comments : array();
 
  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'] : 
'';
 
  733            $mbox->mailbox = $addr_spec[
'local_part'];
 
  734            $mbox->host    = $addr_spec[
'domain'];
 
  755        if (strpos($route_addr, 
':') !== 
false) {
 
  756            $parts = explode(
':', $route_addr);
 
  759            $route = $route_addr;
 
  764        if ($route === $route_addr) {
 
  766            $addr_spec = $route_addr;
 
  776            $addr_spec = substr($route_addr, strlen($route . 
':'));
 
  785            $return[
'adl'] = $route;
 
  790        $return = array_merge($return, $addr_spec);
 
  805        $domains = explode(
',', trim($route));
 
  807        foreach ($domains as 
$domain) {
 
  830        $subdomains = explode(
'.', 
$domain);
 
  832        while (count($subdomains) > 0) {
 
  833            $sub_domains[] = $this->
_splitCheck($subdomains, 
'.');
 
  834            for (
$i = 0; 
$i < $this->index + 1; 
$i++) {
 
  835                array_shift($subdomains);
 
  839        foreach ($sub_domains as $sub_domain) {
 
  859        if (preg_match(
'|^\[(.*)]$|', $subdomain, $arr)) {
 
  883        return !preg_match(
'/(.)[][\x0D\\\\]/', $dliteral, $matches) && $matches[1] != 
'\\';
 
  897        $addr_spec = trim($addr_spec);
 
  903        if (strpos($addr_spec, 
'@') !== 
false) {
 
  904            $parts      = explode(
'@', $addr_spec);
 
  906            $domain     = substr($addr_spec, strlen($local_part . 
'@'));
 
  908            if (substr_count($addr_spec, 
'@') != 1 && $local_part == 
'') {
 
  909                $this->validate = 
false;
 
  910                $local_part = $addr_spec;
 
  916            $local_part = $addr_spec;
 
  924        if ($validateState != $this->validate) {
 
  925            $this->validate = $validateState;
 
  933        return array(
'local_part' => $local_part, 
'domain' => 
$domain);
 
  946        $parts = explode(
'.', $local_part);
 
  950        while (count($parts) > 0) {
 
  952            for (
$i = 0; 
$i < $this->index + 1; 
$i++) {
 
  958        foreach ($words as $word) {
 
  960            if (strpos($word, 
' ') && $word[0] !== 
'"') {
 
  989        return count(preg_split(
'/(?<!\\\\),/', 
$data));
 
 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]);
 
if(!array_key_exists('domain', $_REQUEST)) $domain
An exception for terminatinating execution or to throw for unit testing.
$error
The current error message, if any.
$nestGroups
Should we return a nested array showing groups, or flatten everything?
_validateSubdomain($subdomain)
Function to validate a subdomain: subdomain = domain-ref / domain-literal.
_splitCheck($parts, $char)
A common function that will check an exploded string.
isValidInetAddress($data, $strict=false)
This is a email validating function separate to the rest of the class.
_splitAddresses($address)
Splits an address into separate addresses.
$mailRFC822
A variable so that we can tell whether or not we're inside a Mail_RFC822 object.
$structure
The final array of parsed address information that we build up.
$default_domain
The default domain to use for unqualified addresses.
_validatePhrase($phrase)
Function to validate a phrase.
_validateQuotedString($qstring)
Function to validate quoted string, which is: quoted-string = <"> *(qtext/quoted-pair) <">
__construct($address=null, $default_domain=null, $nest_groups=null, $validate=null, $limit=null)
Sets up the object.
_validateDliteral($dliteral)
Function to validate a domain literal: domain-literal = "[" *(dtext / quoted-pair) "]".
_validateLocalPart($local_part)
Function to validate the local part of an address: local-part = word *("." word)
parseAddressList($address=null, $default_domain=null, $nest_groups=null, $validate=null, $limit=null)
Starts the whole process.
$validate
Whether or not to validate atoms for non-ascii characters.
_hasUnclosedBracketsSub($string, &$num, $char)
Sub function that is used only by hasUnclosedBrackets().
_validateAtom($atom)
Function to validate an atom which from rfc822 is: atom = 1*<any CHAR except specials,...
_validateDomain($domain)
Function to validate a domain, though this is not quite what you expect of a strict internet domain.
approximateCount($data)
Returns an approximate count of how many addresses are in the given string.
validateMailbox(&$mailbox)
Function to validate a mailbox, which is: mailbox = addr-spec ; simple address / phrase route-addr ; ...
_hasUnclosedQuotes($string)
Checks if a string has unclosed quotes or not.
$addresses
The array of raw addresses built up as we parse.
_validateAddrSpec($addr_spec)
Function to validate an addr-spec.
_validateAddress($address)
Function to begin checking the address.
_isGroup($address)
Checks for a group at the start of the string.
_hasUnclosedBrackets($string, $chars)
Checks if a string has an unclosed brackets or not.
$address
The address being parsed by the RFC822 object.
$index
An internal counter/pointer.
$num_groups
The number of groups that have been found in the address list.
_validateRoute($route)
Function to validate a route, which is: route = 1#("@" domain) ":".
$limit
A limit after which processing stops.
_validateRouteAddr($route_addr)
This function validates a route-addr which is: route-addr = "<" [route] addr-spec ">".
error($a_errmsg)
set error message @access public