mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-05 15:37:03 +03:00
Small fixes
This commit is contained in:
parent
300cee0b6e
commit
3e9a7a55c6
15 changed files with 405 additions and 292 deletions
|
|
@ -1,164 +1,164 @@
|
|||
<?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\Cache;
|
||||
|
||||
/**
|
||||
* @category MailSo
|
||||
* @package Cache
|
||||
*/
|
||||
class CacheClient
|
||||
{
|
||||
/**
|
||||
* @var \MailSo\Cache\DriverInterface
|
||||
*/
|
||||
private $oDriver;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sCacheIndex;
|
||||
|
||||
/**
|
||||
* @access private
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
$this->oDriver = null;
|
||||
$this->sCacheIndex = '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \MailSo\Cache\CacheClient
|
||||
*/
|
||||
public static function NewInstance()
|
||||
{
|
||||
return new self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sKey
|
||||
* @param string $sValue
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function Set($sKey, $sValue)
|
||||
{
|
||||
return $this->oDriver ? $this->oDriver->Set($sKey.$this->sCacheIndex, $sValue) : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sKey
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function SetTimer($sKey)
|
||||
{
|
||||
return $this->Set($sKey.'/TIMER', time());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sKey
|
||||
* @param string $bClearAfterGet = false
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function Get($sKey, $bClearAfterGet = false)
|
||||
{
|
||||
$sValue = '';
|
||||
|
||||
if ($this->oDriver)
|
||||
{
|
||||
$sValue = $this->oDriver->Get($sKey.$this->sCacheIndex);
|
||||
}
|
||||
|
||||
if ($bClearAfterGet)
|
||||
{
|
||||
$this->Delete($sKey);
|
||||
}
|
||||
|
||||
return $sValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sKey
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function GetTimer($sKey)
|
||||
{
|
||||
$iTimer = 0;
|
||||
$sValue = $this->Get($sKey.'/TIMER');
|
||||
if (0 < strlen($sValue) && is_numeric($sValue))
|
||||
{
|
||||
$iTimer = (int) $sValue;
|
||||
}
|
||||
|
||||
return $iTimer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sKey
|
||||
*
|
||||
* @return \MailSo\Cache\CacheClient
|
||||
*/
|
||||
public function Delete($sKey)
|
||||
{
|
||||
if ($this->oDriver)
|
||||
{
|
||||
$this->oDriver->Delete($sKey.$this->sCacheIndex);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \MailSo\Cache\DriverInterface $oDriver
|
||||
*
|
||||
* @return \MailSo\Cache\CacheClient
|
||||
*/
|
||||
public function SetDriver(\MailSo\Cache\DriverInterface $oDriver)
|
||||
{
|
||||
$this->oDriver = $oDriver;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $iTimeToClearInHours = 24
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function GC($iTimeToClearInHours = 24)
|
||||
{
|
||||
return $this->oDriver ? $this->oDriver->GC($iTimeToClearInHours) : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function IsInited()
|
||||
{
|
||||
return $this->oDriver instanceof \MailSo\Cache\DriverInterface;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sCacheIndex
|
||||
*
|
||||
* @return \MailSo\Cache\CacheClient
|
||||
*/
|
||||
public function SetCacheIndex($sCacheIndex)
|
||||
{
|
||||
$this->sCacheIndex = 0 < \strlen($sCacheIndex) ? "\x0".$sCacheIndex : '';
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
<?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\Cache;
|
||||
|
||||
/**
|
||||
* @category MailSo
|
||||
* @package Cache
|
||||
*/
|
||||
class CacheClient
|
||||
{
|
||||
/**
|
||||
* @var \MailSo\Cache\DriverInterface
|
||||
*/
|
||||
private $oDriver;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sCacheIndex;
|
||||
|
||||
/**
|
||||
* @access private
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
$this->oDriver = null;
|
||||
$this->sCacheIndex = '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \MailSo\Cache\CacheClient
|
||||
*/
|
||||
public static function NewInstance()
|
||||
{
|
||||
return new self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sKey
|
||||
* @param string $sValue
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function Set($sKey, $sValue)
|
||||
{
|
||||
return $this->oDriver ? $this->oDriver->Set($sKey.$this->sCacheIndex, $sValue) : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sKey
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function SetTimer($sKey)
|
||||
{
|
||||
return $this->Set($sKey.'/TIMER', time());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sKey
|
||||
* @param string $bClearAfterGet = false
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function Get($sKey, $bClearAfterGet = false)
|
||||
{
|
||||
$sValue = '';
|
||||
|
||||
if ($this->oDriver)
|
||||
{
|
||||
$sValue = $this->oDriver->Get($sKey.$this->sCacheIndex);
|
||||
}
|
||||
|
||||
if ($bClearAfterGet)
|
||||
{
|
||||
$this->Delete($sKey);
|
||||
}
|
||||
|
||||
return $sValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sKey
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function GetTimer($sKey)
|
||||
{
|
||||
$iTimer = 0;
|
||||
$sValue = $this->Get($sKey.'/TIMER');
|
||||
if (0 < strlen($sValue) && is_numeric($sValue))
|
||||
{
|
||||
$iTimer = (int) $sValue;
|
||||
}
|
||||
|
||||
return $iTimer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sKey
|
||||
*
|
||||
* @return \MailSo\Cache\CacheClient
|
||||
*/
|
||||
public function Delete($sKey)
|
||||
{
|
||||
if ($this->oDriver)
|
||||
{
|
||||
$this->oDriver->Delete($sKey.$this->sCacheIndex);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \MailSo\Cache\DriverInterface $oDriver
|
||||
*
|
||||
* @return \MailSo\Cache\CacheClient
|
||||
*/
|
||||
public function SetDriver(\MailSo\Cache\DriverInterface $oDriver)
|
||||
{
|
||||
$this->oDriver = $oDriver;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $iTimeToClearInHours = 24
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function GC($iTimeToClearInHours = 24)
|
||||
{
|
||||
return $this->oDriver ? $this->oDriver->GC($iTimeToClearInHours) : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function IsInited()
|
||||
{
|
||||
return $this->oDriver instanceof \MailSo\Cache\DriverInterface;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sCacheIndex
|
||||
*
|
||||
* @return \MailSo\Cache\CacheClient
|
||||
*/
|
||||
public function SetCacheIndex($sCacheIndex)
|
||||
{
|
||||
$this->sCacheIndex = 0 < \strlen($sCacheIndex) ? "\x0".$sCacheIndex : '';
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -330,7 +330,7 @@ class BodyStructure
|
|||
{
|
||||
$mResult = $this->SearchPlainParts();
|
||||
}
|
||||
|
||||
|
||||
return $mResult;
|
||||
}
|
||||
|
||||
|
|
@ -465,7 +465,7 @@ class BodyStructure
|
|||
* @param array $aParams
|
||||
* @param string $sParamName
|
||||
* @param string $sCharset = \MailSo\Base\Enumerations\Charset::UTF_8
|
||||
*
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function decodeAttrParamenter($aParams, $sParamName, $sCharset = \MailSo\Base\Enumerations\Charset::UTF_8)
|
||||
|
|
@ -477,7 +477,7 @@ class BodyStructure
|
|||
}
|
||||
else if (isset($aParams[$sParamName.'*']))
|
||||
{
|
||||
$aValueParts = \explode('\'\'', $aParams[$sParamName.'*'], 2);
|
||||
$aValueParts = \explode("''", $aParams[$sParamName.'*'], 2);
|
||||
if (\is_array($aValueParts) && 2 === \count($aValueParts))
|
||||
{
|
||||
$sCharset = isset($aValueParts[0]) ? $aValueParts[0] : \MailSo\Base\Enumerations\Charset::UTF_8;
|
||||
|
|
@ -490,30 +490,30 @@ class BodyStructure
|
|||
$sResult = \urldecode($aParams[$sParamName.'*']);
|
||||
}
|
||||
}
|
||||
else if (isset($aParams[$sParamName.'*0*']))
|
||||
else
|
||||
{
|
||||
$sCharset = '';
|
||||
$sCharsetIndex = -1;
|
||||
|
||||
$aFileNames = array();
|
||||
foreach ($aParams as $sName => $sValue)
|
||||
{
|
||||
$aMatches = array();
|
||||
if ($sParamName.'*0*' === $sName)
|
||||
if (\preg_match('/^'.\preg_quote($sParamName, '/').'\*([0-9]+)\*$/i', $sName, $aMatches))
|
||||
{
|
||||
if (0 === \strlen($sCharset))
|
||||
$iIndex = (int) $aMatches[1];
|
||||
if ($sCharsetIndex < $iIndex && false !== \strpos($sValue, "''"))
|
||||
{
|
||||
$aValueParts = \explode('\'\'', $sValue, 2);
|
||||
$aValueParts = \explode("''", $sValue, 2);
|
||||
if (\is_array($aValueParts) && 2 === \count($aValueParts) && 0 < \strlen($aValueParts[0]))
|
||||
{
|
||||
$sCharsetIndex = $iIndex;
|
||||
$sCharset = $aValueParts[0];
|
||||
$sValue = $aValueParts[1];
|
||||
}
|
||||
}
|
||||
|
||||
$aFileNames[0] = $sValue;
|
||||
}
|
||||
else if ($sParamName.'*0*' !== $sName && \preg_match('/^'.\preg_quote($sParamName, '/').'\*([0-9]+)\*$/i', $sName, $aMatches) && 0 < \strlen($aMatches[1]))
|
||||
{
|
||||
$aFileNames[(int) $aMatches[1]] = $sValue;
|
||||
|
||||
$aFileNames[$iIndex] = $sValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -662,7 +662,7 @@ class BodyStructure
|
|||
{
|
||||
$sCharset = $aBodyParams['charset'];
|
||||
}
|
||||
|
||||
|
||||
if (\is_array($aBodyParams))
|
||||
{
|
||||
$sName = self::decodeAttrParamenter($aBodyParams, 'name', $sContentType);
|
||||
|
|
@ -675,7 +675,7 @@ class BodyStructure
|
|||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
$sContentID = $aBodyStructure[3];
|
||||
}
|
||||
|
||||
|
|
@ -685,7 +685,7 @@ class BodyStructure
|
|||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
$sDescription = $aBodyStructure[4];
|
||||
}
|
||||
|
||||
|
|
@ -867,7 +867,7 @@ class BodyStructure
|
|||
/**
|
||||
* @param array $aList
|
||||
* @param string $sPartID
|
||||
*
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
private static function findPartByIndexInArray(array $aList, $sPartID)
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class ParameterCollection extends \MailSo\Base\Collection
|
|||
{
|
||||
parent::__construct();
|
||||
|
||||
if (0 < strlen($sRawParams))
|
||||
if (0 < \strlen($sRawParams))
|
||||
{
|
||||
$this->Parse($sRawParams);
|
||||
}
|
||||
|
|
@ -74,12 +74,12 @@ class ParameterCollection extends \MailSo\Base\Collection
|
|||
public function ParameterValueByName($sName)
|
||||
{
|
||||
$sResult = '';
|
||||
$sName = trim($sName);
|
||||
$sName = \trim($sName);
|
||||
|
||||
$aParams =& $this->GetAsArray();
|
||||
foreach ($aParams as /* @var $oParam \MailSo\Mime\ParameterCollection */ $oParam)
|
||||
{
|
||||
if (strtolower($sName) === strtolower($oParam->Name()))
|
||||
if (\strtolower($sName) === \strtolower($oParam->Name()))
|
||||
{
|
||||
$sResult = $oParam->Value();
|
||||
break;
|
||||
|
|
@ -98,7 +98,7 @@ class ParameterCollection extends \MailSo\Base\Collection
|
|||
{
|
||||
$this->Clear();
|
||||
|
||||
$aDataToParse = explode(';', $sRawParams);
|
||||
$aDataToParse = \explode(';', $sRawParams);
|
||||
|
||||
foreach ($aDataToParse as $sParam)
|
||||
{
|
||||
|
|
@ -122,13 +122,13 @@ class ParameterCollection extends \MailSo\Base\Collection
|
|||
foreach ($aParams as /* @var $oParam \MailSo\Mime\Parameter */ $oParam)
|
||||
{
|
||||
$sLine = $oParam->ToString($bConvertSpecialsName);
|
||||
if (0 < strlen($sLine))
|
||||
if (0 < \strlen($sLine))
|
||||
{
|
||||
$aResult[] = $sLine;
|
||||
}
|
||||
}
|
||||
|
||||
return 0 < count($aResult) ? implode('; ', $aResult) : '';
|
||||
return 0 < \count($aResult) ? \implode('; ', $aResult) : '';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -147,8 +147,8 @@ class ParameterCollection extends \MailSo\Base\Collection
|
|||
$aMatch = array();
|
||||
$sParamName = $oParam->Name();
|
||||
|
||||
if (preg_match('/([^\*]+)\*([\d]{1,2})\*/', $sParamName, $aMatch) && isset($aMatch[1], $aMatch[2])
|
||||
&& 0 < strlen($aMatch[1]) && is_numeric($aMatch[2]))
|
||||
if (\preg_match('/([^\*]+)\*([\d]{1,2})\*/', $sParamName, $aMatch) && isset($aMatch[1], $aMatch[2])
|
||||
&& 0 < \strlen($aMatch[1]) && \is_numeric($aMatch[2]))
|
||||
{
|
||||
if (!isset($aPreParams[$aMatch[1]]))
|
||||
{
|
||||
|
|
@ -156,16 +156,20 @@ class ParameterCollection extends \MailSo\Base\Collection
|
|||
}
|
||||
|
||||
$sValue = $oParam->Value();
|
||||
$aValueParts = explode('\'\'', $sValue, 2);
|
||||
if (is_array($aValueParts) && 2 === count($aValueParts) && 0 < strlen($aValueParts[1]))
|
||||
|
||||
if (false !== \strpos($sValue, "''"))
|
||||
{
|
||||
$sCharset = $aValueParts[0];
|
||||
$sValue = $aValueParts[1];
|
||||
$aValueParts = \explode("''", $sValue, 2);
|
||||
if (\is_array($aValueParts) && 2 === \count($aValueParts) && 0 < \strlen($aValueParts[1]))
|
||||
{
|
||||
$sCharset = $aValueParts[0];
|
||||
$sValue = $aValueParts[1];
|
||||
}
|
||||
}
|
||||
|
||||
$aPreParams[$aMatch[1]][(int) $aMatch[2]] = $sValue;
|
||||
}
|
||||
else if (preg_match('/([^\*]+)\*/', $sParamName, $aMatch) && isset($aMatch[1]))
|
||||
else if (\preg_match('/([^\*]+)\*/', $sParamName, $aMatch) && isset($aMatch[1]))
|
||||
{
|
||||
if (!isset($aPreParams[$aMatch[1]]))
|
||||
{
|
||||
|
|
@ -173,11 +177,14 @@ class ParameterCollection extends \MailSo\Base\Collection
|
|||
}
|
||||
|
||||
$sValue = $oParam->Value();
|
||||
$aValueParts = explode('\'\'', $sValue, 2);
|
||||
if (is_array($aValueParts) && 2 === count($aValueParts) && 0 < strlen($aValueParts[1]))
|
||||
if (false !== \strpos($sValue, "''"))
|
||||
{
|
||||
$sCharset = $aValueParts[0];
|
||||
$sValue = $aValueParts[1];
|
||||
$aValueParts = \explode("''", $sValue, 2);
|
||||
if (\is_array($aValueParts) && 2 === \count($aValueParts) && 0 < \strlen($aValueParts[1]))
|
||||
{
|
||||
$sCharset = $aValueParts[0];
|
||||
$sValue = $aValueParts[1];
|
||||
}
|
||||
}
|
||||
|
||||
$aPreParams[$aMatch[1]][0] = $sValue;
|
||||
|
|
@ -191,10 +198,10 @@ class ParameterCollection extends \MailSo\Base\Collection
|
|||
foreach ($aPreParams as $sName => $aValues)
|
||||
{
|
||||
ksort($aValues);
|
||||
$sResult = implode(array_values($aValues));
|
||||
$sResult = urldecode($sResult);
|
||||
$sResult = \implode(\array_values($aValues));
|
||||
$sResult = \urldecode($sResult);
|
||||
|
||||
if (0 < strlen($sCharset))
|
||||
if (0 < \strlen($sCharset))
|
||||
{
|
||||
$sResult = \MailSo\Base\Utils::ConvertEncoding($sResult,
|
||||
$sCharset, \MailSo\Base\Enumerations\Charset::UTF_8);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue