added check if found domain is also configured

changed LOG_KEY variable
This commit is contained in:
cm-schl 2022-11-28 11:49:28 +01:00
parent dc07313869
commit 3aa063d475

View file

@ -22,7 +22,7 @@ class LdapMailAccounts
/** @var Logger */ /** @var Logger */
private $logger; private $logger;
private const LOG_KEY = "Ldap"; private const LOG_KEY = "LDAP MAIL ACCOUNTS PLUGIN";
/** /**
* LdapMailAccount constructor. * LdapMailAccount constructor.
@ -99,6 +99,7 @@ class LdapMailAccounts
} }
//Basing on https://github.com/the-djmaze/snappymail/issues/616 //Basing on https://github.com/the-djmaze/snappymail/issues/616
$oActions = \RainLoop\Api::Actions(); $oActions = \RainLoop\Api::Actions();
//Check if SnappyMail is configured to allow additional accounts //Check if SnappyMail is configured to allow additional accounts
@ -115,10 +116,11 @@ class LdapMailAccounts
$this->logger->Write("Domain: $sDomain Username: $sUsername Login: " . $oAccount->Login() . " E-Mail: " . $oAccount->Email(), \LOG_NOTICE, self::LOG_KEY); $this->logger->Write("Domain: $sDomain Username: $sUsername Login: " . $oAccount->Login() . " E-Mail: " . $oAccount->Email(), \LOG_NOTICE, self::LOG_KEY);
//Check if the domain of the found mail address is in the list of configured domains
if ($oActions->DomainProvider()->Load($sDomain, true))
{
//only execute if the found account isn't already in the list of additional accounts //only execute if the found account isn't already in the list of additional accounts
//and if the found account is different from the main account //and if the found account is different from the main account
//https://github.com/the-djmaze/snappymail/issues/705 should solve the missing logging if a domain is found in ldap
//but is not defined in the admin panel of SnappyMail
if (!$aAccounts["$sUsername@$sDomain"] && $oAccount->Email() !== "$sUsername@$sDomain") if (!$aAccounts["$sUsername@$sDomain"] && $oAccount->Email() !== "$sUsername@$sDomain")
{ {
//Try to login the user with the same password as the primary account has //Try to login the user with the same password as the primary account has
@ -128,6 +130,10 @@ $this->logger->Write("Domain: $sDomain Username: $sUsername Login: " . $oAccount
$aAccounts["$sUsername@$sDomain"] = $oNewAccount->asTokenArray($oAccount); $aAccounts["$sUsername@$sDomain"] = $oNewAccount->asTokenArray($oAccount);
} }
} }
else {
$this->logger->Write("Domain $sDomain is not part of configured domains in SnappyMail Admin Panel - mail address $sUsername@$sDomain will not be added.", \LOG_NOTICE, self::LOG_KEY);
}
}
if ($aAccounts) if ($aAccounts)
{ {