Cleanup some mail address parsing

This commit is contained in:
the-djmaze 2024-02-06 18:31:11 +01:00
parent 04a78ad8bd
commit 728286d16c
4 changed files with 9 additions and 15 deletions

View file

@ -433,15 +433,8 @@ abstract class Utils
public static function GetDomainFromEmail(string $sEmail) : string
{
$sResult = '';
if (\strlen($sEmail)) {
$iPos = \strrpos($sEmail, '@');
if (false !== $iPos && 0 < $iPos) {
$sResult = \substr($sEmail, $iPos + 1);
}
}
return $sResult;
$aParts = \explode('@', $sEmail);
return isset($aParts[1]) ? \array_pop($aParts) : '';
}
public static function GetClearDomainName(string $sDomain) : string

View file

@ -27,13 +27,13 @@ trait UserAuth
string &$sPassword,
string &$sLogin): void
{
$this->Plugins()->RunHook('login.credentials.step-1', array(&$sEmail));
$sEmail = \MailSo\Base\Utils::Trim($sEmail);
if ($this->Config()->Get('login', 'login_lowercase', true)) {
$sEmail = \mb_strtolower($sEmail);
}
$this->Plugins()->RunHook('login.credentials.step-1', array(&$sEmail));
if (!\str_contains($sEmail, '@')) {
$this->logWrite('The email address "' . $sEmail . '" is not complete', \LOG_INFO, 'LOGIN');

View file

@ -9,8 +9,7 @@ abstract class Autoconfig
{
public static function discover(string $emailaddress) : ?array
{
$domain = \explode('@', $emailaddress);
$domain = \array_pop($domain);
$domain = \MailSo\Base\Utils::GetDomainFromEmail($emailaddress);
// First try
$autoconfig = static::resolve($domain, $emailaddress);
if ($autoconfig) {

View file

@ -62,8 +62,10 @@ abstract class IDN
private static function emailAddress(string $address, bool $toAscii) : string
{
if (\strpos($address, '@')) {
list($local, $domain) = \explode('@', $address, 2);
if (\str_contains($address, '@')) {
$local = \explode('@', $address);
$domain = \array_pop($local);
$local = \implode('@', $local);
$arr = \explode('.', $domain);
foreach ($arr as $k => $v) {
$conv = $toAscii ? static::toAscii($v) : static::toUtf8($v);