3 declare(strict_types=1);
155 ?
string $address =
null,
156 ?
string $default_domain =
null,
157 ?
bool $nest_groups =
null,
158 ?
bool $validate =
null,
161 if (isset($address)) {
164 if (isset($default_domain)) {
167 if (isset($nest_groups)) {
168 $this->nestGroups = $nest_groups;
170 if (isset($validate)) {
190 ?
string $address =
null,
191 ?
string $default_domain =
null,
192 ?
bool $nest_groups =
null,
193 ?
bool $validate =
null,
196 if (!isset($this, $this->mailRFC822)) {
197 $obj =
new Mail_RFC822($address, $default_domain, $nest_groups, $validate, $limit);
198 return $obj->parseAddressList();
201 if (isset($address)) {
204 if (isset($default_domain)) {
207 if (isset($nest_groups)) {
208 $this->nestGroups = $nest_groups;
210 if (isset($validate)) {
217 $this->structure = [];
218 $this->addresses = [];
223 $this->address = preg_replace(
'/\r?\n/',
"\r\n", $this->address);
224 $this->address = preg_replace(
'/\r\n(\t| )+/',
' ', $this->address);
226 $tmp_address =
false;
228 $this->address = $tmp_address;
231 if ($tmp_address ===
false || isset($this->error)) {
239 foreach ($this->addresses as $address) {
242 if (
$valid ===
false || isset($this->error)) {
248 if (!$this->nestGroups) {
249 $this->structure = array_merge($this->structure,
$valid);
251 $this->structure[] =
$valid;
266 if (!empty($this->limit) && count($this->addresses) === $this->limit) {
270 if (!isset($this->error) && $this->
_isGroup($address)) {
273 } elseif (!isset($this->error)) {
276 } elseif (isset($this->error)) {
281 $parts = explode($split_char, $address);
290 if (strpos($string,
':') ===
false) {
291 $this->error =
'Invalid address: ' . $string;
296 if (!$this->
_splitCheck(explode(
':', $string),
':')) {
306 $this->addresses[] = [
307 'address' => trim($string),
308 'group' => $is_group,
313 $address = trim((
string) substr($address, strlen($string) + 1));
318 if ($is_group && $address[0] ===
',') {
319 $address = trim(substr($address, 1));
335 $parts = explode(
',', $address);
341 if (count(
$parts = explode(
':', $string)) > 1) {
343 return ($string2 !== $string);
360 for ($i = 0, $iMax = count($parts); $i < $iMax; $i++) {
365 || substr($string, -1) ===
'\\') {
366 if (isset($parts[$i + 1])) {
367 $string .= $char . $parts[$i + 1];
369 $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;
426 $num_angle_start = substr_count($string, $chars[0]);
427 $num_angle_end = substr_count($string, $chars[1]);
432 if ($num_angle_start < $num_angle_end) {
433 $this->error =
'Invalid address spec. Unmatched quote or bracket (' . $chars .
')';
437 return ($num_angle_start > $num_angle_end);
450 $parts = explode($char, $string);
451 for ($i = 0, $iMax = count(
$parts); $i < $iMax; $i++) {
455 if (isset(
$parts[$i + 1])) {
474 if ($address[
'group']) {
478 $parts = explode(
':', $address[
'address']);
484 $this->error =
'Group name did not validate.';
488 if ($this->nestGroups) {
492 $structure->groupname = $groupname;
495 $address[
'address'] = ltrim(substr($address[
'address'], strlen($groupname .
':')));
501 while (strlen($address[
'address']) > 0) {
502 $parts = explode(
',', $address[
'address']);
504 $address[
'address'] = trim(substr($address[
'address'], strlen(end($addresses) .
',')));
507 $addresses[] = $address[
'address'];
518 for ($i = 0, $iMax = count($addresses); $i < $iMax; $i++) {
520 if (empty($this->error)) {
521 $this->error =
'Validation failed for: ' . $addresses[$i];
528 if ($this->nestGroups) {
532 $structure = $addresses[0];
536 } elseif ($is_group) {
537 $structure = array_merge($structure, $addresses);
554 $parts = preg_split(
'/[ \\x09]+/', $phrase, -1, PREG_SPLIT_NO_EMPTY);
557 while (count(
$parts) > 0) {
559 for ($i = 0; $i < $this->index + 1; $i++) {
564 foreach ($phrase_parts as $part) {
566 if (strpos($part,
'"') === 0) {
596 if (!$this->validate) {
604 if (preg_match(
'/[][()<>@,;\\:". ]/', $atom)) {
609 if (preg_match(
'/[\\x00-\\x1F]+/', $atom)) {
614 if (!(
bool) preg_match(
'//u', $atom)) {
632 $qstring = substr($qstring, 1, -1);
635 return !preg_match(
'/[\x0D\\\\"]/', preg_replace(
'/\\\\./',
'', $qstring));
654 $_mailbox = $mailbox;
655 while (trim($_mailbox) !==
'') {
656 $parts = explode(
'(', $_mailbox);
658 if ($before_comment !== $_mailbox) {
660 $comment = substr(str_replace($before_comment,
'', $_mailbox), 1);
666 $_mailbox = substr($_mailbox, strpos($_mailbox,
'(' .
$comment) + strlen(
$comment) + 2);
673 $mailbox = str_replace(
"($comment)",
'', $mailbox);
676 $mailbox = trim($mailbox);
679 if (substr($mailbox, -1) ===
'>' && $mailbox[0] !==
'<') {
680 $parts = explode(
'<', $mailbox);
683 $phrase = trim($name);
684 $route_addr = trim(substr($mailbox, strlen($name .
'<'), -1));
694 if ($mailbox[0] ===
'<' && substr($mailbox, -1) ===
'>') {
695 $addr_spec = substr($mailbox, 1, -1);
697 $addr_spec = $mailbox;
709 $mbox->personal = $phrase;
712 if (isset($route_addr)) {
713 $mbox->mailbox = $route_addr[
'local_part'];
714 $mbox->host = $route_addr[
'domain'];
715 if ($route_addr[
'adl'] !==
'') {
716 $mbox->adl = $route_addr[
'adl'];
719 $mbox->mailbox = $addr_spec[
'local_part'];
720 $mbox->host = $addr_spec[
'domain'];
740 if (strpos($route_addr,
':') !==
false) {
741 $parts = explode(
':', $route_addr);
744 $route = $route_addr;
749 if ($route === $route_addr) {
751 $addr_spec = $route_addr;
761 $addr_spec = substr($route_addr, strlen($route .
':'));
770 $return[
'adl'] = $route;
775 $return = array_merge($return, $addr_spec);
789 $domains = explode(
',', trim($route));
791 foreach ($domains as $domain) {
792 $domain = str_replace(
'@',
'', trim($domain));
813 $subdomains = explode(
'.', $domain);
816 while (count($subdomains) > 0) {
817 $sub_domains[] = $this->
_splitCheck($subdomains,
'.');
818 for ($i = 0; $i < $this->index + 1; $i++) {
819 array_shift($subdomains);
823 foreach ($sub_domains as $sub_domain) {
842 if (preg_match(
'|^\[(.*)]$|', $subdomain, $arr)) {
863 return !preg_match(
'/(.)[][\x0D\\\\]/', $dliteral, $matches) &&
864 ((!isset($matches[1])) || $matches[1] !=
'\\');
877 $addr_spec = trim($addr_spec);
883 if (strpos($addr_spec,
'@') !==
false) {
884 $parts = explode(
'@', $addr_spec);
886 $domain = substr($addr_spec, strlen($local_part .
'@'));
888 if (substr_count($addr_spec,
'@') !== 1 && $local_part ===
'') {
889 $this->validate =
false;
890 $local_part = $addr_spec;
896 $local_part = $addr_spec;
904 if ($validateState !== $this->validate) {
905 $this->validate = $validateState;
913 return [
'local_part' => $local_part,
'domain' => $domain];
926 $parts = explode(
'.', $local_part);
930 while (count(
$parts) > 0) {
932 for ($i = 0; $i < $this->index + 1; $i++) {
938 foreach ($words as $word) {
946 if (strpos($word,
' ') && $word[0] !==
'"') {
975 return count(preg_split(
'/(?<!\\\\),/', $data));
995 '/^([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})$/i' :
996 '/^([*+!.&#$|\'\\%\/0-9a-z^_`{}=?~:-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})$/i';
997 if (preg_match($regex, trim($data), $matches)) {
998 return [$matches[1], $matches[2]];
_validateQuotedString(string $qstring)
Function to validate quoted string, which is: quoted-string = <"> *(qtext/quoted-pair) <"> ...
_validateAddrSpec(string $addr_spec)
Function to validate an addr-spec.
int $num_groups
The number of groups that have been found in the address list.
_isGroup(string $address)
Checks for a group at the start of the string.
bool $nestGroups
Should we return a nested array showing groups, or flatten everything?
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
_hasUnclosedBrackets(string $string, string $chars)
Checks if a string has an unclosed brackets or not.
_validateLocalPart(string $local_part)
Function to validate the local part of an address: local-part = word *("." word)
_validateAddress(array $address)
Function to begin checking the address.
string $default_domain
The default domain to use for unqualified addresses.
_validateDomain(string $domain)
Function to validate a domain, though this is not quite what you expect of a strict internet domain...
_hasUnclosedQuotes(string $string)
Checks if a string has unclosed quotes or not.
_validateRoute(string $route)
Function to validate a route, which is: route = 1#("@" domain) ":".
__construct(?string $address=null, ?string $default_domain=null, ?bool $nest_groups=null, ?bool $validate=null, ?int $limit=null)
Sets up the object.
bool $validate
Whether or not to validate atoms for non-ascii characters.
_validateAtom(string $atom)
Function to validate an atom which from rfc822 is: atom = 1*<any CHAR except specials, SPACE and CTLs>
_validateRouteAddr(string $route_addr)
This function validates a route-addr which is: route-addr = "<" [route] addr-spec ">"...
array $structure
The final array of parsed address information that we build up.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
isValidInetAddress(string $data, bool $strict=false)
This is a email validating function separate to the rest of the class.
_validateSubdomain(string $subdomain)
Function to validate a subdomain: subdomain = domain-ref / domain-literal.
_hasUnclosedBracketsSub(string $string, int &$num, string $char)
Sub function that is used only by hasUnclosedBrackets().
bool $mailRFC822
A variable so that we can tell whether or not we're inside a Mail_RFC822 object.
int $limit
A limit after which processing stops.
string $error
The current error message, if any.
approximateCount(string $data)
Returns an approximate count of how many addresses are in the given string.
parseAddressList(?string $address=null, ?string $default_domain=null, ?bool $nest_groups=null, ?bool $validate=null, ?int $limit=null)
Starts the whole process.
validateMailbox(string &$mailbox)
Function to validate a mailbox, which is: mailbox = addr-spec ; simple address / phrase route-addr ; ...
_splitCheck(array $parts, string $char)
A common function that will check an exploded string.
string $address
The address being parsed by the RFC822 object.
_validateDliteral(string $dliteral)
Function to validate a domain literal: domain-literal = "[" *(dtext / quoted-pair) "]"...
_splitAddresses(string $address)
Splits an address into separate addresses.
array $addresses
The array of raw addresses built up as we parse.
_validatePhrase(string $phrase)
Function to validate a phrase.
int $index
An internal counter/pointer.