@param string $emailAddress

@return string
551657
public function convertEmailAddress(string $emailAddress): string
    {
        if (strpos($emailAddress, '@') === false) {
            throw new InvalidArgumentException('The given string does not look like an email address', 206);
        }

        $parts = explode('@', $emailAddress);

        return sprintf(
            '%s@%s',
            $parts[0],
            $this->convert($parts[1])
        );
    }
1086584
private function addAddress(
                        &$emailAddresses,
                        &$emailAddress,
                        $encoding,
                        $i)
    {
        if (!$emailAddress['invalid']) {
            if ($emailAddress['address_temp'] || $emailAddress['quote_temp']) {
                $emailAddress['invalid'] = true;
                $emailAddress['invalid_reason'] = "Incomplete address";
                $this->log('error', "Email\\Parse->addAddress - corruption during parsing - leftovers:\n\$i: ${i}\n\$emailAddress['address_temp'] : {$emailAddress['address_temp']}\n\$emailAddress['quote_temp']: {$emailAddress['quote_temp']}\n");
            } elseif ($emailAddress['ip'] && $emailAddress['domain']) {
                // Error - this should never occur
                $emailAddress['invalid'] = true;
                $emailAddress['invalid_reason'] = "Confusion during parsing";
                $this->log('error', "Email\\Parse->addAddress - both an IP address '{$emailAddress['ip']}' and a domain '{$emailAddress['domain']}' found for the email address '{$emailAddress['original_address']}'\n");
            } elseif ($emailAddress['ip'] || ($emailAddress['domain'] && preg_match('/\d+\.\d+\.\d+\.\d+/', $emailAddress['domain']))) {
                // also test if the current domain looks like an IP address

                if ($emailAddress['domain']) {
                    // Likely an IP address if we get here

                    $emailAddress['ip'] = $emailAddress['domain'];
                    $emailAddress['domain'] = null;
                }
                if (!$this->ipValidator) {
                    $this->ipValidator = new Ip();
                }
                try {
                    if (!$this->ipValidator->isValid($emailAddress['ip'])) {
                        $emailAddress['invalid'] = true;
                        $emailAddress['invalid_reason'] = 'IP address invalid: \''.$emailAddress['ip'].'\' does not appear to be a valid IP address';
                    } elseif (preg_match('/192\.168\.\d+\.\d+/', $emailAddress['ip']) ||
                        preg_match('/172\.(1[6-9]|2[0-9]|3[0-2])\.\d+\.\d+/', $emailAddress['ip']) ||
                        preg_match('/10\.\d+\.\d+\.\d+/', $emailAddress['ip'])) {
                        $emailAddress['invalid'] = true;
                        $emailAddress['invalid_reason'] = 'IP address invalid (private): '.$emailAddress['ip'];
                    } elseif (preg_match('/169\.254\.\d+\.\d+/', $emailAddress['ip'])) {
                        $emailAddress['invalid'] = true;
                        $emailAddress['invalid_reason'] = 'IP address invalid (APIPA): '.$emailAddress['ip'];
                    }
                } catch (\Exception $e) {
                    $emailAddress['invalid'] = true;
                    $emailAddress['invalid_reason'] = 'IP address invalid: '.$emailAddress['ip'];
                }
            } elseif ($emailAddress['domain']) {
                // Check for IDNA
                if (max(array_keys(count_chars($emailAddress['domain'], 1))) > 127) {
                    try {
                        $emailAddress['domain'] = $this->getPunycode()->encode($emailAddress['domain']);
                    } catch (\Exception $e) {
                        $emailAddress['invalid'] = true;
                        $emailAddress['invalid_reason'] = "Can't convert domain {$emailAddress['domain']} to punycode";
                    }
                }

                $result = $this->validateDomainName($emailAddress['domain']);
                if (!$result['valid']) {
                    $emailAddress['invalid'] = true;
                    $emailAddress['invalid_reason'] = isset($result['reason']) ? 'Domain invalid: '.$result['reason'] : 'Domain invalid for some unknown reason';
                }
            }
        }

        // Prepare some of the fields needed
        $emailAddress['name_parsed'] = rtrim($emailAddress['name_parsed']);
        $emailAddress['original_address'] = rtrim($emailAddress['original_address']);
        $name = $emailAddress['name_quoted'] ? "\"{$emailAddress['name_parsed']}\"" : $emailAddress['name_parsed'];
        $localPart = $emailAddress['local_part_quoted'] ? "\"{$emailAddress['local_part_parsed']}\"" : $emailAddress['local_part_parsed'];
        $domainPart = $emailAddress['ip'] ? '['.$emailAddress['ip'].']' : $emailAddress['domain'];

        if (!$emailAddress['invalid']) {
            if (mb_strlen($domainPart, $encoding) == 0) {
                $emailAddress['invalid'] = true;
                $emailAddress['invalid_reason'] = 'Email address needs a domain after the \'@\'';
            } elseif (mb_strlen($localPart, $encoding) > 63) {
                $emailAddress['invalid'] = true;
                $emailAddress['invalid_reason'] = 'Email address before the \'@\' can not be greater than 63 characters';
            } elseif ((mb_strlen($localPart, $encoding) + mb_strlen($domainPart, $encoding) + 1) > 254) {
                $emailAddress['invalid'] = true;
                $emailAddress['invalid_reason'] = 'Email addresses can not be greater than 254 characters';
            }
        }

        // Build the email address hash
        $emailAddrDef = ['address' => '',
                        'simple_address' => '',
                        'original_address' => rtrim($emailAddress['original_address']),
                        'name' => $name,
                        'name_parsed' => $emailAddress['name_parsed'],
                        'local_part' => $localPart,
                        'local_part_parsed' => $emailAddress['local_part_parsed'],
                        'domain_part' => $domainPart,
                        'domain' => $emailAddress['domain'],
                        'ip' => $emailAddress['ip'],
                        'invalid' => $emailAddress['invalid'],
                        'invalid_reason' => $emailAddress['invalid_reason']];



        // Build the proper address by hand (has comments stripped out and should have quotes in the proper places)
        if (!$emailAddrDef['invalid']) {
            $emailAddrDef['simple_address'] = "{$emailAddrDef['local_part']}@{$emailAddrDef['domain_part']}";
            $properAddress = $emailAddrDef['name'] ? "{$emailAddrDef['name']} <{$emailAddrDef['local_part']}@{$emailAddrDef['domain_part']}>" : $emailAddrDef['simple_address'];
            $emailAddrDef['address'] = $properAddress;
        }

        $emailAddresses[] = $emailAddrDef;
        return $emailAddrDef['invalid'];
    }
1271306
function formatAddressField($message, $field)
    {
        $headers = $message->getHeaders();

        if (!$headers->has($field)) {
            return null;
        }

        $mailboxes = $headers->get($field)->getFieldBodyModel();

        $strings = [];
        foreach ($mailboxes as $email => $name) {
            $mailboxStr = $email;
            if (null !== $name) {
                $mailboxStr = $name . ' <' . $mailboxStr . '>';
            }
            $strings[] = $mailboxStr;
        }
        return implode(', ', $strings);
    }
342221
private function getAllEmailAddresses($parts, $fields = ['to', 'from', 'cc', 'bcc'])
    {
        $addresses = [];
        foreach ($fields as $field) {
            $addressesPerField = [];
            foreach ($parts as $part) {
                 $addressesPerField = array_merge(
                     $addressesPerField,
                     $this->getAddressesFromFieldInPart($field, $part)
                 );
            }
            $addresses[$field] = $addressesPerField;
        }

        return $addresses;
    }
132540
public static function addressParse($addressString)
    {
        // $this->debug->groupCollapsed(__CLASS__.'->'.__FUNCTION__);
        // $this->debug->log('addressString', $addressString);
        $pattern = '/^(?:"?((?:[^"\\\\]|\\\\.)+)"?\s)?'             // name
            .'<?([a-z0-9._%-]+@[a-z0-9.-]+\\.[a-z]{2,4})>?$/i';     // email
        $addresses = str_getcsv($addressString);
        // $this->debug->log('addresses', $addresses);
        $result = array();
        foreach ($addresses as $address) {
            $address = trim($address);
            if (preg_match($pattern, $address, $matches)) {
                $item = array();
                if ($matches[1] != '') {
                    $item['name'] = stripcslashes($matches[1]);
                }
                $item['email'] =  $matches[2];
                $result[] = $item;
            }
        }
        // $this->debug->groupEnd();
        return $result;
    }
581512
@Programmatic
    public ApplicationUser findByEmailAddressCached(final String emailAddress) {
        return queryResultsCache.execute(new Callable<ApplicationUser>() {
            @Override public ApplicationUser call() throws Exception {
                return findByEmailAddress(emailAddress);
            }
        }, ApplicationUserRepository.class, "findByEmailAddressCached", emailAddress);
    }
389743
public static function fromString(string $emailAddress): self
    {
        if (!preg_match('/^([^><]+?)\s*(?:<([^><]+)>)?$/', $emailAddress, $matches)) {
            throw new InvalidArgumentException(sprintf('"%s" is not a valid e-mail address.', $emailAddress));
        }

        return isset($matches[2]) ? new static($matches[2], $matches[1]) : new static($matches[1]);
    }
393499
public function getAllEmailAddresses($fields = ['to', 'from', 'cc', 'bcc'])
    {
        $addresses = [];
        foreach ($fields as $field) {
            if(isset($this->allEmailAddressesByField[$field])) {
                foreach ($this->allEmailAddressesByField[$field] as $emailAddress) {
                    $addresses[] = $emailAddress;
                }
            }
        }

        return array_unique($addresses);
    }
660517
private function setEmailAddress(?string $emailAddress): self
    {
        $this->updatePropertyValue(
            EmailAddressFieldInterface::PROP_EMAIL_ADDRESS,
            $emailAddress
        );

        return $this;
    }
880518
private function decodeEmailAddresses(array $addresses): array
    {
        $return = [];
        foreach ($addresses as $address) {
            if (isset($address->mailbox)) {
                $return[] = $this->decodeEmailAddress($address);
            }
        }

        return $return;
    }
165041
public function getFromId( $contactAddressId){
        $rest = $this->getService( self::API_ADDRESS . $contactAddressId);
        $rest->GET();

        return $rest->getResult( models\Call\ContactAddress::class);
    }
305019
private function hostnameFromEmail($email)
    {
        $parts = explode('@', $email);

        if (count($parts) == 2) {
            return strtolower($parts[1]);
        }

        return null;
    }
1010434
protected function formatAddress($address)
    {
        if (is_array($address)) {
            $email = is_int(key($address)) ? current($address) : key($address);
            return array($email => current($address));
        }

        return array($address => $address);
    }
718867
public static function normalizeMailAddress($address) {
		if (self::isBrokenEmailEnvironment() && FALSE !== ($pos1 = strrpos($address, '<'))) {
			$pos2 = strpos($address, '>', $pos1);
			$address = substr($address, $pos1 + 1, ($pos2 ? $pos2 : strlen($address)) - $pos1 - 1);
		}
		return $address;
	}
267732
public static boolean validateEmailAdress(final String emailAddress)
	{
		boolean isValid = true;
		try
		{
			final InternetAddress internetAddress = new InternetAddress(emailAddress);
			internetAddress.validate();
		}
		catch (final AddressException e)
		{
			isValid = false;
		}
		return isValid;
	}
630558
private function getRemoteAddress() : ?string
    {
        $hostname = null;

        if (isset($_SERVER['REMOTE_ADDR'])) {
            $hostname = filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP);

            if (false === $hostname) {
                $hostname = null;
            }
        }

        if (function_exists('apache_request_headers')) {
            $headers = apache_request_headers();

            if ($headers === false) {
                return $hostname;
            }

            foreach ($headers as $k => $v) {
                if (strcasecmp($k, 'x-forwarded-for')) {
                    continue;
                }

                $hostname = explode(',', $v);
                $hostname = trim($hostname[0]);
                break;
            }
        }

        return $hostname;
    }
1170707
public function getAddressStrings(): array
    {
        $strings = [];
        foreach ($this->addresses as $address) {
            $str = $address->getEncodedAddress();
            if ($address instanceof NamedAddress && $name = $address->getName()) {
                $str = $this->createPhrase($this, $name, $this->getCharset(), empty($strings)).' <'.$str.'>';
            }
            $strings[] = $str;
        }

        return $strings;
    }