183 $this->structure = array();
184 $this->addresses = array();
188 $this->address = preg_replace(
'/\\r?\\n/',
' 190 $this->address = preg_replace(
'/\\r\\n(\\t| )+/',
' ', $this->address);
194 if ($this->address === FALSE || isset($this->error)) {
195 throw new \InvalidArgumentException($this->error, 1294681466);
199 foreach ($this->addresses as
$address) {
201 if ($valid === FALSE || isset($this->error)) {
202 throw new \InvalidArgumentException($this->error, 1294681467);
204 $this->structure = array_merge($this->structure, $valid);
217 if (!empty($this->limit) && count($this->addresses) == $this->limit) {
223 } elseif (!isset($this->error)) {
226 } elseif (isset($this->error)) {
230 $parts = explode($split_char,
$address);
237 if (strpos($string,
':') === FALSE) {
238 $this->error =
'Invalid address: ' . $string;
242 if (!$this->
_splitCheck(explode(
':', $string),
':')) {
250 $this->addresses[] = array(
251 'address' => trim($string),
260 if ($is_group &&
$address[0] ===
',') {
284 if (count(($parts = explode(
':', $string))) > 1) {
286 return $string2 !== $string;
302 $partsCounter = count($parts);
303 for ($i = 0; $i < $partsCounter; $i++) {
305 if (isset($parts[$i + 1])) {
306 $string = $string . $char . $parts[($i + 1)];
308 $this->error =
'Invalid address spec. Unclosed bracket or quotes';
327 $string = trim($string);
328 $iMax = strlen($string);
331 for (; $i < $iMax; ++$i) {
332 switch ($string[$i]) {
337 if ($slashes % 2 == 0) {
338 $in_quote = !$in_quote;
357 $num_angle_start = substr_count($string, $chars[0]);
358 $num_angle_end = substr_count($string, $chars[1]);
361 if ($num_angle_start < $num_angle_end) {
362 $this->error =
'Invalid address spec. Unmatched quote or bracket (' . $chars .
')';
365 return $num_angle_start > $num_angle_end;
379 $parts = explode($char, $string);
380 $partsCounter = count($parts);
381 for ($i = 0; $i < $partsCounter; $i++) {
385 if (isset($parts[$i + 1])) {
386 $parts[$i + 1] = $parts[$i] . $char . $parts[($i + 1)];
405 $parts = explode(
':',
$address[
'address']);
410 $this->error =
'Group name did not validate.';
413 $address[
'address'] = ltrim(substr(
$address[
'address'], strlen($groupname .
':')));
418 while (strlen(
$address[
'address']) > 0) {
419 $parts = explode(
',',
$address[
'address']);
430 $this->error =
'Empty group.';
441 for ($i = 0; $i < $addressesCount; $i++) {
443 if (empty($this->error)) {
444 $this->error =
'Validation failed for: ' .
$addresses[$i];
466 $parts = preg_split(
'/[ \\x09]+/', $phrase, -1, PREG_SPLIT_NO_EMPTY);
467 $phrase_parts = array();
468 while (count($parts) > 0) {
470 for ($i = 0; $i < $this->index + 1; $i++) {
474 foreach ($phrase_parts as $part) {
476 if ($part[0] ===
'"') {
504 if (!$this->validate) {
509 if (!preg_match(
'/^[\\x00-\\x7E]+$/i', $atom, $matches)) {
513 if (preg_match(
'/[][()<>@,;\\:". ]/', $atom)) {
517 if (preg_match(
'/[\\x00-\\x1F]+/', $atom)) {
533 $qstring = substr($qstring, 1, -1);
535 return !preg_match(
'/[\\x0D\\\\"]/', preg_replace(
'/\\\\./',
'', $qstring));
553 $_mailbox = $mailbox;
554 while (strlen(trim($_mailbox)) > 0) {
555 $parts = explode(
'(', $_mailbox);
557 if ($before_comment != $_mailbox) {
559 $comment = substr(str_replace($before_comment,
'', $_mailbox), 1);
560 $parts = explode(
')', $comment);
562 $comments[] = $comment;
564 $_mailbox = substr($_mailbox, strpos($_mailbox, (
'(' . $comment)) + strlen($comment) + 2);
569 foreach ($comments as $comment) {
570 $mailbox = str_replace(
'(' . $comment .
')',
'', $mailbox);
572 $mailbox = trim($mailbox);
574 if (substr($mailbox, -1) ===
'>' && $mailbox[0] !==
'<') {
575 $parts = explode(
'<', $mailbox);
577 $phrase = trim($name);
578 $route_addr = trim(substr($mailbox, strlen($name .
'<'), -1));
584 if ($mailbox[0] ===
'<' && substr($mailbox, -1) ===
'>') {
585 $addr_spec = substr($mailbox, 1, -1);
587 $addr_spec = $mailbox;
594 $mbox = new \stdClass();
596 $mbox->personal = $phrase;
597 $mbox->comment = isset($comments) ? $comments : array();
598 if (isset($route_addr)) {
599 $mbox->mailbox = $route_addr[
'local_part'];
600 $mbox->host = $route_addr[
'domain'];
601 $route_addr[
'adl'] !==
'' ? ($mbox->adl = $route_addr[
'adl']) :
'';
603 $mbox->mailbox = $addr_spec[
'local_part'];
604 $mbox->host = $addr_spec[
'domain'];
623 if (strpos($route_addr,
':') !== FALSE) {
624 $parts = explode(
':', $route_addr);
627 $route = $route_addr;
631 if ($route === $route_addr) {
633 $addr_spec = $route_addr;
642 $addr_spec = substr($route_addr, strlen($route .
':'));
649 $return[
'adl'] = $route;
653 $return = array_merge($return, $addr_spec);
667 $domains = explode(
',', trim($route));
668 foreach ($domains as $domain) {
669 $domain = str_replace(
'@',
'', trim($domain));
689 $subdomains = explode(
'.', $domain);
690 while (count($subdomains) > 0) {
691 $sub_domains[] = $this->
_splitCheck($subdomains,
'.');
692 for ($i = 0; $i < $this->index + 1; $i++) {
693 array_shift($subdomains);
696 foreach ($sub_domains as $sub_domain) {
714 if (preg_match(
'|^\\[(.*)]$|', $subdomain, $arr)) {
736 return !preg_match(
'/(.)[][\\x0D\\\\]/', $dliteral, $matches) && $matches[1] !=
'\\';
749 $addr_spec = trim($addr_spec);
751 if (strpos($addr_spec,
'@') !== FALSE) {
752 $parts = explode(
'@', $addr_spec);
754 $domain = substr($addr_spec, strlen($local_part .
'@'));
756 $local_part = $addr_spec;
766 return array(
'local_part' => $local_part,
'domain' => $domain);
778 $parts = explode(
'.', $local_part);
781 while (count($parts) > 0) {
783 for ($i = 0; $i < $this->index + 1; $i++) {
788 foreach ($words as $word) {
790 if (strpos($word,
' ') && $word[0] !==
'"') {
__construct($address=NULL, $default_domain=NULL, $validate=NULL, $limit=NULL)
_validateDliteral($dliteral)
_hasUnclosedQuotes($string)
_hasUnclosedBracketsSub($string, &$num, $char)
_validateLocalPart($local_part)
validateMailbox(&$mailbox)
parseAddressList($address=NULL, $default_domain=NULL, $validate=NULL, $limit=NULL)
_hasUnclosedBrackets($string, $chars)
_validateSubdomain($subdomain)
_validateQuotedString($qstring)
_splitAddresses($address)
_validateAddress($address)
_validateRouteAddr($route_addr)
_splitCheck($parts, $char)
_validateAddrSpec($addr_spec)