mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-08 22:18:28 +03:00
Improved more handling of Internationalized Domain Names
This commit is contained in:
parent
5c21fea5d7
commit
4fd2f63c07
6 changed files with 19 additions and 43 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
{
|
||||
"name": "*",
|
||||
"IMAP": {
|
||||
"host": "localhost",
|
||||
"port": 143,
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue