Put domain capabilities in ?admin domain test response

This commit is contained in:
the-djmaze 2023-11-22 17:45:24 +01:00
parent 0dfcc52728
commit cb2f641378
3 changed files with 38 additions and 18 deletions

View file

@ -213,12 +213,13 @@ class SieveClient extends \MailSo\Net\NetClient
* @throws \MailSo\Net\Exceptions\*
* @throws \MailSo\Sieve\Exceptions\*
*/
public function Capability() : array
public function Capability(bool $force = false) : array
{
$this->sendRequest('CAPABILITY');
$aResponse = $this->parseResponse();
$this->parseStartupResponse($aResponse);
if (!$this->aCapa || $force) {
$this->sendRequest('CAPABILITY');
$aResponse = $this->parseResponse();
$this->parseStartupResponse($aResponse);
}
return $this->aCapa;
}
@ -348,6 +349,7 @@ class SieveClient extends \MailSo\Net\NetClient
*/
private function parseStartupResponse(array $aResponse) : void
{
$this->aCapa = [];
foreach ($aResponse as $sLine) {
$aTokens = $this->parseLine($sLine);
if (empty($aTokens[0]) || \in_array(\substr($sLine, 0, 2), array('OK', 'NO'))) {

View file

@ -38,6 +38,11 @@ class SmtpClient extends \MailSo\Net\NetClient
private array $aResults = array();
public function Capability() : array
{
return $this->aCapa;
}
public function hasCapability(string $sCapa) : bool
{
return \in_array(\strtoupper($sCapa), $this->aCapa);
@ -478,6 +483,7 @@ class SmtpClient extends \MailSo\Net\NetClient
250-DSN\r\n
250 SMTPUTF8\r\n
*/
$this->aCapa = [];
foreach ($this->aResults as $sLine) {
$aMatch = array();
if (\preg_match('/[\d]+[ \-](.+)$/', $sLine, $aMatch) && isset($aMatch[1]) && \strlen($aMatch[1])) {
@ -510,7 +516,7 @@ class SmtpClient extends \MailSo\Net\NetClient
$this->sendRequestWithCheck('HELO', 250, $sHost);
$this->aAuthTypes = array();
$this->iSizeCapaValue = 0;
$this->aCapa = array();
$this->aCapa = [];
}
/**

View file

@ -78,11 +78,11 @@ trait AdminDomains
{
$this->IsAdminLoggined();
$bImapResult = false;
$mImapResult = false;
$sImapErrorDesc = '';
$bSmtpResult = false;
$mSmtpResult = false;
$sSmtpErrorDesc = '';
$bSieveResult = false;
$mSieveResult = false;
$sSieveErrorDesc = '';
$oDomain = $this->DomainProvider()->LoadOrCreateNewFromAction($this, 'test.example.com');
@ -96,15 +96,18 @@ trait AdminDomains
$oSettings = $oDomain->ImapSettings();
$oImapClient->Connect($oSettings);
$mImapResult = [
'connectCapa' => $oImapClient->Capability()
];
if (!empty($aAuth['user'])) {
$oSettings->Login = $aAuth['user'];
$oSettings->Password = $aAuth['pass'];
$oImapClient->Login($oSettings);
$mImapResult['authCapa'] = $oImapClient->Capability();
}
$oImapClient->Disconnect();
$bImapResult = true;
}
catch (\MailSo\Net\Exceptions\SocketCanNotConnectToHostException $oException)
{
@ -121,8 +124,8 @@ trait AdminDomains
}
if ($oDomain->OutUsePhpMail()) {
$bSmtpResult = \MailSo\Base\Utils::FunctionCallable('mail');
if (!$bSmtpResult) {
$mSmtpResult = \MailSo\Base\Utils::FunctionCallable('mail');
if (!$mSmtpResult) {
$sSmtpErrorDesc = 'PHP: mail() function is undefined';
}
} else {
@ -134,15 +137,18 @@ trait AdminDomains
$oSettings = $oDomain->SmtpSettings();
$oSettings->Ehlo = \MailSo\Smtp\SmtpClient::EhloHelper();
$oSmtpClient->Connect($oSettings);
$mSmtpResult = [
'connectCapa' => $oSmtpClient->Capability()
];
if (!empty($aAuth['user'])) {
$oSettings->Login = $aAuth['user'];
$oSettings->Password = $aAuth['pass'];
$oSmtpClient->Login($oSettings);
$mSmtpResult['authCapa'] = $oSmtpClient->Capability();
}
$oSmtpClient->Disconnect();
$bSmtpResult = true;
}
catch (\MailSo\Net\Exceptions\SocketCanNotConnectToHostException $oException)
{
@ -167,15 +173,18 @@ trait AdminDomains
$oSettings = $oDomain->SieveSettings();
$oSieveClient->Connect($oSettings);
$mSieveResult = [
'connectCapa' => $oSieveClient->Capability()
];
if (!empty($aAuth['user'])) {
$oSettings->Login = $aAuth['user'];
$oSettings->Password = $aAuth['pass'];
$oSieveClient->Login($oSettings);
$mSieveResult['authCapa'] = $oSieveClient->Capability();
}
$oSieveClient->Disconnect();
$bSieveResult = true;
}
catch (\MailSo\Net\Exceptions\SocketCanNotConnectToHostException $oException)
{
@ -191,14 +200,17 @@ trait AdminDomains
$sSieveErrorDesc = $oException->getMessage();
}
} else {
$bSieveResult = true;
$mSieveResult = true;
}
}
return $this->DefaultResponse(array(
'Imap' => $bImapResult ? true : $sImapErrorDesc,
'Smtp' => $bSmtpResult ? true : $sSmtpErrorDesc,
'Sieve' => $bSieveResult ? true : $sSieveErrorDesc
'Imap' => $mImapResult ? true : $sImapErrorDesc,
'Smtp' => $mSmtpResult ? true : $sSmtpErrorDesc,
'Sieve' => $mSieveResult ? true : $sSieveErrorDesc,
'ImapResult' => $mImapResult,
'SmtpResult' => $mSmtpResult,
'SieveResult' => $mSieveResult
));
}