mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-29 12:09:20 +03:00
Improve MailSo\NetClient (and children) code
This commit is contained in:
parent
c8a5ae5c3a
commit
5fcf31f512
10 changed files with 110 additions and 318 deletions
|
|
@ -30,17 +30,17 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $iTagCount;
|
||||
private $iTagCount = 0;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $aCapabilityItems;
|
||||
private $aCapabilityItems = null;
|
||||
|
||||
/**
|
||||
* @var FolderInformation
|
||||
*/
|
||||
private $oCurrentFolderInfo;
|
||||
private $oCurrentFolderInfo = null;
|
||||
|
||||
/**
|
||||
* @var ResponseCollection
|
||||
|
|
@ -55,52 +55,36 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $bNeedNext;
|
||||
private $bNeedNext = true;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $aTagTimeouts;
|
||||
private $aTagTimeouts = array();
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $bIsLoggined;
|
||||
private $bIsLoggined = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $bIsSelected;
|
||||
private $bIsSelected = false;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sLogginedUser;
|
||||
private $sLogginedUser = '';
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $__FORCE_SELECT_ON_EXAMINE__;
|
||||
public $__FORCE_SELECT_ON_EXAMINE__ = false;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->iTagCount = 0;
|
||||
$this->aCapabilityItems = null;
|
||||
$this->oCurrentFolderInfo = null;
|
||||
|
||||
$this->oLastResponse = new ResponseCollection;
|
||||
$this->bNeedNext = true;
|
||||
|
||||
$this->aTagTimeouts = array();
|
||||
|
||||
$this->bIsLoggined = false;
|
||||
$this->bIsSelected = false;
|
||||
$this->sLogginedUser = '';
|
||||
|
||||
$this->__FORCE_SELECT_ON_EXAMINE__ = false;
|
||||
|
||||
\ini_set('xdebug.max_nesting_level', 500);
|
||||
}
|
||||
|
||||
|
|
@ -149,7 +133,7 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
public function Login(string $sLogin, string $sPassword, string $sProxyAuthUser = '',
|
||||
bool $bUseAuthPlainIfSupported = true, bool $bUseAuthCramMd5IfSupported = true) : self
|
||||
{
|
||||
if (!strlen(\trim($sLogin)) || !strlen(\trim($sPassword)))
|
||||
if (!\strlen(\trim($sLogin)) || !\strlen(\trim($sPassword)))
|
||||
{
|
||||
$this->writeLogException(
|
||||
new \MailSo\Base\Exceptions\InvalidArgumentException,
|
||||
|
|
@ -160,7 +144,7 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
|
||||
$this->sLogginedUser = $sLogin;
|
||||
|
||||
// $encrypted = !empty(\stream_get_meta_data($this->rConnect)['crypto']);
|
||||
// $encrypted = !empty(\stream_get_meta_data($this->ConnectionResource())['crypto']);
|
||||
$type = $this->IsSupported('LOGINDISABLED') ? '' : 'LOGIN'; // RFC3501 6.2.3
|
||||
$types = [
|
||||
// 'SCRAM-SHA-256' => 1, // !$encrypted
|
||||
|
|
@ -265,15 +249,13 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
/**
|
||||
* @throws \MailSo\Net\Exceptions\Exception
|
||||
*/
|
||||
public function Logout() : self
|
||||
public function Logout() : void
|
||||
{
|
||||
if ($this->bIsLoggined)
|
||||
{
|
||||
$this->bIsLoggined = false;
|
||||
$this->SendRequestGetResponse('LOGOUT');
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function IsLoggined() : bool
|
||||
|
|
@ -523,7 +505,7 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
}
|
||||
}
|
||||
|
||||
if (!strlen(\trim($sFolderName)))
|
||||
if (!\strlen(\trim($sFolderName)))
|
||||
{
|
||||
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
|
||||
}
|
||||
|
|
@ -548,6 +530,11 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
}
|
||||
|
||||
/**
|
||||
* The EXAMINE command is identical to SELECT and returns the same output;
|
||||
* however, the selected mailbox is identified as read-only.
|
||||
* No changes to the permanent state of the mailbox, including per-user state,
|
||||
* are permitted; in particular, EXAMINE MUST NOT cause messages to lose the \Recent flag.
|
||||
*
|
||||
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||
* @throws \MailSo\Net\Exceptions\Exception
|
||||
* @throws \MailSo\Imap\Exceptions\Exception
|
||||
|
|
@ -579,7 +566,7 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
*/
|
||||
public function Fetch(array $aInputFetchItems, string $sIndexRange, bool $bIndexIsUid) : array
|
||||
{
|
||||
if (!strlen(\trim($sIndexRange)))
|
||||
if (!\strlen(\trim($sIndexRange)))
|
||||
{
|
||||
$this->writeLogException(
|
||||
new \MailSo\Base\Exceptions\InvalidArgumentException,
|
||||
|
|
@ -648,7 +635,7 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
public function MessageSimpleSort(array $aSortTypes, string $sSearchCriterias = 'ALL', bool $bReturnUid = true) : array
|
||||
{
|
||||
$sCommandPrefix = ($bReturnUid) ? 'UID ' : '';
|
||||
$sSearchCriterias = !strlen(\trim($sSearchCriterias)) || '*' === $sSearchCriterias
|
||||
$sSearchCriterias = !\strlen(\trim($sSearchCriterias)) || '*' === $sSearchCriterias
|
||||
? 'ALL' : $sSearchCriterias;
|
||||
|
||||
if (!$aSortTypes)
|
||||
|
|
@ -766,8 +753,6 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
public function MessageSimpleSearch(string $sSearchCriterias = 'ALL', bool $bReturnUid = true, string $sCharset = '') : array
|
||||
{
|
||||
$sCommandPrefix = ($bReturnUid) ? 'UID ' : '';
|
||||
$sSearchCriterias = 0 === \strlen($sSearchCriterias) || '*' === $sSearchCriterias
|
||||
? 'ALL' : $sSearchCriterias;
|
||||
|
||||
$aRequest = array();
|
||||
if (0 < \strlen($sCharset))
|
||||
|
|
@ -776,14 +761,14 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
$aRequest[] = \strtoupper($sCharset);
|
||||
}
|
||||
|
||||
$aRequest[] = $sSearchCriterias;
|
||||
$aRequest[] = !\strlen($sSearchCriterias) || '*' === $sSearchCriterias ? 'ALL' : $sSearchCriterias;
|
||||
|
||||
$sCmd = 'SEARCH';
|
||||
|
||||
$sCont = $this->SendRequest($sCommandPrefix.$sCmd, $aRequest, true);
|
||||
$oResult = $this->getResponse();
|
||||
if ('' !== $sCont)
|
||||
{
|
||||
$oResult = $this->getResponse();
|
||||
$oItem = $oResult->getLast();
|
||||
|
||||
if ($oItem && Enumerations\ResponseType::CONTINUATION === $oItem->ResponseType)
|
||||
|
|
@ -802,10 +787,6 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$oResult = $this->getResponse();
|
||||
}
|
||||
|
||||
return $oResult->getMessageSimpleSearchResult($sCmd, $bReturnUid);
|
||||
}
|
||||
|
|
@ -818,7 +799,7 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
public function MessageSimpleThread(string $sSearchCriterias = 'ALL', bool $bReturnUid = true, string $sCharset = \MailSo\Base\Enumerations\Charset::UTF_8) : array
|
||||
{
|
||||
$sCommandPrefix = ($bReturnUid) ? 'UID ' : '';
|
||||
$sSearchCriterias = !strlen(\trim($sSearchCriterias)) || '*' === $sSearchCriterias
|
||||
$sSearchCriterias = !\strlen(\trim($sSearchCriterias)) || '*' === $sSearchCriterias
|
||||
? 'ALL' : $sSearchCriterias;
|
||||
|
||||
$sThreadType = '';
|
||||
|
|
@ -926,9 +907,9 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
*/
|
||||
public function MessageStoreFlag(string $sIndexRange, bool $bIndexIsUid, array $aInputStoreItems, string $sStoreAction) : self
|
||||
{
|
||||
if (!strlen(\trim($sIndexRange)) ||
|
||||
!strlen(\trim($sStoreAction)) ||
|
||||
0 === \count($aInputStoreItems))
|
||||
if (!\strlen(\trim($sIndexRange)) ||
|
||||
!\strlen(\trim($sStoreAction)) ||
|
||||
!\count($aInputStoreItems))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
@ -959,7 +940,7 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
|
||||
$this->writeLog('Write to connection stream', \MailSo\Log\Enumerations\Type::NOTE);
|
||||
|
||||
\MailSo\Base\Utils::MultipleStreamWriter($rMessageAppendStream, array($this->rConnect));
|
||||
\MailSo\Base\Utils::MultipleStreamWriter($rMessageAppendStream, array($this->ConnectionResource()));
|
||||
|
||||
$this->sendRaw('');
|
||||
$this->getResponse();
|
||||
|
|
@ -1085,7 +1066,7 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
try {
|
||||
$oResult = new ResponseCollection;
|
||||
|
||||
if (\is_resource($this->rConnect)) {
|
||||
if (\is_resource($this->ConnectionResource())) {
|
||||
$sEndTag = (null === $sEndTag) ? $this->getCurrentTag() : $sEndTag;
|
||||
|
||||
while (true) {
|
||||
|
|
@ -1213,7 +1194,7 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
|
||||
while (0 < $iRead)
|
||||
{
|
||||
$sAddRead = \fread($this->rConnect, $iRead);
|
||||
$sAddRead = \fread($this->ConnectionResource(), $iRead);
|
||||
if (false === $sAddRead)
|
||||
{
|
||||
$sLiteral = false;
|
||||
|
|
@ -1636,7 +1617,7 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
}
|
||||
|
||||
$rImapLiteralStream =
|
||||
\MailSo\Base\StreamWrappers\Literal::CreateStream($this->rConnect, $iLiteralLen);
|
||||
\MailSo\Base\StreamWrappers\Literal::CreateStream($this->ConnectionResource(), $iLiteralLen);
|
||||
|
||||
$this->writeLog('Start Callback for '.$sParent.' / '.$sLiteralAtomUpperCase.
|
||||
' - try to read '.$iLiteralLen.' bytes.', \MailSo\Log\Enumerations\Type::NOTE);
|
||||
|
|
@ -1707,7 +1688,7 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
$sReturn = '';
|
||||
foreach ($aParams as $mParamItem)
|
||||
{
|
||||
if (\is_array($mParamItem) && 0 < \count($mParamItem))
|
||||
if (\is_array($mParamItem) && \count($mParamItem))
|
||||
{
|
||||
$sReturn .= ' ('.\trim($this->prepareParamLine($mParamItem)).')';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,15 +65,6 @@ class MailClient
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \MailSo\Net\Exceptions\Exception
|
||||
*/
|
||||
public function Logout() : self
|
||||
{
|
||||
$this->oImapClient->Logout();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \MailSo\Net\Exceptions\Exception
|
||||
*/
|
||||
|
|
@ -83,14 +74,6 @@ class MailClient
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \MailSo\Net\Exceptions\Exception
|
||||
*/
|
||||
public function LogoutAndDisconnect() : self
|
||||
{
|
||||
return $this->Logout()->Disconnect();
|
||||
}
|
||||
|
||||
public function IsConnected() : bool
|
||||
{
|
||||
return $this->oImapClient->IsConnected();
|
||||
|
|
@ -347,7 +330,7 @@ class MailClient
|
|||
*/
|
||||
public function MessageMimeStream($mCallback, string $sFolderName, int $iIndex, bool $bIndexIsUid = true, string $sMimeIndex = '') : bool
|
||||
{
|
||||
if (!is_callable($mCallback))
|
||||
if (!\is_callable($mCallback))
|
||||
{
|
||||
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,118 +20,72 @@ abstract class NetClient
|
|||
/**
|
||||
* @var resource
|
||||
*/
|
||||
protected $rConnect;
|
||||
private $rConnect = null;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $bUnreadBuffer;
|
||||
private $bUnreadBuffer = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $bRunningCallback;
|
||||
protected $bRunningCallback = false;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $sResponseBuffer;
|
||||
protected $sResponseBuffer = '';
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $iSecurityType;
|
||||
protected $iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::NONE;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $sConnectedHost;
|
||||
private $sConnectedHost = '';
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $iConnectedPort;
|
||||
private $iConnectedPort = 0;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $bSecure;
|
||||
private $bSecure = false;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $iConnectTimeOut;
|
||||
private $iConnectTimeOut = 10;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $iSocketTimeOut;
|
||||
private $iSocketTimeOut = 10;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $iStartConnectTime;
|
||||
private $iStartConnectTime = 0;
|
||||
|
||||
/**
|
||||
* @var \MailSo\Log\Logger
|
||||
*/
|
||||
protected $oLogger;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $__AUTOLOGOUT__;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->rConnect = null;
|
||||
$this->bUnreadBuffer = false;
|
||||
$this->bRunningCallback = false;
|
||||
$this->oLogger = null;
|
||||
|
||||
$this->__AUTOLOGOUT__ = true;
|
||||
|
||||
$this->sResponseBuffer = '';
|
||||
|
||||
$this->iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::NONE;
|
||||
$this->sConnectedHost = '';
|
||||
$this->iConnectedPort = 0;
|
||||
|
||||
$this->bSecure = false;
|
||||
|
||||
$this->iConnectTimeOut = 10;
|
||||
$this->iSocketTimeOut = 10;
|
||||
|
||||
$this->Clear();
|
||||
}
|
||||
protected $oLogger = null;
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
try
|
||||
{
|
||||
if ($this->__AUTOLOGOUT__)
|
||||
{
|
||||
$this->LogoutAndDisconnect();
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->Disconnect();
|
||||
}
|
||||
$this->Disconnect();
|
||||
}
|
||||
catch (\Throwable $oException) {}
|
||||
}
|
||||
|
||||
public function Clear() : void
|
||||
{
|
||||
$this->sResponseBuffer = '';
|
||||
|
||||
$this->sConnectedHost = '';
|
||||
$this->iConnectedPort = 0;
|
||||
|
||||
$this->iStartConnectTime = 0;
|
||||
$this->bSecure = false;
|
||||
}
|
||||
|
||||
public function GetConnectedHost() : string
|
||||
{
|
||||
return $this->sConnectedHost;
|
||||
|
|
@ -171,7 +125,7 @@ abstract class NetClient
|
|||
bool $bVerifySsl = false, bool $bAllowSelfSigned = true,
|
||||
string $sClientCert = '') : void
|
||||
{
|
||||
if (!strlen(\trim($sServerName)) || !\MailSo\Base\Validator::PortInt($iPort))
|
||||
if (!\strlen(\trim($sServerName)) || !\MailSo\Base\Validator::PortInt($iPort))
|
||||
{
|
||||
$this->writeLogException(
|
||||
new \MailSo\Base\Exceptions\InvalidArgumentException,
|
||||
|
|
@ -213,9 +167,6 @@ abstract class NetClient
|
|||
$this->writeLog('Start connection to "'.$this->sConnectedHost.':'.$this->iConnectedPort.'"',
|
||||
\MailSo\Log\Enumerations\Type::NOTE);
|
||||
|
||||
// $this->rConnect = \fsockopen($this->sConnectedHost, $this->iConnectedPort,
|
||||
// $iErrorNo, $sErrorStr, $this->iConnectTimeOut);
|
||||
|
||||
$bVerifySsl = !!$bVerifySsl;
|
||||
$bAllowSelfSigned = $bVerifySsl ? !!$bAllowSelfSigned : true;
|
||||
$aStreamContextSettings = array(
|
||||
|
|
@ -251,10 +202,10 @@ abstract class NetClient
|
|||
|
||||
\restore_error_handler();
|
||||
|
||||
$this->writeLog('Connected ('.(\is_resource($this->rConnect) ? 'success' : 'unsuccess').')',
|
||||
$this->writeLog('Connect ('.($this->rConnect ? 'success' : 'failed').')',
|
||||
\MailSo\Log\Enumerations\Type::NOTE);
|
||||
|
||||
if (!\is_resource($this->rConnect))
|
||||
if (!$this->rConnect)
|
||||
{
|
||||
$this->writeLogException(
|
||||
new Exceptions\SocketCanNotConnectToHostException(
|
||||
|
|
@ -278,7 +229,7 @@ abstract class NetClient
|
|||
public function EnableCrypto()
|
||||
{
|
||||
$bError = true;
|
||||
if (\is_resource($this->rConnect) &&
|
||||
if ($this->rConnect &&
|
||||
\MailSo\Base\Utils::FunctionExistsAndEnabled('stream_socket_enable_crypto'))
|
||||
{
|
||||
switch (true)
|
||||
|
|
@ -304,16 +255,24 @@ abstract class NetClient
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \MailSo\Net\Exceptions\Exception
|
||||
*/
|
||||
public function Disconnect() : void
|
||||
{
|
||||
if (\is_resource($this->rConnect))
|
||||
if ($this->rConnect)
|
||||
{
|
||||
if (!$this->bUnreadBuffer && !$this->bRunningCallback)
|
||||
{
|
||||
$this->Logout();
|
||||
}
|
||||
|
||||
$bResult = \fclose($this->rConnect);
|
||||
|
||||
$this->writeLog('Disconnected from "'.$this->sConnectedHost.':'.$this->iConnectedPort.'" ('.
|
||||
(($bResult) ? 'success' : 'unsuccess').')', \MailSo\Log\Enumerations\Type::NOTE);
|
||||
|
||||
if (0 !== $this->iStartConnectTime)
|
||||
if ($this->iStartConnectTime)
|
||||
{
|
||||
$this->writeLog((\microtime(true) - $this->iStartConnectTime).' (net session)',
|
||||
\MailSo\Log\Enumerations\Type::TIME);
|
||||
|
|
@ -325,30 +284,19 @@ abstract class NetClient
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \MailSo\Net\Exceptions\Exception
|
||||
*/
|
||||
public function LogoutAndDisconnect() : void
|
||||
{
|
||||
if (\method_exists($this, 'Logout') && !$this->bUnreadBuffer && !$this->bRunningCallback)
|
||||
{
|
||||
$this->Logout();
|
||||
}
|
||||
|
||||
$this->Disconnect();
|
||||
}
|
||||
abstract public function Logout() : void;
|
||||
|
||||
public function IsConnected(bool $bThrowExceptionOnFalse = false) : bool
|
||||
{
|
||||
$bResult = \is_resource($this->rConnect);
|
||||
if (!$bResult && $bThrowExceptionOnFalse)
|
||||
{
|
||||
if ($this->rConnect) {
|
||||
return true;
|
||||
}
|
||||
if ($bThrowExceptionOnFalse) {
|
||||
$this->writeLogException(
|
||||
new Exceptions\SocketConnectionDoesNotAvailableException,
|
||||
\MailSo\Log\Enumerations\Type::ERROR, true);
|
||||
}
|
||||
|
||||
return $bResult;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -361,7 +309,7 @@ abstract class NetClient
|
|||
|
||||
public function StreamContextParams() : array
|
||||
{
|
||||
return \is_resource($this->rConnect) && \MailSo\Base\Utils::FunctionExistsAndEnabled('stream_context_get_options')
|
||||
return $this->rConnect && \MailSo\Base\Utils::FunctionExistsAndEnabled('stream_context_get_options')
|
||||
? \stream_context_get_params($this->rConnect) : false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,34 +20,27 @@ class ManageSieveClient extends \MailSo\Net\NetClient
|
|||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $bIsLoggined;
|
||||
private $bIsLoggined = false;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $aCapa;
|
||||
private $aCapa = array();
|
||||
|
||||
/**
|
||||
* @var int
|
||||
* @var array
|
||||
*/
|
||||
private $iRequestTime;
|
||||
private $aAuth = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $aModules = array();
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $__USE_INITIAL_AUTH_PLAIN_COMMAND;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->bIsLoggined = false;
|
||||
$this->iRequestTime = 0;
|
||||
$this->aCapa = array();
|
||||
$this->aModules = array();
|
||||
|
||||
$this->__USE_INITIAL_AUTH_PLAIN_COMMAND = true;
|
||||
}
|
||||
public $__USE_INITIAL_AUTH_PLAIN_COMMAND = true;
|
||||
|
||||
public function IsSupported(string $sCapa) : bool
|
||||
{
|
||||
|
|
@ -78,8 +71,6 @@ class ManageSieveClient extends \MailSo\Net\NetClient
|
|||
int $iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::AUTO_DETECT,
|
||||
bool $bVerifySsl = false, bool $bAllowSelfSigned = true, string $sClientCert = '') : void
|
||||
{
|
||||
$this->iRequestTime = \microtime(true);
|
||||
|
||||
parent::Connect($sServerName, $iPort, $iSecurityType, $bVerifySsl, $bAllowSelfSigned);
|
||||
|
||||
$aResponse = $this->parseResponse();
|
||||
|
|
@ -111,7 +102,7 @@ class ManageSieveClient extends \MailSo\Net\NetClient
|
|||
*/
|
||||
public function Login(string $sLogin, string $sPassword, string $sLoginAuthKey = '') : self
|
||||
{
|
||||
if (!strlen(\trim($sLogin)) || !strlen(\trim($sPassword)))
|
||||
if (!\strlen(\trim($sLogin)) || !\strlen(\trim($sPassword)))
|
||||
{
|
||||
$this->writeLogException(
|
||||
new \MailSo\Base\Exceptions\InvalidArgumentException,
|
||||
|
|
@ -120,7 +111,7 @@ class ManageSieveClient extends \MailSo\Net\NetClient
|
|||
|
||||
if ($this->IsSupported('SASL'))
|
||||
{
|
||||
// $encrypted = !empty(\stream_get_meta_data($this->rConnect)['crypto']);
|
||||
// $encrypted = !empty(\stream_get_meta_data($this->ConnectionResource())['crypto']);
|
||||
$type = '';
|
||||
$types = [
|
||||
// 'SCRAM-SHA-256' => 1, // !$encrypted
|
||||
|
|
@ -209,15 +200,13 @@ class ManageSieveClient extends \MailSo\Net\NetClient
|
|||
* @throws \MailSo\Net\Exceptions\Exception
|
||||
* @throws \MailSo\Sieve\Exceptions\NegativeResponseException
|
||||
*/
|
||||
public function Logout() : self
|
||||
public function Logout() : void
|
||||
{
|
||||
if ($this->bIsLoggined)
|
||||
{
|
||||
$this->sendRequestWithCheck('LOGOUT');
|
||||
$this->bIsLoggined = false;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -281,7 +270,7 @@ class ManageSieveClient extends \MailSo\Net\NetClient
|
|||
$this->validateResponse($aResponse);
|
||||
|
||||
$sScript = '';
|
||||
if (0 < \count($aResponse))
|
||||
if (\count($aResponse))
|
||||
{
|
||||
if ('{' === $aResponse[0][0])
|
||||
{
|
||||
|
|
@ -452,7 +441,7 @@ class ManageSieveClient extends \MailSo\Net\NetClient
|
|||
*/
|
||||
private function sendRequest(string $sRequest) : void
|
||||
{
|
||||
if (!strlen(\trim($sRequest)))
|
||||
if (!\strlen(\trim($sRequest)))
|
||||
{
|
||||
$this->writeLogException(
|
||||
new \MailSo\Base\Exceptions\InvalidArgumentException,
|
||||
|
|
@ -502,8 +491,6 @@ class ManageSieveClient extends \MailSo\Net\NetClient
|
|||
|
||||
private function parseResponse() : array
|
||||
{
|
||||
$this->iRequestTime = \microtime(true);
|
||||
|
||||
$aResult = array();
|
||||
do
|
||||
{
|
||||
|
|
@ -526,9 +513,6 @@ class ManageSieveClient extends \MailSo\Net\NetClient
|
|||
}
|
||||
while (true);
|
||||
|
||||
$this->writeLog((\microtime(true) - $this->iRequestTime),
|
||||
\MailSo\Log\Enumerations\Type::TIME);
|
||||
|
||||
return $aResult;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,73 +20,51 @@ class SmtpClient extends \MailSo\Net\NetClient
|
|||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $bHelo;
|
||||
private $bHelo = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $bRcpt;
|
||||
private $bRcpt = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $bMail;
|
||||
private $bMail = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $bData;
|
||||
private $bData = false;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $aAuthTypes;
|
||||
private $aAuthTypes = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $aCapa;
|
||||
private $aCapa = array();
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $iSizeCapaValue;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $iRequestTime;
|
||||
private $iSizeCapaValue = 0;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $aResults;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->aAuthTypes = array();
|
||||
|
||||
$this->iRequestTime = 0;
|
||||
$this->iSizeCapaValue = 0;
|
||||
$this->aResults = array();
|
||||
$this->aCapa = array();
|
||||
|
||||
$this->bHelo = false;
|
||||
$this->bRcpt = false;
|
||||
$this->bMail = false;
|
||||
$this->bData = false;
|
||||
}
|
||||
private $aResults = array();
|
||||
|
||||
public function IsSupported(string $sCapa) : bool
|
||||
{
|
||||
return in_array(strtoupper($sCapa), $this->aCapa);
|
||||
return \in_array(\strtoupper($sCapa), $this->aCapa);
|
||||
}
|
||||
|
||||
public function IsAuthSupported(string $sAuth) : bool
|
||||
{
|
||||
return in_array(strtoupper($sAuth), $this->aAuthTypes);
|
||||
return \in_array(\strtoupper($sAuth), $this->aAuthTypes);
|
||||
}
|
||||
|
||||
public function HasSupportedAuth() : bool
|
||||
|
|
@ -127,8 +105,6 @@ class SmtpClient extends \MailSo\Net\NetClient
|
|||
bool $bVerifySsl = false, bool $bAllowSelfSigned = true,
|
||||
string $sClientCert = '', string $sEhloHost = '[127.0.0.1]') : void
|
||||
{
|
||||
$this->iRequestTime = microtime(true);
|
||||
|
||||
parent::Connect($sServerName, $iPort, $iSecurityType, $bVerifySsl, $bAllowSelfSigned);
|
||||
|
||||
$this->validateResponse(220);
|
||||
|
|
@ -145,7 +121,7 @@ class SmtpClient extends \MailSo\Net\NetClient
|
|||
{
|
||||
$sLogin = \MailSo\Base\Utils::IdnToAscii(\MailSo\Base\Utils::Trim($sLogin));
|
||||
|
||||
// $encrypted = !empty(\stream_get_meta_data($this->rConnect)['crypto']);
|
||||
// $encrypted = !empty(\stream_get_meta_data($this->ConnectionResource())['crypto']);
|
||||
$type = '';
|
||||
$types = [
|
||||
'SCRAM-SHA-256' => 1, // !$encrypted
|
||||
|
|
@ -162,7 +138,7 @@ class SmtpClient extends \MailSo\Net\NetClient
|
|||
}
|
||||
|
||||
if (!$type) {
|
||||
\trigger_error("SMTP {$this->sConnectedHost} no supported AUTH options. Disable login" . ($this->IsSupported('STARTTLS') ? ' or try with STARTTLS' : ''));
|
||||
\trigger_error("SMTP {$this->GetConnectedHost()} no supported AUTH options. Disable login" . ($this->IsSupported('STARTTLS') ? ' or try with STARTTLS' : ''));
|
||||
$this->writeLogException(
|
||||
new \MailSo\Smtp\Exceptions\LoginBadMethodException,
|
||||
\MailSo\Log\Enumerations\Type::NOTICE, true);
|
||||
|
|
@ -315,7 +291,7 @@ class SmtpClient extends \MailSo\Net\NetClient
|
|||
*/
|
||||
public function Data(string $sData) : self
|
||||
{
|
||||
if (!strlen(\trim($sData)))
|
||||
if (!\strlen(\trim($sData)))
|
||||
{
|
||||
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
|
||||
}
|
||||
|
|
@ -433,7 +409,7 @@ class SmtpClient extends \MailSo\Net\NetClient
|
|||
* @throws \MailSo\Net\Exceptions\Exception
|
||||
* @throws \MailSo\Smtp\Exceptions\Exception
|
||||
*/
|
||||
public function Logout() : self
|
||||
public function Logout() : void
|
||||
{
|
||||
if ($this->IsConnected())
|
||||
{
|
||||
|
|
@ -444,8 +420,6 @@ class SmtpClient extends \MailSo\Net\NetClient
|
|||
$this->bMail = false;
|
||||
$this->bRcpt = false;
|
||||
$this->bData = false;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function preLoginStartTLSAndEhloProcess(string $sEhloHost) : void
|
||||
|
|
@ -483,7 +457,7 @@ class SmtpClient extends \MailSo\Net\NetClient
|
|||
*/
|
||||
private function sendRequest(string $sCommand, string $sAddToCommand = '', bool $bSecureLog = false) : void
|
||||
{
|
||||
if (!strlen(\trim($sCommand)))
|
||||
if (!\strlen(\trim($sCommand)))
|
||||
{
|
||||
$this->writeLogException(
|
||||
new \MailSo\Base\Exceptions\InvalidArgumentException,
|
||||
|
|
@ -497,7 +471,6 @@ class SmtpClient extends \MailSo\Net\NetClient
|
|||
|
||||
$sFakeCommand = ($bSecureLog) ? '********' : '';
|
||||
|
||||
$this->iRequestTime = \microtime(true);
|
||||
$this->sendRaw($sRealCommand, true, $sFakeCommand);
|
||||
}
|
||||
|
||||
|
|
@ -612,7 +585,7 @@ class SmtpClient extends \MailSo\Net\NetClient
|
|||
$this->writeLogException(
|
||||
new Exceptions\NegativeResponseException($this->aResults,
|
||||
('' === $sErrorPrefix ? '' : $sErrorPrefix.': ').\trim(
|
||||
(0 < \count($this->aResults) ? \implode("\r\n", $this->aResults)."\r\n" : '').
|
||||
(\count($this->aResults) ? \implode("\r\n", $this->aResults)."\r\n" : '').
|
||||
$this->sResponseBuffer)), \MailSo\Log\Enumerations\Type::ERROR, true);
|
||||
}
|
||||
}
|
||||
|
|
@ -621,16 +594,13 @@ class SmtpClient extends \MailSo\Net\NetClient
|
|||
$this->writeLogException(
|
||||
new Exceptions\ResponseException($this->aResults,
|
||||
('' === $sErrorPrefix ? '' : $sErrorPrefix.': ').\trim(
|
||||
(0 < \count($this->aResults) ? \implode("\r\n", $this->aResults)."\r\n" : '').
|
||||
(\count($this->aResults) ? \implode("\r\n", $this->aResults)."\r\n" : '').
|
||||
$this->sResponseBuffer)), \MailSo\Log\Enumerations\Type::ERROR, true);
|
||||
}
|
||||
|
||||
$this->aResults[] = $this->sResponseBuffer;
|
||||
}
|
||||
while ('-' === \substr($aParts[1], 0, 1));
|
||||
|
||||
$this->writeLog((microtime(true) - $this->iRequestTime),
|
||||
\MailSo\Log\Enumerations\Type::TIME);
|
||||
}
|
||||
|
||||
protected function getLogName() : string
|
||||
|
|
|
|||
|
|
@ -289,7 +289,7 @@ class Actions
|
|||
{
|
||||
try {
|
||||
if ($this->MailClient()->IsLoggined()) {
|
||||
$this->MailClient()->LogoutAndDisconnect();
|
||||
$this->MailClient()->Disconnect();
|
||||
}
|
||||
} catch (\Throwable $oException) {
|
||||
unset($oException);
|
||||
|
|
@ -1560,7 +1560,7 @@ class Actions
|
|||
|
||||
$iResult = $oMailClient->InboxUnreadCount();
|
||||
|
||||
$oMailClient->LogoutAndDisconnect();
|
||||
$oMailClient->Disconnect();
|
||||
} catch (\Throwable $oException) {
|
||||
$this->Logger()->WriteException($oException);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -345,13 +345,9 @@ trait Admin
|
|||
$bSieveResult = false;
|
||||
$sSieveErrorDesc = '';
|
||||
|
||||
$iImapTime = 0;
|
||||
$iSmtpTime = 0;
|
||||
$iSieveTime = 0;
|
||||
|
||||
$iConnectionTimeout = 5;
|
||||
|
||||
$oDomain = $this->DomainProvider()->LoadOrCreateNewFromAction($this, 'domain-test-connection.de');
|
||||
$oDomain = $this->DomainProvider()->LoadOrCreateNewFromAction($this, 'test.example.com');
|
||||
if ($oDomain)
|
||||
{
|
||||
try
|
||||
|
|
@ -367,7 +363,6 @@ trait Admin
|
|||
$this->Config()->Get('ssl', 'client_cert', '')
|
||||
);
|
||||
|
||||
$iImapTime = \microtime(true) - $iTime;
|
||||
$oImapClient->Disconnect();
|
||||
$bImapResult = true;
|
||||
}
|
||||
|
|
@ -409,7 +404,6 @@ trait Admin
|
|||
'', \MailSo\Smtp\SmtpClient::EhloHelper()
|
||||
);
|
||||
|
||||
$iSmtpTime = \microtime(true) - $iTime;
|
||||
$oSmtpClient->Disconnect();
|
||||
$bSmtpResult = true;
|
||||
}
|
||||
|
|
@ -444,7 +438,6 @@ trait Admin
|
|||
!!$this->Config()->Get('ssl', 'allow_self_signed', true)
|
||||
);
|
||||
|
||||
$iSieveTime = \microtime(true) - $iTime;
|
||||
$oSieveClient->Disconnect();
|
||||
$bSieveResult = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -715,7 +715,7 @@ trait Messages
|
|||
$oSmtpClient->SetLogger($this->Logger());
|
||||
$oSmtpClient->SetTimeOuts(10, (int) \RainLoop\Api::Config()->Get('labs', 'smtp_timeout', 60));
|
||||
|
||||
$bLoggined = $oAccount->OutConnectAndLoginHelper(
|
||||
$oAccount->OutConnectAndLoginHelper(
|
||||
$this->Plugins(), $oSmtpClient, $this->Config(), null, $bUsePhpMail
|
||||
);
|
||||
|
||||
|
|
@ -794,11 +794,6 @@ trait Messages
|
|||
|
||||
$oSmtpClient->DataWithStream($rMessageStream);
|
||||
|
||||
if ($bLoggined)
|
||||
{
|
||||
$oSmtpClient->Logout();
|
||||
}
|
||||
|
||||
$oSmtpClient->Disconnect();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ class Domain extends AbstractProvider
|
|||
return $this->oDriver->Count($sSearch);
|
||||
}
|
||||
|
||||
public function LoadOrCreateNewFromAction(\RainLoop\Actions $oActions, string $sNameForTest = '') : ?\RainLoop\Model\Domain
|
||||
public function LoadOrCreateNewFromAction(\RainLoop\Actions $oActions, string $sNameForTest = null) : ?\RainLoop\Model\Domain
|
||||
{
|
||||
$oDomain = null;
|
||||
|
||||
|
|
@ -98,12 +98,12 @@ class Domain extends AbstractProvider
|
|||
{
|
||||
$sName = (string) $oActions->GetActionParam('Name', '');
|
||||
|
||||
if (0 < \strlen($sName) && 0 < \strlen($sNameForTest) && !\str_contains($sName, '*'))
|
||||
if (\strlen($sName) && $sNameForTest && !\str_contains($sName, '*'))
|
||||
{
|
||||
$sNameForTest = '';
|
||||
$sNameForTest = null;
|
||||
}
|
||||
|
||||
if (0 < strlen($sName) || 0 < strlen($sNameForTest))
|
||||
if (\strlen($sName) || $sNameForTest)
|
||||
{
|
||||
$bCreate = '1' === (string) $oActions->GetActionParam('Create', '0');
|
||||
$sIncHost = (string) $oActions->GetActionParam('IncHost', '');
|
||||
|
|
@ -123,7 +123,7 @@ class Domain extends AbstractProvider
|
|||
$bOutUsePhpMail = '1' === (string) $oActions->GetActionParam('OutUsePhpMail', '0');
|
||||
$sWhiteList = (string) $oActions->GetActionParam('WhiteList', '');
|
||||
|
||||
$oDomain = 0 < strlen($sNameForTest) ? null : $this->Load($sName);
|
||||
$oDomain = $sNameForTest ? null : $this->Load($sName);
|
||||
if ($oDomain instanceof \RainLoop\Model\Domain)
|
||||
{
|
||||
if ($bCreate)
|
||||
|
|
@ -141,69 +141,7 @@ class Domain extends AbstractProvider
|
|||
}
|
||||
else
|
||||
{
|
||||
$oDomain = new \RainLoop\Model\Domain(0 < strlen($sNameForTest) ? $sNameForTest : $sName,
|
||||
$sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
|
||||
$bUseSieve, $sSieveHost, $iSievePort, $iSieveSecure,
|
||||
$sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth, $bOutSetSender, $bOutUsePhpMail,
|
||||
$sWhiteList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $oDomain;
|
||||
}
|
||||
|
||||
public function CreateNewAliasFromAction(\RainLoop\Actions $oActions, string $sNameForTest = '') : ?\RainLoop\Model\Domain
|
||||
{
|
||||
$oDomain = null;
|
||||
|
||||
if ($this->bAdmin)
|
||||
{
|
||||
$bCreate = '1' === (string) $oActions->GetActionParam('Create', '0');
|
||||
$sName = (string) $oActions->GetActionParam('Name', '');
|
||||
$sIncHost = (string) $oActions->GetActionParam('IncHost', '');
|
||||
$iIncPort = (int) $oActions->GetActionParam('IncPort', 143);
|
||||
$iIncSecure = (int) $oActions->GetActionParam('IncSecure', \MailSo\Net\Enumerations\ConnectionSecurityType::NONE);
|
||||
$bIncShortLogin = '1' === (string) $oActions->GetActionParam('IncShortLogin', '0');
|
||||
$bUseSieve = '1' === (string) $oActions->GetActionParam('UseSieve', '0');
|
||||
$sSieveHost = (string) $oActions->GetActionParam('SieveHost', '');
|
||||
$iSievePort = (int) $oActions->GetActionParam('SievePort', 4190);
|
||||
$iSieveSecure = (int) $oActions->GetActionParam('SieveSecure', \MailSo\Net\Enumerations\ConnectionSecurityType::NONE);
|
||||
$sOutHost = (string) $oActions->GetActionParam('OutHost', '');
|
||||
$iOutPort = (int) $oActions->GetActionParam('OutPort', 25);
|
||||
$iOutSecure = (int) $oActions->GetActionParam('OutSecure', \MailSo\Net\Enumerations\ConnectionSecurityType::NONE);
|
||||
$bOutShortLogin = '1' === (string) $oActions->GetActionParam('OutShortLogin', '0');
|
||||
$bOutAuth = '1' === (string) $oActions->GetActionParam('OutAuth', '1');
|
||||
$bOutSetSender = '1' === (string) $oActions->GetActionParam('OutSetSender', '0');
|
||||
$bOutUsePhpMail = '1' === (string) $oActions->GetActionParam('OutUsePhpMail', '0');
|
||||
$sWhiteList = (string) $oActions->GetActionParam('WhiteList', '');
|
||||
|
||||
if (0 < \strlen($sName) && 0 < strlen($sNameForTest) && false === \strpos($sName, '*'))
|
||||
{
|
||||
$sNameForTest = '';
|
||||
}
|
||||
|
||||
if (0 < strlen($sName) || 0 < strlen($sNameForTest))
|
||||
{
|
||||
$oDomain = 0 < strlen($sNameForTest) ? null : $this->Load($sName);
|
||||
if ($oDomain instanceof \RainLoop\Model\Domain)
|
||||
{
|
||||
if ($bCreate)
|
||||
{
|
||||
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DomainAlreadyExists);
|
||||
}
|
||||
else
|
||||
{
|
||||
$oDomain->UpdateInstance(
|
||||
$sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
|
||||
$bUseSieve, $sSieveHost, $iSievePort, $iSieveSecure,
|
||||
$sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth, $bOutSetSender, $bOutUsePhpMail,
|
||||
$sWhiteList);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$oDomain = new \RainLoop\Model\Domain(0 < strlen($sNameForTest) ? $sNameForTest : $sName,
|
||||
$oDomain = new \RainLoop\Model\Domain($sNameForTest ?: $sName,
|
||||
$sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
|
||||
$bUseSieve, $sSieveHost, $iSievePort, $iSieveSecure,
|
||||
$sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth, $bOutSetSender, $bOutUsePhpMail,
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ class SieveStorage implements FiltersInterface
|
|||
);
|
||||
}
|
||||
|
||||
$oSieveClient->LogoutAndDisconnect();
|
||||
$oSieveClient->Disconnect();
|
||||
|
||||
if (!isset($aList[self::SIEVE_FILE_NAME])) {
|
||||
$aScripts[self::SIEVE_FILE_NAME] = array(
|
||||
|
|
@ -97,7 +97,7 @@ class SieveStorage implements FiltersInterface
|
|||
} else {
|
||||
$oSieveClient->PutScript($sScriptName, $sRaw);
|
||||
}
|
||||
$oSieveClient->LogoutAndDisconnect();
|
||||
$oSieveClient->Disconnect();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue