156 if (isset($nest_groups)) $this->nestGroups = $nest_groups;
175 if (!isset($this) || !isset($this->mailRFC822)) {
177 return $obj->parseAddressList();
182 if (isset($nest_groups)) $this->nestGroups = $nest_groups;
186 $this->structure = array();
187 $this->addresses = array();
192 $this->address = preg_replace(
'/\r?\n/',
"\r\n", $this->address);
193 $this->address = preg_replace(
'/\r\n(\t| )+/',
' ', $this->address);
197 if ($this->address ===
false || isset($this->error)) {
198 require_once
'PEAR.php';
204 foreach ($this->addresses as
$address) {
207 if (
$valid ===
false || isset($this->error)) {
208 require_once
'PEAR.php';
212 if (!$this->nestGroups) {
213 $this->structure = array_merge($this->structure,
$valid);
215 $this->structure[] =
$valid;
231 if (!empty($this->limit) && count($this->addresses) == $this->limit) {
238 } elseif (!isset($this->error)) {
241 } elseif (isset($this->error)) {
246 $parts = explode($split_char,
$address);
255 if (strpos($string,
':') ===
false) {
256 $this->error =
'Invalid address: ' . $string;
261 if (!$this->
_splitCheck(explode(
':', $string),
':')) {
271 $this->addresses[] = array(
272 'address' => trim($string),
283 if ($is_group && substr(
$address, 0, 1) ==
','){
314 if (count($parts = explode(
':', $string)) > 1) {
316 return ($string2 !== $string);
334 for ($i = 0; $i < count($parts); $i++) {
339 || substr($string, -1) ==
'\\') {
340 if (isset($parts[$i + 1])) {
341 $string = $string . $char . $parts[$i + 1];
343 $this->error =
'Invalid address spec. Unclosed bracket or quotes';
365 $string = trim($string);
366 $iMax = strlen($string);
370 for (; $i < $iMax; ++$i) {
371 switch ($string[$i]) {
377 if ($slashes % 2 == 0) {
378 $in_quote = !$in_quote;
402 $num_angle_start = substr_count($string, $chars[0]);
403 $num_angle_end = substr_count($string, $chars[1]);
408 if ($num_angle_start < $num_angle_end) {
409 $this->error =
'Invalid address spec. Unmatched quote or bracket (' . $chars .
')';
412 return ($num_angle_start > $num_angle_end);
427 $parts = explode($char, $string);
428 for ($i = 0; $i < count($parts); $i++){
431 if (isset($parts[$i + 1]))
432 $parts[$i + 1] = $parts[$i] . $char . $parts[$i + 1];
454 $parts = explode(
':',
$address[
'address']);
460 $this->error =
'Group name did not validate.';
465 if ($this->nestGroups) {
471 $address[
'address'] = ltrim(substr(
$address[
'address'], strlen($groupname .
':')));
477 while (strlen(
$address[
'address']) > 0) {
478 $parts = explode(
',',
$address[
'address']);
490 $this->error =
'Empty group.';
504 if (empty($this->error)) {
505 $this->error =
'Validation failed for: ' .
$addresses[$i];
512 if ($this->nestGroups) {
541 $parts = preg_split(
'/[ \\x09]+/', $phrase, -1, PREG_SPLIT_NO_EMPTY);
543 $phrase_parts = array();
544 while (count($parts) > 0){
546 for ($i = 0; $i < $this->index + 1; $i++)
550 foreach ($phrase_parts as $part) {
552 if (substr($part, 0, 1) ==
'"') {
581 if (!$this->validate) {
587 if (!preg_match(
'/^[\\x00-\\x7E]+$/i', $atom, $matches)) {
592 if (preg_match(
'/[][()<>@,;\\:". ]/', $atom)) {
597 if (preg_match(
'/[\\x00-\\x1F]+/', $atom)) {
615 $qstring = substr($qstring, 1, -1);
618 return !preg_match(
'/[\x0D\\\\"]/', preg_replace(
'/\\\\./',
'', $qstring));
638 $_mailbox = $mailbox;
639 while (strlen(trim($_mailbox)) > 0) {
640 $parts = explode(
'(', $_mailbox);
642 if ($before_comment != $_mailbox) {
644 $comment = substr(str_replace($before_comment,
'', $_mailbox), 1);
650 $_mailbox = substr($_mailbox, strpos($_mailbox,
'('.
$comment)+strlen(
$comment)+2);
657 $mailbox = str_replace(
"($comment)",
'', $mailbox);
660 $mailbox = trim($mailbox);
663 if (substr($mailbox, -1) ==
'>' && substr($mailbox, 0, 1) !=
'<') {
664 $parts = explode(
'<', $mailbox);
667 $phrase = trim(
$name);
668 $route_addr = trim(substr($mailbox, strlen(
$name.
'<'), -1));
677 if (substr($mailbox, 0, 1) ==
'<' && substr($mailbox, -1) ==
'>') {
678 $addr_spec = substr($mailbox, 1, -1);
680 $addr_spec = $mailbox;
689 $mbox =
new stdClass();
692 $mbox->personal = $phrase;
693 $mbox->comment = isset($comments) ? $comments : array();
695 if (isset($route_addr)) {
696 $mbox->mailbox = $route_addr[
'local_part'];
697 $mbox->host = $route_addr[
'domain'];
698 $route_addr[
'adl'] !==
'' ? $mbox->adl = $route_addr[
'adl'] :
'';
700 $mbox->mailbox = $addr_spec[
'local_part'];
701 $mbox->host = $addr_spec[
'domain'];
722 if (strpos($route_addr,
':') !==
false) {
723 $parts = explode(
':', $route_addr);
726 $route = $route_addr;
731 if ($route === $route_addr){
733 $addr_spec = $route_addr;
743 $addr_spec = substr($route_addr, strlen($route .
':'));
752 $return[
'adl'] = $route;
757 $return = array_merge($return, $addr_spec);
772 $domains = explode(
',', trim($route));
774 foreach ($domains as $domain) {
775 $domain = str_replace(
'@',
'', trim($domain));
795 $subdomains = explode(
'.', $domain);
797 while (count($subdomains) > 0) {
798 $sub_domains[] = $this->
_splitCheck($subdomains,
'.');
799 for ($i = 0; $i < $this->index + 1; $i++)
800 array_shift($subdomains);
803 foreach ($sub_domains as $sub_domain) {
822 if (preg_match(
'|^\[(.*)]$|', $subdomain, $arr)){
842 return !preg_match(
'/(.)[][\x0D\\\\]/', $dliteral, $matches) && $matches[1] !=
'\\';
856 $addr_spec = trim($addr_spec);
859 if (strpos($addr_spec,
'@') !==
false) {
860 $parts = explode(
'@', $addr_spec);
862 $domain = substr($addr_spec, strlen($local_part .
'@'));
866 $local_part = $addr_spec;
871 if (($domain = $this->
_validateDomain($domain)) ===
false)
return false;
874 return array(
'local_part' => $local_part,
'domain' => $domain);
887 $parts = explode(
'.', $local_part);
891 while (count($parts) > 0){
893 for ($i = 0; $i < $this->index + 1; $i++) {
899 foreach ($words as $word) {
901 if (strpos($word,
' ') && $word[0] !==
'"')
925 return count(preg_split(
'/(?<!\\\\),/',
$data));
943 $regex = $strict ?
'/^([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})$/i' :
'/^([*+!.&#$|\'\\%\/0-9a-z^_`{}=?~:-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})$/i';
944 if (preg_match($regex, trim(
$data), $matches)) {
945 return array($matches[1], $matches[2]);