mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-03 06:27:02 +03:00
es5 -> es2015 (last stage)
Signature plugin fixes Add view decorator A large number of fixes
This commit is contained in:
parent
e88c193334
commit
17669b7be0
153 changed files with 21193 additions and 21115 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -1,274 +1,273 @@
|
|||
<?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\Imap;
|
||||
|
||||
/**
|
||||
* @category MailSo
|
||||
* @package Imap
|
||||
*/
|
||||
class FetchResponse
|
||||
{
|
||||
/**
|
||||
* @var \MailSo\Imap\Response
|
||||
*/
|
||||
private $oImapResponse;
|
||||
|
||||
/**
|
||||
* @var array|null
|
||||
*/
|
||||
private $aEnvelopeCache;
|
||||
|
||||
/**
|
||||
* @access private
|
||||
*
|
||||
* @param \MailSo\Imap\Response $oImapResponse
|
||||
*/
|
||||
private function __construct($oImapResponse)
|
||||
{
|
||||
$this->oImapResponse = $oImapResponse;
|
||||
$this->aEnvelopeCache = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \MailSo\Imap\Response $oImapResponse
|
||||
* @return \MailSo\Imap\FetchResponse
|
||||
*/
|
||||
public static function NewInstance($oImapResponse)
|
||||
{
|
||||
return new self($oImapResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bForce = false
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function GetEnvelope($bForce = false)
|
||||
{
|
||||
if (null === $this->aEnvelopeCache || $bForce)
|
||||
{
|
||||
$this->aEnvelopeCache = $this->GetFetchValue(Enumerations\FetchType::ENVELOPE);
|
||||
}
|
||||
return $this->aEnvelopeCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $iIndex
|
||||
* @param mixed $mNullResult = null
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function GetFetchEnvelopeValue($iIndex, $mNullResult)
|
||||
{
|
||||
return self::findEnvelopeIndex($this->GetEnvelope(), $iIndex, $mNullResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $iIndex
|
||||
* @param string $sParentCharset = \MailSo\Base\Enumerations\Charset::ISO_8859_1
|
||||
*
|
||||
* @return \MailSo\Mime\EmailCollection|null
|
||||
*/
|
||||
public function GetFetchEnvelopeEmailCollection($iIndex, $sParentCharset = \MailSo\Base\Enumerations\Charset::ISO_8859_1)
|
||||
{
|
||||
$oResult = null;
|
||||
$aEmails = $this->GetFetchEnvelopeValue($iIndex, null);
|
||||
if (is_array($aEmails) && 0 < count($aEmails))
|
||||
{
|
||||
$oResult = \MailSo\Mime\EmailCollection::NewInstance();
|
||||
foreach ($aEmails as $aEmailItem)
|
||||
{
|
||||
if (is_array($aEmailItem) && 4 === count($aEmailItem))
|
||||
{
|
||||
$sDisplayName = \MailSo\Base\Utils::DecodeHeaderValue(
|
||||
self::findEnvelopeIndex($aEmailItem, 0, ''), $sParentCharset);
|
||||
|
||||
$sRemark = \MailSo\Base\Utils::DecodeHeaderValue(
|
||||
self::findEnvelopeIndex($aEmailItem, 1, ''), $sParentCharset);
|
||||
|
||||
$sLocalPart = self::findEnvelopeIndex($aEmailItem, 2, '');
|
||||
$sDomainPart = self::findEnvelopeIndex($aEmailItem, 3, '');
|
||||
|
||||
if (0 < strlen($sLocalPart) && 0 < strlen($sDomainPart))
|
||||
{
|
||||
$oResult->Add(
|
||||
\MailSo\Mime\Email::NewInstance(
|
||||
$sLocalPart.'@'.$sDomainPart, $sDisplayName, $sRemark)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $oResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sRfc822SubMimeIndex = ''
|
||||
*
|
||||
* @return \MailSo\Imap\BodyStructure|null
|
||||
*/
|
||||
public function GetFetchBodyStructure($sRfc822SubMimeIndex = '')
|
||||
{
|
||||
$oBodyStructure = null;
|
||||
$aBodyStructureArray = $this->GetFetchValue(Enumerations\FetchType::BODYSTRUCTURE);
|
||||
|
||||
if (is_array($aBodyStructureArray))
|
||||
{
|
||||
if (0 < strlen($sRfc822SubMimeIndex))
|
||||
{
|
||||
$oBodyStructure = BodyStructure::NewInstanceFromRfc822SubPart($aBodyStructureArray, $sRfc822SubMimeIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
$oBodyStructure = BodyStructure::NewInstance($aBodyStructureArray);
|
||||
}
|
||||
}
|
||||
|
||||
return $oBodyStructure;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sFetchItemName
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function GetFetchValue($sFetchItemName)
|
||||
{
|
||||
$mReturn = null;
|
||||
$bNextIsValue = false;
|
||||
|
||||
if (Enumerations\FetchType::INDEX === $sFetchItemName)
|
||||
{
|
||||
$mReturn = $this->oImapResponse->ResponseList[1];
|
||||
}
|
||||
else if (isset($this->oImapResponse->ResponseList[3]) && \is_array($this->oImapResponse->ResponseList[3]))
|
||||
{
|
||||
foreach ($this->oImapResponse->ResponseList[3] as $mItem)
|
||||
{
|
||||
if ($bNextIsValue)
|
||||
{
|
||||
$mReturn = $mItem;
|
||||
break;
|
||||
}
|
||||
|
||||
if ($sFetchItemName === $mItem)
|
||||
{
|
||||
$bNextIsValue = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $mReturn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sRfc822SubMimeIndex = ''
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetHeaderFieldsValue($sRfc822SubMimeIndex = '')
|
||||
{
|
||||
$sReturn = '';
|
||||
$bNextIsValue = false;
|
||||
|
||||
$sRfc822SubMimeIndex = 0 < \strlen($sRfc822SubMimeIndex) ? ''.$sRfc822SubMimeIndex.'.' : '';
|
||||
|
||||
if (isset($this->oImapResponse->ResponseList[3]) && \is_array($this->oImapResponse->ResponseList[3]))
|
||||
{
|
||||
foreach ($this->oImapResponse->ResponseList[3] as $mItem)
|
||||
{
|
||||
if ($bNextIsValue)
|
||||
{
|
||||
$sReturn = (string) $mItem;
|
||||
break;
|
||||
}
|
||||
|
||||
if (\is_string($mItem) && (
|
||||
$mItem === 'BODY['.$sRfc822SubMimeIndex.'HEADER]' ||
|
||||
0 === \strpos($mItem, 'BODY['.$sRfc822SubMimeIndex.'HEADER.FIELDS') ||
|
||||
$mItem === 'BODY['.$sRfc822SubMimeIndex.'MIME]'))
|
||||
{
|
||||
$bNextIsValue = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $sReturn;
|
||||
}
|
||||
|
||||
private static function findFetchUidAndSize($aList)
|
||||
{
|
||||
$bUid = false;
|
||||
$bSize = false;
|
||||
if (is_array($aList))
|
||||
{
|
||||
foreach ($aList as $mItem)
|
||||
{
|
||||
if (\MailSo\Imap\Enumerations\FetchType::UID === $mItem)
|
||||
{
|
||||
$bUid = true;
|
||||
}
|
||||
else if (\MailSo\Imap\Enumerations\FetchType::RFC822_SIZE === $mItem)
|
||||
{
|
||||
$bSize = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $bUid && $bSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \MailSo\Imap\Response $oImapResponse
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function IsValidFetchImapResponse($oImapResponse)
|
||||
{
|
||||
return (
|
||||
$oImapResponse
|
||||
&& true !== $oImapResponse->IsStatusResponse
|
||||
&& \MailSo\Imap\Enumerations\ResponseType::UNTAGGED === $oImapResponse->ResponseType
|
||||
&& 3 < count($oImapResponse->ResponseList) && 'FETCH' === $oImapResponse->ResponseList[2]
|
||||
&& is_array($oImapResponse->ResponseList[3])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \MailSo\Imap\Response $oImapResponse
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function IsNotEmptyFetchImapResponse($oImapResponse)
|
||||
{
|
||||
return (
|
||||
$oImapResponse
|
||||
&& self::IsValidFetchImapResponse($oImapResponse)
|
||||
&& isset($oImapResponse->ResponseList[3])
|
||||
&& self::findFetchUidAndSize($oImapResponse->ResponseList[3])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $aEnvelope
|
||||
* @param int $iIndex
|
||||
* @param mixed $mNullResult = null
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private static function findEnvelopeIndex($aEnvelope, $iIndex, $mNullResult)
|
||||
{
|
||||
return (isset($aEnvelope[$iIndex]) && 'NIL' !== $aEnvelope[$iIndex] && '' !== $aEnvelope[$iIndex])
|
||||
? $aEnvelope[$iIndex] : $mNullResult;
|
||||
}
|
||||
}
|
||||
<?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\Imap;
|
||||
|
||||
/**
|
||||
* @category MailSo
|
||||
* @package Imap
|
||||
*/
|
||||
class FetchResponse
|
||||
{
|
||||
/**
|
||||
* @var \MailSo\Imap\Response
|
||||
*/
|
||||
private $oImapResponse;
|
||||
|
||||
/**
|
||||
* @var array|null
|
||||
*/
|
||||
private $aEnvelopeCache;
|
||||
|
||||
/**
|
||||
* @access private
|
||||
*
|
||||
* @param \MailSo\Imap\Response $oImapResponse
|
||||
*/
|
||||
private function __construct($oImapResponse)
|
||||
{
|
||||
$this->oImapResponse = $oImapResponse;
|
||||
$this->aEnvelopeCache = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \MailSo\Imap\Response $oImapResponse
|
||||
* @return \MailSo\Imap\FetchResponse
|
||||
*/
|
||||
public static function NewInstance($oImapResponse)
|
||||
{
|
||||
return new self($oImapResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bForce = false
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function GetEnvelope($bForce = false)
|
||||
{
|
||||
if (null === $this->aEnvelopeCache || $bForce)
|
||||
{
|
||||
$this->aEnvelopeCache = $this->GetFetchValue(Enumerations\FetchType::ENVELOPE);
|
||||
}
|
||||
return $this->aEnvelopeCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $iIndex
|
||||
* @param mixed $mNullResult = null
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function GetFetchEnvelopeValue($iIndex, $mNullResult)
|
||||
{
|
||||
return self::findEnvelopeIndex($this->GetEnvelope(), $iIndex, $mNullResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $iIndex
|
||||
* @param string $sParentCharset = \MailSo\Base\Enumerations\Charset::ISO_8859_1
|
||||
*
|
||||
* @return \MailSo\Mime\EmailCollection|null
|
||||
*/
|
||||
public function GetFetchEnvelopeEmailCollection($iIndex, $sParentCharset = \MailSo\Base\Enumerations\Charset::ISO_8859_1)
|
||||
{
|
||||
$oResult = null;
|
||||
$aEmails = $this->GetFetchEnvelopeValue($iIndex, null);
|
||||
if (is_array($aEmails) && 0 < count($aEmails))
|
||||
{
|
||||
$oResult = \MailSo\Mime\EmailCollection::NewInstance();
|
||||
foreach ($aEmails as $aEmailItem)
|
||||
{
|
||||
if (is_array($aEmailItem) && 4 === count($aEmailItem))
|
||||
{
|
||||
$sDisplayName = \MailSo\Base\Utils::DecodeHeaderValue(
|
||||
self::findEnvelopeIndex($aEmailItem, 0, ''), $sParentCharset);
|
||||
|
||||
// $sRemark = \MailSo\Base\Utils::DecodeHeaderValue(
|
||||
// self::findEnvelopeIndex($aEmailItem, 1, ''), $sParentCharset);
|
||||
|
||||
$sLocalPart = self::findEnvelopeIndex($aEmailItem, 2, '');
|
||||
$sDomainPart = self::findEnvelopeIndex($aEmailItem, 3, '');
|
||||
|
||||
if (0 < strlen($sLocalPart) && 0 < strlen($sDomainPart))
|
||||
{
|
||||
$oResult->Add(
|
||||
\MailSo\Mime\Email::NewInstance($sLocalPart.'@'.$sDomainPart, $sDisplayName)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $oResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sRfc822SubMimeIndex = ''
|
||||
*
|
||||
* @return \MailSo\Imap\BodyStructure|null
|
||||
*/
|
||||
public function GetFetchBodyStructure($sRfc822SubMimeIndex = '')
|
||||
{
|
||||
$oBodyStructure = null;
|
||||
$aBodyStructureArray = $this->GetFetchValue(Enumerations\FetchType::BODYSTRUCTURE);
|
||||
|
||||
if (is_array($aBodyStructureArray))
|
||||
{
|
||||
if (0 < strlen($sRfc822SubMimeIndex))
|
||||
{
|
||||
$oBodyStructure = BodyStructure::NewInstanceFromRfc822SubPart($aBodyStructureArray, $sRfc822SubMimeIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
$oBodyStructure = BodyStructure::NewInstance($aBodyStructureArray);
|
||||
}
|
||||
}
|
||||
|
||||
return $oBodyStructure;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sFetchItemName
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function GetFetchValue($sFetchItemName)
|
||||
{
|
||||
$mReturn = null;
|
||||
$bNextIsValue = false;
|
||||
|
||||
if (Enumerations\FetchType::INDEX === $sFetchItemName)
|
||||
{
|
||||
$mReturn = $this->oImapResponse->ResponseList[1];
|
||||
}
|
||||
else if (isset($this->oImapResponse->ResponseList[3]) && \is_array($this->oImapResponse->ResponseList[3]))
|
||||
{
|
||||
foreach ($this->oImapResponse->ResponseList[3] as $mItem)
|
||||
{
|
||||
if ($bNextIsValue)
|
||||
{
|
||||
$mReturn = $mItem;
|
||||
break;
|
||||
}
|
||||
|
||||
if ($sFetchItemName === $mItem)
|
||||
{
|
||||
$bNextIsValue = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $mReturn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sRfc822SubMimeIndex = ''
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetHeaderFieldsValue($sRfc822SubMimeIndex = '')
|
||||
{
|
||||
$sReturn = '';
|
||||
$bNextIsValue = false;
|
||||
|
||||
$sRfc822SubMimeIndex = 0 < \strlen($sRfc822SubMimeIndex) ? ''.$sRfc822SubMimeIndex.'.' : '';
|
||||
|
||||
if (isset($this->oImapResponse->ResponseList[3]) && \is_array($this->oImapResponse->ResponseList[3]))
|
||||
{
|
||||
foreach ($this->oImapResponse->ResponseList[3] as $mItem)
|
||||
{
|
||||
if ($bNextIsValue)
|
||||
{
|
||||
$sReturn = (string) $mItem;
|
||||
break;
|
||||
}
|
||||
|
||||
if (\is_string($mItem) && (
|
||||
$mItem === 'BODY['.$sRfc822SubMimeIndex.'HEADER]' ||
|
||||
0 === \strpos($mItem, 'BODY['.$sRfc822SubMimeIndex.'HEADER.FIELDS') ||
|
||||
$mItem === 'BODY['.$sRfc822SubMimeIndex.'MIME]'))
|
||||
{
|
||||
$bNextIsValue = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $sReturn;
|
||||
}
|
||||
|
||||
private static function findFetchUidAndSize($aList)
|
||||
{
|
||||
$bUid = false;
|
||||
$bSize = false;
|
||||
if (is_array($aList))
|
||||
{
|
||||
foreach ($aList as $mItem)
|
||||
{
|
||||
if (\MailSo\Imap\Enumerations\FetchType::UID === $mItem)
|
||||
{
|
||||
$bUid = true;
|
||||
}
|
||||
else if (\MailSo\Imap\Enumerations\FetchType::RFC822_SIZE === $mItem)
|
||||
{
|
||||
$bSize = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $bUid && $bSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \MailSo\Imap\Response $oImapResponse
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function IsValidFetchImapResponse($oImapResponse)
|
||||
{
|
||||
return (
|
||||
$oImapResponse
|
||||
&& true !== $oImapResponse->IsStatusResponse
|
||||
&& \MailSo\Imap\Enumerations\ResponseType::UNTAGGED === $oImapResponse->ResponseType
|
||||
&& 3 < count($oImapResponse->ResponseList) && 'FETCH' === $oImapResponse->ResponseList[2]
|
||||
&& is_array($oImapResponse->ResponseList[3])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \MailSo\Imap\Response $oImapResponse
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function IsNotEmptyFetchImapResponse($oImapResponse)
|
||||
{
|
||||
return (
|
||||
$oImapResponse
|
||||
&& self::IsValidFetchImapResponse($oImapResponse)
|
||||
&& isset($oImapResponse->ResponseList[3])
|
||||
&& self::findFetchUidAndSize($oImapResponse->ResponseList[3])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $aEnvelope
|
||||
* @param int $iIndex
|
||||
* @param mixed $mNullResult = null
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private static function findEnvelopeIndex($aEnvelope, $iIndex, $mNullResult)
|
||||
{
|
||||
return (isset($aEnvelope[$iIndex]) && 'NIL' !== $aEnvelope[$iIndex] && '' !== $aEnvelope[$iIndex])
|
||||
? $aEnvelope[$iIndex] : $mNullResult;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,338 +1,315 @@
|
|||
<?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;
|
||||
|
||||
/**
|
||||
* @category MailSo
|
||||
* @package Mime
|
||||
*/
|
||||
class Email
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sDisplayName;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sEmail;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sRemark;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sDkimStatus;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sDkimValue;
|
||||
|
||||
/**
|
||||
* @access private
|
||||
*
|
||||
* @param string $sEmail
|
||||
* @param string $sDisplayName = ''
|
||||
* @param string $sRemark = ''
|
||||
*
|
||||
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||
*/
|
||||
private function __construct($sEmail, $sDisplayName = '', $sRemark = '')
|
||||
{
|
||||
if (!\MailSo\Base\Validator::NotEmptyString($sEmail, true))
|
||||
{
|
||||
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 = '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sEmail
|
||||
* @param string $sDisplayName = ''
|
||||
* @param string $sRemark = ''
|
||||
*
|
||||
* @return \MailSo\Mime\Email
|
||||
*
|
||||
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||
*/
|
||||
public static function NewInstance($sEmail, $sDisplayName = '', $sRemark = '')
|
||||
{
|
||||
return new self($sEmail, $sDisplayName, $sRemark);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sEmailAddress
|
||||
* @return \MailSo\Mime\Email
|
||||
*
|
||||
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||
*/
|
||||
public static function Parse($sEmailAddress)
|
||||
{
|
||||
$sEmailAddress = \MailSo\Base\Utils::Trim($sEmailAddress);
|
||||
if (!\MailSo\Base\Validator::NotEmptyString($sEmailAddress, true))
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bIdn = false
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetEmail($bIdn = false)
|
||||
{
|
||||
return $bIdn ? \MailSo\Base\Utils::IdnToUtf8($this->sEmail) : $this->sEmail;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetDisplayName()
|
||||
{
|
||||
return $this->sDisplayName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetRemark()
|
||||
{
|
||||
return $this->sRemark;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetDkimStatus()
|
||||
{
|
||||
return $this->sDkimStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetDkimValue()
|
||||
{
|
||||
return $this->sDkimValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetAccountName()
|
||||
{
|
||||
return \MailSo\Base\Utils::GetAccountNameFromEmail($this->GetEmail(false));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bIdn = false
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetDomain($bIdn = false)
|
||||
{
|
||||
return \MailSo\Base\Utils::GetDomainFromEmail($this->GetEmail($bIdn));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sDkimStatus
|
||||
* @param string $sDkimValue = ''
|
||||
*/
|
||||
public function SetDkimStatusAndValue($sDkimStatus, $sDkimValue = '')
|
||||
{
|
||||
$this->sDkimStatus = \MailSo\Mime\Enumerations\DkimStatus::normalizeValue($sDkimStatus);
|
||||
$this->sDkimValue = $sDkimValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bIdn = false
|
||||
* @param bool $bDkim = true
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function ToArray($bIdn = false, $bDkim = true)
|
||||
{
|
||||
return $bDkim ? array($this->sDisplayName, $this->GetEmail($bIdn), $this->sRemark, $this->sDkimStatus, $this->sDkimValue) :
|
||||
array($this->sDisplayName, $this->GetEmail($bIdn), $this->sRemark);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bConvertSpecialsName = false
|
||||
* @param bool $bIdn = false
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function ToString($bConvertSpecialsName = false, $bIdn = false)
|
||||
{
|
||||
$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);
|
||||
}
|
||||
}
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* @category MailSo
|
||||
* @package Mime
|
||||
*/
|
||||
class Email
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sDisplayName;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sEmail;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sDkimStatus;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sDkimValue;
|
||||
|
||||
/**
|
||||
* @access private
|
||||
*
|
||||
* @param string $sEmail
|
||||
* @param string $sDisplayName = ''
|
||||
*
|
||||
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||
*/
|
||||
private function __construct($sEmail, $sDisplayName = '')
|
||||
{
|
||||
if (!\MailSo\Base\Validator::NotEmptyString($sEmail, true))
|
||||
{
|
||||
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->sDkimStatus = \MailSo\Mime\Enumerations\DkimStatus::NONE;
|
||||
$this->sDkimValue = '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sEmail
|
||||
* @param string $sDisplayName = ''
|
||||
*
|
||||
* @return \MailSo\Mime\Email
|
||||
*
|
||||
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||
*/
|
||||
public static function NewInstance($sEmail, $sDisplayName = '')
|
||||
{
|
||||
return new self($sEmail, $sDisplayName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sEmailAddress
|
||||
* @return \MailSo\Mime\Email
|
||||
*
|
||||
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||
*/
|
||||
public static function Parse($sEmailAddress)
|
||||
{
|
||||
$sEmailAddress = \MailSo\Base\Utils::Trim($sEmailAddress);
|
||||
if (!\MailSo\Base\Validator::NotEmptyString($sEmailAddress, true))
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bIdn = false
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetEmail($bIdn = false)
|
||||
{
|
||||
return $bIdn ? \MailSo\Base\Utils::IdnToUtf8($this->sEmail) : $this->sEmail;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetDisplayName()
|
||||
{
|
||||
return $this->sDisplayName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetDkimStatus()
|
||||
{
|
||||
return $this->sDkimStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetDkimValue()
|
||||
{
|
||||
return $this->sDkimValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetAccountName()
|
||||
{
|
||||
return \MailSo\Base\Utils::GetAccountNameFromEmail($this->GetEmail(false));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bIdn = false
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetDomain($bIdn = false)
|
||||
{
|
||||
return \MailSo\Base\Utils::GetDomainFromEmail($this->GetEmail($bIdn));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sDkimStatus
|
||||
* @param string $sDkimValue = ''
|
||||
*/
|
||||
public function SetDkimStatusAndValue($sDkimStatus, $sDkimValue = '')
|
||||
{
|
||||
$this->sDkimStatus = \MailSo\Mime\Enumerations\DkimStatus::normalizeValue($sDkimStatus);
|
||||
$this->sDkimValue = $sDkimValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bIdn = false
|
||||
* @param bool $bDkim = true
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function ToArray($bIdn = false, $bDkim = true)
|
||||
{
|
||||
return $bDkim ?
|
||||
array($this->sDisplayName, $this->GetEmail($bIdn), $this->sDkimStatus, $this->sDkimValue) :
|
||||
array($this->sDisplayName, $this->GetEmail($bIdn));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bConvertSpecialsName = false
|
||||
* @param bool $bIdn = false
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function ToString($bConvertSpecialsName = false, $bIdn = false)
|
||||
{
|
||||
$sReturn = '';
|
||||
|
||||
$sDisplayName = \str_replace('"', '\"', $this->sDisplayName);
|
||||
if ($bConvertSpecialsName)
|
||||
{
|
||||
$sDisplayName = 0 === \strlen($sDisplayName) ? '' : \MailSo\Base\Utils::EncodeUnencodedValue(
|
||||
\MailSo\Base\Enumerations\Encoding::BASE64_SHORT,
|
||||
$sDisplayName);
|
||||
}
|
||||
|
||||
$sDisplayName = 0 === \strlen($sDisplayName) ? '' : '"'.$sDisplayName.'"';
|
||||
if (0 < \strlen($this->sEmail))
|
||||
{
|
||||
$sReturn = $this->GetEmail($bIdn);
|
||||
if (0 < \strlen($sDisplayName))
|
||||
{
|
||||
$sReturn = $sDisplayName.' <'.$sReturn.'>';
|
||||
}
|
||||
}
|
||||
|
||||
return \trim($sReturn);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
339
rainloop/v/0.0.0/app/libraries/MailSo/Mime/EmailDep.php
Normal file
339
rainloop/v/0.0.0/app/libraries/MailSo/Mime/EmailDep.php
Normal file
|
|
@ -0,0 +1,339 @@
|
|||
<?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;
|
||||
|
||||
/**
|
||||
* @access private
|
||||
*
|
||||
* @param string $sEmail
|
||||
* @param string $sDisplayName = ''
|
||||
* @param string $sRemark = ''
|
||||
*
|
||||
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||
*/
|
||||
private function __construct($sEmail, $sDisplayName = '', $sRemark = '')
|
||||
{
|
||||
if (!\MailSo\Base\Validator::NotEmptyString($sEmail, true))
|
||||
{
|
||||
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 = '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sEmail
|
||||
* @param string $sDisplayName = ''
|
||||
* @param string $sRemark = ''
|
||||
*
|
||||
* @return \MailSo\Mime\Email
|
||||
*
|
||||
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||
*/
|
||||
public static function NewInstance($sEmail, $sDisplayName = '', $sRemark = '')
|
||||
{
|
||||
return new self($sEmail, $sDisplayName, $sRemark);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sEmailAddress
|
||||
* @return \MailSo\Mime\Email
|
||||
*
|
||||
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||
*/
|
||||
public static function Parse($sEmailAddress)
|
||||
{
|
||||
$sEmailAddress = \MailSo\Base\Utils::Trim($sEmailAddress);
|
||||
if (!\MailSo\Base\Validator::NotEmptyString($sEmailAddress, true))
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bIdn = false
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetEmail($bIdn = false)
|
||||
{
|
||||
return $bIdn ? \MailSo\Base\Utils::IdnToUtf8($this->sEmail) : $this->sEmail;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetDisplayName()
|
||||
{
|
||||
return $this->sDisplayName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetRemark()
|
||||
{
|
||||
return $this->sRemark;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetDkimStatus()
|
||||
{
|
||||
return $this->sDkimStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetDkimValue()
|
||||
{
|
||||
return $this->sDkimValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetAccountName()
|
||||
{
|
||||
return \MailSo\Base\Utils::GetAccountNameFromEmail($this->GetEmail(false));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bIdn = false
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetDomain($bIdn = false)
|
||||
{
|
||||
return \MailSo\Base\Utils::GetDomainFromEmail($this->GetEmail($bIdn));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sDkimStatus
|
||||
* @param string $sDkimValue = ''
|
||||
*/
|
||||
public function SetDkimStatusAndValue($sDkimStatus, $sDkimValue = '')
|
||||
{
|
||||
$this->sDkimStatus = \MailSo\Mime\Enumerations\DkimStatus::normalizeValue($sDkimStatus);
|
||||
$this->sDkimValue = $sDkimValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bIdn = false
|
||||
* @param bool $bDkim = true
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function ToArray($bIdn = false, $bDkim = true)
|
||||
{
|
||||
return $bDkim ? array($this->sDisplayName, $this->GetEmail($bIdn), $this->sRemark, $this->sDkimStatus, $this->sDkimValue) :
|
||||
array($this->sDisplayName, $this->GetEmail($bIdn), $this->sRemark);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bConvertSpecialsName = false
|
||||
* @param bool $bIdn = false
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function ToString($bConvertSpecialsName = false, $bIdn = false)
|
||||
{
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
/Prem/**
|
||||
/_Prem/**
|
||||
|
|
@ -820,9 +820,9 @@ class Actions
|
|||
{
|
||||
if (null === $this->oPremProvider)
|
||||
{
|
||||
if (\file_exists(APP_VERSION_ROOT_PATH.'app/libraries/RainLoop/Prem/Provider.php'))
|
||||
if (\file_exists(APP_VERSION_ROOT_PATH.'app/libraries/RainLoop/Providers/Prem.php'))
|
||||
{
|
||||
$this->oPremProvider = new \RainLoop\Prem\Provider(
|
||||
$this->oPremProvider = new \RainLoop\Providers\Prem(
|
||||
$this->Config(), $this->Logger(), $this->Cacher(null, true)
|
||||
);
|
||||
}
|
||||
|
|
@ -1466,8 +1466,7 @@ class Actions
|
|||
'themes' => $this->GetThemes($bMobile, false),
|
||||
'languages' => $this->GetLanguages(false),
|
||||
'languagesAdmin' => $this->GetLanguages(true),
|
||||
'attachmentsActions' => $aAttachmentsActions,
|
||||
'openpgpPublicKeyServer' => $oConfig->Get('security', 'openpgp_public_key_server', '')
|
||||
'attachmentsActions' => $aAttachmentsActions
|
||||
), $bAdmin ? array(
|
||||
'adminHostUse' => '' !== $oConfig->Get('security', 'admin_panel_host', ''),
|
||||
'adminPath' => \strtolower($oConfig->Get('security', 'admin_panel_key', 'admin')),
|
||||
|
|
@ -2357,7 +2356,8 @@ NewThemeLink IncludeCss LoadingDescriptionEsc TemplatesLink LangLink IncludeBack
|
|||
$this->Logger()->AddSecret($sPassword);
|
||||
|
||||
if ('sleep@sleep.dev' === $sEmail && 0 < \strlen($sPassword) &&
|
||||
\is_numeric($sPassword) && $this->Config()->Get('debug', 'enable', false)
|
||||
\is_numeric($sPassword) && $this->Config()->Get('debug', 'enable', false) &&
|
||||
0 < (int) $sPassword && 30 > (int) $sPassword
|
||||
)
|
||||
{
|
||||
\sleep((int) $sPassword);
|
||||
|
|
@ -5179,8 +5179,11 @@ NewThemeLink IncludeCss LoadingDescriptionEsc TemplatesLink LangLink IncludeBack
|
|||
$aCache = array(
|
||||
|
||||
'Sent' => \MailSo\Imap\Enumerations\FolderType::SENT,
|
||||
|
||||
'Send' => \MailSo\Imap\Enumerations\FolderType::SENT,
|
||||
|
||||
'Outbox' => \MailSo\Imap\Enumerations\FolderType::SENT,
|
||||
'Out box' => \MailSo\Imap\Enumerations\FolderType::SENT,
|
||||
|
||||
'Sent Item' => \MailSo\Imap\Enumerations\FolderType::SENT,
|
||||
'Sent Items' => \MailSo\Imap\Enumerations\FolderType::SENT,
|
||||
'Send Item' => \MailSo\Imap\Enumerations\FolderType::SENT,
|
||||
|
|
@ -5199,6 +5202,7 @@ NewThemeLink IncludeCss LoadingDescriptionEsc TemplatesLink LangLink IncludeBack
|
|||
'Drafts Mails' => \MailSo\Imap\Enumerations\FolderType::DRAFTS,
|
||||
|
||||
'Spam' => \MailSo\Imap\Enumerations\FolderType::JUNK,
|
||||
'Spams' => \MailSo\Imap\Enumerations\FolderType::JUNK,
|
||||
|
||||
'Junk' => \MailSo\Imap\Enumerations\FolderType::JUNK,
|
||||
'Bulk Mail' => \MailSo\Imap\Enumerations\FolderType::JUNK,
|
||||
|
|
@ -5209,14 +5213,22 @@ NewThemeLink IncludeCss LoadingDescriptionEsc TemplatesLink LangLink IncludeBack
|
|||
'Bin' => \MailSo\Imap\Enumerations\FolderType::TRASH,
|
||||
|
||||
'Archive' => \MailSo\Imap\Enumerations\FolderType::ALL,
|
||||
'Archives' => \MailSo\Imap\Enumerations\FolderType::ALL,
|
||||
|
||||
'All' => \MailSo\Imap\Enumerations\FolderType::ALL,
|
||||
'All Mail' => \MailSo\Imap\Enumerations\FolderType::ALL,
|
||||
'All Mails' => \MailSo\Imap\Enumerations\FolderType::ALL,
|
||||
'AllMail' => \MailSo\Imap\Enumerations\FolderType::ALL,
|
||||
'AllMails' => \MailSo\Imap\Enumerations\FolderType::ALL,
|
||||
);
|
||||
|
||||
$aNewCache = array();
|
||||
foreach ($aCache as $sKey => $iType)
|
||||
{
|
||||
$aNewCache[$sKey] = $iType;
|
||||
$aNewCache[\str_replace(' ', '', $sKey)] = $iType;
|
||||
}
|
||||
|
||||
$aCache = $aNewCache;
|
||||
|
||||
$this->Plugins()->RunHook('filter.system-folders-names', array($oAccount, &$aCache));
|
||||
}
|
||||
|
||||
|
|
@ -8416,35 +8428,35 @@ NewThemeLink IncludeCss LoadingDescriptionEsc TemplatesLink LangLink IncludeBack
|
|||
case 1:
|
||||
break;
|
||||
|
||||
case 2: // horizontal flip
|
||||
case 2: // flip horizontal
|
||||
$oImage->flipHorizontally();
|
||||
break;
|
||||
|
||||
case 3: // 180 rotate left
|
||||
case 3: // rotate 180
|
||||
$oImage->rotate(180);
|
||||
break;
|
||||
|
||||
case 4: // vertical flip
|
||||
case 4: // flip vertical
|
||||
$oImage->flipVertically();
|
||||
break;
|
||||
|
||||
case 5: // vertical flip + 90 rotate right
|
||||
case 5: // vertical flip + 90 rotate
|
||||
$oImage->flipVertically();
|
||||
$oImage->rotate(-90);
|
||||
break;
|
||||
|
||||
case 6: // 90 rotate right
|
||||
$oImage->rotate(-90);
|
||||
break;
|
||||
|
||||
case 7: // horizontal flip + 90 rotate right
|
||||
$oImage->flipHorizontally();
|
||||
$oImage->rotate(-90);
|
||||
break;
|
||||
|
||||
case 8: // 90 rotate left
|
||||
$oImage->rotate(90);
|
||||
break;
|
||||
|
||||
case 6: // rotate 90
|
||||
$oImage->rotate(90);
|
||||
break;
|
||||
|
||||
case 7: // horizontal flip + 90 rotate
|
||||
$oImage->flipHorizontally();
|
||||
$oImage->rotate(90);
|
||||
break;
|
||||
|
||||
case 8: // rotate 270
|
||||
$oImage->rotate(270);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -8586,8 +8598,6 @@ NewThemeLink IncludeCss LoadingDescriptionEsc TemplatesLink LangLink IncludeBack
|
|||
$self->cacheByKey($sRawKey);
|
||||
|
||||
$sLoadedData = null;
|
||||
$bDetectImageOrientation = false;
|
||||
|
||||
if (!$bDownload)
|
||||
{
|
||||
if ($bThumbnail)
|
||||
|
|
@ -9606,7 +9616,7 @@ NewThemeLink IncludeCss LoadingDescriptionEsc TemplatesLink LangLink IncludeBack
|
|||
private function hashFolderFullName($sFolderFullName)
|
||||
{
|
||||
return \in_array(\strtolower($sFolderFullName), array('inbox', 'sent', 'send', 'drafts',
|
||||
'spam', 'junk', 'bin', 'trash', 'archive', 'allmail')) ?
|
||||
'spam', 'junk', 'bin', 'trash', 'archive', 'allmail', 'all')) ?
|
||||
$sFolderFullName : \md5($sFolderFullName);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,273 +1,273 @@
|
|||
<?php
|
||||
|
||||
namespace RainLoop;
|
||||
|
||||
class Api
|
||||
{
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public static function RunResult()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @staticvar bool $bOne
|
||||
* @return bool
|
||||
*/
|
||||
public static function Handle()
|
||||
{
|
||||
static $bOne = null;
|
||||
if (null === $bOne)
|
||||
{
|
||||
$bOne = \class_exists('MailSo\Version');
|
||||
if ($bOne)
|
||||
{
|
||||
\RainLoop\Api::SetupDefaultMailSoConfig();
|
||||
|
||||
$bOne = \RainLoop\Api::RunResult();
|
||||
}
|
||||
}
|
||||
|
||||
return $bOne;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \RainLoop\Actions
|
||||
*/
|
||||
public static function Actions()
|
||||
{
|
||||
static $oActions = null;
|
||||
if (null === $oActions)
|
||||
{
|
||||
$oActions = \RainLoop\Actions::NewInstance();
|
||||
}
|
||||
|
||||
return $oActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \RainLoop\Application
|
||||
*/
|
||||
public static function Config()
|
||||
{
|
||||
return \RainLoop\Api::Actions()->Config();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \MailSo\Log\Logger
|
||||
*/
|
||||
public static function Logger()
|
||||
{
|
||||
return \RainLoop\Api::Actions()->Logger();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public static function SetupDefaultMailSoConfig()
|
||||
{
|
||||
if (\class_exists('MailSo\Config'))
|
||||
{
|
||||
if (\RainLoop\Api::Config()->Get('labs', 'disable_iconv_if_mbstring_supported', false) &&
|
||||
\MailSo\Base\Utils::IsMbStringSupported() && \MailSo\Config::$MBSTRING)
|
||||
{
|
||||
\MailSo\Config::$ICONV = false;
|
||||
}
|
||||
|
||||
\MailSo\Config::$MessageListFastSimpleSearch =
|
||||
!!\RainLoop\Api::Config()->Get('labs', 'imap_message_list_fast_simple_search', true);
|
||||
|
||||
\MailSo\Config::$MessageListCountLimitTrigger =
|
||||
(int) \RainLoop\Api::Config()->Get('labs', 'imap_message_list_count_limit_trigger', 0);
|
||||
|
||||
\MailSo\Config::$MessageListDateFilter =
|
||||
(int) \RainLoop\Api::Config()->Get('labs', 'imap_message_list_date_filter', 0);
|
||||
|
||||
\MailSo\Config::$MessageListPermanentFilter =
|
||||
\trim(\RainLoop\Api::Config()->Get('labs', 'imap_message_list_permanent_filter', ''));
|
||||
|
||||
\MailSo\Config::$MessageAllHeaders =
|
||||
!!\RainLoop\Api::Config()->Get('labs', 'imap_message_all_headers', false);
|
||||
|
||||
\MailSo\Config::$LargeThreadLimit =
|
||||
(int) \RainLoop\Api::Config()->Get('labs', 'imap_large_thread_limit', 50);
|
||||
|
||||
\MailSo\Config::$ImapTimeout =
|
||||
(int) \RainLoop\Api::Config()->Get('labs', 'imap_timeout', 300);
|
||||
|
||||
\MailSo\Config::$BoundaryPrefix = '_RainLoop_';
|
||||
|
||||
\MailSo\Config::$SystemLogger = \RainLoop\Api::Logger();
|
||||
|
||||
$sSslCafile = \RainLoop\Api::Config()->Get('ssl', 'cafile', '');
|
||||
$sSslCapath = \RainLoop\Api::Config()->Get('ssl', 'capath', '');
|
||||
|
||||
\RainLoop\Utils::$CookieDefaultPath = \RainLoop\Api::Config()->Get('labs', 'cookie_default_path', '');
|
||||
if (\RainLoop\Api::Config()->Get('labs', 'cookie_default_secure', false))
|
||||
{
|
||||
\RainLoop\Utils::$CookieDefaultSecure = true;
|
||||
}
|
||||
|
||||
if (!empty($sSslCafile) || !empty($sSslCapath))
|
||||
{
|
||||
\MailSo\Hooks::Add('Net.NetClient.StreamContextSettings/Filter', function (&$aStreamContextSettings) use ($sSslCafile, $sSslCapath) {
|
||||
if (isset($aStreamContextSettings['ssl']) && \is_array($aStreamContextSettings['ssl']))
|
||||
{
|
||||
if (empty($aStreamContextSettings['ssl']['cafile']) && !empty($sSslCafile))
|
||||
{
|
||||
$aStreamContextSettings['ssl']['cafile'] = $sSslCafile;
|
||||
}
|
||||
|
||||
if (empty($aStreamContextSettings['ssl']['capath']) && !empty($sSslCapath))
|
||||
{
|
||||
$aStreamContextSettings['ssl']['capath'] = $sSslCapath;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
\MailSo\Config::$HtmlStrictDebug = !!\RainLoop\Api::Config()->Get('debug', 'enable', false);
|
||||
|
||||
if (\RainLoop\Api::Config()->Get('labs', 'strict_html_parser', true))
|
||||
{
|
||||
\MailSo\Config::$HtmlStrictAllowedAttributes = array(
|
||||
// rainloop
|
||||
'data-wrp',
|
||||
// defaults
|
||||
'name',
|
||||
'dir', 'lang', 'style', 'title',
|
||||
'background', 'bgcolor', 'alt', 'height', 'width', 'src', 'href',
|
||||
'border', 'bordercolor', 'charset', 'direction', 'language',
|
||||
// a
|
||||
'coords', 'download', 'hreflang', 'shape',
|
||||
// body
|
||||
'alink', 'bgproperties', 'bottommargin', 'leftmargin', 'link', 'rightmargin', 'text', 'topmargin', 'vlink',
|
||||
'marginwidth', 'marginheight', 'offset',
|
||||
// button,
|
||||
'disabled', 'type', 'value',
|
||||
// col
|
||||
'align', 'valign',
|
||||
// font
|
||||
'color', 'face', 'size',
|
||||
// form
|
||||
'novalidate',
|
||||
// hr
|
||||
'noshade',
|
||||
// img
|
||||
'hspace', 'sizes', 'srcset', 'vspace', 'usemap',
|
||||
// input, textarea
|
||||
'checked', 'max', 'min', 'maxlength', 'multiple', 'pattern', 'placeholder', 'readonly', 'required', 'step', 'wrap',
|
||||
// label
|
||||
'for',
|
||||
// meter
|
||||
'low', 'high', 'optimum',
|
||||
// ol
|
||||
'reversed', 'start',
|
||||
// option
|
||||
'selected', 'label',
|
||||
// table
|
||||
'cols', 'rows', 'frame', 'rules', 'summary', 'cellpadding', 'cellspacing',
|
||||
// td
|
||||
'abbr', 'axis', 'colspan', 'rowspan', 'headers', 'nowrap'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public static function Version()
|
||||
{
|
||||
return APP_VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sEmail
|
||||
* @param string $sPassword
|
||||
* @param array $aAdditionalOptions = array()
|
||||
* @param bool $bUseTimeout = true
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function GetUserSsoHash($sEmail, $sPassword, $aAdditionalOptions = array(), $bUseTimeout = true)
|
||||
{
|
||||
$sSsoHash = \MailSo\Base\Utils::Sha1Rand($sEmail.$sPassword);
|
||||
|
||||
return \RainLoop\Api::Actions()->Cacher()->Set(\RainLoop\KeyPathHelper::SsoCacherKey($sSsoHash),
|
||||
\RainLoop\Utils::EncodeKeyValuesQ(array(
|
||||
'Email' => $sEmail,
|
||||
'Password' => $sPassword,
|
||||
'AdditionalOptions' => $aAdditionalOptions,
|
||||
'Time' => $bUseTimeout ? \time() : 0
|
||||
))) ? $sSsoHash : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sSsoHash
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function ClearUserSsoHash($sSsoHash)
|
||||
{
|
||||
return \RainLoop\Api::Actions()->Cacher()->Delete(\RainLoop\KeyPathHelper::SsoCacherKey($sSsoHash));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sEmail
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function ClearUserData($sEmail)
|
||||
{
|
||||
if (0 < \strlen($sEmail))
|
||||
{
|
||||
$sEmail = \MailSo\Base\Utils::IdnToAscii($sEmail);
|
||||
|
||||
$oStorageProvider = \RainLoop\Api::Actions()->StorageProvider();
|
||||
if ($oStorageProvider && $oStorageProvider->IsActive())
|
||||
{
|
||||
$oStorageProvider->DeleteStorage($sEmail);
|
||||
}
|
||||
|
||||
if (\RainLoop\Api::Actions()->AddressBookProvider() &&
|
||||
\RainLoop\Api::Actions()->AddressBookProvider()->IsActive())
|
||||
{
|
||||
\RainLoop\Api::Actions()->AddressBookProvider()->DeleteAllContacts($sEmail);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public static function LogoutCurrentLogginedUser()
|
||||
{
|
||||
\RainLoop\Utils::ClearCookie('rlsession');
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public static function ExitOnEnd()
|
||||
{
|
||||
if (!\defined('RAINLOOP_EXIT_ON_END'))
|
||||
{
|
||||
\define('RAINLOOP_EXIT_ON_END', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace RainLoop;
|
||||
|
||||
class Api
|
||||
{
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public static function RunResult()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @staticvar bool $bOne
|
||||
* @return bool
|
||||
*/
|
||||
public static function Handle()
|
||||
{
|
||||
static $bOne = null;
|
||||
if (null === $bOne)
|
||||
{
|
||||
$bOne = \class_exists('MailSo\Version');
|
||||
if ($bOne)
|
||||
{
|
||||
\RainLoop\Api::SetupDefaultMailSoConfig();
|
||||
|
||||
$bOne = \RainLoop\Api::RunResult();
|
||||
}
|
||||
}
|
||||
|
||||
return $bOne;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \RainLoop\Actions
|
||||
*/
|
||||
public static function Actions()
|
||||
{
|
||||
static $oActions = null;
|
||||
if (null === $oActions)
|
||||
{
|
||||
$oActions = \RainLoop\Actions::NewInstance();
|
||||
}
|
||||
|
||||
return $oActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \RainLoop\Application
|
||||
*/
|
||||
public static function Config()
|
||||
{
|
||||
return \RainLoop\Api::Actions()->Config();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \MailSo\Log\Logger
|
||||
*/
|
||||
public static function Logger()
|
||||
{
|
||||
return \RainLoop\Api::Actions()->Logger();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public static function SetupDefaultMailSoConfig()
|
||||
{
|
||||
if (\class_exists('MailSo\Config'))
|
||||
{
|
||||
if (\RainLoop\Api::Config()->Get('labs', 'disable_iconv_if_mbstring_supported', false) &&
|
||||
\MailSo\Base\Utils::IsMbStringSupported() && \MailSo\Config::$MBSTRING)
|
||||
{
|
||||
\MailSo\Config::$ICONV = false;
|
||||
}
|
||||
|
||||
\MailSo\Config::$MessageListFastSimpleSearch =
|
||||
!!\RainLoop\Api::Config()->Get('labs', 'imap_message_list_fast_simple_search', true);
|
||||
|
||||
\MailSo\Config::$MessageListCountLimitTrigger =
|
||||
(int) \RainLoop\Api::Config()->Get('labs', 'imap_message_list_count_limit_trigger', 0);
|
||||
|
||||
\MailSo\Config::$MessageListDateFilter =
|
||||
(int) \RainLoop\Api::Config()->Get('labs', 'imap_message_list_date_filter', 0);
|
||||
|
||||
\MailSo\Config::$MessageListPermanentFilter =
|
||||
\trim(\RainLoop\Api::Config()->Get('labs', 'imap_message_list_permanent_filter', ''));
|
||||
|
||||
\MailSo\Config::$MessageAllHeaders =
|
||||
!!\RainLoop\Api::Config()->Get('labs', 'imap_message_all_headers', false);
|
||||
|
||||
\MailSo\Config::$LargeThreadLimit =
|
||||
(int) \RainLoop\Api::Config()->Get('labs', 'imap_large_thread_limit', 50);
|
||||
|
||||
\MailSo\Config::$ImapTimeout =
|
||||
(int) \RainLoop\Api::Config()->Get('labs', 'imap_timeout', 300);
|
||||
|
||||
\MailSo\Config::$BoundaryPrefix = '_RainLoop_';
|
||||
|
||||
\MailSo\Config::$SystemLogger = \RainLoop\Api::Logger();
|
||||
|
||||
$sSslCafile = \RainLoop\Api::Config()->Get('ssl', 'cafile', '');
|
||||
$sSslCapath = \RainLoop\Api::Config()->Get('ssl', 'capath', '');
|
||||
|
||||
\RainLoop\Utils::$CookieDefaultPath = \RainLoop\Api::Config()->Get('labs', 'cookie_default_path', '');
|
||||
if (\RainLoop\Api::Config()->Get('labs', 'cookie_default_secure', false))
|
||||
{
|
||||
\RainLoop\Utils::$CookieDefaultSecure = true;
|
||||
}
|
||||
|
||||
if (!empty($sSslCafile) || !empty($sSslCapath))
|
||||
{
|
||||
\MailSo\Hooks::Add('Net.NetClient.StreamContextSettings/Filter', function (&$aStreamContextSettings) use ($sSslCafile, $sSslCapath) {
|
||||
if (isset($aStreamContextSettings['ssl']) && \is_array($aStreamContextSettings['ssl']))
|
||||
{
|
||||
if (empty($aStreamContextSettings['ssl']['cafile']) && !empty($sSslCafile))
|
||||
{
|
||||
$aStreamContextSettings['ssl']['cafile'] = $sSslCafile;
|
||||
}
|
||||
|
||||
if (empty($aStreamContextSettings['ssl']['capath']) && !empty($sSslCapath))
|
||||
{
|
||||
$aStreamContextSettings['ssl']['capath'] = $sSslCapath;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
\MailSo\Config::$HtmlStrictDebug = !!\RainLoop\Api::Config()->Get('debug', 'enable', false);
|
||||
|
||||
if (\RainLoop\Api::Config()->Get('labs', 'strict_html_parser', true))
|
||||
{
|
||||
\MailSo\Config::$HtmlStrictAllowedAttributes = array(
|
||||
// rainloop
|
||||
'data-wrp',
|
||||
// defaults
|
||||
'name',
|
||||
'dir', 'lang', 'style', 'title',
|
||||
'background', 'bgcolor', 'alt', 'height', 'width', 'src', 'href',
|
||||
'border', 'bordercolor', 'charset', 'direction', 'language',
|
||||
// a
|
||||
'coords', 'download', 'hreflang', 'shape',
|
||||
// body
|
||||
'alink', 'bgproperties', 'bottommargin', 'leftmargin', 'link', 'rightmargin', 'text', 'topmargin', 'vlink',
|
||||
'marginwidth', 'marginheight', 'offset',
|
||||
// button,
|
||||
'disabled', 'type', 'value',
|
||||
// col
|
||||
'align', 'valign',
|
||||
// font
|
||||
'color', 'face', 'size',
|
||||
// form
|
||||
'novalidate',
|
||||
// hr
|
||||
'noshade',
|
||||
// img
|
||||
'hspace', 'sizes', 'srcset', 'vspace', 'usemap',
|
||||
// input, textarea
|
||||
'checked', 'max', 'min', 'maxlength', 'multiple', 'pattern', 'placeholder', 'readonly', 'required', 'step', 'wrap',
|
||||
// label
|
||||
'for',
|
||||
// meter
|
||||
'low', 'high', 'optimum',
|
||||
// ol
|
||||
'reversed', 'start',
|
||||
// option
|
||||
'selected', 'label',
|
||||
// table
|
||||
'cols', 'rows', 'frame', 'rules', 'summary', 'cellpadding', 'cellspacing',
|
||||
// td
|
||||
'abbr', 'axis', 'colspan', 'rowspan', 'headers', 'nowrap'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public static function Version()
|
||||
{
|
||||
return APP_VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sEmail
|
||||
* @param string $sPassword
|
||||
* @param array $aAdditionalOptions = array()
|
||||
* @param bool $bUseTimeout = true
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function GetUserSsoHash($sEmail, $sPassword, $aAdditionalOptions = array(), $bUseTimeout = true)
|
||||
{
|
||||
$sSsoHash = \MailSo\Base\Utils::Sha1Rand(\md5($sEmail).\md5($sPassword));
|
||||
|
||||
return \RainLoop\Api::Actions()->Cacher()->Set(\RainLoop\KeyPathHelper::SsoCacherKey($sSsoHash),
|
||||
\RainLoop\Utils::EncodeKeyValuesQ(array(
|
||||
'Email' => $sEmail,
|
||||
'Password' => $sPassword,
|
||||
'AdditionalOptions' => $aAdditionalOptions,
|
||||
'Time' => $bUseTimeout ? \time() : 0
|
||||
))) ? $sSsoHash : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sSsoHash
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function ClearUserSsoHash($sSsoHash)
|
||||
{
|
||||
return \RainLoop\Api::Actions()->Cacher()->Delete(\RainLoop\KeyPathHelper::SsoCacherKey($sSsoHash));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sEmail
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function ClearUserData($sEmail)
|
||||
{
|
||||
if (0 < \strlen($sEmail))
|
||||
{
|
||||
$sEmail = \MailSo\Base\Utils::IdnToAscii($sEmail);
|
||||
|
||||
$oStorageProvider = \RainLoop\Api::Actions()->StorageProvider();
|
||||
if ($oStorageProvider && $oStorageProvider->IsActive())
|
||||
{
|
||||
$oStorageProvider->DeleteStorage($sEmail);
|
||||
}
|
||||
|
||||
if (\RainLoop\Api::Actions()->AddressBookProvider() &&
|
||||
\RainLoop\Api::Actions()->AddressBookProvider()->IsActive())
|
||||
{
|
||||
\RainLoop\Api::Actions()->AddressBookProvider()->DeleteAllContacts($sEmail);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public static function LogoutCurrentLogginedUser()
|
||||
{
|
||||
\RainLoop\Utils::ClearCookie('rlsession');
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public static function ExitOnEnd()
|
||||
{
|
||||
if (!\defined('RAINLOOP_EXIT_ON_END'))
|
||||
{
|
||||
\define('RAINLOOP_EXIT_ON_END', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -200,7 +200,6 @@ class Application extends \RainLoop\Config\AbstractConfig
|
|||
'x_frame_options_header' => array(''),
|
||||
|
||||
'openpgp' => array(false),
|
||||
'openpgp_public_key_server' => array(''),
|
||||
|
||||
'admin_login' => array('admin', 'Login and password for web admin panel'),
|
||||
'admin_password' => array('12345'),
|
||||
|
|
|
|||
|
|
@ -1,404 +1,410 @@
|
|||
<?php
|
||||
|
||||
namespace RainLoop\Providers\Domain;
|
||||
|
||||
class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $sDomainPath;
|
||||
|
||||
/**
|
||||
* @var \MailSo\Cache\CacheClient
|
||||
*/
|
||||
protected $oCacher;
|
||||
|
||||
/**
|
||||
* @param string $sDomainPath
|
||||
* @param \MailSo\Cache\CacheClient $oCacher = null
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($sDomainPath, $oCacher = null)
|
||||
{
|
||||
$this->sDomainPath = \rtrim(\trim($sDomainPath), '\\/');
|
||||
$this->oCacher = $oCacher;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sName
|
||||
* @param bool $bBack = false
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function codeFileName($sName, $bBack = false)
|
||||
{
|
||||
if ($bBack && 'default' === $sName)
|
||||
{
|
||||
return '*';
|
||||
}
|
||||
else if (!$bBack && '*' === $sName)
|
||||
{
|
||||
return 'default';
|
||||
}
|
||||
|
||||
if ($bBack)
|
||||
{
|
||||
$sName = \MailSo\Base\Utils::IdnToUtf8($sName, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
$sName = \MailSo\Base\Utils::IdnToAscii($sName, true);
|
||||
}
|
||||
|
||||
return $bBack ? \str_replace('_wildcard_', '*', $sName) : \str_replace('*', '_wildcard_', $sName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function wildcardDomainsCacheKey()
|
||||
{
|
||||
return '/WildCard/DomainCache/'.\md5(APP_VERSION.APP_PRIVATE_DATA_NAME).'/';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getWildcardDomainsLine()
|
||||
{
|
||||
if ($this->oCacher)
|
||||
{
|
||||
$sResult = $this->oCacher->Get($this->wildcardDomainsCacheKey());
|
||||
if (0 < \strlen($sResult))
|
||||
{
|
||||
return $sResult;
|
||||
}
|
||||
}
|
||||
|
||||
$sResult = '';
|
||||
$aNames = array();
|
||||
|
||||
$aList = \glob($this->sDomainPath.'/*.ini');
|
||||
foreach ($aList as $sFile)
|
||||
{
|
||||
$sName = \substr(\basename($sFile), 0, -4);
|
||||
if ('default' === $sName || false !== \strpos($sName, '_wildcard_'))
|
||||
{
|
||||
$aNames[] = $this->codeFileName($sName, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (0 < \count($aNames))
|
||||
{
|
||||
\rsort($aNames, SORT_STRING);
|
||||
$sResult = \implode(' ', $aNames);
|
||||
}
|
||||
|
||||
if ($this->oCacher)
|
||||
{
|
||||
$this->oCacher->Set($this->wildcardDomainsCacheKey(), $sResult);
|
||||
}
|
||||
|
||||
return $sResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sName
|
||||
* @param bool $bFindWithWildCard = false
|
||||
* @param bool $bCheckDisabled = true
|
||||
* @param bool $bCheckAliases = true
|
||||
*
|
||||
* @return \RainLoop\Model\Domain|null
|
||||
*/
|
||||
public function Load($sName, $bFindWithWildCard = false, $bCheckDisabled = true, $bCheckAliases = true)
|
||||
{
|
||||
$mResult = null;
|
||||
|
||||
$sDisabled = '';
|
||||
$sFoundedValue = '';
|
||||
|
||||
$sRealFileName = $this->codeFileName($sName);
|
||||
|
||||
if (\file_exists($this->sDomainPath.'/disabled'))
|
||||
{
|
||||
$sDisabled = @\file_get_contents($this->sDomainPath.'/disabled');
|
||||
}
|
||||
|
||||
if (\file_exists($this->sDomainPath.'/'.$sRealFileName.'.ini') &&
|
||||
(!$bCheckDisabled || 0 === \strlen($sDisabled) || false === \strpos(','.$sDisabled.',', ','.\MailSo\Base\Utils::IdnToAscii($sName, true).',')))
|
||||
{
|
||||
$aDomain = \RainLoop\Utils::CustomParseIniFile($this->sDomainPath.'/'.$sRealFileName.'.ini');
|
||||
// if ($bCheckAliases && !empty($aDomain['alias']))
|
||||
// {
|
||||
// $oDomain = $this->Load($aDomain['alias'], false, false, false);
|
||||
// if ($oDomain && $oDomain instanceof \RainLoop\Model\Domain)
|
||||
// {
|
||||
// $oDomain->SetAliasName($sName);
|
||||
// }
|
||||
//
|
||||
// return $oDomain;
|
||||
// }
|
||||
|
||||
// fix misspellings (#119)
|
||||
if (\is_array($aDomain))
|
||||
{
|
||||
if (isset($aDomain['smpt_host']))
|
||||
{
|
||||
$aDomain['smtp_host'] = $aDomain['smpt_host'];
|
||||
}
|
||||
|
||||
if (isset($aDomain['smpt_port']))
|
||||
{
|
||||
$aDomain['smtp_port'] = $aDomain['smpt_port'];
|
||||
}
|
||||
|
||||
if (isset($aDomain['smpt_secure']))
|
||||
{
|
||||
$aDomain['smtp_secure'] = $aDomain['smpt_secure'];
|
||||
}
|
||||
|
||||
if (isset($aDomain['smpt_auth']))
|
||||
{
|
||||
$aDomain['smtp_auth'] = $aDomain['smpt_auth'];
|
||||
}
|
||||
}
|
||||
//---
|
||||
|
||||
$mResult = \RainLoop\Model\Domain::NewInstanceFromDomainConfigArray($sName, $aDomain);
|
||||
}
|
||||
else if ($bCheckAliases && \file_exists($this->sDomainPath.'/'.$sRealFileName.'.alias') &&
|
||||
(!$bCheckDisabled || 0 === \strlen($sDisabled) || false === \strpos(','.$sDisabled.',', ','.\MailSo\Base\Utils::IdnToAscii($sName, true).',')))
|
||||
{
|
||||
$sAlias = \trim(\file_get_contents($this->sDomainPath.'/'.$sRealFileName.'.alias'));
|
||||
if (!empty($sAlias))
|
||||
{
|
||||
$oDomain = $this->Load($sAlias, false, false, false);
|
||||
if ($oDomain && $oDomain instanceof \RainLoop\Model\Domain)
|
||||
{
|
||||
$oDomain->SetAliasName($sName);
|
||||
}
|
||||
|
||||
return $oDomain;
|
||||
}
|
||||
}
|
||||
else if ($bFindWithWildCard)
|
||||
{
|
||||
$sNames = $this->getWildcardDomainsLine();
|
||||
if (0 < \strlen($sNames))
|
||||
{
|
||||
if (\RainLoop\Plugins\Helper::ValidateWildcardValues(
|
||||
\MailSo\Base\Utils::IdnToUtf8($sName, true), $sNames, $sFoundedValue) && 0 < \strlen($sFoundedValue))
|
||||
{
|
||||
if (!$bCheckDisabled || 0 === \strlen($sDisabled) || false === \strpos(','.$sDisabled.',', ','.$sFoundedValue.','))
|
||||
{
|
||||
$mResult = $this->Load($sFoundedValue, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $mResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \RainLoop\Model\Domain $oDomain
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function Save(\RainLoop\Model\Domain $oDomain)
|
||||
{
|
||||
$sRealFileName = $this->codeFileName($oDomain->Name());
|
||||
|
||||
if ($this->oCacher)
|
||||
{
|
||||
$this->oCacher->Delete($this->wildcardDomainsCacheKey());
|
||||
}
|
||||
|
||||
$mResult = \file_put_contents($this->sDomainPath.'/'.$sRealFileName.'.ini', $oDomain->ToIniString());
|
||||
return \is_int($mResult) && 0 < $mResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sName
|
||||
* @param string $sAlias
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function SaveAlias($sName, $sAlias)
|
||||
{
|
||||
$sRealFileName = $this->codeFileName($sName);
|
||||
|
||||
if ($this->oCacher)
|
||||
{
|
||||
$this->oCacher->Delete($this->wildcardDomainsCacheKey());
|
||||
}
|
||||
|
||||
$mResult = \file_put_contents($this->sDomainPath.'/'.$sRealFileName.'.alias', $sAlias);
|
||||
return \is_int($mResult) && 0 < $mResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sName
|
||||
* @param bool $bDisable
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function Disable($sName, $bDisable)
|
||||
{
|
||||
$sName = \MailSo\Base\Utils::IdnToAscii($sName, true);
|
||||
|
||||
$sFile = '';
|
||||
if (\file_exists($this->sDomainPath.'/disabled'))
|
||||
{
|
||||
$sFile = @\file_get_contents($this->sDomainPath.'/disabled');
|
||||
}
|
||||
|
||||
$aResult = array();
|
||||
$aNames = \explode(',', $sFile);
|
||||
if ($bDisable)
|
||||
{
|
||||
\array_push($aNames, $sName);
|
||||
$aResult = $aNames;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($aNames as $sItem)
|
||||
{
|
||||
if ($sName !== $sItem)
|
||||
{
|
||||
$aResult[] = $sItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$aResult = \array_unique($aResult);
|
||||
return false !== \file_put_contents($this->sDomainPath.'/disabled', \trim(\implode(',', $aResult), ', '));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sName
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function Delete($sName)
|
||||
{
|
||||
$bResult = true;
|
||||
$sRealFileName = $this->codeFileName($sName);
|
||||
|
||||
if (0 < \strlen($sName))
|
||||
{
|
||||
if (\file_exists($this->sDomainPath.'/'.$sRealFileName.'.ini'))
|
||||
{
|
||||
$bResult = \unlink($this->sDomainPath.'/'.$sRealFileName.'.ini');
|
||||
}
|
||||
else if (\file_exists($this->sDomainPath.'/'.$sRealFileName.'.alias'))
|
||||
{
|
||||
$bResult = \unlink($this->sDomainPath.'/'.$sRealFileName.'.alias');
|
||||
}
|
||||
}
|
||||
|
||||
if ($bResult)
|
||||
{
|
||||
$this->Disable($sName, false);
|
||||
}
|
||||
|
||||
if ($this->oCacher)
|
||||
{
|
||||
$this->oCacher->Delete($this->wildcardDomainsCacheKey());
|
||||
}
|
||||
|
||||
return $bResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $iOffset = 0
|
||||
* @param int $iLimit = 20
|
||||
* @param int $sSearch = ''
|
||||
* @param bool $bIncludeAliases = true
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function GetList($iOffset = 0, $iLimit = 20, $sSearch = '', $bIncludeAliases = true)
|
||||
{
|
||||
$aResult = array();
|
||||
$aWildCards = array();
|
||||
$aAliases = array();
|
||||
|
||||
$aList = \glob($this->sDomainPath.'/*.{ini,alias}', GLOB_BRACE);
|
||||
|
||||
foreach ($aList as $sFile)
|
||||
{
|
||||
$sName = \basename($sFile);
|
||||
$bAlias = '.alias' === \substr($sName, -6);
|
||||
|
||||
$sName = \preg_replace('/\.(ini|alias)$/', '', $sName);
|
||||
$sName = $this->codeFileName($sName, true);
|
||||
|
||||
if ($bAlias)
|
||||
{
|
||||
if ($bIncludeAliases)
|
||||
{
|
||||
$aAliases[] = $sName;
|
||||
}
|
||||
}
|
||||
else if (false !== \strpos($sName, '*'))
|
||||
{
|
||||
$aWildCards[] = $sName;
|
||||
}
|
||||
else
|
||||
{
|
||||
$aResult[] = $sName;
|
||||
}
|
||||
}
|
||||
|
||||
\sort($aResult, SORT_STRING);
|
||||
\sort($aAliases, SORT_STRING);
|
||||
\rsort($aWildCards, SORT_STRING);
|
||||
|
||||
$aResult = \array_merge($aResult, $aAliases, $aWildCards);
|
||||
|
||||
$iOffset = (0 > $iOffset) ? 0 : $iOffset;
|
||||
$iLimit = (0 > $iLimit) ? 0 : ((999 < $iLimit) ? 999 : $iLimit);
|
||||
|
||||
$aResult = \array_slice($aResult, $iOffset, $iLimit);
|
||||
|
||||
$aDisabledNames = array();
|
||||
if (0 < \count($aResult) && \file_exists($this->sDomainPath.'/disabled'))
|
||||
{
|
||||
$sDisabled = @\file_get_contents($this->sDomainPath.'/disabled');
|
||||
if (false !== $sDisabled && 0 < strlen($sDisabled))
|
||||
{
|
||||
$aDisabledNames = \explode(',', $sDisabled);
|
||||
$aDisabledNames = \array_unique($aDisabledNames);
|
||||
foreach ($aDisabledNames as $iIndex => $sValue)
|
||||
{
|
||||
$aDisabledNames[$iIndex] = \MailSo\Base\Utils::IdnToUtf8($sValue, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$aReturn = array();
|
||||
foreach ($aResult as $sName)
|
||||
{
|
||||
$aReturn[$sName] = array(
|
||||
!\in_array($sName, $aDisabledNames),
|
||||
\in_array($sName, $aAliases)
|
||||
);
|
||||
}
|
||||
|
||||
return $aReturn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sSearch = ''
|
||||
* @param bool $bIncludeAliases = true
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function Count($sSearch = '', $bIncludeAliases = true)
|
||||
{
|
||||
return \count($this->GetList(0, 999, $sSearch, $bIncludeAliases));
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace RainLoop\Providers\Domain;
|
||||
|
||||
class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $sDomainPath;
|
||||
|
||||
/**
|
||||
* @var \MailSo\Cache\CacheClient
|
||||
*/
|
||||
protected $oCacher;
|
||||
|
||||
/**
|
||||
* @param string $sDomainPath
|
||||
* @param \MailSo\Cache\CacheClient $oCacher = null
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($sDomainPath, $oCacher = null)
|
||||
{
|
||||
$this->sDomainPath = \rtrim(\trim($sDomainPath), '\\/');
|
||||
$this->oCacher = $oCacher;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sName
|
||||
* @param bool $bBack = false
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function codeFileName($sName, $bBack = false)
|
||||
{
|
||||
if ($bBack && 'default' === $sName)
|
||||
{
|
||||
return '*';
|
||||
}
|
||||
else if (!$bBack && '*' === $sName)
|
||||
{
|
||||
return 'default';
|
||||
}
|
||||
|
||||
if ($bBack)
|
||||
{
|
||||
$sName = \MailSo\Base\Utils::IdnToUtf8($sName, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
$sName = \MailSo\Base\Utils::IdnToAscii($sName, true);
|
||||
}
|
||||
|
||||
return $bBack ? \str_replace('_wildcard_', '*', $sName) : \str_replace('*', '_wildcard_', $sName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function wildcardDomainsCacheKey()
|
||||
{
|
||||
return '/WildCard/DomainCache/'.\md5(APP_VERSION.APP_PRIVATE_DATA_NAME).'/';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getWildcardDomainsLine()
|
||||
{
|
||||
if ($this->oCacher)
|
||||
{
|
||||
$sResult = $this->oCacher->Get($this->wildcardDomainsCacheKey());
|
||||
if (0 < \strlen($sResult))
|
||||
{
|
||||
return $sResult;
|
||||
}
|
||||
}
|
||||
|
||||
$sResult = '';
|
||||
$aNames = array();
|
||||
|
||||
$aList = \glob($this->sDomainPath.'/*.ini');
|
||||
foreach ($aList as $sFile)
|
||||
{
|
||||
$sName = \substr(\basename($sFile), 0, -4);
|
||||
if ('default' === $sName || false !== \strpos($sName, '_wildcard_'))
|
||||
{
|
||||
$aNames[] = $this->codeFileName($sName, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (0 < \count($aNames))
|
||||
{
|
||||
\rsort($aNames, SORT_STRING);
|
||||
$sResult = \implode(' ', $aNames);
|
||||
}
|
||||
|
||||
if ($this->oCacher)
|
||||
{
|
||||
$this->oCacher->Set($this->wildcardDomainsCacheKey(), $sResult);
|
||||
}
|
||||
|
||||
return $sResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sName
|
||||
* @param bool $bFindWithWildCard = false
|
||||
* @param bool $bCheckDisabled = true
|
||||
* @param bool $bCheckAliases = true
|
||||
*
|
||||
* @return \RainLoop\Model\Domain|null
|
||||
*/
|
||||
public function Load($sName, $bFindWithWildCard = false, $bCheckDisabled = true, $bCheckAliases = true)
|
||||
{
|
||||
$mResult = null;
|
||||
|
||||
$sDisabled = '';
|
||||
$sFoundedValue = '';
|
||||
|
||||
$sRealFileName = $this->codeFileName($sName);
|
||||
|
||||
if (\file_exists($this->sDomainPath.'/disabled'))
|
||||
{
|
||||
$sDisabled = @\file_get_contents($this->sDomainPath.'/disabled');
|
||||
}
|
||||
|
||||
if (\file_exists($this->sDomainPath.'/'.$sRealFileName.'.ini') &&
|
||||
(!$bCheckDisabled || 0 === \strlen($sDisabled) || false === \strpos(','.$sDisabled.',', ','.\MailSo\Base\Utils::IdnToAscii($sName, true).',')))
|
||||
{
|
||||
$aDomain = \RainLoop\Utils::CustomParseIniFile($this->sDomainPath.'/'.$sRealFileName.'.ini');
|
||||
// if ($bCheckAliases && !empty($aDomain['alias']))
|
||||
// {
|
||||
// $oDomain = $this->Load($aDomain['alias'], false, false, false);
|
||||
// if ($oDomain && $oDomain instanceof \RainLoop\Model\Domain)
|
||||
// {
|
||||
// $oDomain->SetAliasName($sName);
|
||||
// }
|
||||
//
|
||||
// return $oDomain;
|
||||
// }
|
||||
|
||||
// fix misspellings (#119)
|
||||
if (\is_array($aDomain))
|
||||
{
|
||||
if (isset($aDomain['smpt_host']))
|
||||
{
|
||||
$aDomain['smtp_host'] = $aDomain['smpt_host'];
|
||||
}
|
||||
|
||||
if (isset($aDomain['smpt_port']))
|
||||
{
|
||||
$aDomain['smtp_port'] = $aDomain['smpt_port'];
|
||||
}
|
||||
|
||||
if (isset($aDomain['smpt_secure']))
|
||||
{
|
||||
$aDomain['smtp_secure'] = $aDomain['smpt_secure'];
|
||||
}
|
||||
|
||||
if (isset($aDomain['smpt_auth']))
|
||||
{
|
||||
$aDomain['smtp_auth'] = $aDomain['smpt_auth'];
|
||||
}
|
||||
}
|
||||
//---
|
||||
|
||||
$mResult = \RainLoop\Model\Domain::NewInstanceFromDomainConfigArray($sName, $aDomain);
|
||||
}
|
||||
else if ($bCheckAliases && \file_exists($this->sDomainPath.'/'.$sRealFileName.'.alias') &&
|
||||
(!$bCheckDisabled || 0 === \strlen($sDisabled) || false === \strpos(','.$sDisabled.',', ','.\MailSo\Base\Utils::IdnToAscii($sName, true).',')))
|
||||
{
|
||||
$sAlias = \trim(\file_get_contents($this->sDomainPath.'/'.$sRealFileName.'.alias'));
|
||||
if (!empty($sAlias))
|
||||
{
|
||||
$oDomain = $this->Load($sAlias, false, false, false);
|
||||
if ($oDomain && $oDomain instanceof \RainLoop\Model\Domain)
|
||||
{
|
||||
$oDomain->SetAliasName($sName);
|
||||
}
|
||||
|
||||
return $oDomain;
|
||||
}
|
||||
}
|
||||
else if ($bFindWithWildCard)
|
||||
{
|
||||
$sNames = $this->getWildcardDomainsLine();
|
||||
if (0 < \strlen($sNames))
|
||||
{
|
||||
if (\RainLoop\Plugins\Helper::ValidateWildcardValues(
|
||||
\MailSo\Base\Utils::IdnToUtf8($sName, true), $sNames, $sFoundedValue) && 0 < \strlen($sFoundedValue))
|
||||
{
|
||||
if (!$bCheckDisabled || 0 === \strlen($sDisabled) || false === \strpos(','.$sDisabled.',', ','.$sFoundedValue.','))
|
||||
{
|
||||
$mResult = $this->Load($sFoundedValue, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $mResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \RainLoop\Model\Domain $oDomain
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function Save(\RainLoop\Model\Domain $oDomain)
|
||||
{
|
||||
$sRealFileName = $this->codeFileName($oDomain->Name());
|
||||
|
||||
if ($this->oCacher)
|
||||
{
|
||||
$this->oCacher->Delete($this->wildcardDomainsCacheKey());
|
||||
}
|
||||
|
||||
$mResult = \file_put_contents($this->sDomainPath.'/'.$sRealFileName.'.ini', $oDomain->ToIniString());
|
||||
return \is_int($mResult) && 0 < $mResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sName
|
||||
* @param string $sAlias
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function SaveAlias($sName, $sAlias)
|
||||
{
|
||||
$sRealFileName = $this->codeFileName($sName);
|
||||
|
||||
if ($this->oCacher)
|
||||
{
|
||||
$this->oCacher->Delete($this->wildcardDomainsCacheKey());
|
||||
}
|
||||
|
||||
$mResult = \file_put_contents($this->sDomainPath.'/'.$sRealFileName.'.alias', $sAlias);
|
||||
return \is_int($mResult) && 0 < $mResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sName
|
||||
* @param bool $bDisable
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function Disable($sName, $bDisable)
|
||||
{
|
||||
$sName = \MailSo\Base\Utils::IdnToAscii($sName, true);
|
||||
|
||||
$sFile = '';
|
||||
if (\file_exists($this->sDomainPath.'/disabled'))
|
||||
{
|
||||
$sFile = @\file_get_contents($this->sDomainPath.'/disabled');
|
||||
}
|
||||
|
||||
$aResult = array();
|
||||
$aNames = \explode(',', $sFile);
|
||||
if ($bDisable)
|
||||
{
|
||||
\array_push($aNames, $sName);
|
||||
$aResult = $aNames;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($aNames as $sItem)
|
||||
{
|
||||
if ($sName !== $sItem)
|
||||
{
|
||||
$aResult[] = $sItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$aResult = \array_unique($aResult);
|
||||
return false !== \file_put_contents($this->sDomainPath.'/disabled', \trim(\implode(',', $aResult), ', '));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sName
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function Delete($sName)
|
||||
{
|
||||
$bResult = true;
|
||||
$sRealFileName = $this->codeFileName($sName);
|
||||
|
||||
if (0 < \strlen($sName))
|
||||
{
|
||||
if (\file_exists($this->sDomainPath.'/'.$sRealFileName.'.ini'))
|
||||
{
|
||||
$bResult = \unlink($this->sDomainPath.'/'.$sRealFileName.'.ini');
|
||||
}
|
||||
else if (\file_exists($this->sDomainPath.'/'.$sRealFileName.'.alias'))
|
||||
{
|
||||
$bResult = \unlink($this->sDomainPath.'/'.$sRealFileName.'.alias');
|
||||
}
|
||||
}
|
||||
|
||||
if ($bResult)
|
||||
{
|
||||
$this->Disable($sName, false);
|
||||
}
|
||||
|
||||
if ($this->oCacher)
|
||||
{
|
||||
$this->oCacher->Delete($this->wildcardDomainsCacheKey());
|
||||
}
|
||||
|
||||
return $bResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $iOffset = 0
|
||||
* @param int $iLimit = 20
|
||||
* @param int $sSearch = ''
|
||||
* @param bool $bIncludeAliases = true
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function GetList($iOffset = 0, $iLimit = 20, $sSearch = '', $bIncludeAliases = true)
|
||||
{
|
||||
$aResult = array();
|
||||
$aWildCards = array();
|
||||
$aAliases = array();
|
||||
|
||||
// $aList = \glob($this->sDomainPath.'/*.{ini,alias}', GLOB_BRACE);
|
||||
$aList = @\array_diff(\scandir($this->sDomainPath), array('.', '..'));
|
||||
if (\is_array($aList))
|
||||
{
|
||||
foreach ($aList as $sFile)
|
||||
{
|
||||
$sName = $sFile;
|
||||
if ('.ini' === \substr($sName, -4) || '.alias' === \substr($sName, -6))
|
||||
{
|
||||
$bAlias = '.alias' === \substr($sName, -6);
|
||||
|
||||
$sName = \preg_replace('/\.(ini|alias)$/', '', $sName);
|
||||
$sName = $this->codeFileName($sName, true);
|
||||
|
||||
if ($bAlias)
|
||||
{
|
||||
if ($bIncludeAliases)
|
||||
{
|
||||
$aAliases[] = $sName;
|
||||
}
|
||||
}
|
||||
else if (false !== \strpos($sName, '*'))
|
||||
{
|
||||
$aWildCards[] = $sName;
|
||||
}
|
||||
else
|
||||
{
|
||||
$aResult[] = $sName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
\sort($aResult, SORT_STRING);
|
||||
\sort($aAliases, SORT_STRING);
|
||||
\rsort($aWildCards, SORT_STRING);
|
||||
|
||||
$aResult = \array_merge($aResult, $aAliases, $aWildCards);
|
||||
|
||||
$iOffset = (0 > $iOffset) ? 0 : $iOffset;
|
||||
$iLimit = (0 > $iLimit) ? 0 : ((999 < $iLimit) ? 999 : $iLimit);
|
||||
|
||||
$aResult = \array_slice($aResult, $iOffset, $iLimit);
|
||||
|
||||
$aDisabledNames = array();
|
||||
if (0 < \count($aResult) && \file_exists($this->sDomainPath.'/disabled'))
|
||||
{
|
||||
$sDisabled = @\file_get_contents($this->sDomainPath.'/disabled');
|
||||
if (false !== $sDisabled && 0 < strlen($sDisabled))
|
||||
{
|
||||
$aDisabledNames = \explode(',', $sDisabled);
|
||||
$aDisabledNames = \array_unique($aDisabledNames);
|
||||
foreach ($aDisabledNames as $iIndex => $sValue)
|
||||
{
|
||||
$aDisabledNames[$iIndex] = \MailSo\Base\Utils::IdnToUtf8($sValue, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$aReturn = array();
|
||||
foreach ($aResult as $sName)
|
||||
{
|
||||
$aReturn[$sName] = array(
|
||||
!\in_array($sName, $aDisabledNames),
|
||||
\in_array($sName, $aAliases)
|
||||
);
|
||||
}
|
||||
|
||||
return $aReturn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sSearch = ''
|
||||
* @param bool $bIncludeAliases = true
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function Count($sSearch = '', $bIncludeAliases = true)
|
||||
{
|
||||
return \count($this->GetList(0, 999, $sSearch, $bIncludeAliases));
|
||||
}
|
||||
}
|
||||
392
rainloop/v/0.0.0/app/libraries/RainLoop/Providers/Prem.php
Normal file
392
rainloop/v/0.0.0/app/libraries/RainLoop/Providers/Prem.php
Normal file
|
|
@ -0,0 +1,392 @@
|
|||
<?php
|
||||
|
||||
namespace RainLoop\Providers;
|
||||
|
||||
class Prem
|
||||
{
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($oConfig, $oLogger, $oCacher)
|
||||
{
|
||||
$this->oConfig = $oConfig;
|
||||
$this->oLogger = $oLogger;
|
||||
$this->oCacher = $oCacher;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function Type()
|
||||
{
|
||||
static $bResult = null;
|
||||
if (null === $bResult)
|
||||
{
|
||||
$bResult = $this->Parser($this->Fetcher(false, true));
|
||||
}
|
||||
|
||||
return $bResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function IsActive()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sInput
|
||||
* @param int $iExpired = 0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function Parser($sInput, &$iExpired = 0)
|
||||
{
|
||||
$aMatch = array();
|
||||
if (\preg_match('/^EXPIRED:([\d]+)$/', $sInput, $aMatch))
|
||||
{
|
||||
$iExpired = (int) $aMatch[1];
|
||||
return \time() < $iExpired;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $aAppData
|
||||
*/
|
||||
public function PopulateAppData(&$aAppData)
|
||||
{
|
||||
if (\is_array($aAppData))
|
||||
{
|
||||
$aAppData['Community'] = false;
|
||||
|
||||
$oConfig = $this->oConfig;
|
||||
if ($oConfig && $this->Type())
|
||||
{
|
||||
$aAppData['PremType'] = true;
|
||||
$aAppData['LoginLogo'] = $oConfig->Get('branding', 'login_logo', '');
|
||||
$aAppData['LoginBackground'] = $oConfig->Get('branding', 'login_background', '');
|
||||
$aAppData['LoginCss'] = $oConfig->Get('branding', 'login_css', '');
|
||||
$aAppData['LoginDescription'] = $oConfig->Get('branding', 'login_desc', '');
|
||||
$aAppData['LoginPowered'] = !!$oConfig->Get('branding', 'login_powered', true);
|
||||
$aAppData['UserLogo'] = $oConfig->Get('branding', 'user_logo', '');
|
||||
$aAppData['UserLogoTitle'] = $oConfig->Get('branding', 'user_logo_title', '');
|
||||
$aAppData['UserLogoMessage'] = $oConfig->Get('branding', 'user_logo_message', '');
|
||||
$aAppData['UserIframeMessage'] = $oConfig->Get('branding', 'user_iframe_message', '');
|
||||
$aAppData['UserCss'] = $oConfig->Get('branding', 'user_css', '');
|
||||
$aAppData['WelcomePageUrl'] = $oConfig->Get('branding', 'welcome_page_url', '');
|
||||
$aAppData['WelcomePageDisplay'] = \strtolower($oConfig->Get('branding', 'welcome_page_display', 'none'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function PremSection(&$oActions, &$oConfig)
|
||||
{
|
||||
if ($oActions && $oActions->HasOneOfActionParams(array(
|
||||
'LoginLogo', 'LoginBackground', 'LoginDescription', 'LoginCss', 'LoginPowered',
|
||||
'UserLogo', 'UserLogoTitle', 'UserLogoMessage', 'UserIframeMessage', 'UserCss',
|
||||
'WelcomePageUrl', 'WelcomePageDisplay'
|
||||
)) && $this->Type())
|
||||
{
|
||||
$oActions->setConfigFromParams($oConfig, 'LoginLogo', 'branding', 'login_logo', 'string');
|
||||
$oActions->setConfigFromParams($oConfig, 'LoginBackground', 'branding', 'login_background', 'string');
|
||||
$oActions->setConfigFromParams($oConfig, 'LoginDescription', 'branding', 'login_desc', 'string');
|
||||
$oActions->setConfigFromParams($oConfig, 'LoginCss', 'branding', 'login_css', 'string');
|
||||
$oActions->setConfigFromParams($oConfig, 'LoginPowered', 'branding', 'login_powered', 'bool');
|
||||
|
||||
$oActions->setConfigFromParams($oConfig, 'UserLogo', 'branding', 'user_logo', 'string');
|
||||
$oActions->setConfigFromParams($oConfig, 'UserLogoTitle', 'branding', 'user_logo_title', 'string');
|
||||
$oActions->setConfigFromParams($oConfig, 'UserLogoMessage', 'branding', 'user_logo_message', 'string');
|
||||
$oActions->setConfigFromParams($oConfig, 'UserIframeMessage', 'branding', 'user_iframe_message', 'string');
|
||||
$oActions->setConfigFromParams($oConfig, 'UserCss', 'branding', 'user_css', 'string');
|
||||
|
||||
$oActions->setConfigFromParams($oConfig, 'WelcomePageUrl', 'branding', 'welcome_page_url', 'string');
|
||||
$oActions->setConfigFromParams($oConfig, 'WelcomePageDisplay', 'branding', 'welcome_page_display', 'string');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function Activate($sDomain, $sKey, &$iCode)
|
||||
{
|
||||
$iCode = 0;
|
||||
$sContentType = '';
|
||||
|
||||
$oHttp = \MailSo\Base\Http::SingletonInstance();
|
||||
|
||||
$sResult = $oHttp->GetUrlAsString(APP_API_PATH.'activate/'.\urlencode($sDomain).'/'.\urlencode($sKey),
|
||||
'RainLoop/'.APP_VERSION, $sContentType, $iCode, $this->oLogger, 10,
|
||||
$this->oConfig->Get('labs', 'curl_proxy', ''), $this->oConfig->Get('labs', 'curl_proxy_auth', ''),
|
||||
array(), false
|
||||
);
|
||||
|
||||
if (200 !== $iCode)
|
||||
{
|
||||
$sResult = '';
|
||||
}
|
||||
|
||||
return $sResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function Fetcher($sForce = false, $bLongCache = false, $iFastCacheTimeInMin = 10, $iLongCacheTimeInDays = 3)
|
||||
{
|
||||
$sDomain = \trim(APP_SITE);
|
||||
|
||||
$oConfig = $this->oConfig;
|
||||
$oLogger = $this->oLogger;
|
||||
$oCacher = $this->oCacher;
|
||||
|
||||
$oHttp = \MailSo\Base\Http::SingletonInstance();
|
||||
|
||||
if (0 === \strlen($sDomain) || $oHttp->CheckLocalhost($sDomain) || !$oCacher || !$oConfig || !$oCacher->Verify(true))
|
||||
{
|
||||
return 'NO';
|
||||
}
|
||||
|
||||
$sDomainKeyValue = \RainLoop\KeyPathHelper::LicensingDomainKeyValue($sDomain);
|
||||
$sDomainLongKeyValue = \RainLoop\KeyPathHelper::LicensingDomainKeyOtherValue($sDomain);
|
||||
|
||||
$sValue = '';
|
||||
if (!$sForce)
|
||||
{
|
||||
if ($bLongCache)
|
||||
{
|
||||
$bLock = $oCacher->GetLock($sDomainLongKeyValue);
|
||||
$iTime = $bLock ? 0 : $oCacher->GetTimer($sDomainLongKeyValue);
|
||||
|
||||
if ($bLock || (0 < $iTime && \time() < $iTime + (60 * 60 * 24) * $iLongCacheTimeInDays))
|
||||
{
|
||||
$sValue = $oCacher->Get($sDomainLongKeyValue);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$iTime = $oCacher->GetTimer($sDomainKeyValue);
|
||||
if (0 < $iTime && \time() < $iTime + 60 * $iFastCacheTimeInMin)
|
||||
{
|
||||
$sValue = $oCacher->Get($sDomainKeyValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (0 === \strlen($sValue))
|
||||
{
|
||||
if ($bLongCache)
|
||||
{
|
||||
if (!$oCacher->SetTimer($sDomainLongKeyValue))
|
||||
{
|
||||
return 'NO';
|
||||
}
|
||||
|
||||
$oCacher->SetLock($sDomainLongKeyValue);
|
||||
}
|
||||
|
||||
$iCode = 0;
|
||||
$sContentType = '';
|
||||
|
||||
$sValue = $oHttp->GetUrlAsString(APP_API_PATH.'status/'.\urlencode($sDomain),
|
||||
'RainLoop/'.APP_VERSION, $sContentType, $iCode, $oLogger, 5,
|
||||
$oConfig->Get('labs', 'curl_proxy', ''), $oConfig->Get('labs', 'curl_proxy_auth', ''),
|
||||
array(), false
|
||||
);
|
||||
|
||||
if ($oLogger)
|
||||
{
|
||||
$oLogger->Write($sValue);
|
||||
}
|
||||
|
||||
if (404 === $iCode)
|
||||
{
|
||||
$sValue = 'NO';
|
||||
}
|
||||
else if (200 !== $iCode)
|
||||
{
|
||||
$sValue = '';
|
||||
}
|
||||
|
||||
$oCacher->SetTimer($sDomainKeyValue);
|
||||
|
||||
$oCacher->Set($sDomainKeyValue, $sValue);
|
||||
$oCacher->Set($sDomainLongKeyValue, $sValue);
|
||||
|
||||
if ($bLongCache)
|
||||
{
|
||||
$oCacher->RemoveLock($sDomainLongKeyValue);
|
||||
}
|
||||
}
|
||||
|
||||
return $sValue;
|
||||
}
|
||||
|
||||
public function ClearOldVersion()
|
||||
{
|
||||
$sVPath = APP_INDEX_ROOT_PATH.'rainloop/v/';
|
||||
|
||||
if ($this->oLogger)
|
||||
{
|
||||
$this->oLogger->Write('Versions GC: Begin');
|
||||
}
|
||||
|
||||
$aDirs = @\array_map('basename', @\array_filter(@\glob($sVPath.'*'), 'is_dir'));
|
||||
|
||||
if ($this->oLogger)
|
||||
{
|
||||
$this->oLogger->Write('Versions GC: Count:'.(\is_array($aDirs) ? \count($aDirs) : 0));
|
||||
}
|
||||
|
||||
if (\is_array($aDirs) && 5 < \count($aDirs))
|
||||
{
|
||||
\uasort($aDirs, 'version_compare');
|
||||
|
||||
foreach ($aDirs as $sName)
|
||||
{
|
||||
if (APP_DEV_VERSION !== $sName && APP_VERSION !== $sName)
|
||||
{
|
||||
if ($this->oLogger)
|
||||
{
|
||||
$this->oLogger->Write('Versions GC: Begin to remove "'.$sVPath.$sName.'" version');
|
||||
}
|
||||
|
||||
if (@\unlink($sVPath.$sName.'/index.php'))
|
||||
{
|
||||
@\MailSo\Base\Utils::RecRmDir($sVPath.$sName);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($this->oLogger)
|
||||
{
|
||||
$this->oLogger->Write('Versions GC (Error): index file cant be removed from"'.$sVPath.$sName.'"',
|
||||
\MailSo\Log\Enumerations\Type::ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->oLogger)
|
||||
{
|
||||
$this->oLogger->Write('Versions GC: End to remove "'.$sVPath.$sName.'" version');
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->oLogger)
|
||||
{
|
||||
$this->oLogger->Write('Versions GC: End');
|
||||
}
|
||||
}
|
||||
|
||||
public function UpdateCore($oActions, $sFile)
|
||||
{
|
||||
$bResult = false;
|
||||
|
||||
$sNewVersion = '';
|
||||
$sTmp = $oActions->downloadRemotePackageByUrl($sFile);
|
||||
if (!empty($sTmp))
|
||||
{
|
||||
include_once APP_VERSION_ROOT_PATH.'app/libraries/pclzip/pclzip.lib.php';
|
||||
|
||||
$oArchive = new \PclZip($sTmp);
|
||||
$sTmpFolder = APP_PRIVATE_DATA.\md5($sTmp);
|
||||
|
||||
\mkdir($sTmpFolder);
|
||||
if (\is_dir($sTmpFolder))
|
||||
{
|
||||
$bResult = 0 !== $oArchive->extract(PCLZIP_OPT_PATH, $sTmpFolder);
|
||||
if (!$bResult)
|
||||
{
|
||||
if ($this->oLogger)
|
||||
{
|
||||
$this->oLogger->Write('Cannot extract package files: '.$oArchive->errorInfo(), \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
|
||||
}
|
||||
}
|
||||
|
||||
if ($bResult && \file_exists($sTmpFolder.'/index.php') &&
|
||||
\is_writable(APP_INDEX_ROOT_PATH.'rainloop/') &&
|
||||
\is_writable(APP_INDEX_ROOT_PATH.'index.php') &&
|
||||
\is_dir($sTmpFolder.'/rainloop/'))
|
||||
{
|
||||
$aMatch = array();
|
||||
$sIndexFile = \file_get_contents($sTmpFolder.'/index.php');
|
||||
if (\preg_match('/\'APP_VERSION\', \'([^\']+)\'/', $sIndexFile, $aMatch) && !empty($aMatch[1]))
|
||||
{
|
||||
$sNewVersion = \trim($aMatch[1]);
|
||||
}
|
||||
|
||||
if (empty($sNewVersion))
|
||||
{
|
||||
if ($this->oLogger)
|
||||
{
|
||||
$this->oLogger->Write('Unknown version', \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
|
||||
}
|
||||
}
|
||||
else if (!\is_dir(APP_INDEX_ROOT_PATH.'rainloop/v/'.$sNewVersion))
|
||||
{
|
||||
\MailSo\Base\Utils::CopyDir($sTmpFolder.'/rainloop/', APP_INDEX_ROOT_PATH.'rainloop/');
|
||||
|
||||
if (\is_dir(APP_INDEX_ROOT_PATH.'rainloop/v/'.$sNewVersion) &&
|
||||
\is_file(APP_INDEX_ROOT_PATH.'rainloop/v/'.$sNewVersion.'/index.php'))
|
||||
{
|
||||
$bResult = \copy($sTmpFolder.'/index.php', APP_INDEX_ROOT_PATH.'index.php');
|
||||
|
||||
if ($bResult)
|
||||
{
|
||||
if (\MailSo\Base\Utils::FunctionExistsAndEnabled('opcache_invalidate'))
|
||||
{
|
||||
@\opcache_invalidate(APP_INDEX_ROOT_PATH.'index.php', true);
|
||||
}
|
||||
|
||||
if (\MailSo\Base\Utils::FunctionExistsAndEnabled('apc_delete_file'))
|
||||
{
|
||||
@\apc_delete_file(APP_INDEX_ROOT_PATH.'index.php');
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($this->oLogger)
|
||||
{
|
||||
$this->oLogger->Write('Cannot copy new package files', \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
|
||||
$this->oLogger->Write($sTmpFolder.'/rainloop/ -> '.APP_INDEX_ROOT_PATH.'rainloop/', \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!empty($sNewVersion))
|
||||
{
|
||||
if ($this->oLogger)
|
||||
{
|
||||
$this->oLogger->Write('"'.$sNewVersion.'" version already installed', \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ($bResult)
|
||||
{
|
||||
if ($this->oLogger)
|
||||
{
|
||||
$this->oLogger->Write('Cannot validate package files', \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
|
||||
}
|
||||
}
|
||||
|
||||
\MailSo\Base\Utils::RecRmDir($sTmpFolder);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($this->oLogger)
|
||||
{
|
||||
$this->oLogger->Write('Cannot create tmp folder: '.$sTmpFolder, \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
|
||||
}
|
||||
}
|
||||
|
||||
@\unlink($sTmp);
|
||||
}
|
||||
|
||||
return $bResult;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue