mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-09-08 22:24:14 +08:00
Small fixes
This commit is contained in:
parent
7348b9b8a4
commit
58d8e92902
6 changed files with 111 additions and 46 deletions
|
@ -6,8 +6,8 @@ namespace MailSo\Base;
|
|||
* @category MailSo
|
||||
* @package Base
|
||||
*/
|
||||
class Crypt {
|
||||
|
||||
class Crypt
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @param string $sString
|
||||
|
|
|
@ -188,12 +188,21 @@ class Utils
|
|||
return $sEncoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public static function IsMbStringSupported()
|
||||
{
|
||||
return \MailSo\Config::$MBSTRING &&
|
||||
\MailSo\Base\Utils::FunctionExistsAndEnabled('mb_convert_encoding');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public static function IsIconvSupported()
|
||||
{
|
||||
return \MailSo\Capa::$ICONV &&
|
||||
return \MailSo\Config::$ICONV &&
|
||||
\MailSo\Base\Utils::FunctionExistsAndEnabled('iconv');
|
||||
}
|
||||
|
||||
|
@ -223,10 +232,24 @@ class Utils
|
|||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public static function IsMbStringSupported()
|
||||
public static function IsIconvTranslitSupported()
|
||||
{
|
||||
return \MailSo\Capa::$MBSTRING &&
|
||||
\MailSo\Base\Utils::FunctionExistsAndEnabled('mb_convert_encoding');
|
||||
static $bCache = null;
|
||||
if (null !== $bCache)
|
||||
{
|
||||
return $bCache;
|
||||
}
|
||||
|
||||
$bCache = false;
|
||||
if (\MailSo\Base\Utils::IsIconvSupported())
|
||||
{
|
||||
if (false !== @\iconv('', '//TRANSLIT', ''))
|
||||
{
|
||||
$bCache = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $bCache;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -250,13 +273,36 @@ class Utils
|
|||
*/
|
||||
public static function IconvConvertEncoding($sInputString, $sInputFromEncoding, $sInputToEncoding)
|
||||
{
|
||||
$sIconvIgnorOption = '';
|
||||
$sIconvOptions = '';
|
||||
if (\MailSo\Base\Utils::IsIconvIgnoreSupported())
|
||||
{
|
||||
$sIconvIgnorOption = '//IGNORE';
|
||||
$sIconvOptions .= '//IGNORE';
|
||||
}
|
||||
// if (\MailSo\Base\Utils::IsIconvTranslitSupported())
|
||||
// {
|
||||
// $sIconvOptions .= '//TRANSLIT';
|
||||
// }
|
||||
|
||||
$mResult = @\iconv(\strtoupper($sInputFromEncoding), \strtoupper($sInputToEncoding).$sIconvOptions, $sInputString);
|
||||
if (false === $mResult)
|
||||
{
|
||||
if (\MailSo\Config::$SystemLogger instanceof \MailSo\Log\Logger)
|
||||
{
|
||||
$sHex = 500 < \strlen($sInputString) ? '' : \bin2hex($sInputString);
|
||||
\MailSo\Config::$SystemLogger->WriteDump(array(
|
||||
'inc' => \strtoupper($sInputFromEncoding),
|
||||
'out' => \strtoupper($sInputToEncoding).$sIconvOptions,
|
||||
'val' => $sInputString,
|
||||
'hex' => $sHex
|
||||
), \MailSo\Log\Enumerations\Type::NOTICE);
|
||||
}
|
||||
|
||||
return @\iconv(\strtoupper($sInputFromEncoding), \strtoupper($sInputToEncoding).$sIconvIgnorOption, $sInputString);
|
||||
if (\MailSo\Config::$FixIconvByMbstring && \MailSo\Base\Utils::IsMbStringSupported())
|
||||
{
|
||||
$mResult = \MailSo\Base\Utils::MbConvertEncoding($sInputString, $sInputFromEncoding, $sInputToEncoding);
|
||||
}
|
||||
}
|
||||
return $mResult;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1081,6 +1127,11 @@ class Utils
|
|||
$sResult = @\json_encode($mInput, $iOpt);
|
||||
if (!\is_string($sResult) || '' === $sResult)
|
||||
{
|
||||
if (!$oLogger && \MailSo\Config::$SystemLogger instanceof \MailSo\Log\Logger)
|
||||
{
|
||||
$oLogger = \MailSo\Config::$SystemLogger;
|
||||
}
|
||||
|
||||
if ($oLogger instanceof \MailSo\Log\Logger)
|
||||
{
|
||||
$oLogger->Write('json_encode: '.\trim(
|
||||
|
@ -1094,7 +1145,8 @@ class Utils
|
|||
{
|
||||
if ($oLogger instanceof \MailSo\Log\Logger)
|
||||
{
|
||||
$oLogger->Write('Try to clear Utf8 before json_encode', \MailSo\Log\Enumerations\Type::INFO, 'JSON');
|
||||
$oLogger->WriteDump($mInput, \MailSo\Log\Enumerations\Type::INFO, 'JSON');
|
||||
$oLogger->Write('Trying to clear Utf8 before json_encode', \MailSo\Log\Enumerations\Type::INFO, 'JSON');
|
||||
}
|
||||
|
||||
\MailSo\Base\Utils::ClearArrayUtf8Values($mInput);
|
||||
|
@ -1329,6 +1381,23 @@ class Utils
|
|||
return $sUtfString;
|
||||
}
|
||||
|
||||
$sUtfString = \preg_replace(
|
||||
'/[\x00-\x08\x10\x0B\x0C\x0E-\x1F\x7F]'.
|
||||
'|[\x00-\x7F][\x80-\xBF]+'.
|
||||
'|([\xC0\xC1]|[\xF0-\xFF])[\x80-\xBF]*'.
|
||||
'|[\xC2-\xDF]((?![\x80-\xBF])|[\x80-\xBF]{2,})'.
|
||||
'|[\xE0-\xEF](([\x80-\xBF](?![\x80-\xBF]))|(?![\x80-\xBF]{2})|[\x80-\xBF]{3,})/S',
|
||||
$sReplaceOn,
|
||||
$sUtfString
|
||||
);
|
||||
|
||||
$sUtfString = \preg_replace(
|
||||
'/\xE0[\x80-\x9F][\x80-\xBF]'.
|
||||
'|\xEF\xBF\xBF'.
|
||||
'|\xED[\xA0-\xBF][\x80-\xBF]/S', $sReplaceOn, $sUtfString);
|
||||
|
||||
$sUtfString = \preg_replace('/\xEF\xBF\xBD/', '?', $sUtfString);
|
||||
|
||||
$sNewUtfString = false;
|
||||
if (\MailSo\Base\Utils::IsIconvSupported())
|
||||
{
|
||||
|
@ -1344,21 +1413,6 @@ class Utils
|
|||
$sUtfString = $sNewUtfString;
|
||||
}
|
||||
|
||||
$sUtfString = \preg_replace(
|
||||
'/[\x00-\x08\x10\x0B\x0C\x0E-\x1F\x7F]'.
|
||||
'|[\x00-\x7F][\x80-\xBF]+'.
|
||||
'|([\xC0\xC1]|[\xF0-\xFF])[\x80-\xBF]*'.
|
||||
'|[\xC2-\xDF]((?![\x80-\xBF])|[\x80-\xBF]{2,})'.
|
||||
'|[\xE0-\xEF](([\x80-\xBF](?![\x80-\xBF]))|(?![\x80-\xBF]{2})|[\x80-\xBF]{3,})/S',
|
||||
$sReplaceOn, $sUtfString);
|
||||
|
||||
$sUtfString = \preg_replace(
|
||||
'/\xE0[\x80-\x9F][\x80-\xBF]'.
|
||||
'|\xEF\xBF\xBF'.
|
||||
'|\xED[\xA0-\xBF][\x80-\xBF]/S', $sReplaceOn, $sUtfString);
|
||||
|
||||
$sUtfString = \preg_replace('/\xEF\xBF\xBD/', '?', $sUtfString);
|
||||
|
||||
return $sUtfString;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace MailSo;
|
||||
|
||||
/**
|
||||
* @category MailSo
|
||||
*/
|
||||
final class Capa
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
static $ICONV = true;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
static $MBSTRING = true;
|
||||
}
|
30
rainloop/v/0.0.0/app/libraries/MailSo/Config.php
Normal file
30
rainloop/v/0.0.0/app/libraries/MailSo/Config.php
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace MailSo;
|
||||
|
||||
/**
|
||||
* @category MailSo
|
||||
* @package Base
|
||||
*/
|
||||
class Config
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public static $ICONV = true;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public static $MBSTRING = true;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public static $FixIconvByMbstring = true;
|
||||
|
||||
/**
|
||||
* @var \MailSo\Log\Logger
|
||||
*/
|
||||
public static $SystemLogger = null;
|
||||
}
|
|
@ -52,7 +52,7 @@ class Api
|
|||
if (self::Config()->Get('labs', 'disable_iconv_if_mbstring_supported', false) &&
|
||||
\class_exists('MailSo\Capa') && \MailSo\Base\Utils::IsMbStringSupported())
|
||||
{
|
||||
\MailSo\Capa::$ICONV = false;
|
||||
\MailSo\Config::$ICONV = false;
|
||||
}
|
||||
|
||||
$bOne = true;
|
||||
|
|
|
@ -45,7 +45,7 @@ class Service
|
|||
if ($this->oActions->Config()->Get('labs', 'disable_iconv_if_mbstring_supported', false) &&
|
||||
\class_exists('MailSo\Capa') && \MailSo\Base\Utils::IsMbStringSupported())
|
||||
{
|
||||
\MailSo\Capa::$ICONV = false;
|
||||
\MailSo\Config::$ICONV = false;
|
||||
}
|
||||
|
||||
$sServer = \trim($this->oActions->Config()->Get('security', 'custom_server_signature', ''));
|
||||
|
|
Loading…
Add table
Reference in a new issue