mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-06 07:57:02 +03:00
More params and returns to PHP 7.3+
This commit is contained in:
parent
3d246ae842
commit
26c38b3ec9
95 changed files with 1028 additions and 4865 deletions
|
|
@ -67,9 +67,6 @@ class SmtpClient extends \MailSo\Net\NetClient
|
|||
*/
|
||||
public $__USE_SINGLE_LINE_AUTH_PLAIN_COMMAND = false;
|
||||
|
||||
/**
|
||||
* @access protected
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
|
@ -87,42 +84,27 @@ class SmtpClient extends \MailSo\Net\NetClient
|
|||
$this->bData = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \MailSo\Smtp\SmtpClient
|
||||
*/
|
||||
public static function NewInstance()
|
||||
public static function NewInstance() : self
|
||||
{
|
||||
return new self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function IsSupported($sCapa)
|
||||
public function IsSupported(string $sCapa) : bool
|
||||
{
|
||||
return in_array(strtoupper($sCapa), $this->aCapa);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function IsAuthSupported($sAuth)
|
||||
public function IsAuthSupported(string $sAuth) : bool
|
||||
{
|
||||
return in_array(strtoupper($sAuth), $this->aAuthTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function HasSupportedAuth()
|
||||
public function HasSupportedAuth() : bool
|
||||
{
|
||||
return $this->IsAuthSupported('PLAIN') || $this->IsAuthSupported('LOGIN');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public static function EhloHelper()
|
||||
public static function EhloHelper() : string
|
||||
{
|
||||
$sEhloHost = empty($_SERVER['SERVER_NAME']) ? '' : \trim($_SERVER['SERVER_NAME']);
|
||||
if (empty($sEhloHost))
|
||||
|
|
@ -146,20 +128,14 @@ class SmtpClient extends \MailSo\Net\NetClient
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $sServerName
|
||||
* @param int $iPort = 25
|
||||
* @param string $sEhloHost = '[127.0.0.1]'
|
||||
* @param int $iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::AUTO_DETECT
|
||||
* @param bool $bVerifySsl = false
|
||||
* @param bool $bAllowSelfSigned = true
|
||||
*
|
||||
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||
* @throws \MailSo\Net\Exceptions\Exception
|
||||
* @throws \MailSo\Smtp\Exceptions\ResponseException
|
||||
*/
|
||||
public function Connect($sServerName, $iPort = 25, $sEhloHost = '[127.0.0.1]',
|
||||
$iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::AUTO_DETECT,
|
||||
$bVerifySsl = false, $bAllowSelfSigned = true) : void
|
||||
public function Connect(string $sServerName, int $iPort = 25,
|
||||
int $iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::AUTO_DETECT,
|
||||
bool $bVerifySsl = false, bool $bAllowSelfSigned = true,
|
||||
string $sClientCert = '', string $sEhloHost = '[127.0.0.1]') : void
|
||||
{
|
||||
$this->iRequestTime = microtime(true);
|
||||
|
||||
|
|
@ -171,18 +147,11 @@ class SmtpClient extends \MailSo\Net\NetClient
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $sLogin
|
||||
* @param string $sPassword
|
||||
* @param boolean $bUseAuthPlainIfSupported = true
|
||||
* @param boolean $bUseAuthCramMd5IfSupported = true
|
||||
*
|
||||
* @return \MailSo\Smtp\SmtpClient
|
||||
*
|
||||
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||
* @throws \MailSo\Net\Exceptions\Exception
|
||||
* @throws \MailSo\Smtp\Exceptions\Exception
|
||||
*/
|
||||
public function Login($sLogin, $sPassword, $bUseAuthPlainIfSupported = true, $bUseAuthCramMd5IfSupported = true)
|
||||
public function Login(string $sLogin, string $sPassword, bool $bUseAuthPlainIfSupported = true, bool $bUseAuthCramMd5IfSupported = true) : self
|
||||
{
|
||||
$sLogin = \MailSo\Base\Utils::IdnToAscii(\MailSo\Base\Utils::Trim($sLogin));
|
||||
|
||||
|
|
@ -310,16 +279,10 @@ class SmtpClient extends \MailSo\Net\NetClient
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $sFrom
|
||||
* @param string $sSizeIfSupported = ''
|
||||
* @param bool $bDsn = false
|
||||
*
|
||||
* @return \MailSo\Smtp\SmtpClient
|
||||
*
|
||||
* @throws \MailSo\Net\Exceptions\Exception
|
||||
* @throws \MailSo\Smtp\Exceptions\Exception
|
||||
*/
|
||||
public function MailFrom($sFrom, $sSizeIfSupported = '', $bDsn = false)
|
||||
public function MailFrom(string $sFrom, string $sSizeIfSupported = '', bool $bDsn = false) : self
|
||||
{
|
||||
$sFrom = \MailSo\Base\Utils::IdnToAscii(
|
||||
\MailSo\Base\Utils::Trim($sFrom), true);
|
||||
|
|
@ -347,15 +310,10 @@ class SmtpClient extends \MailSo\Net\NetClient
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $sTo
|
||||
* @param bool $bDsn = false
|
||||
*
|
||||
* @return \MailSo\Smtp\SmtpClient
|
||||
*
|
||||
* @throws \MailSo\Net\Exceptions\Exception
|
||||
* @throws \MailSo\Smtp\Exceptions\Exception
|
||||
*/
|
||||
public function Rcpt($sTo, $bDsn = false)
|
||||
public function Rcpt(string $sTo, bool $bDsn = false) : self
|
||||
{
|
||||
if (!$this->bMail)
|
||||
{
|
||||
|
|
@ -385,27 +343,19 @@ class SmtpClient extends \MailSo\Net\NetClient
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $sTo
|
||||
*
|
||||
* @return \MailSo\Smtp\SmtpClient
|
||||
*
|
||||
* @throws \MailSo\Net\Exceptions\Exception
|
||||
* @throws \MailSo\Smtp\Exceptions\Exception
|
||||
*/
|
||||
public function MailTo($sTo)
|
||||
public function MailTo(string $sTo) : self
|
||||
{
|
||||
return $this->Rcpt($sTo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sData
|
||||
*
|
||||
* @return \MailSo\Smtp\SmtpClient
|
||||
*
|
||||
* @throws \MailSo\Net\Exceptions\Exception
|
||||
* @throws \MailSo\Smtp\Exceptions\Exception
|
||||
*/
|
||||
public function Data($sData)
|
||||
public function Data(string $sData) : self
|
||||
{
|
||||
if (!\MailSo\Base\Validator::NotEmptyString($sData, true))
|
||||
{
|
||||
|
|
@ -423,13 +373,11 @@ class SmtpClient extends \MailSo\Net\NetClient
|
|||
/**
|
||||
* @param resource $rDataStream
|
||||
*
|
||||
* @return \MailSo\Smtp\SmtpClient
|
||||
*
|
||||
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||
* @throws \MailSo\Net\Exceptions\Exception
|
||||
* @throws \MailSo\Smtp\Exceptions\Exception
|
||||
*/
|
||||
public function DataWithStream($rDataStream)
|
||||
public function DataWithStream($rDataStream) : self
|
||||
{
|
||||
if (!\is_resource($rDataStream))
|
||||
{
|
||||
|
|
@ -484,12 +432,10 @@ class SmtpClient extends \MailSo\Net\NetClient
|
|||
}
|
||||
|
||||
/**
|
||||
* @return \MailSo\Smtp\SmtpClient
|
||||
*
|
||||
* @throws \MailSo\Net\Exceptions\Exception
|
||||
* @throws \MailSo\Smtp\Exceptions\Exception
|
||||
*/
|
||||
public function Rset()
|
||||
public function Rset() : self
|
||||
{
|
||||
$this->sendRequestWithCheck('RSET', array(250, 220));
|
||||
|
||||
|
|
@ -501,12 +447,10 @@ class SmtpClient extends \MailSo\Net\NetClient
|
|||
}
|
||||
|
||||
/**
|
||||
* @return \MailSo\Smtp\SmtpClient
|
||||
*
|
||||
* @throws \MailSo\Net\Exceptions\Exception
|
||||
* @throws \MailSo\Smtp\Exceptions\Exception
|
||||
*/
|
||||
public function Vrfy($sUser)
|
||||
public function Vrfy(string $sUser) : self
|
||||
{
|
||||
$sUser = \MailSo\Base\Utils::IdnToAscii(
|
||||
\MailSo\Base\Utils::Trim($sUser));
|
||||
|
|
@ -517,12 +461,10 @@ class SmtpClient extends \MailSo\Net\NetClient
|
|||
}
|
||||
|
||||
/**
|
||||
* @return \MailSo\Smtp\SmtpClient
|
||||
*
|
||||
* @throws \MailSo\Net\Exceptions\Exception
|
||||
* @throws \MailSo\Smtp\Exceptions\Exception
|
||||
*/
|
||||
public function Noop()
|
||||
public function Noop() : self
|
||||
{
|
||||
$this->sendRequestWithCheck('NOOP', 250);
|
||||
|
||||
|
|
@ -530,12 +472,10 @@ class SmtpClient extends \MailSo\Net\NetClient
|
|||
}
|
||||
|
||||
/**
|
||||
* @return \MailSo\Smtp\SmtpClient
|
||||
*
|
||||
* @throws \MailSo\Net\Exceptions\Exception
|
||||
* @throws \MailSo\Smtp\Exceptions\Exception
|
||||
*/
|
||||
public function Logout()
|
||||
public function Logout() : self
|
||||
{
|
||||
if ($this->IsConnected())
|
||||
{
|
||||
|
|
@ -550,10 +490,7 @@ class SmtpClient extends \MailSo\Net\NetClient
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sEhloHost
|
||||
*/
|
||||
private function preLoginStartTLSAndEhloProcess($sEhloHost) : void
|
||||
private function preLoginStartTLSAndEhloProcess(string $sEhloHost) : void
|
||||
{
|
||||
if ($this->bHelo)
|
||||
{
|
||||
|
|
@ -583,14 +520,10 @@ class SmtpClient extends \MailSo\Net\NetClient
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $sCommand
|
||||
* @param string $sAddToCommand = ''
|
||||
* @param bool $bSecureLog = false
|
||||
*
|
||||
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||
* @throws \MailSo\Net\Exceptions\Exception
|
||||
*/
|
||||
private function sendRequest($sCommand, $sAddToCommand = '', $bSecureLog = false) : void
|
||||
private function sendRequest(string $sCommand, string $sAddToCommand = '', bool $bSecureLog = false) : void
|
||||
{
|
||||
if (!\MailSo\Base\Validator::NotEmptyString($sCommand, true))
|
||||
{
|
||||
|
|
@ -611,38 +544,29 @@ class SmtpClient extends \MailSo\Net\NetClient
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $sCommand
|
||||
* @param int|array $mExpectCode
|
||||
* @param string $sAddToCommand = ''
|
||||
* @param bool $bSecureLog = false
|
||||
* @param string $sErrorPrefix = ''
|
||||
*
|
||||
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||
* @throws \MailSo\Net\Exceptions\Exception
|
||||
* @throws \MailSo\Smtp\Exceptions\Exception
|
||||
*/
|
||||
private function sendRequestWithCheck($sCommand, $mExpectCode, $sAddToCommand = '', $bSecureLog = false, $sErrorPrefix = '') : void
|
||||
private function sendRequestWithCheck(string $sCommand, $mExpectCode, string $sAddToCommand = '', bool $bSecureLog = false, string $sErrorPrefix = '') : void
|
||||
{
|
||||
$this->sendRequest($sCommand, $sAddToCommand, $bSecureLog);
|
||||
$this->validateResponse($mExpectCode, $sErrorPrefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sHost
|
||||
*/
|
||||
private function ehloOrHelo($sHost) : void
|
||||
private function ehloOrHelo(string $sHost) : void
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->ehlo($sHost);
|
||||
}
|
||||
catch (\Exception $oException)
|
||||
catch (\Throwable $oException)
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->helo($sHost);
|
||||
}
|
||||
catch (\Exception $oException)
|
||||
catch (\Throwable $oException)
|
||||
{
|
||||
throw $oException;
|
||||
}
|
||||
|
|
@ -650,8 +574,6 @@ class SmtpClient extends \MailSo\Net\NetClient
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $sHost
|
||||
*
|
||||
* @throws \MailSo\Net\Exceptions\Exception
|
||||
* @throws \MailSo\Smtp\Exceptions\Exception
|
||||
*/
|
||||
|
|
@ -692,12 +614,10 @@ class SmtpClient extends \MailSo\Net\NetClient
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $sHost
|
||||
*
|
||||
* @throws \MailSo\Net\Exceptions\Exception
|
||||
* @throws \MailSo\Smtp\Exceptions\Exception
|
||||
*/
|
||||
private function helo($sHost) : void
|
||||
private function helo(string $sHost) : void
|
||||
{
|
||||
$this->sendRequestWithCheck('HELO', 250, $sHost);
|
||||
$this->aAuthTypes = array();
|
||||
|
|
@ -706,12 +626,9 @@ class SmtpClient extends \MailSo\Net\NetClient
|
|||
}
|
||||
|
||||
/**
|
||||
* @param int|array $mExpectCode
|
||||
* @param string $sErrorPrefix = ''
|
||||
*
|
||||
* @throws \MailSo\Smtp\Exceptions\ResponseException
|
||||
*/
|
||||
private function validateResponse($mExpectCode, $sErrorPrefix = '') : void
|
||||
private function validateResponse($mExpectCode, string $sErrorPrefix = '') : void
|
||||
{
|
||||
if (!\is_array($mExpectCode))
|
||||
{
|
||||
|
|
@ -757,10 +674,7 @@ class SmtpClient extends \MailSo\Net\NetClient
|
|||
\MailSo\Log\Enumerations\Type::TIME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getLogName()
|
||||
protected function getLogName() : string
|
||||
{
|
||||
return 'SMTP';
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue