Remove useless NewInstance

Bugfix: BodyStructure->SearchCharset return value
This commit is contained in:
djmaze 2020-05-08 11:49:18 +02:00
parent 82e560bc53
commit 693e0f4c10
61 changed files with 802 additions and 1345 deletions

View file

@ -17,6 +17,14 @@ namespace MailSo\Base;
*/
abstract class Collection extends \ArrayObject
{
function __construct($input = array(), int $flags = 0, string $iterator_class = "ArrayIterator")
{
parent::__construct();
foreach ($input as $item) {
$this->append($item);
}
}
/**
* @param mixed $mItem
*/

View file

@ -446,7 +446,7 @@ abstract class HtmlUtils
{
if ($oTextNode && 0 < \strlen($oTextNode->wholeText)/* && \preg_match('/http[s]?:\/\//i', $oTextNode->wholeText)*/)
{
$sText = \MailSo\Base\LinkFinder::NewInstance()
$sText = (new \MailSo\Base\LinkFinder)
->Text($oTextNode->wholeText)
->UseDefaultWrappers(true)
->CompileText()
@ -1037,7 +1037,7 @@ abstract class HtmlUtils
return '';
}
$sText = \MailSo\Base\LinkFinder::NewInstance()
$sText = (new \MailSo\Base\LinkFinder)
->Text($sText)
->UseDefaultWrappers($bLinksWithTargetBlank)
->CompileText()

View file

@ -17,11 +17,6 @@ namespace MailSo\Base;
*/
class Http
{
public static function NewInstance() : self
{
return new self();
}
/**
* @staticvar \MailSo\Base\Http $oInstance;
*/
@ -30,7 +25,7 @@ class Http
static $oInstance = null;
if (null === $oInstance)
{
$oInstance = self::NewInstance();
$oInstance = new self;
}
return $oInstance;

View file

@ -53,7 +53,7 @@ class LinkFinder
*/
private $iOptimizationLimit;
private function __construct()
function __construct()
{
$this->iHtmlSpecialCharsFlags = (\defined('ENT_QUOTES') && \defined('ENT_SUBSTITUTE') && \defined('ENT_HTML401'))
? ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 : ENT_QUOTES;
@ -68,11 +68,6 @@ class LinkFinder
$this->Clear();
}
public static function NewInstance() : self
{
return new self();
}
public function Clear() : self
{
$this->aPrepearPlainStringUrls = array();

View file

@ -1083,8 +1083,7 @@ END;
public static function Trim(string $sValue) : string
{
return \trim(\preg_replace('/^[\x00-\x1F]+/u', '',
\preg_replace('/[\x00-\x1F]+$/u', '', \trim($sValue))));
return \trim(\preg_replace('/^[\x00-\x1F]+|[\x00-\x1F]+$/Du', '', \trim($sValue)));
}
public static function RecRmDir(string $sDir) : bool
@ -1859,7 +1858,7 @@ END;
if (null === $oIdn)
{
include_once dirname(__DIR__).'/Vendors/Net/IDNA2.php';
$oIdn = new \Net_IDNA2();
$oIdn = new \Net_IDNA2;
$oIdn->setParams('utf8', true);
}

View file

@ -27,17 +27,12 @@ class CacheClient
*/
private $sCacheIndex;
private function __construct()
function __construct()
{
$this->oDriver = null;
$this->sCacheIndex = '';
}
public static function NewInstance() : self
{
return new self();
}
public function Set(string $sKey, string $sValue) : bool
{
return $this->oDriver ? $this->oDriver->Set($sKey.$this->sCacheIndex, $sValue) : false;

View file

@ -23,7 +23,7 @@ class APC implements \MailSo\Cache\DriverInterface
*/
private $sKeyPrefix;
private function __construct(string $sKeyPrefix = '')
function __construct(string $sKeyPrefix = '')
{
$this->sKeyPrefix = $sKeyPrefix;
if (!empty($this->sKeyPrefix))
@ -33,11 +33,6 @@ class APC implements \MailSo\Cache\DriverInterface
}
}
public static function NewInstance(string $sKeyPrefix = '') : self
{
return new self($sKeyPrefix);
}
public function Set(string $sKey, string $sValue) : bool
{
return \apc_store($this->generateCachedKey($sKey), (string) $sValue);

View file

@ -28,7 +28,7 @@ class File implements \MailSo\Cache\DriverInterface
*/
private $sKeyPrefix;
private function __construct(string $sCacheFolder, string $sKeyPrefix = '')
function __construct(string $sCacheFolder, string $sKeyPrefix = '')
{
$this->sCacheFolder = $sCacheFolder;
$this->sCacheFolder = rtrim(trim($this->sCacheFolder), '\\/').'/';
@ -45,11 +45,6 @@ class File implements \MailSo\Cache\DriverInterface
}
}
public static function NewInstance(string $sCacheFolder, string $sKeyPrefix = '') : self
{
return new self($sCacheFolder, $sKeyPrefix);
}
public function Set(string $sKey, string $sValue) : bool
{
$sPath = $this->generateCachedFileName($sKey, true);

View file

@ -43,13 +43,13 @@ class Memcache implements \MailSo\Cache\DriverInterface
*/
private $sKeyPrefix;
private function __construct(string $sHost = '127.0.0.1', int $iPost = 11211, int $iExpire = 43200, string $sKeyPrefix = '')
function __construct(string $sHost = '127.0.0.1', int $iPost = 11211, int $iExpire = 43200, string $sKeyPrefix = '')
{
$this->sHost = $sHost;
$this->iPost = $iPost;
$this->iExpire = 0 < $iExpire ? $iExpire : 43200;
$this->oMem = new \Memcache();
$this->oMem = new \Memcache;
if (!$this->oMem->connect($this->sHost, $this->iPost))
{
$this->oMem = null;
@ -63,11 +63,6 @@ class Memcache implements \MailSo\Cache\DriverInterface
}
}
public static function NewInstance(string $sHost = '127.0.0.1', int $iPost = 11211, int $iExpire = 43200, string $sKeyPrefix = '') : self
{
return new self($sHost, $iPost, $iExpire, $sKeyPrefix);
}
public function Set(string $sKey, string $sValue) : bool
{
return $this->oMem ? $this->oMem->set($this->generateCachedKey($sKey), $sValue, 0, $this->iExpire) : false;

View file

@ -43,7 +43,7 @@ class Redis implements \MailSo\Cache\DriverInterface
*/
private $sKeyPrefix;
private function __construct(string $sHost = '127.0.0.1', int $iPost = 6379, int $iExpire = 43200, string $sKeyPrefix = '')
function __construct(string $sHost = '127.0.0.1', int $iPost = 6379, int $iExpire = 43200, string $sKeyPrefix = '')
{
$this->sHost = $sHost;
$this->iPost = $iPost;
@ -79,11 +79,6 @@ class Redis implements \MailSo\Cache\DriverInterface
}
}
public static function NewInstance(string $sHost = '127.0.0.1', int $iPost = 6379, int $iExpire = 43200, string $sKeyPrefix = '') : self
{
return new self($sHost, $iPost, $iExpire, $sKeyPrefix);
}
public function Set(string $sKey, string $sValue) : bool
{
return $this->oRedis ? $this->oRedis->setex($this->generateCachedKey($sKey), $this->iExpire, $sValue) : false;

View file

@ -92,7 +92,7 @@ class BodyStructure
*/
private $aSubParts;
private function __construct(string $sContentType, ?string $sCharset, array $aBodyParams, ?string $sContentID,
function __construct(string $sContentType, ?string $sCharset, array $aBodyParams, ?string $sContentID,
?string $sDescription, ?string $sMailEncodingName, ?string $sDisposition, ?array $aDispositionParams, string $sFileName,
?string $sLanguage, ?string $sLocation, int $iSize, int $iTextLineCount, string $sPartID, array $aSubParts)
{
@ -300,29 +300,26 @@ class BodyStructure
foreach ($mParts as $oPart)
{
$sResult = $oPart ? $oPart->Charset() : '';
if (!empty($sResult))
if ($sResult)
{
break;
}
}
if (0 === strlen($sResult))
if (!$sResult)
{
$aParts = $this->SearchAttachmentsParts();
foreach ($aParts as $oPart)
{
if (0 === \strlen($sResult))
{
$sResult = $oPart ? $oPart->Charset() : '';
}
else
$sResult = $oPart ? $oPart->Charset() : '';
if ($sResult)
{
break;
}
}
}
return $sResult;
return $sResult ?: '';
}
/**

View file

@ -27,17 +27,12 @@ class FetchResponse
*/
private $aEnvelopeCache;
private function __construct(Response $oImapResponse)
function __construct(Response $oImapResponse)
{
$this->oImapResponse = $oImapResponse;
$this->aEnvelopeCache = null;
}
public static function NewInstance(Response $oImapResponse) : self
{
return new self($oImapResponse);
}
public function GetEnvelope(bool $bForce = false) : ?array
{
if (null === $this->aEnvelopeCache || $bForce)
@ -61,7 +56,7 @@ class FetchResponse
$aEmails = $this->GetFetchEnvelopeValue($iIndex);
if (is_array($aEmails) && 0 < count($aEmails))
{
$oResult = \MailSo\Mime\EmailCollection::NewInstance();
$oResult = new \MailSo\Mime\EmailCollection;
foreach ($aEmails as $aEmailItem)
{
if (is_array($aEmailItem) && 4 === count($aEmailItem))
@ -78,7 +73,7 @@ class FetchResponse
if (0 < strlen($sLocalPart) && 0 < strlen($sDomainPart))
{
$oResult->append(
\MailSo\Mime\Email::NewInstance($sLocalPart.'@'.$sDomainPart, $sDisplayName)
new \MailSo\Mime\Email($sLocalPart.'@'.$sDomainPart, $sDisplayName)
);
}
}

View file

@ -50,7 +50,7 @@ class Folder
/**
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
private function __construct(string $sFullNameRaw, string $sDelimiter, array $aFlags)
function __construct(string $sFullNameRaw, string $sDelimiter = '.', array $aFlags = array())
{
$sDelimiter = 'NIL' === \strtoupper($sDelimiter) ? '' : $sDelimiter;
if (empty($sDelimiter))
@ -60,7 +60,7 @@ class Folder
if (1 < \strlen($sDelimiter) || 0 === \strlen($sFullNameRaw))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$this->sFullNameRaw = $sFullNameRaw;
@ -82,21 +82,13 @@ class Folder
$aNames = \explode($this->sDelimiter, $this->sFullNameRaw);
if (false !== \array_search('', $aNames))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$this->sNameRaw = \end($aNames);
}
}
/**
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
public static function NewInstance(string $sFullNameRaw, string $sDelimiter = '.', array $aFlags = array()) : self
{
return new self($sFullNameRaw, $sDelimiter, $aFlags);
}
public function NameRaw() : string
{
return $this->sNameRaw;

View file

@ -67,7 +67,7 @@ class FolderInformation
*/
public $HighestModSeq;
private function __construct(string $sFolderName, bool $bIsWritable)
function __construct(string $sFolderName, bool $bIsWritable)
{
$this->FolderName = $sFolderName;
$this->IsWritable = $bIsWritable;
@ -81,11 +81,6 @@ class FolderInformation
$this->HighestModSeq = null;
}
public static function NewInstance(string $sFolderName, bool $bIsWritable) : self
{
return new self($sFolderName, $bIsWritable);
}
public function IsFlagSupported(string $sFlag) : bool
{
return \in_array('\\*', $this->PermanentFlags) ||

View file

@ -82,7 +82,7 @@ class ImapClient extends \MailSo\Net\NetClient
*/
public $__FORCE_SELECT_ON_EXAMINE__;
protected function __construct()
function __construct()
{
parent::__construct();
@ -90,7 +90,7 @@ class ImapClient extends \MailSo\Net\NetClient
$this->aCapabilityItems = null;
$this->oCurrentFolderInfo = null;
$this->oLastResponse = new ResponseCollection();
$this->oLastResponse = new ResponseCollection;
$this->bNeedNext = true;
$this->aTagTimeouts = array();
@ -104,11 +104,6 @@ class ImapClient extends \MailSo\Net\NetClient
\ini_set('xdebug.max_nesting_level', 500);
}
public static function NewInstance() : self
{
return new self();
}
public function GetLogginedUser() : string
{
return $this->sLogginedUser;
@ -157,7 +152,7 @@ class ImapClient extends \MailSo\Net\NetClient
if (!strlen(\trim($sLogin)) || !strlen(\trim($sPassword)))
{
$this->writeLogException(
new \MailSo\Base\Exceptions\InvalidArgumentException(),
new \MailSo\Base\Exceptions\InvalidArgumentException,
\MailSo\Log\Enumerations\Type::ERROR, true);
}
@ -193,14 +188,14 @@ class ImapClient extends \MailSo\Net\NetClient
else
{
$this->writeLogException(
new Exceptions\LoginException(),
new Exceptions\LoginException,
\MailSo\Log\Enumerations\Type::NOTICE, true);
}
}
else
{
$this->writeLogException(
new Exceptions\LoginException(),
new Exceptions\LoginException,
\MailSo\Log\Enumerations\Type::NOTICE, true);
}
}
@ -239,7 +234,7 @@ class ImapClient extends \MailSo\Net\NetClient
// else
// {
// $this->writeLogException(
// new Exceptions\LoginBadMethodException(),
// new Exceptions\LoginBadMethodException,
// \MailSo\Log\Enumerations\Type::NOTICE, true);
// }
@ -505,7 +500,7 @@ class ImapClient extends \MailSo\Net\NetClient
if (!strlen(\trim($sFolderName)))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$this->oCurrentFolderInfo = $this->SendRequestGetResponse($bIsWritable ? 'SELECT' : 'EXAMINE',
@ -562,7 +557,7 @@ class ImapClient extends \MailSo\Net\NetClient
if (!strlen(\trim($sIndexRange)))
{
$this->writeLogException(
new \MailSo\Base\Exceptions\InvalidArgumentException(),
new \MailSo\Base\Exceptions\InvalidArgumentException,
\MailSo\Log\Enumerations\Type::ERROR, true);
}
@ -614,13 +609,13 @@ class ImapClient extends \MailSo\Net\NetClient
if (!$aSortTypes)
{
$this->writeLogException(
new \MailSo\Base\Exceptions\InvalidArgumentException(),
new \MailSo\Base\Exceptions\InvalidArgumentException,
\MailSo\Log\Enumerations\Type::ERROR, true);
}
if (!$this->IsSupported('SORT'))
{
$this->writeLogException(
new \MailSo\Base\Exceptions\InvalidArgumentException(),
new \MailSo\Base\Exceptions\InvalidArgumentException,
\MailSo\Log\Enumerations\Type::ERROR, true);
}
@ -650,14 +645,14 @@ class ImapClient extends \MailSo\Net\NetClient
if ($bSort && (!$aSortTypes || !$this->IsSupported('SORT')))
{
$this->writeLogException(
new \MailSo\Base\Exceptions\InvalidArgumentException(),
new \MailSo\Base\Exceptions\InvalidArgumentException,
\MailSo\Log\Enumerations\Type::ERROR, true);
}
if (!$this->IsSupported($bSort ? 'ESORT' : 'ESEARCH'))
{
$this->writeLogException(
new \MailSo\Base\Exceptions\InvalidArgumentException(),
new \MailSo\Base\Exceptions\InvalidArgumentException,
\MailSo\Log\Enumerations\Type::ERROR, true);
}
@ -821,7 +816,7 @@ class ImapClient extends \MailSo\Net\NetClient
if (0 === \strlen($sIndexRange))
{
$this->writeLogException(
new \MailSo\Base\Exceptions\InvalidArgumentException(),
new \MailSo\Base\Exceptions\InvalidArgumentException,
\MailSo\Log\Enumerations\Type::ERROR, true);
}
@ -841,7 +836,7 @@ class ImapClient extends \MailSo\Net\NetClient
if (0 === \strlen($sIndexRange))
{
$this->writeLogException(
new \MailSo\Base\Exceptions\InvalidArgumentException(),
new \MailSo\Base\Exceptions\InvalidArgumentException,
\MailSo\Log\Enumerations\Type::ERROR, true);
}
@ -958,7 +953,7 @@ class ImapClient extends \MailSo\Net\NetClient
if (!\strlen($sCommand))
{
$this->writeLogException(
new \MailSo\Base\Exceptions\InvalidArgumentException(),
new \MailSo\Base\Exceptions\InvalidArgumentException,
\MailSo\Log\Enumerations\Type::ERROR, true);
}
@ -1026,18 +1021,18 @@ class ImapClient extends \MailSo\Net\NetClient
private function getResponse(string $sEndTag = null) : ResponseCollection
{
try {
$oResult = new ResponseCollection();
$oResult = new ResponseCollection;
if (\is_resource($this->rConnect)) {
$sEndTag = (null === $sEndTag) ? $this->getCurrentTag() : $sEndTag;
while (true) {
$oResponse = Response::NewInstance();
$oResponse = new Response;
$this->partialParseResponseBranch($oResponse);
if (Enumerations\ResponseType::UNKNOWN === $oResponse->ResponseType) {
throw new Exceptions\ResponseNotFoundException();
throw new Exceptions\ResponseNotFoundException;
}
$oResult->append($oResponse);

View file

@ -47,7 +47,7 @@ class NamespaceResult
*/
private $sSharedDelimiter;
private function __construct()
function __construct()
{
$this->sPersonal = '';
$this->sPersonalDelimiter = '';
@ -57,11 +57,6 @@ class NamespaceResult
$this->sSharedDelimiter = '';
}
public static function NewInstance() : self
{
return new self();
}
public function InitByImapResponse(\MailSo\Imap\Response $oImapResponse) : self
{
if ($oImapResponse && $oImapResponse instanceof \MailSo\Imap\Response)

View file

@ -52,7 +52,7 @@ class Response
*/
public $Tag;
private function __construct()
function __construct()
{
$this->ResponseList = array();
$this->OptionalResponse = null;
@ -63,11 +63,6 @@ class Response
$this->Tag = '';
}
public static function NewInstance() : self
{
return new self();
}
private function recToLine(array $aList) : string
{
$aResult = array();

View file

@ -18,11 +18,6 @@ namespace MailSo\Imap;
*/
class ResponseCollection extends \MailSo\Base\Collection
{
public static function NewInstance() : self
{
return new self();
}
public function append($oResponse, bool $bToTop = false) : void
{
assert($oResponse instanceof Response);
@ -39,7 +34,7 @@ class ResponseCollection extends \MailSo\Base\Collection
{
$oItem = $this->getLast();
if (!$oItem) {
throw new Exceptions\ResponseNotFoundException();
throw new Exceptions\ResponseNotFoundException;
}
if ($oItem->ResponseType !== Enumerations\ResponseType::CONTINUATION) {
@ -87,7 +82,7 @@ class ResponseCollection extends \MailSo\Base\Collection
foreach ($this as $oResponse) {
if (FetchResponse::IsValidFetchImapResponse($oResponse)) {
if (FetchResponse::IsNotEmptyFetchImapResponse($oResponse)) {
$aReturn[] = FetchResponse::NewInstance($oResponse);
$aReturn[] = new FetchResponse($oResponse);
} else if ($this->oLogger) {
$this->oLogger->Write('Skipped Imap Response! ['.$oResponse->ToLine().']', \MailSo\Log\Enumerations\Type::NOTICE);
}
@ -109,7 +104,7 @@ class ResponseCollection extends \MailSo\Base\Collection
{
try
{
$oFolder = Folder::NewInstance($oResponse->ResponseList[4],
$oFolder = new Folder($oResponse->ResponseList[4],
$oResponse->ResponseList[3], $oResponse->ResponseList[2]);
if ($oFolder->IsInbox()) {
@ -132,7 +127,7 @@ class ResponseCollection extends \MailSo\Base\Collection
}
if (!$bInbox && !empty($sDelimiter)) {
$aReturn[] = Folder::NewInstance('INBOX', $sDelimiter);
$aReturn[] = new Folder('INBOX', $sDelimiter);
}
if ($bUseListStatus) {
@ -241,7 +236,7 @@ class ResponseCollection extends \MailSo\Base\Collection
public function getCurrentFolderInformation(string $sFolderName, bool $bIsWritable) : FolderInformation
{
$oResult = FolderInformation::NewInstance($sFolderName, $bIsWritable);
$oResult = new FolderInformation($sFolderName, $bIsWritable);
foreach ($this as $oResponse) {
if (\MailSo\Imap\Enumerations\ResponseType::UNTAGGED === $oResponse->ResponseType) {
if (\count($oResponse->ResponseList) > 2 &&
@ -306,12 +301,12 @@ class ResponseCollection extends \MailSo\Base\Collection
if (Enumerations\ResponseType::UNTAGGED === $oResponse->ResponseType &&
'NAMESPACE' === $oResponse->StatusOrIndex)
{
$oReturn = NamespaceResult::NewInstance();
$oReturn = new NamespaceResult;
$oReturn->InitByImapResponse($oResponse);
return $oReturn;
}
}
throw new Exceptions\ResponseException();
throw new Exceptions\ResponseException;
}
public function getQuotaResult() : array

View file

@ -82,7 +82,7 @@ abstract class Driver
*/
private $aCache;
protected function __construct()
function __construct()
{
$this->sDatePattern = 'H:i:s';
$this->sName = 'INFO';

View file

@ -32,7 +32,7 @@ class Callback extends \MailSo\Log\Driver
* @param mixed $fWriteCallback
* @param mixed $fClearCallback
*/
protected function __construct($fWriteCallback, $fClearCallback)
function __construct($fWriteCallback, $fClearCallback)
{
parent::__construct();
@ -40,15 +40,6 @@ class Callback extends \MailSo\Log\Driver
$this->fClearCallback = \is_callable($fClearCallback) ? $fClearCallback : null;
}
/**
* @param mixed $fWriteCallback
* @param mixed $fClearCallback = null
*/
public static function NewInstance($fWriteCallback, $fClearCallback = null) : \MailSo\Log\Drivers\Callback
{
return new self($fWriteCallback, $fClearCallback);
}
protected function writeImplementation($mDesc) : bool
{
if ($this->fWriteCallback)

View file

@ -23,7 +23,7 @@ class File extends \MailSo\Log\Driver
*/
private $sLoggerFileName;
protected function __construct(string $sLoggerFileName, string $sNewLine = "\r\n")
function __construct(string $sLoggerFileName, string $sNewLine = "\r\n")
{
parent::__construct();
@ -36,11 +36,6 @@ class File extends \MailSo\Log\Driver
$this->sLoggerFileName = $sLoggerFileName;
}
public static function NewInstance(string $sLoggerFileName, string $sNewLine = "\r\n") : \MailSo\Log\Drivers\File
{
return new self($sLoggerFileName, $sNewLine);
}
protected function writeImplementation($mDesc) : bool
{
return $this->writeToLogFile($mDesc);

View file

@ -23,7 +23,7 @@ class Inline extends \MailSo\Log\Driver
*/
private $bHtmlEncodeSpecialChars;
protected function __construct(string $sNewLine = "\r\n", bool $bHtmlEncodeSpecialChars = false)
function __construct(string $sNewLine = "\r\n", bool $bHtmlEncodeSpecialChars = false)
{
parent::__construct();
@ -31,11 +31,6 @@ class Inline extends \MailSo\Log\Driver
$this->bHtmlEncodeSpecialChars = $bHtmlEncodeSpecialChars;
}
public static function NewInstance(string $sNewLine = "\r\n", bool $bHtmlEncodeSpecialChars = false) : \MailSo\Log\Drivers\Inline
{
return new self($sNewLine, $bHtmlEncodeSpecialChars);
}
protected function writeImplementation($mDesc) : bool
{
if (\is_array($mDesc))

View file

@ -20,7 +20,7 @@ class Syslog extends \MailSo\Log\Driver
{
private $iLogLevel;
protected function __construct()
function __construct()
{
parent::__construct();
@ -40,11 +40,6 @@ class Syslog extends \MailSo\Log\Driver
}
}
public static function NewInstance() : \MailSo\Log\Drivers\Syslog
{
return new self();
}
protected function writeImplementation($mDesc) : bool
{
if (null === $this->iLogLevel)

View file

@ -42,7 +42,7 @@ class Logger extends \MailSo\Base\Collection
*/
private $bHideErrorNotices;
protected function __construct(bool $bRegPhpErrorHandler = true)
function __construct(bool $bRegPhpErrorHandler = true)
{
parent::__construct();
@ -60,11 +60,6 @@ class Logger extends \MailSo\Base\Collection
\register_shutdown_function(array(&$this, '__loggerShutDown'));
}
public static function NewInstance(bool $bRegPhpErrorHandler = false) : self
{
return new self($bRegPhpErrorHandler);
}
/**
* @staticvar \MailSo\Log\Logger $oInstance;
*/
@ -73,7 +68,7 @@ class Logger extends \MailSo\Base\Collection
static $oInstance = null;
if (null === $oInstance)
{
$oInstance = self::NewInstance();
$oInstance = new self;
}
return $oInstance;

View file

@ -32,7 +32,7 @@ class Attachment
*/
private $oBodyStructure;
private function __construct()
function __construct()
{
$this->Clear();
}
@ -148,14 +148,9 @@ class Attachment
return $this->oBodyStructure ? $this->oBodyStructure->IsPgpSignature() : false;
}
public static function NewInstance() : self
{
return new self();
}
public static function NewBodyStructureInstance(string $sFolder, int $iUid, \MailSo\Imap\BodyStructure $oBodyStructure) : self
{
return self::NewInstance()->InitByBodyStructure($sFolder, $iUid, $oBodyStructure);
return (new self)->InitByBodyStructure($sFolder, $iUid, $oBodyStructure);
}
public function InitByBodyStructure(string $sFolder, int $iUid, \MailSo\Imap\BodyStructure $oBodyStructure) : self

View file

@ -17,11 +17,6 @@ namespace MailSo\Mail;
*/
class AttachmentCollection extends \MailSo\Base\Collection
{
public static function NewInstance() : self
{
return new self();
}
public function append($oAttachment, bool $bToTop = false) : void
{
assert($oAttachment instanceof Attachment);

View file

@ -50,7 +50,7 @@ class Folder
/**
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
private function __construct(\MailSo\Imap\Folder $oImapFolder, bool $bSubscribed = true, bool $bExisten = true)
function __construct(\MailSo\Imap\Folder $oImapFolder, bool $bSubscribed = true, bool $bExisten = true)
{
$this->oImapFolder = $oImapFolder;
$this->oSubFolders = null;
@ -69,22 +69,14 @@ class Folder
$this->bExisten = $bExisten;
}
/**
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
public static function NewInstance(\MailSo\Imap\Folder $oImapFolder, bool $bSubscribed = true, bool $bExisten = true) : self
{
return new self($oImapFolder, $bSubscribed, $bExisten);
}
/**
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
public static function NewNonExistenInstance(string $sFullNameRaw, string $sDelimiter) : self
{
return self::NewInstance(
\MailSo\Imap\Folder::NewInstance($sFullNameRaw, $sDelimiter, array('\NoSelect')), true, false);
return new self(
new \MailSo\Imap\Folder($sFullNameRaw, $sDelimiter, array('\NoSelect')), true, false);
}
public function Name() : string
@ -142,7 +134,7 @@ class Folder
{
if ($bCreateIfNull && !$this->oSubFolders)
{
$this->oSubFolders = FolderCollection::NewInstance();
$this->oSubFolders = new FolderCollection;
}
return $this->oSubFolders;

View file

@ -42,9 +42,9 @@ class FolderCollection extends \MailSo\Base\Collection
*/
public $SystemFolders;
protected function __construct()
function __construct($input = array())
{
parent::__construct();
parent::__construct($input);
$this->Namespace = '';
$this->FoldersHash = '';
@ -53,11 +53,6 @@ class FolderCollection extends \MailSo\Base\Collection
$this->Optimized = false;
}
public static function NewInstance() : self
{
return new self();
}
public function append($oFolder, bool $bToTop = false) : void
{
assert($oFolder instanceof Folder);

View file

@ -27,19 +27,14 @@ class MailClient
*/
private $oImapClient;
private function __construct()
function __construct()
{
$this->oLogger = null;
$this->oImapClient = \MailSo\Imap\ImapClient::NewInstance();
$this->oImapClient = new \MailSo\Imap\ImapClient;
$this->oImapClient->SetTimeOuts(10, \MailSo\Config::$ImapTimeout);
}
public static function NewInstance() : self
{
return new self();
}
public function ImapClient() : \MailSo\Imap\ImapClient
{
return $this->oImapClient;
@ -274,7 +269,7 @@ class MailClient
{
if (!\MailSo\Base\Validator::RangeInt($iIndex, 1))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$this->oImapClient->FolderSelect($sFolderName);
@ -364,7 +359,7 @@ class MailClient
{
if (!is_callable($mCallback))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$this->oImapClient->FolderSelect($sFolderName);
@ -390,7 +385,7 @@ class MailClient
if (0 < \strlen($sMime))
{
$oHeaders = \MailSo\Mime\HeaderCollection::NewInstance()->Parse($sMime);
$oHeaders = new \MailSo\Mime\HeaderCollection($sMime);
if (0 < \strlen($sMimeIndex))
{
@ -455,7 +450,7 @@ class MailClient
{
if (0 === \strlen($sFolder) || 0 === \count($aIndexRange))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$this->oImapClient->FolderSelect($sFolder);
@ -484,7 +479,7 @@ class MailClient
{
if (!$sFromFolder || !$sToFolder || 0 === \count($aIndexRange))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$this->oImapClient->FolderSelect($sFromFolder);
@ -514,7 +509,7 @@ class MailClient
{
if (!$sFromFolder || !$sToFolder || 0 === \count($aIndexRange))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$this->oImapClient->FolderSelect($sFromFolder);
@ -545,7 +540,7 @@ class MailClient
{
if (!\is_resource($rMessageStream) || 0 === \strlen($sFolderToSave))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$this->oImapClient->MessageAppendStream(
@ -558,7 +553,7 @@ class MailClient
{
if (!\is_file($sMessageFileName) || !\is_readable($sMessageFileName))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$iMessageStreamSize = \filesize($sMessageFileName);
@ -650,7 +645,7 @@ class MailClient
$sUid = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::UID);
$sHeaders = $oFetchResponse->GetHeaderFieldsValue();
$oHeaders = \MailSo\Mime\HeaderCollection::NewInstance()->Parse($sHeaders);
$oHeaders = new \MailSo\Mime\HeaderCollection($sHeaders);
$sContentTypeCharset = $oHeaders->ParameterValue(
\MailSo\Mime\Enumerations\Header::CONTENT_TYPE,
@ -1563,14 +1558,14 @@ class MailClient
if (!\MailSo\Base\Validator::RangeInt($iOffset, 0) ||
!\MailSo\Base\Validator::RangeInt($iLimit, 0, 999))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$bUseFilter = '' !== $sFilter;
$this->oImapClient->FolderSelect($sFolderName);
$oMessageCollection = MessageCollection::NewInstance();
$oMessageCollection = new MessageCollection;
$oMessageCollection->FolderName = $sFolderName;
$oMessageCollection->Offset = $iOffset;
$oMessageCollection->Limit = $iLimit;
@ -1596,7 +1591,7 @@ class MailClient
if (!empty($sThreadUid) && !$bUseThreadSortIfSupported)
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
if (!$oCacher || !($oCacher instanceof \MailSo\Cache\CacheClient))
@ -1805,7 +1800,7 @@ class MailClient
{
if (0 === \strlen($sMessageId))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$this->oImapClient->FolderExamine($sFolderName);
@ -1974,7 +1969,7 @@ class MailClient
foreach ($aFolders as /* @var $oImapFolder \MailSo\Imap\Folder */ $oImapFolder)
{
$aMailFoldersHelper[] = Folder::NewInstance($oImapFolder,
$aMailFoldersHelper[] = new Folder($oImapFolder,
(null === $aImapSubscribedFoldersHelper || \in_array($oImapFolder->FullNameRaw(), $aImapSubscribedFoldersHelper)) ||
$oImapFolder->IsInbox()
);
@ -1985,7 +1980,7 @@ class MailClient
if ($aMailFoldersHelper)
{
$oFolderCollection = FolderCollection::NewInstance();
$oFolderCollection = new FolderCollection;
$oFolderCollection->InitByUnsortedMailFolderArray($aMailFoldersHelper);
$oFolderCollection->Optimized = $iCount !== \count($aMailFoldersHelper);
@ -2027,7 +2022,7 @@ class MailClient
{
if (!strlen(\trim($sFolderNameInUtf8)))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$sFolderNameInUtf8 = \trim($sFolderNameInUtf8);
@ -2097,7 +2092,7 @@ class MailClient
{
if (0 === \strlen($sPrevFolderFullNameRaw) || 0 === \strlen($sNextFolderNameInUtf))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$aFolders = $this->oImapClient->FolderList('', $sPrevFolderFullNameRaw);
@ -2161,7 +2156,7 @@ class MailClient
{
if (0 === \strlen($sFolderFullNameRaw) || 'INBOX' === $sFolderFullNameRaw)
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$this->oImapClient->FolderExamine($sFolderFullNameRaw);
@ -2169,7 +2164,7 @@ class MailClient
$aIndexOrUids = $this->oImapClient->MessageSimpleSearch('ALL');
if (0 < \count($aIndexOrUids))
{
throw new \MailSo\Mail\Exceptions\NonEmptyFolder();
throw new \MailSo\Mail\Exceptions\NonEmptyFolder;
}
$this->oImapClient->FolderExamine('INBOX');
@ -2212,7 +2207,7 @@ class MailClient
{
if (0 === \strlen($sFolderFullNameRaw))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$this->oImapClient->{($bSubscribe) ? 'FolderSubscribe' : 'FolderUnSubscribe'}($sFolderFullNameRaw);
@ -2227,7 +2222,7 @@ class MailClient
{
if (!($oLogger instanceof \MailSo\Log\Logger))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$this->oLogger = $oLogger;

View file

@ -123,7 +123,7 @@ class Message
private $sHtml;
/**
* @var \MailSo\Mail\AttachmentCollection
* @var AttachmentCollection
*/
private $oAttachments;
@ -187,12 +187,12 @@ class Message
*/
private $bPgpEncrypted;
private function __construct()
function __construct()
{
$this->Clear();
}
public function Clear() : \MailSo\Mail\Message
public function Clear() : self
{
$this->sFolder = '';
$this->iUid = 0;
@ -240,11 +240,6 @@ class Message
return $this;
}
public static function NewInstance() : \MailSo\Mail\Message
{
return new self();
}
public function Plain() : string
{
return $this->sPlain;
@ -375,7 +370,7 @@ class Message
return $this->oBcc;
}
public function Attachments() : ?\MailSo\Mail\AttachmentCollection
public function Attachments() : ?AttachmentCollection
{
return $this->oAttachments;
}
@ -430,12 +425,12 @@ class Message
return $this->bTextPartIsTrimmed;
}
public static function NewFetchResponseInstance(string $sFolder, \MailSo\Imap\FetchResponse $oFetchResponse, ?\MailSo\Imap\BodyStructure $oBodyStructure = null) : \MailSo\Mail\Message
public static function NewFetchResponseInstance(string $sFolder, \MailSo\Imap\FetchResponse $oFetchResponse, ?\MailSo\Imap\BodyStructure $oBodyStructure = null) : self
{
return self::NewInstance()->InitByFetchResponse($sFolder, $oFetchResponse, $oBodyStructure);
return (new self)->InitByFetchResponse($sFolder, $oFetchResponse, $oBodyStructure);
}
public function InitByFetchResponse(string $sFolder, \MailSo\Imap\FetchResponse $oFetchResponse, ?\MailSo\Imap\BodyStructure $oBodyStructure = null) : \MailSo\Mail\Message
public function InitByFetchResponse(string $sFolder, \MailSo\Imap\FetchResponse $oFetchResponse, ?\MailSo\Imap\BodyStructure $oBodyStructure = null) : self
{
if (!$oBodyStructure)
{
@ -460,9 +455,9 @@ class Message
$sCharset = \MailSo\Base\Utils::NormalizeCharset($sCharset);
$sHeaders = $oFetchResponse->GetHeaderFieldsValue();
if (0 < \strlen($sHeaders))
if (\strlen($sHeaders))
{
$oHeaders = \MailSo\Mime\HeaderCollection::NewInstance()->Parse($sHeaders, false, $sCharset);
$oHeaders = new \MailSo\Mime\HeaderCollection($sHeaders, false, $sCharset);
$sContentTypeCharset = $oHeaders->ParameterValue(
\MailSo\Mime\Enumerations\Header::CONTENT_TYPE,
@ -589,7 +584,7 @@ class Message
$sFolder = '';
$sUid = '';
$oParameters = \MailSo\Mime\ParameterCollection::NewInstance($sDraftInfo);
$oParameters = new \MailSo\Mime\ParameterCollection($sDraftInfo);
foreach ($oParameters as $oParameter) {
switch (\strtolower($oParameter->Name()))
{
@ -737,11 +732,11 @@ class Message
$aAttachmentsParts = $oBodyStructure->SearchAttachmentsParts();
if ($aAttachmentsParts && 0 < count($aAttachmentsParts))
{
$this->oAttachments = AttachmentCollection::NewInstance();
$this->oAttachments = new AttachmentCollection;
foreach ($aAttachmentsParts as /* @var $oAttachmentItem \MailSo\Imap\BodyStructure */ $oAttachmentItem)
{
$this->oAttachments->append(
\MailSo\Mail\Attachment::NewBodyStructureInstance($this->sFolder, $this->iUid, $oAttachmentItem)
Attachment::NewBodyStructureInstance($this->sFolder, $this->iUid, $oAttachmentItem)
);
}
}

View file

@ -77,18 +77,13 @@ class MessageCollection extends \MailSo\Base\Collection
*/
public $Filtered;
protected function __construct()
function __construct()
{
parent::__construct();
$this->Clear();
}
public static function NewInstance() : self
{
return new self();
}
public function append($oMessage, bool $bToTop = false) : void
{
assert($oMessage instanceof Message);

View file

@ -57,8 +57,11 @@ class Attachment
*/
private $sContentLocation;
private function __construct($rResource, string $sFileName, int $iFileSize, bool $bIsInline, bool $bIsLinked, string $sCID,
array $aCustomContentTypeParams = array(), string $sContentLocation = '')
/**
* @param resource $rResource
*/
function __construct($rResource, string $sFileName, int $iFileSize, bool $bIsInline,
bool $bIsLinked, string $sCID, array $aCustomContentTypeParams = [], string $sContentLocation = '')
{
$this->rResource = $rResource;
$this->sFileName = $sFileName;
@ -70,15 +73,6 @@ class Attachment
$this->sContentLocation = $sContentLocation;
}
/**
* @param resource $rResource
*/
public static function NewInstance($rResource, string $sFileName = '', int $iFileSize = 0, bool $bIsInline = false,
bool $bIsLinked = false, string $sCID = '', array $aCustomContentTypeParams = array(), string $sContentLocation = '') : self
{
return new self($rResource, $sFileName, $iFileSize, $bIsInline, $bIsLinked, $sCID, $aCustomContentTypeParams, $sContentLocation);
}
/**
* @return resource
*/

View file

@ -17,11 +17,6 @@ namespace MailSo\Mime;
*/
class AttachmentCollection extends \MailSo\Base\Collection
{
public static function NewInstance() : self
{
return new self();
}
public function append($oAttachment, bool $bToTop = false) : void
{
assert($oAttachment instanceof Attachment);

View file

@ -40,11 +40,11 @@ class Email
/**
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
private function __construct(string $sEmail, string $sDisplayName = '')
function __construct(string $sEmail, string $sDisplayName = '')
{
if (!strlen(\trim($sEmail)))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$this->sEmail = \MailSo\Base\Utils::IdnToAscii(
@ -52,18 +52,10 @@ class Email
$this->sDisplayName = \MailSo\Base\Utils::Trim($sDisplayName);
$this->sDkimStatus = \MailSo\Mime\Enumerations\DkimStatus::NONE;
$this->sDkimStatus = Enumerations\DkimStatus::NONE;
$this->sDkimValue = '';
}
/**
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
public static function NewInstance(string $sEmail, string $sDisplayName = '') : self
{
return new self($sEmail, $sDisplayName);
}
/**
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
@ -72,7 +64,7 @@ class Email
$sEmailAddress = \MailSo\Base\Utils::Trim($sEmailAddress);
if (!strlen(\trim($sEmailAddress)))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$sName = '';
@ -191,7 +183,7 @@ class Email
$sName = \preg_replace('/\\\\(.)/s', '$1', $sName);
$sComment = \preg_replace('/\\\\(.)/s', '$1', $sComment);
return Email::NewInstance($sEmail, $sName);
return new self($sEmail, $sName);
}
public function GetEmail(bool $bIdn = false) : string
@ -226,7 +218,7 @@ class Email
public function SetDkimStatusAndValue(string $sDkimStatus, string $sDkimValue = '')
{
$this->sDkimStatus = \MailSo\Mime\Enumerations\DkimStatus::normalizeValue($sDkimStatus);
$this->sDkimStatus = Enumerations\DkimStatus::normalizeValue($sDkimStatus);
$this->sDkimValue = $sDkimValue;
}

View file

@ -17,33 +17,22 @@ namespace MailSo\Mime;
*/
class EmailCollection extends \MailSo\Base\Collection
{
protected function __construct(string $sEmailAddresses = '')
function __construct($mEmailAddresses = '')
{
parent::__construct();
$sEmailAddresses = \MailSo\Base\Utils::Trim($sEmailAddresses);
if (0 < \strlen($sEmailAddresses))
{
$this->parseEmailAddresses($sEmailAddresses);
if (\is_string($mEmailAddresses)) {
parent::__construct();
$this->parseEmailAddresses($mEmailAddresses);
} else {
parent::__construct($mEmailAddresses);
}
}
public static function NewInstance(string $sEmailAddresses = '') : self
{
return new self($sEmailAddresses);
}
public function append($oEmail, bool $bToTop = false) : void
{
assert($oEmail instanceof Email);
parent::append($oEmail, $bToTop);
}
public static function Parse(string $sEmailAddresses) : self
{
return self::NewInstance($sEmailAddresses);
}
public function ToArray() : array
{
$aReturn = array();
@ -78,9 +67,7 @@ class EmailCollection extends \MailSo\Base\Collection
}
}
$this->exchangeArray(array_values($aReturn));
return $this;
return new static($aReturn);
}
public function ToString(bool $bConvertSpecialsName = false, bool $bIdn = false) : string
@ -94,15 +81,15 @@ class EmailCollection extends \MailSo\Base\Collection
return \implode(', ', $aReturn);
}
private function parseEmailAddresses(string $sRawEmails) : self
private function parseEmailAddresses(string $sRawEmails) : void
{
$this->Clear();
// $sRawEmails = \MailSo\Base\Utils::Trim($sRawEmails);
$sRawEmails = \trim($sRawEmails);
$sWorkingRecipients = \trim($sRawEmails);
if (0 === \strlen($sWorkingRecipients))
$sWorkingRecipientsLen = \strlen($sRawEmails);
if (!$sWorkingRecipientsLen)
{
return $this;
return;
}
$iEmailStartPos = 0;
@ -115,20 +102,18 @@ class EmailCollection extends \MailSo\Base\Collection
$iCurrentPos = 0;
$sWorkingRecipientsLen = \strlen($sWorkingRecipients);
while ($iCurrentPos < $sWorkingRecipientsLen)
{
switch ($sWorkingRecipients[$iCurrentPos])
switch ($sRawEmails[$iCurrentPos])
{
case '\'':
case '"':
if (!$bIsInQuotes)
{
$sChQuote = $sWorkingRecipients[$iCurrentPos];
$sChQuote = $sRawEmails[$iCurrentPos];
$bIsInQuotes = true;
}
else if ($sChQuote == $sWorkingRecipients[$iCurrentPos])
else if ($sChQuote == $sRawEmails[$iCurrentPos])
{
$bIsInQuotes = false;
}
@ -175,7 +160,7 @@ class EmailCollection extends \MailSo\Base\Collection
try
{
$this->append(
Email::Parse(\substr($sWorkingRecipients, $iEmailStartPos, $iEmailEndPos - $iEmailStartPos))
Email::Parse(\substr($sRawEmails, $iEmailStartPos, $iEmailEndPos - $iEmailStartPos))
);
$iEmailStartPos = $iCurrentPos + 1;
@ -187,7 +172,7 @@ class EmailCollection extends \MailSo\Base\Collection
break;
}
$iCurrentPos++;
++$iCurrentPos;
}
if ($iEmailStartPos < $iCurrentPos)
@ -195,12 +180,10 @@ class EmailCollection extends \MailSo\Base\Collection
try
{
$this->append(
Email::Parse(\substr($sWorkingRecipients, $iEmailStartPos, $iCurrentPos - $iEmailStartPos))
Email::Parse(\substr($sRawEmails, $iEmailStartPos, $iCurrentPos - $iEmailStartPos))
);
}
catch (\MailSo\Base\Exceptions\InvalidArgumentException $oException) {}
}
return $this;
}
}

View file

@ -1,283 +0,0 @@
<?php
/*
* This file is part of MailSo.
*
* (c) 2014 Usenko Timur
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace MailSo\Mime;
/**
* @deprecated
* @category MailSo
* @package Mime
*/
class EmailDep
{
/**
* @var string
*/
private $sDisplayName;
/**
* @var string
*/
private $sEmail;
/**
* @var string
*/
private $sRemark;
/**
* @var string
*/
private $sDkimStatus;
/**
* @var string
*/
private $sDkimValue;
/**
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
private function __construct(string $sEmail, string $sDisplayName = '', string $sRemark = '')
{
if (!strlen(\trim($sEmail)))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
}
$this->sEmail = \MailSo\Base\Utils::IdnToAscii(
\MailSo\Base\Utils::Trim($sEmail), true);
$this->sDisplayName = \MailSo\Base\Utils::Trim($sDisplayName);
$this->sRemark = \MailSo\Base\Utils::Trim($sRemark);
$this->sDkimStatus = \MailSo\Mime\Enumerations\DkimStatus::NONE;
$this->sDkimValue = '';
}
/**
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
public static function NewInstance(string $sEmail, string $sDisplayName = '', string $sRemark = '') : \MailSo\Mime\Email
{
return new self($sEmail, $sDisplayName, $sRemark);
}
/**
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
public static function Parse(string $sEmailAddress) : \MailSo\Mime\Email
{
$sEmailAddress = \MailSo\Base\Utils::Trim($sEmailAddress);
if (!strlen(\trim($sEmailAddress)))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
}
$sName = '';
$sEmail = '';
$sComment = '';
$bInName = false;
$bInAddress = false;
$bInComment = false;
$iStartIndex = 0;
$iEndIndex = 0;
$iCurrentIndex = 0;
while ($iCurrentIndex < \strlen($sEmailAddress))
{
switch ($sEmailAddress[$iCurrentIndex])
{
// case '\'':
case '"':
// $sQuoteChar = $sEmailAddress[$iCurrentIndex];
if ((!$bInName) && (!$bInAddress) && (!$bInComment))
{
$bInName = true;
$iStartIndex = $iCurrentIndex;
}
else if ((!$bInAddress) && (!$bInComment))
{
$iEndIndex = $iCurrentIndex;
$sName = \substr($sEmailAddress, $iStartIndex + 1, $iEndIndex - $iStartIndex - 1);
$sEmailAddress = \substr_replace($sEmailAddress, '', $iStartIndex, $iEndIndex - $iStartIndex + 1);
$iEndIndex = 0;
$iCurrentIndex = 0;
$iStartIndex = 0;
$bInName = false;
}
break;
case '<':
if ((!$bInName) && (!$bInAddress) && (!$bInComment))
{
if ($iCurrentIndex > 0 && \strlen($sName) === 0)
{
$sName = \substr($sEmailAddress, 0, $iCurrentIndex);
}
$bInAddress = true;
$iStartIndex = $iCurrentIndex;
}
break;
case '>':
if ($bInAddress)
{
$iEndIndex = $iCurrentIndex;
$sEmail = \substr($sEmailAddress, $iStartIndex + 1, $iEndIndex - $iStartIndex - 1);
$sEmailAddress = \substr_replace($sEmailAddress, '', $iStartIndex, $iEndIndex - $iStartIndex + 1);
$iEndIndex = 0;
$iCurrentIndex = 0;
$iStartIndex = 0;
$bInAddress = false;
}
break;
case '(':
if ((!$bInName) && (!$bInAddress) && (!$bInComment))
{
$bInComment = true;
$iStartIndex = $iCurrentIndex;
}
break;
case ')':
if ($bInComment)
{
$iEndIndex = $iCurrentIndex;
$sComment = \substr($sEmailAddress, $iStartIndex + 1, $iEndIndex - $iStartIndex - 1);
$sEmailAddress = \substr_replace($sEmailAddress, '', $iStartIndex, $iEndIndex - $iStartIndex + 1);
$iEndIndex = 0;
$iCurrentIndex = 0;
$iStartIndex = 0;
$bInComment = false;
}
break;
case '\\':
$iCurrentIndex++;
break;
}
$iCurrentIndex++;
}
if (\strlen($sEmail) === 0)
{
$aRegs = array('');
if (\preg_match('/[^@\s]+@\S+/i', $sEmailAddress, $aRegs) && isset($aRegs[0]))
{
$sEmail = $aRegs[0];
}
else
{
$sName = $sEmailAddress;
}
}
if ((\strlen($sEmail) > 0) && (\strlen($sName) == 0) && (\strlen($sComment) == 0))
{
$sName = \str_replace($sEmail, '', $sEmailAddress);
}
$sEmail = \trim(\trim($sEmail), '<>');
$sEmail = \rtrim(\trim($sEmail), '.');
$sEmail = \trim($sEmail);
$sName = \trim(\trim($sName), '"');
$sName = \trim($sName, '\'');
$sComment = \trim(\trim($sComment), '()');
// Remove backslash
$sName = \preg_replace('/\\\\(.)/s', '$1', $sName);
$sComment = \preg_replace('/\\\\(.)/s', '$1', $sComment);
return Email::NewInstance($sEmail, $sName, $sComment);
}
public function GetEmail(bool $bIdn = false) : string
{
return $bIdn ? \MailSo\Base\Utils::IdnToUtf8($this->sEmail) : $this->sEmail;
}
public function GetDisplayName() : string
{
return $this->sDisplayName;
}
public function GetRemark() : string
{
return $this->sRemark;
}
public function GetDkimStatus() : string
{
return $this->sDkimStatus;
}
public function GetDkimValue() : string
{
return $this->sDkimValue;
}
public function GetAccountName() : string
{
return \MailSo\Base\Utils::GetAccountNameFromEmail($this->GetEmail(false));
}
public function GetDomain(bool $bIdn = false) : string
{
return \MailSo\Base\Utils::GetDomainFromEmail($this->GetEmail($bIdn));
}
public function SetDkimStatusAndValue(string $sDkimStatus, string $sDkimValue = '') : void
{
$this->sDkimStatus = \MailSo\Mime\Enumerations\DkimStatus::normalizeValue($sDkimStatus);
$this->sDkimValue = $sDkimValue;
}
public function ToArray(bool $bIdn = false, bool $bDkim = true) : array
{
return $bDkim ? array($this->sDisplayName, $this->GetEmail($bIdn), $this->sRemark, $this->sDkimStatus, $this->sDkimValue) :
array($this->sDisplayName, $this->GetEmail($bIdn), $this->sRemark);
}
public function ToString(bool $bConvertSpecialsName = false, bool $bIdn = false) : string
{
$sReturn = '';
$sRemark = \str_replace(')', '\)', $this->sRemark);
$sDisplayName = \str_replace('"', '\"', $this->sDisplayName);
if ($bConvertSpecialsName)
{
$sDisplayName = 0 === \strlen($sDisplayName) ? '' : \MailSo\Base\Utils::EncodeUnencodedValue(
\MailSo\Base\Enumerations\Encoding::BASE64_SHORT,
$sDisplayName);
$sRemark = 0 === \strlen($sRemark) ? '' : \MailSo\Base\Utils::EncodeUnencodedValue(
\MailSo\Base\Enumerations\Encoding::BASE64_SHORT,
$sRemark);
}
$sDisplayName = 0 === \strlen($sDisplayName) ? '' : '"'.$sDisplayName.'"';
$sRemark = 0 === \strlen($sRemark) ? '' : '('.$sRemark.')';
if (0 < \strlen($this->sEmail))
{
$sReturn = $this->GetEmail($bIdn);
if (0 < \strlen($sDisplayName.$sRemark))
{
$sReturn = $sDisplayName.' <'.$sReturn.'> '.$sRemark;
}
}
return \trim($sReturn);
}
}

View file

@ -47,7 +47,7 @@ class Header
*/
private $sParentCharset;
private function __construct(string $sName, string $sValue, string $sEncodedValueForReparse, string $sParentCharset = '')
function __construct(string $sName, string $sValue = '', string $sEncodedValueForReparse = '', string $sParentCharset = '')
{
$this->sParentCharset = $sParentCharset;
@ -72,8 +72,7 @@ class Header
if (2 === \count($aRawExplode))
{
$this->sValue = $aRawExplode[0];
$this->oParameters =
\MailSo\Mime\ParameterCollection::NewInstance($aRawExplode[1]);
$this->oParameters = new ParameterCollection($aRawExplode[1]);
}
else
{
@ -86,12 +85,7 @@ class Header
}
}
public static function NewInstance(string $sName, string $sValue = '', string $sEncodedValueForReparse = '', string $sParentCharset = '') : \MailSo\Mime\Header
{
return new self($sName, $sValue, $sEncodedValueForReparse, $sParentCharset);
}
public static function NewInstanceFromEncodedString(string $sEncodedLines, string $sIncomingCharset = \MailSo\Base\Enumerations\Charset::ISO_8859_1) : \MailSo\Mime\Header
public static function NewInstanceFromEncodedString(string $sEncodedLines, string $sIncomingCharset = \MailSo\Base\Enumerations\Charset::ISO_8859_1) : Header
{
if (empty($sIncomingCharset))
{
@ -101,7 +95,7 @@ class Header
$aParts = \explode(':', \str_replace("\r", '', $sEncodedLines), 2);
if (isset($aParts[0]) && isset($aParts[1]) && 0 < \strlen($aParts[0]) && 0 < \strlen($aParts[1]))
{
return self::NewInstance(
return new self(
\trim($aParts[0]),
\trim(\MailSo\Base\Utils::DecodeHeaderValue(\trim($aParts[1]), $sIncomingCharset)),
\trim($aParts[1]),
@ -132,7 +126,7 @@ class Header
return $this->sFullValue;
}
public function SetParentCharset(string $sParentCharset) : \MailSo\Mime\Header
public function SetParentCharset(string $sParentCharset) : Header
{
if ($this->sParentCharset !== $sParentCharset && $this->IsReparsed() && 0 < \strlen($this->sEncodedValueForReparse))
{
@ -148,7 +142,7 @@ class Header
return $this;
}
public function Parameters() : ?\MailSo\Mime\ParameterCollection
public function Parameters() : ?ParameterCollection
{
return $this->oParameters;
}
@ -156,7 +150,7 @@ class Header
private function wordWrapHelper(string $sValue, string $sGlue = "\r\n ") : string
{
return \trim(substr(wordwrap($this->NameWithDelimitrom().$sValue,
\MailSo\Mime\Enumerations\Constants::LINE_LENGTH, $sGlue
Enumerations\Constants::LINE_LENGTH, $sGlue
), \strlen($this->NameWithDelimitrom())));
}
@ -174,8 +168,8 @@ class Header
'scheme' => \MailSo\Base\Enumerations\Encoding::BASE64_SHORT,
'input-charset' => \MailSo\Base\Enumerations\Charset::UTF_8,
'output-charset' => \MailSo\Base\Enumerations\Charset::UTF_8,
'line-length' => \MailSo\Mime\Enumerations\Constants::LINE_LENGTH,
'line-break-chars' => \MailSo\Mime\Enumerations\Constants::CRLF
'line-length' => Enumerations\Constants::LINE_LENGTH,
'line-break-chars' => Enumerations\Constants::CRLF
);
return \iconv_mime_encode($this->Name(), $sResult, $aPreferences);
@ -187,7 +181,7 @@ class Header
}
else if ($this->IsEmail())
{
$oEmailCollection = \MailSo\Mime\EmailCollection::NewInstance($this->sFullValue);
$oEmailCollection = new EmailCollection($this->sFullValue);
if ($oEmailCollection && 0 < $oEmailCollection->Count())
{
$sResult = $oEmailCollection->ToString(true, false);
@ -199,27 +193,27 @@ class Header
public function IsSubject() : bool
{
return \strtolower(\MailSo\Mime\Enumerations\Header::SUBJECT) === \strtolower($this->Name());
return \strtolower(Enumerations\Header::SUBJECT) === \strtolower($this->Name());
}
public function IsParameterized() : bool
{
return \in_array(\strtolower($this->sName), array(
\strtolower(\MailSo\Mime\Enumerations\Header::CONTENT_TYPE),
\strtolower(\MailSo\Mime\Enumerations\Header::CONTENT_DISPOSITION)
\strtolower(Enumerations\Header::CONTENT_TYPE),
\strtolower(Enumerations\Header::CONTENT_DISPOSITION)
));
}
public function IsEmail() : bool
{
return \in_array(\strtolower($this->sName), array(
\strtolower(\MailSo\Mime\Enumerations\Header::FROM_),
\strtolower(\MailSo\Mime\Enumerations\Header::TO_),
\strtolower(\MailSo\Mime\Enumerations\Header::CC),
\strtolower(\MailSo\Mime\Enumerations\Header::BCC),
\strtolower(\MailSo\Mime\Enumerations\Header::REPLY_TO),
\strtolower(\MailSo\Mime\Enumerations\Header::RETURN_PATH),
\strtolower(\MailSo\Mime\Enumerations\Header::SENDER)
\strtolower(Enumerations\Header::FROM_),
\strtolower(Enumerations\Header::TO_),
\strtolower(Enumerations\Header::CC),
\strtolower(Enumerations\Header::BCC),
\strtolower(Enumerations\Header::REPLY_TO),
\strtolower(Enumerations\Header::RETURN_PATH),
\strtolower(Enumerations\Header::SENDER)
));
}

View file

@ -25,20 +25,14 @@ class HeaderCollection extends \MailSo\Base\Collection
*/
protected $sParentCharset = '';
protected function __construct(string $sRawHeaders = '', bool $bStoreRawHeaders = true)
function __construct(string $sRawHeaders = '', bool $bStoreRawHeaders = true, string $sParentCharset = '')
{
parent::__construct();
if (0 < \strlen($sRawHeaders)) {
$this->Parse($sRawHeaders, $bStoreRawHeaders);
if (\strlen($sRawHeaders)) {
$this->Parse($sRawHeaders, $bStoreRawHeaders, $sParentCharset);
}
}
public static function NewInstance(string $sRawHeaders = '', bool $bStoreRawHeaders = true) : self
{
return new self($sRawHeaders, $bStoreRawHeaders);
}
public function append($oHeader, bool $bToTop = false) : void
{
assert($oHeader instanceof Header);
@ -47,13 +41,13 @@ class HeaderCollection extends \MailSo\Base\Collection
public function AddByName(string $sName, string $sValue, bool $bToTop = false) : self
{
$this->append(Header::NewInstance($sName, $sValue), $bToTop);
$this->append(new Header($sName, $sValue), $bToTop);
return $this;
}
public function SetByName(string $sName, string $sValue, bool $bToTop = false) : self
{
return $this->RemoveByName($sName)->Add(Header::NewInstance($sName, $sValue), $bToTop);
return $this->RemoveByName($sName)->Add(new Header($sName, $sValue), $bToTop);
}
public function ValueByName(string $sHeaderName, bool $bCharsetAutoDetect = false) : string
@ -88,7 +82,7 @@ class HeaderCollection extends \MailSo\Base\Collection
$oResult = null;
$sValue = $this->ValueByName($sHeaderName, $bCharsetAutoDetect);
if (0 < \strlen($sValue)) {
$oResult = EmailCollection::NewInstance($sValue);
$oResult = new EmailCollection($sValue);
}
return $oResult && 0 < $oResult->Count() ? $oResult : null;
}
@ -118,20 +112,18 @@ class HeaderCollection extends \MailSo\Base\Collection
public function SetParentCharset(string $sParentCharset) : self
{
if (0 < \strlen($sParentCharset)){
if ($this->sParentCharset !== $sParentCharset) {
foreach ($this as $oHeader) {
$oHeader->SetParentCharset($sParentCharset);
}
$this->sParentCharset = $sParentCharset;
if (\strlen($sParentCharset) && $this->sParentCharset !== $sParentCharset) {
foreach ($this as $oHeader) {
$oHeader->SetParentCharset($sParentCharset);
}
$this->sParentCharset = $sParentCharset;
}
return $this;
}
public function Clear() : void
{
$this->exchangeArray(array());
parent::Clear();
$this->sRawHeaders = '';
}
@ -143,7 +135,7 @@ class HeaderCollection extends \MailSo\Base\Collection
$this->sRawHeaders = $sRawHeaders;
}
if (0 === \strlen($this->sParentCharset)) {
if (\strlen($this->sParentCharset)) {
$this->sParentCharset = $sParentCharset;
}

View file

@ -42,20 +42,15 @@ class Message
*/
private $bAddDefaultXMailer;
private function __construct()
function __construct()
{
$this->aHeadersValue = array();
$this->aAlternativeParts = array();
$this->oAttachmentCollection = AttachmentCollection::NewInstance();
$this->oAttachmentCollection = new AttachmentCollection;
$this->bAddEmptyTextPart = true;
$this->bAddDefaultXMailer = true;
}
public static function NewInstance() : self
{
return new self();
}
public function DoesNotCreateEmptyTextPart() : self
{
$this->bAddEmptyTextPart = false;
@ -103,64 +98,66 @@ class Message
public function GetFrom() : ?Email
{
$oResult = null;
if (isset($this->aHeadersValue[Enumerations\Header::FROM_]) &&
$this->aHeadersValue[Enumerations\Header::FROM_] instanceof Email)
{
$oResult = $this->aHeadersValue[Enumerations\Header::FROM_];
return $this->aHeadersValue[Enumerations\Header::FROM_];
}
return $oResult;
return null;
}
public function GetTo() : EmailCollection
{
$oResult = EmailCollection::NewInstance();
if (isset($this->aHeadersValue[Enumerations\Header::TO_]) &&
$this->aHeadersValue[Enumerations\Header::TO_] instanceof EmailCollection)
{
$oResult->MergeWithOtherCollection($this->aHeadersValue[Enumerations\Header::TO_]);
return $this->aHeadersValue[Enumerations\Header::TO_]->Unique();
}
return $oResult->Unique();
return new EmailCollection;
}
public function GetBcc() : ?EmailCollection
{
$oResult = null;
if (isset($this->aHeadersValue[Enumerations\Header::BCC]) &&
$this->aHeadersValue[Enumerations\Header::BCC] instanceof EmailCollection)
{
$oResult = $this->aHeadersValue[Enumerations\Header::BCC];
return $this->aHeadersValue[Enumerations\Header::BCC]->Unique();
}
return $oResult ? $oResult->Unique() : null;
return null;
}
public function GetRcpt() : EmailCollection
{
$oResult = EmailCollection::NewInstance();
$oResult = new EmailCollection;
if (isset($this->aHeadersValue[Enumerations\Header::TO_]) &&
$this->aHeadersValue[Enumerations\Header::TO_] instanceof EmailCollection)
{
$oResult->MergeWithOtherCollection($this->aHeadersValue[Enumerations\Header::TO_]);
$headers = array(Enumerations\Header::TO_, Enumerations\Header::CC, Enumerations\Header::BCC);
foreach ($headers as $header) {
if (isset($this->aHeadersValue[$header]) && $this->aHeadersValue[$header] instanceof EmailCollection) {
foreach ($this->aHeadersValue[$header] as $oEmail) {
$oResult->append($oEmail);
}
}
}
if (isset($this->aHeadersValue[Enumerations\Header::CC]) &&
$this->aHeadersValue[Enumerations\Header::CC] instanceof EmailCollection)
{
$oResult->MergeWithOtherCollection($this->aHeadersValue[Enumerations\Header::CC]);
}
if (isset($this->aHeadersValue[Enumerations\Header::BCC]) &&
$this->aHeadersValue[Enumerations\Header::BCC] instanceof EmailCollection)
{
$oResult->MergeWithOtherCollection($this->aHeadersValue[Enumerations\Header::BCC]);
/*
$aReturn = array();
$headers = array(Enumerations\Header::TO_, Enumerations\Header::CC, Enumerations\Header::BCC);
foreach ($headers as $header) {
if (isset($this->aHeadersValue[$header]) && $this->aHeadersValue[$header] instanceof EmailCollection) {
foreach ($this->aHeadersValue[$header] as $oEmail) {
$oResult->append($oEmail);
$sEmail = $oEmail->GetEmail();
if (!isset($aReturn[$sEmail])) {
$aReturn[$sEmail] = $oEmail;
}
}
}
}
return new EmailCollection($aReturn);
*/
return $oResult->Unique();
}
@ -317,10 +314,10 @@ class Message
public function SetDraftInfo(string $sType, string $sUid, string $sFolder) : self
{
$this->aHeadersValue[Enumerations\Header::X_DRAFT_INFO] = ParameterCollection::NewInstance()
->Add(Parameter::NewInstance('type', $sType))
->Add(Parameter::NewInstance('uid', $sUid))
->Add(Parameter::NewInstance('folder', base64_encode($sFolder)))
$this->aHeadersValue[Enumerations\Header::X_DRAFT_INFO] = (new ParameterCollection)
->Add(new Parameter('type', $sType))
->Add(new Parameter('uid', $sUid))
->Add(new Parameter('folder', base64_encode($sFolder)))
;
return $this;
@ -382,7 +379,7 @@ class Message
private function createNewMessageAttachmentBody(Attachment $oAttachment) : Part
{
$oAttachmentPart = Part::NewInstance();
$oAttachmentPart = new Part;
$sFileName = $oAttachment->FileName();
$sCID = $oAttachment->CID();
@ -394,23 +391,23 @@ class Message
if (0 < strlen(trim($sFileName)))
{
$oContentTypeParameters =
ParameterCollection::NewInstance()->Add(Parameter::NewInstance(
(new ParameterCollection)->Add(new Parameter(
Enumerations\Parameter::NAME, $sFileName));
$oContentDispositionParameters =
ParameterCollection::NewInstance()->Add(Parameter::NewInstance(
(new ParameterCollection)->Add(new Parameter(
Enumerations\Parameter::FILENAME, $sFileName));
}
$oAttachmentPart->Headers->append(
Header::NewInstance(Enumerations\Header::CONTENT_TYPE,
new Header(Enumerations\Header::CONTENT_TYPE,
$oAttachment->ContentType().';'.
(($oContentTypeParameters) ? ' '.$oContentTypeParameters->ToString() : '')
)
);
$oAttachmentPart->Headers->append(
Header::NewInstance(Enumerations\Header::CONTENT_DISPOSITION,
new Header(Enumerations\Header::CONTENT_DISPOSITION,
($oAttachment->IsInline() ? 'inline' : 'attachment').';'.
(($oContentDispositionParameters) ? ' '.$oContentDispositionParameters->ToString() : '')
)
@ -419,14 +416,14 @@ class Message
if (0 < strlen($sCID))
{
$oAttachmentPart->Headers->append(
Header::NewInstance(Enumerations\Header::CONTENT_ID, $sCID)
new Header(Enumerations\Header::CONTENT_ID, $sCID)
);
}
if (0 < strlen($sContentLocation))
{
$oAttachmentPart->Headers->append(
Header::NewInstance(Enumerations\Header::CONTENT_LOCATION, $sContentLocation)
new Header(Enumerations\Header::CONTENT_LOCATION, $sContentLocation)
);
}
@ -435,7 +432,7 @@ class Message
if ('message/rfc822' !== strtolower($oAttachment->ContentType()))
{
$oAttachmentPart->Headers->append(
Header::NewInstance(
new Header(
Enumerations\Header::CONTENT_TRANSFER_ENCODING,
\MailSo\Base\Enumerations\Encoding::BASE64_LOWER
)
@ -464,10 +461,10 @@ class Message
if (isset($aAlternativeData[0]))
{
$oAlternativePart = Part::NewInstance();
$oParameters = ParameterCollection::NewInstance();
$oAlternativePart = new Part;
$oParameters = new ParameterCollection;
$oParameters->append(
Parameter::NewInstance(
new Parameter(
Enumerations\Parameter::CHARSET,
\MailSo\Base\Enumerations\Charset::UTF_8)
);
@ -476,12 +473,12 @@ class Message
{
foreach ($aAlternativeData[3] as $sName => $sValue)
{
$oParameters->append(Parameter::NewInstance($sName, $sValue));
$oParameters->append(new Parameter($sName, $sValue));
}
}
$oAlternativePart->Headers->append(
Header::NewInstance(Enumerations\Header::CONTENT_TYPE,
new Header(Enumerations\Header::CONTENT_TYPE,
$aAlternativeData[0].'; '.$oParameters->ToString())
);
@ -502,7 +499,7 @@ class Message
if (isset($aAlternativeData[2]) && 0 < strlen($aAlternativeData[2]))
{
$oAlternativePart->Headers->append(
Header::NewInstance(Enumerations\Header::CONTENT_TRANSFER_ENCODING,
new Header(Enumerations\Header::CONTENT_TRANSFER_ENCODING,
$aAlternativeData[2]
)
);
@ -536,13 +533,13 @@ class Message
$oResultPart = null;
if (1 < count($this->aAlternativeParts))
{
$oResultPart = Part::NewInstance();
$oResultPart = new Part;
$oResultPart->Headers->append(
Header::NewInstance(Enumerations\Header::CONTENT_TYPE,
new Header(Enumerations\Header::CONTENT_TYPE,
Enumerations\MimeType::MULTIPART_ALTERNATIVE.'; '.
ParameterCollection::NewInstance()->Add(
Parameter::NewInstance(
(new ParameterCollection)->Add(
new Parameter(
Enumerations\Parameter::BOUNDARY,
$this->generateNewBoundary())
)->ToString()
@ -603,13 +600,13 @@ class Message
$aAttachments = $this->oAttachmentCollection->LinkedAttachments();
if (0 < count($aAttachments))
{
$oResultPart = Part::NewInstance();
$oResultPart = new Part;
$oResultPart->Headers->append(
Header::NewInstance(Enumerations\Header::CONTENT_TYPE,
new Header(Enumerations\Header::CONTENT_TYPE,
Enumerations\MimeType::MULTIPART_RELATED.'; '.
ParameterCollection::NewInstance()->Add(
Parameter::NewInstance(
(new ParameterCollection)->Add(
new Parameter(
Enumerations\Parameter::BOUNDARY,
$this->generateNewBoundary())
)->ToString()
@ -638,12 +635,12 @@ class Message
$aAttachments = $this->oAttachmentCollection->UnlinkedAttachments();
if (0 < count($aAttachments))
{
$oResultPart = Part::NewInstance();
$oResultPart = new Part;
$oResultPart->Headers->AddByName(Enumerations\Header::CONTENT_TYPE,
Enumerations\MimeType::MULTIPART_MIXED.'; '.
ParameterCollection::NewInstance()->Add(
Parameter::NewInstance(
(new ParameterCollection)->Add(
new Parameter(
Enumerations\Parameter::BOUNDARY,
$this->generateNewBoundary())
)->ToString()

View file

@ -27,20 +27,15 @@ class Parameter
*/
private $sValue;
private function __construct(string $sName, string $sValue)
function __construct(string $sName, string $sValue)
{
$this->sName = $sName;
$this->sValue = $sValue;
}
public static function NewInstance(string $sName, string $sValue = '') : self
{
return new self($sName, $sValue);
}
public static function CreateFromParameterLine(string $sRawParam) : self
{
$oParameter = self::NewInstance('');
$oParameter = new self('', '');
return $oParameter->Parse($sRawParam);
}
@ -84,8 +79,8 @@ class Parameter
{
$sResult = $this->sName.'=';
if ($bConvertSpecialsName && in_array(strtolower($this->sName), array(
strtolower(\MailSo\Mime\Enumerations\Parameter::NAME),
strtolower(\MailSo\Mime\Enumerations\Parameter::FILENAME)
strtolower(Enumerations\Parameter::NAME),
strtolower(Enumerations\Parameter::FILENAME)
)))
{
$sResult .= '"'.\MailSo\Base\Utils::EncodeUnencodedValue(

View file

@ -17,7 +17,7 @@ namespace MailSo\Mime;
*/
class ParameterCollection extends \MailSo\Base\Collection
{
protected function __construct(string $sRawParams = '')
function __construct(string $sRawParams = '')
{
parent::__construct();
@ -27,11 +27,6 @@ class ParameterCollection extends \MailSo\Base\Collection
}
}
public static function NewInstance(string $sRawParams = '') : self
{
return new self($sRawParams);
}
public function append($oParameter, bool $bToTop = false) : void
{
assert($oParameter instanceof Parameter);
@ -157,7 +152,7 @@ class ParameterCollection extends \MailSo\Base\Collection
$sCharset, \MailSo\Base\Enumerations\Charset::UTF_8);
}
$this->append(Parameter::NewInstance($sName, $sResult));
$this->append(new Parameter($sName, $sResult));
}
}
}

View file

@ -35,7 +35,7 @@ class Part
public static $ForceCharset = '';
/**
* @var \MailSo\Mime\HeaderCollection
* @var HeaderCollection
*/
public $Headers;
@ -45,7 +45,7 @@ class Part
public $Body;
/**
* @var \MailSo\Mime\PartCollection
* @var PartCollection
*/
public $SubParts;
@ -69,24 +69,19 @@ class Part
*/
private $iParseBuffer;
private function __construct()
function __construct()
{
$this->iParseBuffer = \MailSo\Mime\Part::DEFAUL_BUFFER;
$this->iParseBuffer = self::DEFAUL_BUFFER;
$this->Reset();
}
public static function NewInstance() : self
{
return new self();
}
public function Reset() : self
{
\MailSo\Base\ResourceRegistry::CloseMemoryResource($this->Body);
$this->Body = null;
$this->Headers = HeaderCollection::NewInstance();
$this->SubParts = PartCollection::NewInstance();
$this->Headers = new HeaderCollection;
$this->SubParts = new PartCollection;
$this->LineParts = array();
$this->sBoundary = '';
$this->sParentCharset = \MailSo\Base\Enumerations\Charset::ISO_8859_1;
@ -128,41 +123,41 @@ class Part
public function HeaderCharset() : string
{
return ($this->Headers) ? trim(strtolower($this->Headers->ParameterValue(
\MailSo\Mime\Enumerations\Header::CONTENT_TYPE,
\MailSo\Mime\Enumerations\Parameter::CHARSET))) : '';
Enumerations\Header::CONTENT_TYPE,
Enumerations\Parameter::CHARSET))) : '';
}
public function HeaderBoundary() : string
{
return ($this->Headers) ? trim($this->Headers->ParameterValue(
\MailSo\Mime\Enumerations\Header::CONTENT_TYPE,
\MailSo\Mime\Enumerations\Parameter::BOUNDARY)) : '';
Enumerations\Header::CONTENT_TYPE,
Enumerations\Parameter::BOUNDARY)) : '';
}
public function ContentType() : string
{
return ($this->Headers) ?
trim(strtolower($this->Headers->ValueByName(
\MailSo\Mime\Enumerations\Header::CONTENT_TYPE))) : '';
Enumerations\Header::CONTENT_TYPE))) : '';
}
public function ContentTransferEncoding() : string
{
return ($this->Headers) ?
trim(strtolower($this->Headers->ValueByName(
\MailSo\Mime\Enumerations\Header::CONTENT_TRANSFER_ENCODING))) : '';
Enumerations\Header::CONTENT_TRANSFER_ENCODING))) : '';
}
public function ContentID() : string
{
return ($this->Headers) ? trim($this->Headers->ValueByName(
\MailSo\Mime\Enumerations\Header::CONTENT_ID)) : '';
Enumerations\Header::CONTENT_ID)) : '';
}
public function ContentLocation() : string
{
return ($this->Headers) ? trim($this->Headers->ValueByName(
\MailSo\Mime\Enumerations\Header::CONTENT_LOCATION)) : '';
Enumerations\Header::CONTENT_LOCATION)) : '';
}
public function IsFlowedFormat() : bool
@ -171,8 +166,8 @@ class Part
if ($this->Headers)
{
$bResult = 'flowed' === \trim(\strtolower($this->Headers->ParameterValue(
\MailSo\Mime\Enumerations\Header::CONTENT_TYPE,
\MailSo\Mime\Enumerations\Parameter::FORMAT)));
Enumerations\Header::CONTENT_TYPE,
Enumerations\Parameter::FORMAT)));
if ($bResult && \in_array(\strtolower($this->MailEncodingName()), array('base64', 'quoted-printable')))
{
@ -189,14 +184,14 @@ class Part
if ($this->Headers)
{
$sResult = trim($this->Headers->ParameterValue(
\MailSo\Mime\Enumerations\Header::CONTENT_DISPOSITION,
\MailSo\Mime\Enumerations\Parameter::FILENAME));
Enumerations\Header::CONTENT_DISPOSITION,
Enumerations\Parameter::FILENAME));
if (0 === strlen($sResult))
{
$sResult = trim($this->Headers->ParameterValue(
\MailSo\Mime\Enumerations\Header::CONTENT_TYPE,
\MailSo\Mime\Enumerations\Parameter::NAME));
Enumerations\Header::CONTENT_TYPE,
Enumerations\Parameter::NAME));
}
}
@ -245,7 +240,7 @@ class Part
{
$this->Reset();
$oParserClass = new \MailSo\Mime\Parser\ParserMemory();
$oParserClass = new Parser\ParserMemory;
$oMimePart = null;
$bIsOef = false;
@ -262,7 +257,7 @@ class Part
$sPrevBuffer, $sBuffer, $aBoundaryStack, $bIsOef);
$sFirstNotNullCharset = null;
foreach ($this->LineParts as /* @var $oMimePart \MailSo\Mime\Part */ $oMimePart)
foreach ($this->LineParts as /* @var $oMimePart Part */ $oMimePart)
{
$sCharset = $oMimePart->HeaderCharset();
if (0 < strlen($sCharset))
@ -275,7 +270,7 @@ class Part
$sForceCharset = self::$ForceCharset;
if (0 < strlen($sForceCharset))
{
foreach ($this->LineParts as /* @var $oMimePart \MailSo\Mime\Part */ $oMimePart)
foreach ($this->LineParts as /* @var $oMimePart Part */ $oMimePart)
{
$oMimePart->SetParentCharset($sForceCharset);
$oMimePart->Headers->SetParentCharset($sForceCharset);
@ -286,7 +281,7 @@ class Part
$sFirstNotNullCharset = (null !== $sFirstNotNullCharset)
? $sFirstNotNullCharset : self::$DefaultCharset;
foreach ($this->LineParts as /* @var $oMimePart \MailSo\Mime\Part */ $oMimePart)
foreach ($this->LineParts as /* @var $oMimePart Part */ $oMimePart)
{
$sHeaderCharset = $oMimePart->HeaderCharset();
$oMimePart->SetParentCharset((0 < strlen($sHeaderCharset)) ? $sHeaderCharset : $sFirstNotNullCharset);
@ -489,7 +484,7 @@ class Part
{
$iOffset = $iPos + $sBoundaryLen;
$oSubPart = self::NewInstance();
$oSubPart = new self;
$oSubPart
->SetParseBuffer($this->iParseBuffer)
@ -573,12 +568,12 @@ class Part
$aSubStreams = array(
$this->Headers->ToEncodedString().
\MailSo\Mime\Enumerations\Constants::CRLF.
\MailSo\Mime\Enumerations\Constants::CRLF,
Enumerations\Constants::CRLF.
Enumerations\Constants::CRLF,
null === $this->Body ? '' : $this->Body,
\MailSo\Mime\Enumerations\Constants::CRLF
Enumerations\Constants::CRLF
);
if (0 < $this->SubParts->Count())
@ -586,7 +581,7 @@ class Part
$sBoundary = $this->HeaderBoundary();
if (0 < strlen($sBoundary))
{
$aSubStreams[] = '--'.$sBoundary.\MailSo\Mime\Enumerations\Constants::CRLF;
$aSubStreams[] = '--'.$sBoundary.Enumerations\Constants::CRLF;
$rSubPartsStream = $this->SubParts->ToStream($sBoundary);
if (is_resource($rSubPartsStream))
@ -594,8 +589,8 @@ class Part
$aSubStreams[] = $rSubPartsStream;
}
$aSubStreams[] = \MailSo\Mime\Enumerations\Constants::CRLF.
'--'.$sBoundary.'--'.\MailSo\Mime\Enumerations\Constants::CRLF;
$aSubStreams[] = Enumerations\Constants::CRLF.
'--'.$sBoundary.'--'.Enumerations\Constants::CRLF;
}
}

View file

@ -17,11 +17,6 @@ namespace MailSo\Mime;
*/
class PartCollection extends \MailSo\Base\Collection
{
public static function NewInstance() : self
{
return new self();
}
public function append($oPart, bool $bToTop = false) : void
{
assert($oPart instanceof Part);

View file

@ -82,7 +82,7 @@ abstract class NetClient
*/
public $__AUTOLOGOUT__;
protected function __construct()
function __construct()
{
$this->rConnect = null;
$this->bUnreadBuffer = false;
@ -174,14 +174,14 @@ abstract class NetClient
if (!strlen(\trim($sServerName)) || !\MailSo\Base\Validator::PortInt($iPort))
{
$this->writeLogException(
new \MailSo\Base\Exceptions\InvalidArgumentException(),
new \MailSo\Base\Exceptions\InvalidArgumentException,
\MailSo\Log\Enumerations\Type::ERROR, true);
}
if ($this->IsConnected())
{
$this->writeLogException(
new Exceptions\SocketAlreadyConnectedException(),
new Exceptions\SocketAlreadyConnectedException,
\MailSo\Log\Enumerations\Type::ERROR, true);
}
@ -342,7 +342,7 @@ abstract class NetClient
if (!$bResult && $bThrowExceptionOnFalse)
{
$this->writeLogException(
new Exceptions\SocketConnectionDoesNotAvailableException(),
new Exceptions\SocketConnectionDoesNotAvailableException,
\MailSo\Log\Enumerations\Type::ERROR, true);
}
@ -372,7 +372,7 @@ abstract class NetClient
if ($this->bUnreadBuffer)
{
$this->writeLogException(
new Exceptions\SocketUnreadBufferException(),
new Exceptions\SocketUnreadBufferException,
\MailSo\Log\Enumerations\Type::ERROR, true);
}
@ -395,7 +395,7 @@ abstract class NetClient
$this->IsConnected(true);
$this->writeLogException(
new Exceptions\SocketWriteException(),
new Exceptions\SocketWriteException,
\MailSo\Log\Enumerations\Type::ERROR, true);
}
else
@ -447,7 +447,7 @@ abstract class NetClient
if (isset($aSocketStatus['timed_out']) && $aSocketStatus['timed_out'])
{
$this->writeLogException(
new Exceptions\SocketReadTimeoutException(),
new Exceptions\SocketReadTimeoutException,
\MailSo\Log\Enumerations\Type::ERROR, true);
}
else
@ -456,7 +456,7 @@ abstract class NetClient
\print_r($aSocketStatus, true), \MailSo\Log\Enumerations\Type::ERROR);
$this->writeLogException(
new Exceptions\SocketReadException(),
new Exceptions\SocketReadException,
\MailSo\Log\Enumerations\Type::ERROR, true);
}
}

View file

@ -37,7 +37,7 @@ class ManageSieveClient extends \MailSo\Net\NetClient
*/
public $__USE_INITIAL_AUTH_PLAIN_COMMAND;
protected function __construct()
function __construct()
{
parent::__construct();
@ -49,11 +49,6 @@ class ManageSieveClient extends \MailSo\Net\NetClient
$this->__USE_INITIAL_AUTH_PLAIN_COMMAND = true;
}
public static function NewInstance() : self
{
return new self();
}
public function IsSupported(string $sCapa) : bool
{
return isset($this->aCapa[\strtoupper($sCapa)]);
@ -119,7 +114,7 @@ class ManageSieveClient extends \MailSo\Net\NetClient
if (!strlen(\trim($sLogin)) || !strlen(\trim($sPassword)))
{
$this->writeLogException(
new \MailSo\Base\Exceptions\InvalidArgumentException(),
new \MailSo\Base\Exceptions\InvalidArgumentException,
\MailSo\Log\Enumerations\Type::ERROR, true);
}
@ -175,14 +170,14 @@ class ManageSieveClient extends \MailSo\Net\NetClient
if (!$bAuth)
{
$this->writeLogException(
new \MailSo\Sieve\Exceptions\LoginBadMethodException(),
new \MailSo\Sieve\Exceptions\LoginBadMethodException,
\MailSo\Log\Enumerations\Type::ERROR, true);
}
}
else
{
$this->writeLogException(
new \MailSo\Sieve\Exceptions\LoginException(),
new \MailSo\Sieve\Exceptions\LoginException,
\MailSo\Log\Enumerations\Type::ERROR, true);
}
@ -430,7 +425,7 @@ class ManageSieveClient extends \MailSo\Net\NetClient
if (!strlen(\trim($sRequest)))
{
$this->writeLogException(
new \MailSo\Base\Exceptions\InvalidArgumentException(),
new \MailSo\Base\Exceptions\InvalidArgumentException,
\MailSo\Log\Enumerations\Type::ERROR, true);
}

View file

@ -67,7 +67,7 @@ class SmtpClient extends \MailSo\Net\NetClient
*/
public $__USE_SINGLE_LINE_AUTH_PLAIN_COMMAND = false;
protected function __construct()
function __construct()
{
parent::__construct();
@ -84,11 +84,6 @@ class SmtpClient extends \MailSo\Net\NetClient
$this->bData = false;
}
public static function NewInstance() : self
{
return new self();
}
public function IsSupported(string $sCapa) : bool
{
return in_array(strtoupper($sCapa), $this->aCapa);
@ -181,7 +176,7 @@ class SmtpClient extends \MailSo\Net\NetClient
if (empty($sTicket))
{
$this->writeLogException(
new \MailSo\Smtp\Exceptions\NegativeResponseException(),
new \MailSo\Smtp\Exceptions\NegativeResponseException,
\MailSo\Log\Enumerations\Type::NOTICE, true
);
}
@ -271,7 +266,7 @@ class SmtpClient extends \MailSo\Net\NetClient
else
{
$this->writeLogException(
new \MailSo\Smtp\Exceptions\LoginBadMethodException(),
new \MailSo\Smtp\Exceptions\LoginBadMethodException,
\MailSo\Log\Enumerations\Type::NOTICE, true);
}
@ -358,7 +353,7 @@ class SmtpClient extends \MailSo\Net\NetClient
{
if (!strlen(\trim($sData)))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$rDataStream = \MailSo\Base\ResourceRegistry::CreateMemoryResourceFromString($sData);
@ -380,7 +375,7 @@ class SmtpClient extends \MailSo\Net\NetClient
{
if (!\is_resource($rDataStream))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
if (!$this->bRcpt)
@ -527,7 +522,7 @@ class SmtpClient extends \MailSo\Net\NetClient
if (!strlen(\trim($sCommand)))
{
$this->writeLogException(
new \MailSo\Base\Exceptions\InvalidArgumentException(),
new \MailSo\Base\Exceptions\InvalidArgumentException,
\MailSo\Log\Enumerations\Type::ERROR, true);
}

File diff suppressed because it is too large Load diff

View file

@ -5,7 +5,7 @@ namespace RainLoop;
class Api
{
private function __construct()
function __construct()
{
}
@ -33,13 +33,13 @@ class Api
static $oActions = null;
if (null === $oActions)
{
$oActions = \RainLoop\Actions::NewInstance();
$oActions = new Actions();
}
return $oActions;
}
public static function Config() : \RainLoop\Config\Application
public static function Config() : Config\Application
{
return static::Actions()->Config();
}
@ -81,10 +81,10 @@ class Api
$sSslCafile = static::Config()->Get('ssl', 'cafile', '');
$sSslCapath = static::Config()->Get('ssl', 'capath', '');
\RainLoop\Utils::$CookieDefaultPath = static::Config()->Get('labs', 'cookie_default_path', '');
Utils::$CookieDefaultPath = static::Config()->Get('labs', 'cookie_default_path', '');
if (static::Config()->Get('labs', 'cookie_default_secure', false))
{
\RainLoop\Utils::$CookieDefaultSecure = true;
Utils::$CookieDefaultSecure = true;
}
if (!empty($sSslCafile) || !empty($sSslCapath))
@ -164,8 +164,8 @@ class Api
{
$sSsoHash = \MailSo\Base\Utils::Sha1Rand(\md5($sEmail).\md5($sPassword));
return static::Actions()->Cacher()->Set(\RainLoop\KeyPathHelper::SsoCacherKey($sSsoHash),
\RainLoop\Utils::EncodeKeyValuesQ(array(
return static::Actions()->Cacher()->Set(KeyPathHelper::SsoCacherKey($sSsoHash),
Utils::EncodeKeyValuesQ(array(
'Email' => $sEmail,
'Password' => $sPassword,
'AdditionalOptions' => $aAdditionalOptions,
@ -175,7 +175,7 @@ class Api
public static function ClearUserSsoHash(string $sSsoHash) : bool
{
return static::Actions()->Cacher()->Delete(\RainLoop\KeyPathHelper::SsoCacherKey($sSsoHash));
return static::Actions()->Cacher()->Delete(KeyPathHelper::SsoCacherKey($sSsoHash));
}
public static function ClearUserData(string $sEmail) : bool
@ -204,7 +204,7 @@ class Api
public static function LogoutCurrentLogginedUser() : bool
{
\RainLoop\Utils::ClearCookie('rlsession');
Utils::ClearCookie('rlsession');
return true;
}

View file

@ -49,7 +49,7 @@ class Account
*/
private $sParentEmail;
protected function __construct(string $sEmail, string $sLogin, string $sPassword,
function __construct(string $sEmail, string $sLogin, string $sPassword,
\RainLoop\Model\Domain $oDomain, string $sSignMeToken = '', string $sProxyAuthUser = '',
string $sProxyAuthPassword = '', string $sClientCert = '')
{
@ -64,13 +64,6 @@ class Account
$this->sParentEmail = '';
}
public static function NewInstance(string $sEmail, string $sLogin, string $sPassword,
\RainLoop\Model\Domain $oDomain, string $sSignMeToken = '', string $sProxyAuthUser = '',
string $sProxyAuthPassword = '', string $sClientCert = '') : self
{
return new self($sEmail, $sLogin, $sPassword, $oDomain, $sSignMeToken, $sProxyAuthUser, $sProxyAuthPassword, $sClientCert);
}
public function Email() : string
{
return $this->sEmail;

View file

@ -98,7 +98,7 @@ class Domain
*/
private $sAliasName;
private function __construct(string $sName,
function __construct(string $sName,
string $sIncHost, int $iIncPort, int $iIncSecure, bool $bIncShortLogin,
bool $bUseSieve, string $sSieveHost, int $iSievePort, int $iSieveSecure,
string $sOutHost, int $iOutPort, int $iOutSecure, bool $bOutShortLogin,
@ -128,19 +128,6 @@ class Domain
$this->sAliasName = '';
}
public static function NewInstance(string $sName,
string $sIncHost, int $iIncPort, int $iIncSecure, bool $bIncShortLogin,
bool $bUseSieve, string $sSieveHost, int $iSievePort, int $iSieveSecure,
string $sOutHost, int $iOutPort, int $iOutSecure, bool $bOutShortLogin,
bool $bOutAuth, bool $bOutUsePhpMail, string $sWhiteList = '') : self
{
return new self($sName,
$sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
$bUseSieve, $sSieveHost, $iSievePort, $iSieveSecure,
$sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth, $bOutUsePhpMail,
$sWhiteList);
}
public static function NewInstanceFromDomainConfigArray(string $sName, array $aDomain) : ?\RainLoop\Model\Domain
{
$oDomain = null;
@ -172,7 +159,7 @@ class Domain
$bIncShortLogin = !empty($aDomain['imap_short_login']);
$bOutShortLogin = !empty($aDomain['smtp_short_login']);
$oDomain = self::NewInstance($sName,
$oDomain = new self($sName,
$sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
$bUseSieve, $sSieveHost, $iSievePort, $iSieveSecure,
$sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth, $bOutUsePhpMail,

View file

@ -39,7 +39,7 @@ class Identity
*/
private $bSignatureInsertBefore;
protected function __construct(string $sId = '', string $sEmail = '')
function __construct(string $sId = '', string $sEmail = '')
{
$this->sId = empty($sId) ? '' : $sId;
$this->sEmail = empty($sEmail) ? '' : $sEmail;
@ -50,16 +50,6 @@ class Identity
$this->bSignatureInsertBefore = false;
}
public static function NewInstance() : self
{
return new self();
}
public static function NewInstanceFromAccount(\RainLoop\Model\Account $oAccount) : self
{
return new self('', $oAccount->Email());
}
public function Id(bool $bFillOnEmpty = false) : string
{
return $bFillOnEmpty ? ('' === $this->sId ? '---' : $this->sId) : $this->sId;

View file

@ -24,7 +24,7 @@ class Template
*/
private $bPopulateAlways;
protected function __construct(string $sId = '', string $sName = '', string $sBody = '')
function __construct(string $sId = '', string $sName = '', string $sBody = '')
{
$this->sId = $sId;
$this->sName = $sName;
@ -32,11 +32,6 @@ class Template
$this->bPopulateAlways = false;
}
public static function NewInstance(string $sId = '', string $sName = '', string $sBody = '') : self
{
return new self($sId, $sName, $sBody);
}
public function Id() : string
{
return $this->sId;

View file

@ -4,7 +4,7 @@ namespace RainLoop\Plugins;
class Helper
{
private function __construct()
function __construct()
{
}

View file

@ -39,7 +39,7 @@ class Property
*/
private $sPlaceholder;
private function __construct(string $sName)
function __construct(string $sName)
{
$this->sName = $sName;
$this->iType = \RainLoop\Enumerations\PluginPropertyType::STRING;

View file

@ -2,10 +2,10 @@
namespace RainLoop\Providers;
class Domain extends \RainLoop\Providers\AbstractProvider
class Domain extends AbstractProvider
{
/**
* @var \RainLoop\Providers\Domain\DomainInterface
* @var Domain\DomainInterface
*/
private $oDriver;
@ -19,12 +19,12 @@ class Domain extends \RainLoop\Providers\AbstractProvider
*/
private $bAdmin;
public function __construct(\RainLoop\Providers\Domain\DomainInterface $oDriver,
public function __construct(Domain\DomainInterface $oDriver,
\RainLoop\Plugins\Manager $oPlugins)
{
$this->oDriver = $oDriver;
$this->oPlugins = $oPlugins;
$this->bAdmin = $this->oDriver instanceof \RainLoop\Providers\Domain\DomainAdminInterface;
$this->bAdmin = $this->oDriver instanceof Domain\DomainAdminInterface;
}
public function IsAdmin() : bool
@ -140,7 +140,7 @@ class Domain extends \RainLoop\Providers\AbstractProvider
}
else
{
$oDomain = \RainLoop\Model\Domain::NewInstance(0 < strlen($sNameForTest) ? $sNameForTest : $sName,
$oDomain = new \RainLoop\Model\Domain(0 < strlen($sNameForTest) ? $sNameForTest : $sName,
$sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
$bUseSieve, $sSieveHost, $iSievePort, $iSieveSecure,
$sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth, $bOutUsePhpMail,
@ -207,7 +207,7 @@ class Domain extends \RainLoop\Providers\AbstractProvider
}
else
{
$oDomain = \RainLoop\Model\Domain::NewInstance(0 < strlen($sNameForTest) ? $sNameForTest : $sName,
$oDomain = new \RainLoop\Model\Domain(0 < strlen($sNameForTest) ? $sNameForTest : $sName,
$sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
$bUseSieve, $sSieveHost, $iSievePort, $iSieveSecure,
$sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth, $bOutUsePhpMail,
@ -226,6 +226,6 @@ class Domain extends \RainLoop\Providers\AbstractProvider
public function IsActive() : bool
{
return $this->oDriver instanceof \RainLoop\Providers\Domain\DomainInterface;
return $this->oDriver instanceof Domain\DomainInterface;
}
}

View file

@ -204,7 +204,7 @@ class Filter
$this->bStop = isset($aFilter['Stop']) ? '1' === (string) $aFilter['Stop'] : true;
$this->bMarkAsRead = isset($aFilter['MarkAsRead']) ? '1' === (string) $aFilter['MarkAsRead'] : false;
$this->aConditions = \RainLoop\Providers\Filters\Classes\FilterCondition::CollectionFromJSON(
$this->aConditions = FilterCondition::CollectionFromJSON(
isset($aFilter['Conditions']) ? $aFilter['Conditions'] : array());
return true;

View file

@ -49,7 +49,7 @@ class SieveStorage implements \RainLoop\Providers\Filters\FiltersInterface
$aModules = array();
$aFilters = array();
$oSieveClient = \MailSo\Sieve\ManageSieveClient::NewInstance();
$oSieveClient = new \MailSo\Sieve\ManageSieveClient();
$oSieveClient->SetLogger($this->oLogger);
$oSieveClient->SetTimeOuts(10, (int) $this->oConfig->Get('labs', 'sieve_timeout', 10));
@ -101,7 +101,7 @@ class SieveStorage implements \RainLoop\Providers\Filters\FiltersInterface
public function Save(\RainLoop\Model\Account $oAccount, array $aFilters, string $sRaw = '', bool $bRawIsActive = false) : bool
{
$oSieveClient = \MailSo\Sieve\ManageSieveClient::NewInstance();
$oSieveClient = new \MailSo\Sieve\ManageSieveClient();
$oSieveClient->SetLogger($this->oLogger);
$oSieveClient->SetTimeOuts(10, (int) \RainLoop\Api::Config()->Get('labs', 'sieve_timeout', 10));

View file

@ -2,7 +2,7 @@
namespace RainLoop\Providers\Settings;
class DefaultSettings implements \RainLoop\Providers\Settings\ISettings
class DefaultSettings implements ISettings
{
const FILE_NAME = 'settings';
const FILE_NAME_LOCAL = 'settings_local';
@ -22,8 +22,8 @@ class DefaultSettings implements \RainLoop\Providers\Settings\ISettings
$sValue = $this->oStorageProvider->Get($oAccount,
\RainLoop\Providers\Storage\Enumerations\StorageType::CONFIG,
$this->oStorageProvider->IsLocal() ?
\RainLoop\Providers\Settings\DefaultSettings::FILE_NAME_LOCAL :
\RainLoop\Providers\Settings\DefaultSettings::FILE_NAME
self::FILE_NAME_LOCAL :
self::FILE_NAME
);
if (\is_string($sValue))
@ -43,8 +43,8 @@ class DefaultSettings implements \RainLoop\Providers\Settings\ISettings
return $this->oStorageProvider->Put($oAccount,
\RainLoop\Providers\Storage\Enumerations\StorageType::CONFIG,
$this->oStorageProvider->IsLocal() ?
\RainLoop\Providers\Settings\DefaultSettings::FILE_NAME_LOCAL :
\RainLoop\Providers\Settings\DefaultSettings::FILE_NAME,
self::FILE_NAME_LOCAL :
self::FILE_NAME,
\json_encode($aSettings));
}
@ -53,7 +53,7 @@ class DefaultSettings implements \RainLoop\Providers\Settings\ISettings
return $this->oStorageProvider->Clear($oAccount,
\RainLoop\Providers\Storage\Enumerations\StorageType::CONFIG,
$this->oStorageProvider->IsLocal() ?
\RainLoop\Providers\Settings\DefaultSettings::FILE_NAME_LOCAL :
\RainLoop\Providers\Settings\DefaultSettings::FILE_NAME);
self::FILE_NAME_LOCAL :
self::FILE_NAME);
}
}

View file

@ -19,12 +19,12 @@ class Service
*/
private $oServiceActions;
private function __construct()
function __construct()
{
$this->oHttp = \MailSo\Base\Http::SingletonInstance();
$this->oActions = \RainLoop\Api::Actions();
$this->oActions = Api::Actions();
$this->oServiceActions = new \RainLoop\ServiceActions($this->oHttp, $this->oActions);
$this->oServiceActions = new ServiceActions($this->oHttp, $this->oActions);
if ($this->oActions->Config()->Get('debug', 'enable', false))
{
@ -72,8 +72,7 @@ class Service
static $bOne = null;
if (null === $bOne)
{
$oService = new self();
$bOne = $oService->RunResult();
$bOne = (new self)->RunResult();
}
return $bOne;
@ -141,9 +140,9 @@ class Service
$bMobileDevice = false;
if ($this->oActions->Config()->Get('labs', 'allow_mobile_version', false)) {
$bUseMobileVersionForTablets = $this->oActions->Config()->Get('labs', 'use_mobile_version_for_tablets', false);
$bMobileDevice = \RainLoop\UserAgent::isMobile() &&
($bUseMobileVersionForTablets ? true : !\RainLoop\UserAgent::isTablet());
$sMobileType = (string) \RainLoop\Utils::GetCookie(\RainLoop\Actions::RL_MOBILE_TYPE, '');
$bMobileDevice = UserAgent::isMobile() &&
($bUseMobileVersionForTablets ? true : !UserAgent::isTablet());
$sMobileType = (string) Utils::GetCookie(Actions::RL_MOBILE_TYPE, '');
switch ($sMobileType) {
default:
$bMobile = $bMobileDevice;
@ -187,7 +186,7 @@ class Service
// $aTemplateParameters['{{BaseTemplates}}'] = $this->oServiceActions->compileTemplates($bAdmin, false);
$sResult = \strtr(\file_get_contents(APP_VERSION_ROOT_PATH.'app/templates/Index.html'), $aTemplateParameters);
$sResult = \RainLoop\Utils::ClearHtmlOutput($sResult);
$sResult = Utils::ClearHtmlOutput($sResult);
if (0 < \strlen($sCacheFileName))
{
$this->oActions->Cacher()->Set($sCacheFileName, $sResult);
@ -203,7 +202,7 @@ class Service
$sResult .= '][AGPLv3';
$sResult .= '][cached:'.($bCached ? 'true' : 'false');
// $sResult .= '][hash:'.$aTemplateParameters['{{BaseHash}}'];
// $sResult .= '][session:'.\md5(\RainLoop\Utils::GetShortToken());
// $sResult .= '][session:'.\md5(Utils::GetShortToken());
if ($bMobile)
{
@ -278,7 +277,7 @@ class Service
$bAdmin ? '1' : '0',
\md5($this->oActions->Config()->Get('cache', 'index', '')),
$this->oActions->Plugins()->Hash(),
\RainLoop\Utils::WebVersionPath(),
Utils::WebVersionPath(),
APP_VERSION,
)).
\implode('~', $aTemplateParameters)

View file

@ -24,7 +24,7 @@ class ServiceActions
*/
protected $sQuery;
public function __construct(\MailSo\Base\Http $oHttp, \RainLoop\Actions $oActions)
public function __construct(\MailSo\Base\Http $oHttp, Actions $oActions)
{
$this->oHttp = $oHttp;
$this->oActions = $oActions;
@ -37,12 +37,12 @@ class ServiceActions
return $this->oActions->Logger();
}
public function Plugins() : \RainLoop\Plugins\Manager
public function Plugins() : Plugins\Manager
{
return $this->oActions->Plugins();
}
public function Config() : \RainLoop\Config\Application
public function Config() : Config\Application
{
return $this->oActions->Config();
}
@ -52,12 +52,12 @@ class ServiceActions
return $this->oActions->Cacher();
}
public function StorageProvider() : \RainLoop\Providers\Storage
public function StorageProvider() : Providers\Storage
{
return $this->oActions->StorageProvider();
}
public function SettingsProvider() : \RainLoop\Providers\Settings
public function SettingsProvider() : Providers\Settings
{
return $this->oActions->SettingsProvider();
}
@ -93,9 +93,9 @@ class ServiceActions
{
if ($this->oHttp->IsPost() &&
$this->Config()->Get('security', 'csrf_protection', false) &&
$this->oHttp->GetPost('XToken', '') !== \RainLoop\Utils::GetCsrfToken())
$this->oHttp->GetPost('XToken', '') !== Utils::GetCsrfToken())
{
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::InvalidToken);
throw new Exceptions\ClientException(Notifications::InvalidToken);
}
else if (!empty($sAction))
{
@ -143,7 +143,7 @@ class ServiceActions
if (!\is_array($aResponseItem))
{
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::UnknownError);
throw new Exceptions\ClientException(Notifications::UnknownError);
}
}
catch (\Throwable $oException)
@ -156,7 +156,7 @@ class ServiceActions
$aResponseItem = $this->oActions->ExceptionResponse(
empty($sAction) ? 'Unknown' : $sAction, $oException);
if (\is_array($aResponseItem) && $oException instanceof \RainLoop\Exceptions\ClientException)
if (\is_array($aResponseItem) && $oException instanceof Exceptions\ClientException)
{
if ('Folders' === $sAction)
{
@ -261,7 +261,7 @@ class ServiceActions
{
$aFile = null;
$sInputName = 'uploader';
$iError = \RainLoop\Enumerations\UploadError::UNKNOWN;
$iError = Enumerations\UploadError::UNKNOWN;
$iSizeLimit = (0 < $iSizeLimit ? $iSizeLimit : ((int) $oConfig->Get('webmail', 'attachment_size_limit', 0))) * 1024 * 1024;
$iError = UPLOAD_ERR_OK;
@ -272,7 +272,7 @@ class ServiceActions
if (UPLOAD_ERR_OK === $iError && 0 < $iSizeLimit && $iSizeLimit < (int) $_FILES[$sInputName]['size'])
{
$iError = \RainLoop\Enumerations\UploadError::CONFIG_SIZE;
$iError = Enumerations\UploadError::CONFIG_SIZE;
}
if (UPLOAD_ERR_OK === $iError)
@ -286,7 +286,7 @@ class ServiceActions
}
else
{
$iError = \RainLoop\Enumerations\UploadError::EMPTY_FILES_DATA;
$iError = Enumerations\UploadError::EMPTY_FILES_DATA;
}
if (\method_exists($this->oActions, $sAction) &&
@ -304,7 +304,7 @@ class ServiceActions
if (!is_array($aResponseItem))
{
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::UnknownError);
throw new Exceptions\ClientException(Notifications::UnknownError);
}
}
catch (\Throwable $oException)
@ -358,8 +358,8 @@ class ServiceActions
{
$this->oActions->verifyCacheByKey($sData);
$aData = \RainLoop\Utils::DecodeKeyValuesQ($sData);
if (\is_array($aData) && !empty($aData['Token']) && !empty($aData['Url']) && $aData['Token'] === \RainLoop\Utils::GetConnectionToken())
$aData = Utils::DecodeKeyValuesQ($sData);
if (\is_array($aData) && !empty($aData['Token']) && !empty($aData['Url']) && $aData['Token'] === Utils::GetConnectionToken())
{
$iCode = 404;
$sContentType = '';
@ -429,12 +429,12 @@ class ServiceActions
$sRawError = 'Empty action';
}
}
catch (\RainLoop\Exceptions\ClientException $oException)
catch (Exceptions\ClientException $oException)
{
$sRawError = 'Exception as result';
switch ($oException->getCode())
{
case \RainLoop\Notifications::AuthError:
case Notifications::AuthError:
$sRawError = 'Authentication failed';
break;
}
@ -478,7 +478,7 @@ class ServiceActions
$sCacheFileName = '';
if ($bCacheEnabled)
{
$sCacheFileName = \RainLoop\KeyPathHelper::LangCache(
$sCacheFileName = KeyPathHelper::LangCache(
$sLanguage, $bAdmim, $this->oActions->Plugins()->Hash());
$sResult = $this->Cacher()->Get($sCacheFileName);
@ -518,7 +518,7 @@ class ServiceActions
$sCacheFileName = '';
if ($bCacheEnabled)
{
$sCacheFileName = \RainLoop\KeyPathHelper::TemplatesCache($bAdmin, $this->oActions->Plugins()->Hash());
$sCacheFileName = KeyPathHelper::TemplatesCache($bAdmin, $this->oActions->Plugins()->Hash());
$sResult = $this->Cacher()->Get($sCacheFileName);
}
@ -555,7 +555,7 @@ class ServiceActions
$sCacheFileName = '';
if ($bCacheEnabled)
{
$sCacheFileName = \RainLoop\KeyPathHelper::PluginsJsCache($this->oActions->Plugins()->Hash());
$sCacheFileName = KeyPathHelper::PluginsJsCache($this->oActions->Plugins()->Hash());
$sResult = $this->Cacher()->Get($sCacheFileName);
}
@ -613,7 +613,7 @@ class ServiceActions
$sCacheFileName = '';
if ($bCacheEnabled)
{
$sCacheFileName = \RainLoop\KeyPathHelper::CssCache($sTheme, $this->oActions->Plugins()->Hash());
$sCacheFileName = KeyPathHelper::CssCache($sTheme, $this->oActions->Plugins()->Hash());
$sResult = $this->Cacher()->Get($sCacheFileName);
}
@ -638,7 +638,7 @@ class ServiceActions
if (\file_exists($sThemeFile) && \file_exists($sThemeTemplateFile) && \file_exists($sThemeValuesFile))
{
$aResult[] = '@base: "'.
($bCustomTheme ? \RainLoop\Utils::WebPath() : \RainLoop\Utils::WebVersionPath()).
($bCustomTheme ? Utils::WebPath() : Utils::WebVersionPath()).
'themes/'.$sRealTheme.'/";';
$aResult[] = \file_get_contents($sThemeValuesFile);
@ -690,14 +690,14 @@ class ServiceActions
public function ServiceMobileVersion() : string
{
\RainLoop\Utils::SetCookie(\RainLoop\Actions::RL_MOBILE_TYPE, 'mobile');
Utils::SetCookie(Actions::RL_MOBILE_TYPE, 'mobile');
$this->oActions->Location('./');
return '';
}
public function ServiceDesktopVersion() : string
{
\RainLoop\Utils::SetCookie(\RainLoop\Actions::RL_MOBILE_TYPE, 'desktop');
Utils::SetCookie(Actions::RL_MOBILE_TYPE, 'desktop');
$this->oActions->Location('./');
return '';
}
@ -719,7 +719,7 @@ class ServiceActions
\header('Content-Type: text/html; charset=utf-8');
return \strtr(\file_get_contents(APP_VERSION_ROOT_PATH.'app/templates/BadBrowser.html'), array(
'{{BaseWebStaticPath}}' => \RainLoop\Utils::WebStaticPath(),
'{{BaseWebStaticPath}}' => Utils::WebStaticPath(),
'{{ErrorTitle}}' => $sTitle,
'{{ErrorHeader}}' => $sTitle,
'{{ErrorDesc}}' => $sDesc
@ -766,11 +766,11 @@ class ServiceActions
{
$mData = null;
$sSsoSubData = $this->Cacher()->Get(\RainLoop\KeyPathHelper::SsoCacherKey($sSsoHash));
$sSsoSubData = $this->Cacher()->Get(KeyPathHelper::SsoCacherKey($sSsoHash));
if (!empty($sSsoSubData))
{
$mData = \RainLoop\Utils::DecodeKeyValuesQ($sSsoSubData);
$this->Cacher()->Delete(\RainLoop\KeyPathHelper::SsoCacherKey($sSsoHash));
$mData = Utils::DecodeKeyValuesQ($sSsoSubData);
$this->Cacher()->Delete(KeyPathHelper::SsoCacherKey($sSsoHash));
if (\is_array($mData) && !empty($mData['Email']) && isset($mData['Password'], $mData['Time']) &&
(0 === $mData['Time'] || \time() - 10 < $mData['Time']))
@ -785,7 +785,7 @@ class ServiceActions
{
$oAccount = $this->oActions->LoginProcess($sEmail, $sPassword);
if ($oAccount instanceof \RainLoop\Model\Account && $aAdditionalOptions)
if ($oAccount instanceof Model\Account && $aAdditionalOptions)
{
$bNeedToSettings = false;
@ -814,7 +814,7 @@ class ServiceActions
$this->oActions->AuthToken($oAccount);
$bLogout = !($oAccount instanceof \RainLoop\Model\Account);
$bLogout = !($oAccount instanceof Model\Account);
}
catch (\Throwable $oException)
{
@ -848,7 +848,7 @@ class ServiceActions
{
$oAccount = $this->oActions->LoginProcess($sEmail, $sPassword);
$this->oActions->AuthToken($oAccount);
$bLogout = !($oAccount instanceof \RainLoop\Model\Account);
$bLogout = !($oAccount instanceof Model\Account);
}
catch (\Throwable $oException)
{
@ -881,19 +881,19 @@ class ServiceActions
$aResult = array(
'Action' => 'ExternalLogin',
'Result' => $oAccount instanceof \RainLoop\Model\Account ? true : false,
'Result' => $oAccount instanceof Model\Account ? true : false,
'ErrorCode' => 0
);
if (!$aResult['Result'])
{
if ($oException instanceof \RainLoop\Exceptions\ClientException)
if ($oException instanceof Exceptions\ClientException)
{
$aResult['ErrorCode'] = $oException->getCode();
}
else
{
$aResult['ErrorCode'] = \RainLoop\Notifications::AuthError;
$aResult['ErrorCode'] = Notifications::AuthError;
}
}
@ -914,7 +914,7 @@ class ServiceActions
$oAccount = $this->oActions->GetAccount();
if ($oAccount && $this->oActions->GetCapa(false, false, \RainLoop\Enumerations\Capa::ADDITIONAL_ACCOUNTS, $oAccount))
if ($oAccount && $this->oActions->GetCapa(false, false, Enumerations\Capa::ADDITIONAL_ACCOUNTS, $oAccount))
{
$oAccountToLogin = null;
$sEmail = empty($this->aPaths[2]) ? '' : \urldecode(\trim($this->aPaths[2]));
@ -949,7 +949,7 @@ class ServiceActions
public function ErrorTemplates(string $sTitle, string $sDesc, bool $bShowBackLink = true)
{
return strtr(file_get_contents(APP_VERSION_ROOT_PATH.'app/templates/Error.html'), array(
'{{BaseWebStaticPath}}' => \RainLoop\Utils::WebStaticPath(),
'{{BaseWebStaticPath}}' => Utils::WebStaticPath(),
'{{ErrorTitle}}' => $sTitle,
'{{ErrorHeader}}' => $sTitle,
'{{ErrorDesc}}' => $sDesc,
@ -1016,9 +1016,9 @@ class ServiceActions
{
$aTemplates = array();
\RainLoop\Utils::CompileTemplates($aTemplates, APP_VERSION_ROOT_PATH.'app/templates/Views/Components', 'Component');
\RainLoop\Utils::CompileTemplates($aTemplates, APP_VERSION_ROOT_PATH.'app/templates/Views/'.($bAdmin ? 'Admin' : 'User'));
\RainLoop\Utils::CompileTemplates($aTemplates, APP_VERSION_ROOT_PATH.'app/templates/Views/Common');
Utils::CompileTemplates($aTemplates, APP_VERSION_ROOT_PATH.'app/templates/Views/Components', 'Component');
Utils::CompileTemplates($aTemplates, APP_VERSION_ROOT_PATH.'app/templates/Views/'.($bAdmin ? 'Admin' : 'User'));
Utils::CompileTemplates($aTemplates, APP_VERSION_ROOT_PATH.'app/templates/Views/Common');
$this->oActions->Plugins()->CompileTemplate($aTemplates, $bAdmin);
@ -1057,10 +1057,10 @@ class ServiceActions
$sMoment = \preg_replace('/\/\/[^\n]+\n/', '', $sMoment);
}
\RainLoop\Utils::ReadAndAddLang(APP_VERSION_ROOT_PATH.'app/localization/langs.yml', $aResultLang);
\RainLoop\Utils::ReadAndAddLang(APP_VERSION_ROOT_PATH.'app/localization/'.
Utils::ReadAndAddLang(APP_VERSION_ROOT_PATH.'app/localization/langs.yml', $aResultLang);
Utils::ReadAndAddLang(APP_VERSION_ROOT_PATH.'app/localization/'.
($bAdmin ? 'admin' : 'webmail').'/_source.en.yml', $aResultLang);
\RainLoop\Utils::ReadAndAddLang(APP_VERSION_ROOT_PATH.'app/localization/'.
Utils::ReadAndAddLang(APP_VERSION_ROOT_PATH.'app/localization/'.
($bAdmin ? 'admin' : 'webmail').'/'.$sLanguage.'.yml', $aResultLang);
$this->Plugins()->ReadLang($sLanguage, $aResultLang);

View file

@ -18,7 +18,7 @@ class Utils
static $RsaKey = null;
private function __construct()
function __construct()
{
}