Upgrade to 3.4.1
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Kirby\Http;
|
||||
|
||||
use Kirby\Toolkit\Str;
|
||||
use TrueBV\Punycode;
|
||||
|
||||
/**
|
||||
@@ -24,4 +25,40 @@ class Idn
|
||||
{
|
||||
return (new Punycode())->encode($domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a email address to the Unicode format
|
||||
*
|
||||
* @param string $email
|
||||
* @return string
|
||||
*/
|
||||
public static function decodeEmail(string $email): string
|
||||
{
|
||||
if (Str::contains($email, 'xn--') === true) {
|
||||
$parts = Str::split($email, '@');
|
||||
$address = $parts[0];
|
||||
$domain = Idn::decode($parts[1] ?? '');
|
||||
$email = $address . '@' . $domain;
|
||||
}
|
||||
|
||||
return $email;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes a email address to the Punycode format
|
||||
*
|
||||
* @param string $email
|
||||
* @return string
|
||||
*/
|
||||
public static function encodeEmail(string $email): string
|
||||
{
|
||||
if (mb_detect_encoding($email, 'ASCII', true) === false) {
|
||||
$parts = Str::split($email, '@');
|
||||
$address = $parts[0];
|
||||
$domain = Idn::encode($parts[1] ?? '');
|
||||
$email = $address . '@' . $domain;
|
||||
}
|
||||
|
||||
return $email;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user