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 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 * @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)*/) 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) ->Text($oTextNode->wholeText)
->UseDefaultWrappers(true) ->UseDefaultWrappers(true)
->CompileText() ->CompileText()
@ -1037,7 +1037,7 @@ abstract class HtmlUtils
return ''; return '';
} }
$sText = \MailSo\Base\LinkFinder::NewInstance() $sText = (new \MailSo\Base\LinkFinder)
->Text($sText) ->Text($sText)
->UseDefaultWrappers($bLinksWithTargetBlank) ->UseDefaultWrappers($bLinksWithTargetBlank)
->CompileText() ->CompileText()

View file

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

View file

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

View file

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

View file

@ -27,17 +27,12 @@ class CacheClient
*/ */
private $sCacheIndex; private $sCacheIndex;
private function __construct() function __construct()
{ {
$this->oDriver = null; $this->oDriver = null;
$this->sCacheIndex = ''; $this->sCacheIndex = '';
} }
public static function NewInstance() : self
{
return new self();
}
public function Set(string $sKey, string $sValue) : bool public function Set(string $sKey, string $sValue) : bool
{ {
return $this->oDriver ? $this->oDriver->Set($sKey.$this->sCacheIndex, $sValue) : false; 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 $sKeyPrefix;
private function __construct(string $sKeyPrefix = '') function __construct(string $sKeyPrefix = '')
{ {
$this->sKeyPrefix = $sKeyPrefix; $this->sKeyPrefix = $sKeyPrefix;
if (!empty($this->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 public function Set(string $sKey, string $sValue) : bool
{ {
return \apc_store($this->generateCachedKey($sKey), (string) $sValue); return \apc_store($this->generateCachedKey($sKey), (string) $sValue);

View file

@ -28,7 +28,7 @@ class File implements \MailSo\Cache\DriverInterface
*/ */
private $sKeyPrefix; private $sKeyPrefix;
private function __construct(string $sCacheFolder, string $sKeyPrefix = '') function __construct(string $sCacheFolder, string $sKeyPrefix = '')
{ {
$this->sCacheFolder = $sCacheFolder; $this->sCacheFolder = $sCacheFolder;
$this->sCacheFolder = rtrim(trim($this->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 public function Set(string $sKey, string $sValue) : bool
{ {
$sPath = $this->generateCachedFileName($sKey, true); $sPath = $this->generateCachedFileName($sKey, true);

View file

@ -43,13 +43,13 @@ class Memcache implements \MailSo\Cache\DriverInterface
*/ */
private $sKeyPrefix; 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->sHost = $sHost;
$this->iPost = $iPost; $this->iPost = $iPost;
$this->iExpire = 0 < $iExpire ? $iExpire : 43200; $this->iExpire = 0 < $iExpire ? $iExpire : 43200;
$this->oMem = new \Memcache(); $this->oMem = new \Memcache;
if (!$this->oMem->connect($this->sHost, $this->iPost)) if (!$this->oMem->connect($this->sHost, $this->iPost))
{ {
$this->oMem = null; $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 public function Set(string $sKey, string $sValue) : bool
{ {
return $this->oMem ? $this->oMem->set($this->generateCachedKey($sKey), $sValue, 0, $this->iExpire) : false; 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 $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->sHost = $sHost;
$this->iPost = $iPost; $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 public function Set(string $sKey, string $sValue) : bool
{ {
return $this->oRedis ? $this->oRedis->setex($this->generateCachedKey($sKey), $this->iExpire, $sValue) : false; return $this->oRedis ? $this->oRedis->setex($this->generateCachedKey($sKey), $this->iExpire, $sValue) : false;

View file

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

View file

@ -27,17 +27,12 @@ class FetchResponse
*/ */
private $aEnvelopeCache; private $aEnvelopeCache;
private function __construct(Response $oImapResponse) function __construct(Response $oImapResponse)
{ {
$this->oImapResponse = $oImapResponse; $this->oImapResponse = $oImapResponse;
$this->aEnvelopeCache = null; $this->aEnvelopeCache = null;
} }
public static function NewInstance(Response $oImapResponse) : self
{
return new self($oImapResponse);
}
public function GetEnvelope(bool $bForce = false) : ?array public function GetEnvelope(bool $bForce = false) : ?array
{ {
if (null === $this->aEnvelopeCache || $bForce) if (null === $this->aEnvelopeCache || $bForce)
@ -61,7 +56,7 @@ class FetchResponse
$aEmails = $this->GetFetchEnvelopeValue($iIndex); $aEmails = $this->GetFetchEnvelopeValue($iIndex);
if (is_array($aEmails) && 0 < count($aEmails)) if (is_array($aEmails) && 0 < count($aEmails))
{ {
$oResult = \MailSo\Mime\EmailCollection::NewInstance(); $oResult = new \MailSo\Mime\EmailCollection;
foreach ($aEmails as $aEmailItem) foreach ($aEmails as $aEmailItem)
{ {
if (is_array($aEmailItem) && 4 === count($aEmailItem)) if (is_array($aEmailItem) && 4 === count($aEmailItem))
@ -78,7 +73,7 @@ class FetchResponse
if (0 < strlen($sLocalPart) && 0 < strlen($sDomainPart)) if (0 < strlen($sLocalPart) && 0 < strlen($sDomainPart))
{ {
$oResult->append( $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 * @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; $sDelimiter = 'NIL' === \strtoupper($sDelimiter) ? '' : $sDelimiter;
if (empty($sDelimiter)) if (empty($sDelimiter))
@ -60,7 +60,7 @@ class Folder
if (1 < \strlen($sDelimiter) || 0 === \strlen($sFullNameRaw)) if (1 < \strlen($sDelimiter) || 0 === \strlen($sFullNameRaw))
{ {
throw new \MailSo\Base\Exceptions\InvalidArgumentException(); throw new \MailSo\Base\Exceptions\InvalidArgumentException;
} }
$this->sFullNameRaw = $sFullNameRaw; $this->sFullNameRaw = $sFullNameRaw;
@ -82,21 +82,13 @@ class Folder
$aNames = \explode($this->sDelimiter, $this->sFullNameRaw); $aNames = \explode($this->sDelimiter, $this->sFullNameRaw);
if (false !== \array_search('', $aNames)) if (false !== \array_search('', $aNames))
{ {
throw new \MailSo\Base\Exceptions\InvalidArgumentException(); throw new \MailSo\Base\Exceptions\InvalidArgumentException;
} }
$this->sNameRaw = \end($aNames); $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 public function NameRaw() : string
{ {
return $this->sNameRaw; return $this->sNameRaw;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -32,7 +32,7 @@ class Callback extends \MailSo\Log\Driver
* @param mixed $fWriteCallback * @param mixed $fWriteCallback
* @param mixed $fClearCallback * @param mixed $fClearCallback
*/ */
protected function __construct($fWriteCallback, $fClearCallback) function __construct($fWriteCallback, $fClearCallback)
{ {
parent::__construct(); parent::__construct();
@ -40,15 +40,6 @@ class Callback extends \MailSo\Log\Driver
$this->fClearCallback = \is_callable($fClearCallback) ? $fClearCallback : null; $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 protected function writeImplementation($mDesc) : bool
{ {
if ($this->fWriteCallback) if ($this->fWriteCallback)

View file

@ -23,7 +23,7 @@ class File extends \MailSo\Log\Driver
*/ */
private $sLoggerFileName; private $sLoggerFileName;
protected function __construct(string $sLoggerFileName, string $sNewLine = "\r\n") function __construct(string $sLoggerFileName, string $sNewLine = "\r\n")
{ {
parent::__construct(); parent::__construct();
@ -36,11 +36,6 @@ class File extends \MailSo\Log\Driver
$this->sLoggerFileName = $sLoggerFileName; $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 protected function writeImplementation($mDesc) : bool
{ {
return $this->writeToLogFile($mDesc); return $this->writeToLogFile($mDesc);

View file

@ -23,7 +23,7 @@ class Inline extends \MailSo\Log\Driver
*/ */
private $bHtmlEncodeSpecialChars; private $bHtmlEncodeSpecialChars;
protected function __construct(string $sNewLine = "\r\n", bool $bHtmlEncodeSpecialChars = false) function __construct(string $sNewLine = "\r\n", bool $bHtmlEncodeSpecialChars = false)
{ {
parent::__construct(); parent::__construct();
@ -31,11 +31,6 @@ class Inline extends \MailSo\Log\Driver
$this->bHtmlEncodeSpecialChars = $bHtmlEncodeSpecialChars; $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 protected function writeImplementation($mDesc) : bool
{ {
if (\is_array($mDesc)) if (\is_array($mDesc))

View file

@ -20,7 +20,7 @@ class Syslog extends \MailSo\Log\Driver
{ {
private $iLogLevel; private $iLogLevel;
protected function __construct() function __construct()
{ {
parent::__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 protected function writeImplementation($mDesc) : bool
{ {
if (null === $this->iLogLevel) if (null === $this->iLogLevel)

View file

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

View file

@ -32,7 +32,7 @@ class Attachment
*/ */
private $oBodyStructure; private $oBodyStructure;
private function __construct() function __construct()
{ {
$this->Clear(); $this->Clear();
} }
@ -148,14 +148,9 @@ class Attachment
return $this->oBodyStructure ? $this->oBodyStructure->IsPgpSignature() : false; 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 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 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 class AttachmentCollection extends \MailSo\Base\Collection
{ {
public static function NewInstance() : self
{
return new self();
}
public function append($oAttachment, bool $bToTop = false) : void public function append($oAttachment, bool $bToTop = false) : void
{ {
assert($oAttachment instanceof Attachment); assert($oAttachment instanceof Attachment);

View file

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

View file

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

View file

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

View file

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

View file

@ -57,8 +57,11 @@ class Attachment
*/ */
private $sContentLocation; 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->rResource = $rResource;
$this->sFileName = $sFileName; $this->sFileName = $sFileName;
@ -70,15 +73,6 @@ class Attachment
$this->sContentLocation = $sContentLocation; $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 * @return resource
*/ */

View file

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

View file

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

View file

@ -17,33 +17,22 @@ namespace MailSo\Mime;
*/ */
class EmailCollection extends \MailSo\Base\Collection class EmailCollection extends \MailSo\Base\Collection
{ {
protected function __construct(string $sEmailAddresses = '') function __construct($mEmailAddresses = '')
{ {
parent::__construct(); if (\is_string($mEmailAddresses)) {
parent::__construct();
$sEmailAddresses = \MailSo\Base\Utils::Trim($sEmailAddresses); $this->parseEmailAddresses($mEmailAddresses);
if (0 < \strlen($sEmailAddresses)) } else {
{ parent::__construct($mEmailAddresses);
$this->parseEmailAddresses($sEmailAddresses);
} }
} }
public static function NewInstance(string $sEmailAddresses = '') : self
{
return new self($sEmailAddresses);
}
public function append($oEmail, bool $bToTop = false) : void public function append($oEmail, bool $bToTop = false) : void
{ {
assert($oEmail instanceof Email); assert($oEmail instanceof Email);
parent::append($oEmail, $bToTop); parent::append($oEmail, $bToTop);
} }
public static function Parse(string $sEmailAddresses) : self
{
return self::NewInstance($sEmailAddresses);
}
public function ToArray() : array public function ToArray() : array
{ {
$aReturn = array(); $aReturn = array();
@ -78,9 +67,7 @@ class EmailCollection extends \MailSo\Base\Collection
} }
} }
$this->exchangeArray(array_values($aReturn)); return new static($aReturn);
return $this;
} }
public function ToString(bool $bConvertSpecialsName = false, bool $bIdn = false) : string public function ToString(bool $bConvertSpecialsName = false, bool $bIdn = false) : string
@ -94,15 +81,15 @@ class EmailCollection extends \MailSo\Base\Collection
return \implode(', ', $aReturn); 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); $sWorkingRecipientsLen = \strlen($sRawEmails);
if (!$sWorkingRecipientsLen)
if (0 === \strlen($sWorkingRecipients))
{ {
return $this; return;
} }
$iEmailStartPos = 0; $iEmailStartPos = 0;
@ -115,20 +102,18 @@ class EmailCollection extends \MailSo\Base\Collection
$iCurrentPos = 0; $iCurrentPos = 0;
$sWorkingRecipientsLen = \strlen($sWorkingRecipients);
while ($iCurrentPos < $sWorkingRecipientsLen) while ($iCurrentPos < $sWorkingRecipientsLen)
{ {
switch ($sWorkingRecipients[$iCurrentPos]) switch ($sRawEmails[$iCurrentPos])
{ {
case '\'': case '\'':
case '"': case '"':
if (!$bIsInQuotes) if (!$bIsInQuotes)
{ {
$sChQuote = $sWorkingRecipients[$iCurrentPos]; $sChQuote = $sRawEmails[$iCurrentPos];
$bIsInQuotes = true; $bIsInQuotes = true;
} }
else if ($sChQuote == $sWorkingRecipients[$iCurrentPos]) else if ($sChQuote == $sRawEmails[$iCurrentPos])
{ {
$bIsInQuotes = false; $bIsInQuotes = false;
} }
@ -175,7 +160,7 @@ class EmailCollection extends \MailSo\Base\Collection
try try
{ {
$this->append( $this->append(
Email::Parse(\substr($sWorkingRecipients, $iEmailStartPos, $iEmailEndPos - $iEmailStartPos)) Email::Parse(\substr($sRawEmails, $iEmailStartPos, $iEmailEndPos - $iEmailStartPos))
); );
$iEmailStartPos = $iCurrentPos + 1; $iEmailStartPos = $iCurrentPos + 1;
@ -187,7 +172,7 @@ class EmailCollection extends \MailSo\Base\Collection
break; break;
} }
$iCurrentPos++; ++$iCurrentPos;
} }
if ($iEmailStartPos < $iCurrentPos) if ($iEmailStartPos < $iCurrentPos)
@ -195,12 +180,10 @@ class EmailCollection extends \MailSo\Base\Collection
try try
{ {
$this->append( $this->append(
Email::Parse(\substr($sWorkingRecipients, $iEmailStartPos, $iCurrentPos - $iEmailStartPos)) Email::Parse(\substr($sRawEmails, $iEmailStartPos, $iCurrentPos - $iEmailStartPos))
); );
} }
catch (\MailSo\Base\Exceptions\InvalidArgumentException $oException) {} 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 $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; $this->sParentCharset = $sParentCharset;
@ -72,8 +72,7 @@ class Header
if (2 === \count($aRawExplode)) if (2 === \count($aRawExplode))
{ {
$this->sValue = $aRawExplode[0]; $this->sValue = $aRawExplode[0];
$this->oParameters = $this->oParameters = new ParameterCollection($aRawExplode[1]);
\MailSo\Mime\ParameterCollection::NewInstance($aRawExplode[1]);
} }
else else
{ {
@ -86,12 +85,7 @@ class Header
} }
} }
public static function NewInstance(string $sName, string $sValue = '', string $sEncodedValueForReparse = '', string $sParentCharset = '') : \MailSo\Mime\Header public static function NewInstanceFromEncodedString(string $sEncodedLines, string $sIncomingCharset = \MailSo\Base\Enumerations\Charset::ISO_8859_1) : 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
{ {
if (empty($sIncomingCharset)) if (empty($sIncomingCharset))
{ {
@ -101,7 +95,7 @@ class Header
$aParts = \explode(':', \str_replace("\r", '', $sEncodedLines), 2); $aParts = \explode(':', \str_replace("\r", '', $sEncodedLines), 2);
if (isset($aParts[0]) && isset($aParts[1]) && 0 < \strlen($aParts[0]) && 0 < \strlen($aParts[1])) 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($aParts[0]),
\trim(\MailSo\Base\Utils::DecodeHeaderValue(\trim($aParts[1]), $sIncomingCharset)), \trim(\MailSo\Base\Utils::DecodeHeaderValue(\trim($aParts[1]), $sIncomingCharset)),
\trim($aParts[1]), \trim($aParts[1]),
@ -132,7 +126,7 @@ class Header
return $this->sFullValue; 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)) if ($this->sParentCharset !== $sParentCharset && $this->IsReparsed() && 0 < \strlen($this->sEncodedValueForReparse))
{ {
@ -148,7 +142,7 @@ class Header
return $this; return $this;
} }
public function Parameters() : ?\MailSo\Mime\ParameterCollection public function Parameters() : ?ParameterCollection
{ {
return $this->oParameters; return $this->oParameters;
} }
@ -156,7 +150,7 @@ class Header
private function wordWrapHelper(string $sValue, string $sGlue = "\r\n ") : string private function wordWrapHelper(string $sValue, string $sGlue = "\r\n ") : string
{ {
return \trim(substr(wordwrap($this->NameWithDelimitrom().$sValue, return \trim(substr(wordwrap($this->NameWithDelimitrom().$sValue,
\MailSo\Mime\Enumerations\Constants::LINE_LENGTH, $sGlue Enumerations\Constants::LINE_LENGTH, $sGlue
), \strlen($this->NameWithDelimitrom()))); ), \strlen($this->NameWithDelimitrom())));
} }
@ -174,8 +168,8 @@ class Header
'scheme' => \MailSo\Base\Enumerations\Encoding::BASE64_SHORT, 'scheme' => \MailSo\Base\Enumerations\Encoding::BASE64_SHORT,
'input-charset' => \MailSo\Base\Enumerations\Charset::UTF_8, 'input-charset' => \MailSo\Base\Enumerations\Charset::UTF_8,
'output-charset' => \MailSo\Base\Enumerations\Charset::UTF_8, 'output-charset' => \MailSo\Base\Enumerations\Charset::UTF_8,
'line-length' => \MailSo\Mime\Enumerations\Constants::LINE_LENGTH, 'line-length' => Enumerations\Constants::LINE_LENGTH,
'line-break-chars' => \MailSo\Mime\Enumerations\Constants::CRLF 'line-break-chars' => Enumerations\Constants::CRLF
); );
return \iconv_mime_encode($this->Name(), $sResult, $aPreferences); return \iconv_mime_encode($this->Name(), $sResult, $aPreferences);
@ -187,7 +181,7 @@ class Header
} }
else if ($this->IsEmail()) else if ($this->IsEmail())
{ {
$oEmailCollection = \MailSo\Mime\EmailCollection::NewInstance($this->sFullValue); $oEmailCollection = new EmailCollection($this->sFullValue);
if ($oEmailCollection && 0 < $oEmailCollection->Count()) if ($oEmailCollection && 0 < $oEmailCollection->Count())
{ {
$sResult = $oEmailCollection->ToString(true, false); $sResult = $oEmailCollection->ToString(true, false);
@ -199,27 +193,27 @@ class Header
public function IsSubject() : bool 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 public function IsParameterized() : bool
{ {
return \in_array(\strtolower($this->sName), array( return \in_array(\strtolower($this->sName), array(
\strtolower(\MailSo\Mime\Enumerations\Header::CONTENT_TYPE), \strtolower(Enumerations\Header::CONTENT_TYPE),
\strtolower(\MailSo\Mime\Enumerations\Header::CONTENT_DISPOSITION) \strtolower(Enumerations\Header::CONTENT_DISPOSITION)
)); ));
} }
public function IsEmail() : bool public function IsEmail() : bool
{ {
return \in_array(\strtolower($this->sName), array( return \in_array(\strtolower($this->sName), array(
\strtolower(\MailSo\Mime\Enumerations\Header::FROM_), \strtolower(Enumerations\Header::FROM_),
\strtolower(\MailSo\Mime\Enumerations\Header::TO_), \strtolower(Enumerations\Header::TO_),
\strtolower(\MailSo\Mime\Enumerations\Header::CC), \strtolower(Enumerations\Header::CC),
\strtolower(\MailSo\Mime\Enumerations\Header::BCC), \strtolower(Enumerations\Header::BCC),
\strtolower(\MailSo\Mime\Enumerations\Header::REPLY_TO), \strtolower(Enumerations\Header::REPLY_TO),
\strtolower(\MailSo\Mime\Enumerations\Header::RETURN_PATH), \strtolower(Enumerations\Header::RETURN_PATH),
\strtolower(\MailSo\Mime\Enumerations\Header::SENDER) \strtolower(Enumerations\Header::SENDER)
)); ));
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -37,7 +37,7 @@ class ManageSieveClient extends \MailSo\Net\NetClient
*/ */
public $__USE_INITIAL_AUTH_PLAIN_COMMAND; public $__USE_INITIAL_AUTH_PLAIN_COMMAND;
protected function __construct() function __construct()
{ {
parent::__construct(); parent::__construct();
@ -49,11 +49,6 @@ class ManageSieveClient extends \MailSo\Net\NetClient
$this->__USE_INITIAL_AUTH_PLAIN_COMMAND = true; $this->__USE_INITIAL_AUTH_PLAIN_COMMAND = true;
} }
public static function NewInstance() : self
{
return new self();
}
public function IsSupported(string $sCapa) : bool public function IsSupported(string $sCapa) : bool
{ {
return isset($this->aCapa[\strtoupper($sCapa)]); return isset($this->aCapa[\strtoupper($sCapa)]);
@ -119,7 +114,7 @@ class ManageSieveClient extends \MailSo\Net\NetClient
if (!strlen(\trim($sLogin)) || !strlen(\trim($sPassword))) if (!strlen(\trim($sLogin)) || !strlen(\trim($sPassword)))
{ {
$this->writeLogException( $this->writeLogException(
new \MailSo\Base\Exceptions\InvalidArgumentException(), new \MailSo\Base\Exceptions\InvalidArgumentException,
\MailSo\Log\Enumerations\Type::ERROR, true); \MailSo\Log\Enumerations\Type::ERROR, true);
} }
@ -175,14 +170,14 @@ class ManageSieveClient extends \MailSo\Net\NetClient
if (!$bAuth) if (!$bAuth)
{ {
$this->writeLogException( $this->writeLogException(
new \MailSo\Sieve\Exceptions\LoginBadMethodException(), new \MailSo\Sieve\Exceptions\LoginBadMethodException,
\MailSo\Log\Enumerations\Type::ERROR, true); \MailSo\Log\Enumerations\Type::ERROR, true);
} }
} }
else else
{ {
$this->writeLogException( $this->writeLogException(
new \MailSo\Sieve\Exceptions\LoginException(), new \MailSo\Sieve\Exceptions\LoginException,
\MailSo\Log\Enumerations\Type::ERROR, true); \MailSo\Log\Enumerations\Type::ERROR, true);
} }
@ -430,7 +425,7 @@ class ManageSieveClient extends \MailSo\Net\NetClient
if (!strlen(\trim($sRequest))) if (!strlen(\trim($sRequest)))
{ {
$this->writeLogException( $this->writeLogException(
new \MailSo\Base\Exceptions\InvalidArgumentException(), new \MailSo\Base\Exceptions\InvalidArgumentException,
\MailSo\Log\Enumerations\Type::ERROR, true); \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; public $__USE_SINGLE_LINE_AUTH_PLAIN_COMMAND = false;
protected function __construct() function __construct()
{ {
parent::__construct(); parent::__construct();
@ -84,11 +84,6 @@ class SmtpClient extends \MailSo\Net\NetClient
$this->bData = false; $this->bData = false;
} }
public static function NewInstance() : self
{
return new self();
}
public function IsSupported(string $sCapa) : bool public function IsSupported(string $sCapa) : bool
{ {
return in_array(strtoupper($sCapa), $this->aCapa); return in_array(strtoupper($sCapa), $this->aCapa);
@ -181,7 +176,7 @@ class SmtpClient extends \MailSo\Net\NetClient
if (empty($sTicket)) if (empty($sTicket))
{ {
$this->writeLogException( $this->writeLogException(
new \MailSo\Smtp\Exceptions\NegativeResponseException(), new \MailSo\Smtp\Exceptions\NegativeResponseException,
\MailSo\Log\Enumerations\Type::NOTICE, true \MailSo\Log\Enumerations\Type::NOTICE, true
); );
} }
@ -271,7 +266,7 @@ class SmtpClient extends \MailSo\Net\NetClient
else else
{ {
$this->writeLogException( $this->writeLogException(
new \MailSo\Smtp\Exceptions\LoginBadMethodException(), new \MailSo\Smtp\Exceptions\LoginBadMethodException,
\MailSo\Log\Enumerations\Type::NOTICE, true); \MailSo\Log\Enumerations\Type::NOTICE, true);
} }
@ -358,7 +353,7 @@ class SmtpClient extends \MailSo\Net\NetClient
{ {
if (!strlen(\trim($sData))) if (!strlen(\trim($sData)))
{ {
throw new \MailSo\Base\Exceptions\InvalidArgumentException(); throw new \MailSo\Base\Exceptions\InvalidArgumentException;
} }
$rDataStream = \MailSo\Base\ResourceRegistry::CreateMemoryResourceFromString($sData); $rDataStream = \MailSo\Base\ResourceRegistry::CreateMemoryResourceFromString($sData);
@ -380,7 +375,7 @@ class SmtpClient extends \MailSo\Net\NetClient
{ {
if (!\is_resource($rDataStream)) if (!\is_resource($rDataStream))
{ {
throw new \MailSo\Base\Exceptions\InvalidArgumentException(); throw new \MailSo\Base\Exceptions\InvalidArgumentException;
} }
if (!$this->bRcpt) if (!$this->bRcpt)
@ -527,7 +522,7 @@ class SmtpClient extends \MailSo\Net\NetClient
if (!strlen(\trim($sCommand))) if (!strlen(\trim($sCommand)))
{ {
$this->writeLogException( $this->writeLogException(
new \MailSo\Base\Exceptions\InvalidArgumentException(), new \MailSo\Base\Exceptions\InvalidArgumentException,
\MailSo\Log\Enumerations\Type::ERROR, true); \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 class Api
{ {
private function __construct() function __construct()
{ {
} }
@ -33,13 +33,13 @@ class Api
static $oActions = null; static $oActions = null;
if (null === $oActions) if (null === $oActions)
{ {
$oActions = \RainLoop\Actions::NewInstance(); $oActions = new Actions();
} }
return $oActions; return $oActions;
} }
public static function Config() : \RainLoop\Config\Application public static function Config() : Config\Application
{ {
return static::Actions()->Config(); return static::Actions()->Config();
} }
@ -81,10 +81,10 @@ class Api
$sSslCafile = static::Config()->Get('ssl', 'cafile', ''); $sSslCafile = static::Config()->Get('ssl', 'cafile', '');
$sSslCapath = static::Config()->Get('ssl', 'capath', ''); $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)) if (static::Config()->Get('labs', 'cookie_default_secure', false))
{ {
\RainLoop\Utils::$CookieDefaultSecure = true; Utils::$CookieDefaultSecure = true;
} }
if (!empty($sSslCafile) || !empty($sSslCapath)) if (!empty($sSslCafile) || !empty($sSslCapath))
@ -164,8 +164,8 @@ class Api
{ {
$sSsoHash = \MailSo\Base\Utils::Sha1Rand(\md5($sEmail).\md5($sPassword)); $sSsoHash = \MailSo\Base\Utils::Sha1Rand(\md5($sEmail).\md5($sPassword));
return static::Actions()->Cacher()->Set(\RainLoop\KeyPathHelper::SsoCacherKey($sSsoHash), return static::Actions()->Cacher()->Set(KeyPathHelper::SsoCacherKey($sSsoHash),
\RainLoop\Utils::EncodeKeyValuesQ(array( Utils::EncodeKeyValuesQ(array(
'Email' => $sEmail, 'Email' => $sEmail,
'Password' => $sPassword, 'Password' => $sPassword,
'AdditionalOptions' => $aAdditionalOptions, 'AdditionalOptions' => $aAdditionalOptions,
@ -175,7 +175,7 @@ class Api
public static function ClearUserSsoHash(string $sSsoHash) : bool 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 public static function ClearUserData(string $sEmail) : bool
@ -204,7 +204,7 @@ class Api
public static function LogoutCurrentLogginedUser() : bool public static function LogoutCurrentLogginedUser() : bool
{ {
\RainLoop\Utils::ClearCookie('rlsession'); Utils::ClearCookie('rlsession');
return true; return true;
} }

View file

@ -49,7 +49,7 @@ class Account
*/ */
private $sParentEmail; 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 = '', \RainLoop\Model\Domain $oDomain, string $sSignMeToken = '', string $sProxyAuthUser = '',
string $sProxyAuthPassword = '', string $sClientCert = '') string $sProxyAuthPassword = '', string $sClientCert = '')
{ {
@ -64,13 +64,6 @@ class Account
$this->sParentEmail = ''; $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 public function Email() : string
{ {
return $this->sEmail; return $this->sEmail;

View file

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

View file

@ -39,7 +39,7 @@ class Identity
*/ */
private $bSignatureInsertBefore; private $bSignatureInsertBefore;
protected function __construct(string $sId = '', string $sEmail = '') function __construct(string $sId = '', string $sEmail = '')
{ {
$this->sId = empty($sId) ? '' : $sId; $this->sId = empty($sId) ? '' : $sId;
$this->sEmail = empty($sEmail) ? '' : $sEmail; $this->sEmail = empty($sEmail) ? '' : $sEmail;
@ -50,16 +50,6 @@ class Identity
$this->bSignatureInsertBefore = false; $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 public function Id(bool $bFillOnEmpty = false) : string
{ {
return $bFillOnEmpty ? ('' === $this->sId ? '---' : $this->sId) : $this->sId; return $bFillOnEmpty ? ('' === $this->sId ? '---' : $this->sId) : $this->sId;

View file

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

View file

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

View file

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

View file

@ -2,10 +2,10 @@
namespace RainLoop\Providers; namespace RainLoop\Providers;
class Domain extends \RainLoop\Providers\AbstractProvider class Domain extends AbstractProvider
{ {
/** /**
* @var \RainLoop\Providers\Domain\DomainInterface * @var Domain\DomainInterface
*/ */
private $oDriver; private $oDriver;
@ -19,12 +19,12 @@ class Domain extends \RainLoop\Providers\AbstractProvider
*/ */
private $bAdmin; private $bAdmin;
public function __construct(\RainLoop\Providers\Domain\DomainInterface $oDriver, public function __construct(Domain\DomainInterface $oDriver,
\RainLoop\Plugins\Manager $oPlugins) \RainLoop\Plugins\Manager $oPlugins)
{ {
$this->oDriver = $oDriver; $this->oDriver = $oDriver;
$this->oPlugins = $oPlugins; $this->oPlugins = $oPlugins;
$this->bAdmin = $this->oDriver instanceof \RainLoop\Providers\Domain\DomainAdminInterface; $this->bAdmin = $this->oDriver instanceof Domain\DomainAdminInterface;
} }
public function IsAdmin() : bool public function IsAdmin() : bool
@ -140,7 +140,7 @@ class Domain extends \RainLoop\Providers\AbstractProvider
} }
else 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, $sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
$bUseSieve, $sSieveHost, $iSievePort, $iSieveSecure, $bUseSieve, $sSieveHost, $iSievePort, $iSieveSecure,
$sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth, $bOutUsePhpMail, $sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth, $bOutUsePhpMail,
@ -207,7 +207,7 @@ class Domain extends \RainLoop\Providers\AbstractProvider
} }
else 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, $sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
$bUseSieve, $sSieveHost, $iSievePort, $iSieveSecure, $bUseSieve, $sSieveHost, $iSievePort, $iSieveSecure,
$sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth, $bOutUsePhpMail, $sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth, $bOutUsePhpMail,
@ -226,6 +226,6 @@ class Domain extends \RainLoop\Providers\AbstractProvider
public function IsActive() : bool 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->bStop = isset($aFilter['Stop']) ? '1' === (string) $aFilter['Stop'] : true;
$this->bMarkAsRead = isset($aFilter['MarkAsRead']) ? '1' === (string) $aFilter['MarkAsRead'] : false; $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()); isset($aFilter['Conditions']) ? $aFilter['Conditions'] : array());
return true; return true;

View file

@ -49,7 +49,7 @@ class SieveStorage implements \RainLoop\Providers\Filters\FiltersInterface
$aModules = array(); $aModules = array();
$aFilters = array(); $aFilters = array();
$oSieveClient = \MailSo\Sieve\ManageSieveClient::NewInstance(); $oSieveClient = new \MailSo\Sieve\ManageSieveClient();
$oSieveClient->SetLogger($this->oLogger); $oSieveClient->SetLogger($this->oLogger);
$oSieveClient->SetTimeOuts(10, (int) $this->oConfig->Get('labs', 'sieve_timeout', 10)); $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 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->SetLogger($this->oLogger);
$oSieveClient->SetTimeOuts(10, (int) \RainLoop\Api::Config()->Get('labs', 'sieve_timeout', 10)); $oSieveClient->SetTimeOuts(10, (int) \RainLoop\Api::Config()->Get('labs', 'sieve_timeout', 10));

View file

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

View file

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

View file

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

View file

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