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) {
589 if (preg_match(
'/[][()<>@,;\\:". ]/', $atom)) {
594 if (preg_match(
'/[\\x00-\\x1F]+/', $atom)) {
599 if (!(
bool)preg_match(
'//u', $atom)) {
618 $qstring = substr($qstring, 1, -1);
621 return !preg_match(
'/[\x0D\\\\"]/', preg_replace(
'/\\\\./',
'', $qstring));
641 $_mailbox = $mailbox;
642 while (strlen(trim($_mailbox)) > 0) {
643 $parts = explode(
'(', $_mailbox);
645 if ($before_comment != $_mailbox) {
647 $comment = substr(str_replace($before_comment,
'', $_mailbox), 1);
653 $_mailbox = substr($_mailbox, strpos($_mailbox,
'('.
$comment)+strlen(
$comment)+2);
660 $mailbox = str_replace(
"($comment)",
'', $mailbox);
663 $mailbox = trim($mailbox);
666 if (substr($mailbox, -1) ==
'>' && substr($mailbox, 0, 1) !=
'<') {
667 $parts = explode(
'<', $mailbox);
670 $phrase = trim($name);
671 $route_addr = trim(substr($mailbox, strlen($name.
'<'), -1));
680 if (substr($mailbox, 0, 1) ==
'<' && substr($mailbox, -1) ==
'>') {
681 $addr_spec = substr($mailbox, 1, -1);
683 $addr_spec = $mailbox;
692 $mbox =
new stdClass();
695 $mbox->personal = $phrase;
696 $mbox->comment = isset($comments) ? $comments : array();
698 if (isset($route_addr)) {
699 $mbox->mailbox = $route_addr[
'local_part'];
700 $mbox->host = $route_addr[
'domain'];
701 $route_addr[
'adl'] !==
'' ? $mbox->adl = $route_addr[
'adl'] :
'';
703 $mbox->mailbox = $addr_spec[
'local_part'];
704 $mbox->host = $addr_spec[
'domain'];
725 if (strpos($route_addr,
':') !==
false) {
726 $parts = explode(
':', $route_addr);
729 $route = $route_addr;
734 if ($route === $route_addr){
736 $addr_spec = $route_addr;
746 $addr_spec = substr($route_addr, strlen($route .
':'));
755 $return[
'adl'] = $route;
760 $return = array_merge($return, $addr_spec);
775 $domains = explode(
',', trim($route));
777 foreach ($domains as $domain) {
778 $domain = str_replace(
'@',
'', trim($domain));
798 $subdomains = explode(
'.', $domain);
800 while (count($subdomains) > 0) {
801 $sub_domains[] = $this->
_splitCheck($subdomains,
'.');
802 for ($i = 0; $i < $this->index + 1; $i++)
803 array_shift($subdomains);
806 foreach ($sub_domains as $sub_domain) {
825 if (preg_match(
'|^\[(.*)]$|', $subdomain, $arr)){
845 return !preg_match(
'/(.)[][\x0D\\\\]/', $dliteral, $matches) && $matches[1] !=
'\\';
859 $addr_spec = trim($addr_spec);
862 if (strpos($addr_spec,
'@') !==
false) {
863 $parts = explode(
'@', $addr_spec);
865 $domain = substr($addr_spec, strlen($local_part .
'@'));
869 $local_part = $addr_spec;
874 if (($domain = $this->
_validateDomain($domain)) ===
false)
return false;
877 return array(
'local_part' => $local_part,
'domain' => $domain);
890 $parts = explode(
'.', $local_part);
894 while (count($parts) > 0){
896 for ($i = 0; $i < $this->index + 1; $i++) {
902 foreach ($words as $word) {
904 if (strpos($word,
' ') && $word[0] !==
'"')
928 return count(preg_split(
'/(?<!\\\\),/', $data));
946 $regex = $strict ?
'/^([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})$/i' :
'/^([*+!.&#$|\'\\%\/0-9a-z^_`{}=?~:-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})$/i';
947 if (preg_match($regex, trim($data), $matches)) {
948 return array($matches[1], $matches[2]);