Added \SnappyMail\IDN::toAscii()

This commit is contained in:
the-djmaze 2024-03-12 21:47:38 +01:00
parent aa7323ba43
commit 4ebb3e7082
6 changed files with 24 additions and 1 deletions

View file

@ -81,6 +81,7 @@ trait AdminDomains
public function DoAdminDomainAutoconfig() : array
{
$this->IsAdminLoggined();
// $sDomain = \SnappyMail\IDN::toAscii($this->GetActionParam('domain'));
$sDomain = \strtolower(\idn_to_ascii($this->GetActionParam('domain')));
$sEmail = "test@{$sDomain}";
return $this->DefaultResponse(array(

View file

@ -25,7 +25,7 @@ trait UserAuth
*/
public function resolveLoginCredentials(string &$sEmail, \SnappyMail\SensitiveString $oPassword, string &$sLogin): void
{
$sEmail = \MailSo\Base\Utils::Trim($sEmail);
$sEmail = \SnappyMail\IDN::emailToAscii(\MailSo\Base\Utils::Trim($sEmail));
if ($this->Config()->Get('login', 'login_lowercase', true)) {
$sEmail = \mb_strtolower($sEmail);
}
@ -36,6 +36,7 @@ trait UserAuth
$this->logWrite("The email address '{$sEmail}' is incomplete", \LOG_INFO, 'LOGIN');
$oDomain = null;
if ($this->Config()->Get('login', 'determine_user_domain', false)) {
// $sUserHost = \SnappyMail\IDN::toAscii($this->Http()->GetHost(false, true));
$sUserHost = \strtolower(\idn_to_ascii($this->Http()->GetHost(false, true)));
$this->logWrite("Determined user domain: {$sUserHost}", \LOG_INFO, 'LOGIN');

View file

@ -24,6 +24,7 @@ class Domain implements \JsonSerializable
function __construct(string $sName)
{
// $this->Name = \SnappyMail\IDN::toAscii($sName);
$this->Name = \strtolower(\idn_to_ascii($sName));
$this->IMAP = new \MailSo\Imap\Settings;
$this->SMTP = new \MailSo\Smtp\Settings;
@ -99,6 +100,7 @@ class Domain implements \JsonSerializable
public function SetAliasName(string $sAliasName) : void
{
// $this->aliasName = \SnappyMail\IDN::toAscii($sAliasName);
$this->aliasName = \strtolower(\idn_to_ascii($sAliasName));
}

View file

@ -11,6 +11,7 @@ abstract class Autoconfig
{
// $emailaddress = \SnappyMail\IDN::emailToAscii($emailaddress);
$domain = \MailSo\Base\Utils::getEmailAddressDomain($emailaddress);
// $domain = \SnappyMail\IDN::toAscii($domain);
$domain = \strtolower(\idn_to_ascii($domain));
// First try
$autoconfig = static::resolve($domain, $emailaddress);

View file

@ -29,6 +29,7 @@ class DefaultDomain implements DomainInterface
private static function encodeFileName(string $sName) : string
{
// return ('*' === $sName) ? 'default' : \str_replace('*', '_wildcard_', \SnappyMail\IDN::toAscii($sName));
return ('*' === $sName) ? 'default' : \str_replace('*', '_wildcard_', \strtolower(\idn_to_ascii($sName)));
}
@ -79,6 +80,7 @@ class DefaultDomain implements DomainInterface
public function Load(string $sName, bool $bFindWithWildCard = false, bool $bCheckDisabled = true, bool $bCheckAliases = true) : ?\RainLoop\Model\Domain
{
// $sName = \SnappyMail\IDN::toAscii($sName);
$sName = \strtolower(\idn_to_ascii($sName));
if ($bCheckDisabled && \in_array($sName, $this->getDisabled())) {
return null;
@ -131,6 +133,7 @@ class DefaultDomain implements DomainInterface
public function SaveAlias(string $sName, string $sTarget) : bool
{
// $this->Delete($sName);
// $sTarget = \SnappyMail\IDN::toAscii($sTarget);
$sTarget = \strtolower(\idn_to_ascii($sTarget));
$sRealFileName = static::encodeFileName($sName);
\RainLoop\Utils::saveFile($this->sDomainPath.'/'.$sRealFileName.'.alias', $sTarget);
@ -148,6 +151,7 @@ class DefaultDomain implements DomainInterface
// RainLoop use comma, we use newline
$sItem = \strtok($sFile, ",\n");
while (false !== $sItem) {
// $aDisabled[] = \SnappyMail\IDN::toAscii($sItem);
$aDisabled[] = \strtolower(\idn_to_ascii($sItem));
$sItem = \strtok(",\n");
}
@ -157,6 +161,7 @@ class DefaultDomain implements DomainInterface
public function Disable(string $sName, bool $bDisable) : bool
{
// $sName = \SnappyMail\IDN::toAscii($sName);
$sName = \strtolower(\idn_to_ascii($sName));
if ($sName) {
$aResult = $this->getDisabled();

View file

@ -7,6 +7,19 @@ namespace SnappyMail;
abstract class IDN
{
/**
* Converts domain name to lowercased punycode
* When the '@' is in, only the part after is changed
* Like: '📧.SnappyMail.EU' to 'xn--du8h.snappymail.eu'
*/
public static function toAscii(string $value) : string
{
$local = \explode('@', $value);
$domain = static::domain(\array_pop($local), true);
$local[] = $domain;
return \implode('@', $local);
}
/**
* Converts IDN domain part to lowercased punycode
* Like: 'Smile😀@📧.SnappyMail.eu' to 'Smile😀@xn--du8h.snappymail.eu'