Improved more handling of Internationalized Domain Names

This commit is contained in:
the-djmaze 2024-03-12 18:01:27 +01:00
parent 5c21fea5d7
commit 4fd2f63c07
6 changed files with 19 additions and 43 deletions

View file

@ -365,6 +365,8 @@ export class DomainPopupView extends AbstractViewPopup {
this[key]?.(value);
}
});
this.name(IDN.toUnicode(this.name()));
this.aliasName(IDN.toUnicode(this.aliasName()));
this.imapCapabilities(this.imapCapabilities.concat(this.imapDisabled_capabilities()).unique());
this.enableSmartPorts(true);
}

View file

@ -1,5 +1,4 @@
{
"name": "*",
"IMAP": {
"host": "localhost",
"port": 143,

View file

@ -695,13 +695,11 @@ abstract class Utils
public static function IdnToUtf8(string $sStr) : string
{
$trace = \debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1];
\trigger_error("Deprecated function IdnToAscii called at {$trace['file']}#{$trace['line']}", \E_USER_DEPRECATED);
\SnappyMail\Log::warning('MailSo', "Deprecated function IdnToUtf8 called at {$trace['file']}#{$trace['line']}");
if (\preg_match('/(^|\.|@)xn--/i', $sStr)) {
try
{
$sStr = \SnappyMail\IDN::anyToUtf8($sStr);
}
catch (\Throwable $oException) {}
$sStr = \str_contains($sStr, '@')
? \SnappyMail\IDN::emailToUtf8($string)
: \idn_to_utf8($string);
}
return $sStr;
}
@ -712,15 +710,11 @@ abstract class Utils
public static function IdnToAscii(string $sStr, bool $bLowerCase = false) : string
{
$trace = \debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1];
\trigger_error("Deprecated function IdnToAscii called at {$trace['file']}#{$trace['line']}", \E_USER_DEPRECATED);
\SnappyMail\Log::warning('MailSo', "Deprecated function IdnToAscii called at {$trace['file']}#{$trace['line']}");
$aParts = \explode('@', $sStr);
$sDomain = \array_pop($aParts);
if (\strlen($sDomain) && \preg_match('/[^\x20-\x7E]/', $sDomain)) {
try
{
$sDomain = \SnappyMail\IDN::anyToAscii($sDomain);
}
catch (\Throwable $oException) {}
if (\preg_match('/[^\x20-\x7E]/', $sDomain)) {
$sDomain = \idn_to_ascii($string);
}
if ($bLowerCase) {
$sDomain = \strtolower($sDomain);

View file

@ -10,8 +10,13 @@ trait AdminDomains
public function DoAdminDomainLoad() : array
{
$this->IsAdminLoggined();
return $this->DefaultResponse($this->DomainProvider()->Load($this->GetActionParam('name', ''), false, false));
$mResult = false;
$oDomain = $this->DomainProvider()->Load($this->GetActionParam('name', ''), false, false);
if ($oDomain) {
$mResult = $oDomain->jsonSerialize();
$mResult['name'] = $oDomain->Name();
}
return $this->DefaultResponse($mResult);
}
public function DoAdminDomainList() : array
@ -24,8 +29,7 @@ trait AdminDomains
public function DoAdminDomainDelete() : array
{
$this->IsAdminLoggined();
return $this->DefaultResponse($this->DomainProvider()->Delete((string) $this->GetActionParam('name', '')));
return $this->DefaultResponse($this->DomainProvider()->Delete($this->GetActionParam('name', '')));
}
public function DoAdminDomainDisable() : array
@ -77,7 +81,7 @@ trait AdminDomains
public function DoAdminDomainAutoconfig() : array
{
$this->IsAdminLoggined();
$sDomain = $this->GetActionParam('domain');
$sDomain = \strtolower(\idn_to_ascii($this->GetActionParam('domain')));
$sEmail = "test@{$sDomain}";
return $this->DefaultResponse(array(
'email' => $sEmail,

View file

@ -240,14 +240,13 @@ class Domain implements \JsonSerializable
{
$aResult = array(
// '@Object' => 'Object/Domain',
'name' => \idn_to_utf8($this->Name),
'IMAP' => $this->IMAP,
'SMTP' => $this->SMTP,
'Sieve' => $this->Sieve,
'whiteList' => $this->whiteList
);
if ($this->aliasName) {
$aResult['aliasName'] = \idn_to_utf8($this->aliasName);
$aResult['aliasName'] = $this->aliasName;
}
return $aResult;
}

View file

@ -7,28 +7,6 @@ namespace SnappyMail;
abstract class IDN
{
public static function anyToAscii(string $string) : string
{
if (\strspn($string, ':/')) {
return static::uri($string, true);
}
if (\str_contains($string, '@')) {
return static::emailToAscii($string);
}
return \idn_to_ascii($string);
}
public static function anyToUtf8(string $string) : string
{
if (\strspn($string, ':/')) {
return static::uri($string, false);
}
if (\str_contains($string, '@')) {
return static::emailToUtf8($string);
}
return \idn_to_utf8($string);
}
/**
* Converts IDN domain part to lowercased punycode
* Like: 'Smile😀@📧.SnappyMail.eu' to 'Smile😀@xn--du8h.snappymail.eu'