• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/mail/mail.php
  • Класс: BitrixMainMailMail
  • Вызов: Mail::toPunycode
static function toPunycode($to)
{
	$email = $to;
	$withComment = false;

	if (preg_match("#.*?[<\[(](.*?)[>\])].*#i", $to, $matches) && $matches[1] <> '')
	{
		$email = $matches[1];
		$withComment = true;
	}

	$parts = explode("@", $email);
	$domain = $parts[1];

	$errors = [];
	$domain = CBXPunycode::ToASCII($domain, $errors);

	if (empty($errors))
	{
		$email = "{$parts[0]}@{$domain}";

		if ($withComment)
		{
			$email = preg_replace("#(.*?)[<\[(](.*?)[>\])](.*)#i", '$1<'.$email.'>$3', $to);
		}

		return $email;
	}

	return $to;
}