|
|
|
|
@ -15,7 +15,7 @@ namespace MailSo\Base;
|
|
|
|
|
* @category MailSo
|
|
|
|
|
* @package Base
|
|
|
|
|
*/
|
|
|
|
|
class Utils
|
|
|
|
|
abstract class Utils
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* @var string
|
|
|
|
|
@ -114,13 +114,6 @@ END;
|
|
|
|
|
'.949' => 'euc-kr',
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @access private
|
|
|
|
|
*/
|
|
|
|
|
private function __construct()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
@ -130,7 +123,7 @@ END;
|
|
|
|
|
$sLocale = @\setlocale(LC_ALL, '');
|
|
|
|
|
$sLocaleLower = \strtolower(\trim($sLocale));
|
|
|
|
|
|
|
|
|
|
foreach (\MailSo\Base\Utils::$aLocaleMapping as $sKey => $sValue)
|
|
|
|
|
foreach (static::$aLocaleMapping as $sKey => $sValue)
|
|
|
|
|
{
|
|
|
|
|
if (false !== \strpos($sLocaleLower, $sKey) ||
|
|
|
|
|
false !== \strpos($sLocaleLower, '.'.$sValue))
|
|
|
|
|
@ -149,12 +142,12 @@ END;
|
|
|
|
|
public static function ConvertSystemString($sSrt)
|
|
|
|
|
{
|
|
|
|
|
$sSrt = \trim($sSrt);
|
|
|
|
|
if (!empty($sSrt) && !\MailSo\Base\Utils::IsUtf8($sSrt))
|
|
|
|
|
if (!empty($sSrt) && !static::IsUtf8($sSrt))
|
|
|
|
|
{
|
|
|
|
|
$sCharset = \MailSo\Base\Utils::DetectSystemCharset();
|
|
|
|
|
$sCharset = static::DetectSystemCharset();
|
|
|
|
|
if (!empty($sCharset))
|
|
|
|
|
{
|
|
|
|
|
$sSrt = \MailSo\Base\Utils::ConvertEncoding(
|
|
|
|
|
$sSrt = static::ConvertEncoding(
|
|
|
|
|
$sSrt, $sCharset, \MailSo\Base\Enumerations\Charset::UTF_8);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
@ -229,10 +222,10 @@ END;
|
|
|
|
|
*/
|
|
|
|
|
public static function NormalizeCharsetByValue($sCharset, $sValue)
|
|
|
|
|
{
|
|
|
|
|
$sCharset = \MailSo\Base\Utils::NormalizeCharset($sCharset);
|
|
|
|
|
$sCharset = static::NormalizeCharset($sCharset);
|
|
|
|
|
|
|
|
|
|
if (\MailSo\Base\Enumerations\Charset::UTF_8 !== $sCharset &&
|
|
|
|
|
\MailSo\Base\Utils::IsUtf8($sValue) &&
|
|
|
|
|
static::IsUtf8($sValue) &&
|
|
|
|
|
false === \strpos($sCharset, \MailSo\Base\Enumerations\Charset::ISO_2022_JP)
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
@ -292,70 +285,6 @@ END;
|
|
|
|
|
return $sFilePath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @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\Config::$ICONV &&
|
|
|
|
|
\MailSo\Base\Utils::FunctionExistsAndEnabled('iconv');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public static function IsIconvIgnoreSupported()
|
|
|
|
|
{
|
|
|
|
|
static $bCache = null;
|
|
|
|
|
if (null !== $bCache)
|
|
|
|
|
{
|
|
|
|
|
return $bCache;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$bCache = false;
|
|
|
|
|
if (\MailSo\Base\Utils::IsIconvSupported())
|
|
|
|
|
{
|
|
|
|
|
if (false !== @\iconv('', '//IGNORE', ''))
|
|
|
|
|
{
|
|
|
|
|
$bCache = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $bCache;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public static function IsIconvTranslitSupported()
|
|
|
|
|
{
|
|
|
|
|
static $bCache = null;
|
|
|
|
|
if (null !== $bCache)
|
|
|
|
|
{
|
|
|
|
|
return $bCache;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$bCache = false;
|
|
|
|
|
if (\MailSo\Base\Utils::IsIconvSupported())
|
|
|
|
|
{
|
|
|
|
|
if (false !== @\iconv('', '//TRANSLIT', ''))
|
|
|
|
|
{
|
|
|
|
|
$bCache = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $bCache;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $sCharset
|
|
|
|
|
*
|
|
|
|
|
@ -363,49 +292,9 @@ END;
|
|
|
|
|
*/
|
|
|
|
|
public static function ValidateCharsetName($sCharset)
|
|
|
|
|
{
|
|
|
|
|
$sCharset = \strtolower(\MailSo\Base\Utils::NormalizeCharset($sCharset));
|
|
|
|
|
$sCharset = \strtolower(static::NormalizeCharset($sCharset));
|
|
|
|
|
return 0 < \strlen($sCharset) && (\in_array($sCharset, array(\MailSo\Base\Enumerations\Charset::UTF_7_IMAP)) ||
|
|
|
|
|
\in_array($sCharset, \MailSo\Base\Utils::$SuppostedCharsets));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $sInputString
|
|
|
|
|
* @param string $sInputFromEncoding
|
|
|
|
|
* @param string $sInputToEncoding
|
|
|
|
|
*
|
|
|
|
|
* @return string|bool
|
|
|
|
|
*/
|
|
|
|
|
public static function IconvConvertEncoding($sInputString, $sInputFromEncoding, $sInputToEncoding)
|
|
|
|
|
{
|
|
|
|
|
$sIconvOptions = '';
|
|
|
|
|
if (\MailSo\Base\Utils::IsIconvIgnoreSupported())
|
|
|
|
|
{
|
|
|
|
|
$sIconvOptions .= '//IGNORE';
|
|
|
|
|
}
|
|
|
|
|
// if (\MailSo\Base\Utils::IsIconvTranslitSupported())
|
|
|
|
|
// {
|
|
|
|
|
// $sIconvOptions .= '//TRANSLIT';
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
$mResult = @\iconv(\strtoupper($sInputFromEncoding), \strtoupper($sInputToEncoding).$sIconvOptions, $sInputString);
|
|
|
|
|
if (false === $mResult)
|
|
|
|
|
{
|
|
|
|
|
if (\MailSo\Log\Logger::IsSystemEnabled())
|
|
|
|
|
{
|
|
|
|
|
\MailSo\Log\Logger::SystemLog(array(
|
|
|
|
|
'inc' => \strtoupper($sInputFromEncoding),
|
|
|
|
|
'out' => \strtoupper($sInputToEncoding).$sIconvOptions,
|
|
|
|
|
'val' => 500 < \strlen($sInputString) ? \substr($sInputString, 0, 500) : $sInputString,
|
|
|
|
|
'hex' => 500 < \strlen($sInputString) ? '-- to long --' : \bin2hex($sInputString)
|
|
|
|
|
), \MailSo\Log\Enumerations\Type::NOTICE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (\MailSo\Config::$FixIconvByMbstring && \MailSo\Base\Utils::IsMbStringSupported())
|
|
|
|
|
{
|
|
|
|
|
$mResult = \MailSo\Base\Utils::MbConvertEncoding($sInputString, $sInputFromEncoding, $sInputToEncoding);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $mResult;
|
|
|
|
|
\in_array($sCharset, static::$SuppostedCharsets));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -424,7 +313,7 @@ END;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
\mb_substitute_character('none');
|
|
|
|
|
$sResult = @\mb_convert_encoding($sInputString, \strtoupper($sInputToEncoding), \strtoupper($sInputFromEncoding));
|
|
|
|
|
$sResult = \mb_convert_encoding($sInputString, \strtoupper($sInputToEncoding), \strtoupper($sInputFromEncoding));
|
|
|
|
|
\mb_substitute_character($sMbstringSubCh);
|
|
|
|
|
|
|
|
|
|
return $sResult;
|
|
|
|
|
@ -441,8 +330,8 @@ END;
|
|
|
|
|
{
|
|
|
|
|
$sResult = $sInputString;
|
|
|
|
|
|
|
|
|
|
$sFromEncoding = \MailSo\Base\Utils::NormalizeCharset($sInputFromEncoding);
|
|
|
|
|
$sToEncoding = \MailSo\Base\Utils::NormalizeCharset($sInputToEncoding);
|
|
|
|
|
$sFromEncoding = static::NormalizeCharset($sInputFromEncoding);
|
|
|
|
|
$sToEncoding = static::NormalizeCharset($sInputToEncoding);
|
|
|
|
|
|
|
|
|
|
if ('' === \trim($sResult) || ($sFromEncoding === $sToEncoding && \MailSo\Base\Enumerations\Charset::UTF_8 !== $sFromEncoding))
|
|
|
|
|
{
|
|
|
|
|
@ -473,7 +362,7 @@ END;
|
|
|
|
|
case ($sFromEncoding === \MailSo\Base\Enumerations\Charset::UTF_7_IMAP &&
|
|
|
|
|
$sToEncoding === \MailSo\Base\Enumerations\Charset::UTF_8):
|
|
|
|
|
|
|
|
|
|
$sResult = \MailSo\Base\Utils::Utf7ModifiedToUtf8($sResult);
|
|
|
|
|
$sResult = static::Utf7ModifiedToUtf8($sResult);
|
|
|
|
|
if (false === $sResult)
|
|
|
|
|
{
|
|
|
|
|
$sResult = $sInputString;
|
|
|
|
|
@ -483,7 +372,7 @@ END;
|
|
|
|
|
case ($sFromEncoding === \MailSo\Base\Enumerations\Charset::UTF_8 &&
|
|
|
|
|
$sToEncoding === \MailSo\Base\Enumerations\Charset::UTF_7_IMAP):
|
|
|
|
|
|
|
|
|
|
$sResult = \MailSo\Base\Utils::Utf8ToUtf7Modified($sResult);
|
|
|
|
|
$sResult = static::Utf8ToUtf7Modified($sResult);
|
|
|
|
|
if (false === $sResult)
|
|
|
|
|
{
|
|
|
|
|
$sResult = $sInputString;
|
|
|
|
|
@ -492,31 +381,23 @@ END;
|
|
|
|
|
|
|
|
|
|
case ($sFromEncoding === \MailSo\Base\Enumerations\Charset::UTF_7_IMAP):
|
|
|
|
|
|
|
|
|
|
$sResult = \MailSo\Base\Utils::ConvertEncoding(
|
|
|
|
|
\MailSo\Base\Utils::ModifiedToPlainUtf7($sResult),
|
|
|
|
|
$sResult = static::ConvertEncoding(
|
|
|
|
|
static::ModifiedToPlainUtf7($sResult),
|
|
|
|
|
\MailSo\Base\Enumerations\Charset::UTF_7,
|
|
|
|
|
$sToEncoding
|
|
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case (\in_array(\strtolower($sFromEncoding), \MailSo\Base\Utils::$SuppostedCharsets)):
|
|
|
|
|
|
|
|
|
|
if (\MailSo\Base\Utils::IsIconvSupported())
|
|
|
|
|
{
|
|
|
|
|
$sResult = \MailSo\Base\Utils::IconvConvertEncoding($sResult, $sFromEncoding, $sToEncoding);
|
|
|
|
|
}
|
|
|
|
|
else if (\MailSo\Base\Utils::IsMbStringSupported())
|
|
|
|
|
{
|
|
|
|
|
$sResult = \MailSo\Base\Utils::MbConvertEncoding($sResult, $sFromEncoding, $sToEncoding);
|
|
|
|
|
}
|
|
|
|
|
case (\in_array(\strtolower($sFromEncoding), static::$SuppostedCharsets)):
|
|
|
|
|
|
|
|
|
|
$sResult = static::MbConvertEncoding($sResult, $sFromEncoding, $sToEncoding);
|
|
|
|
|
$sResult = (false !== $sResult) ? $sResult : $sInputString;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($bUnknown && \MailSo\Base\Utils::IsMbStringSupported())
|
|
|
|
|
if ($bUnknown)
|
|
|
|
|
{
|
|
|
|
|
$sResult = @\mb_convert_encoding($sResult, $sToEncoding);
|
|
|
|
|
$sResult = \mb_convert_encoding($sResult, $sToEncoding);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $sResult;
|
|
|
|
|
@ -544,7 +425,7 @@ END;
|
|
|
|
|
*/
|
|
|
|
|
public static function StrToLowerIfAscii($sValue)
|
|
|
|
|
{
|
|
|
|
|
return \MailSo\Base\Utils::IsAscii($sValue) ? \strtolower($sValue) : $sValue;
|
|
|
|
|
return static::IsAscii($sValue) ? \strtolower($sValue) : $sValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -554,7 +435,7 @@ END;
|
|
|
|
|
*/
|
|
|
|
|
public static function StrToUpperIfAscii($sValue)
|
|
|
|
|
{
|
|
|
|
|
return \MailSo\Base\Utils::IsAscii($sValue) ? \strtoupper($sValue) : $sValue;
|
|
|
|
|
return static::IsAscii($sValue) ? \strtoupper($sValue) : $sValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -567,7 +448,7 @@ END;
|
|
|
|
|
$aParts = \explode('@', $sValue, 2);
|
|
|
|
|
if (!empty($aParts[1]))
|
|
|
|
|
{
|
|
|
|
|
$aParts[1] = \MailSo\Base\Utils::IsAscii($aParts[1]) ? \strtolower($aParts[1]) : $aParts[1];
|
|
|
|
|
$aParts[1] = static::IsAscii($aParts[1]) ? \strtolower($aParts[1]) : $aParts[1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return \implode('@', $aParts);
|
|
|
|
|
@ -580,7 +461,7 @@ END;
|
|
|
|
|
*/
|
|
|
|
|
public static function StripSpaces($sValue)
|
|
|
|
|
{
|
|
|
|
|
return \MailSo\Base\Utils::Trim(
|
|
|
|
|
return static::Trim(
|
|
|
|
|
\preg_replace('/[\s]+/u', ' ', $sValue));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -629,7 +510,7 @@ END;
|
|
|
|
|
break;
|
|
|
|
|
case 'b':
|
|
|
|
|
case 'base64':
|
|
|
|
|
$sResult = \MailSo\Base\Utils::Base64Decode($sResult);
|
|
|
|
|
$sResult = static::Base64Decode($sResult);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return $sResult;
|
|
|
|
|
@ -657,9 +538,9 @@ END;
|
|
|
|
|
$sValue = $sEncodedValue;
|
|
|
|
|
if (0 < \strlen($sIncomingCharset))
|
|
|
|
|
{
|
|
|
|
|
$sIncomingCharset = \MailSo\Base\Utils::NormalizeCharsetByValue($sIncomingCharset, $sValue);
|
|
|
|
|
$sIncomingCharset = static::NormalizeCharsetByValue($sIncomingCharset, $sValue);
|
|
|
|
|
|
|
|
|
|
$sValue = \MailSo\Base\Utils::ConvertEncoding($sValue, $sIncomingCharset,
|
|
|
|
|
$sValue = static::ConvertEncoding($sValue, $sIncomingCharset,
|
|
|
|
|
\MailSo\Base\Enumerations\Charset::UTF_8);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -710,7 +591,7 @@ END;
|
|
|
|
|
break;
|
|
|
|
|
case 'B':
|
|
|
|
|
$sHeaderValuePart = $aTempArr[1];
|
|
|
|
|
$aTempArr[1] = \MailSo\Base\Utils::Base64Decode(\substr(
|
|
|
|
|
$aTempArr[1] = static::Base64Decode(\substr(
|
|
|
|
|
$sHeaderValuePart, $iPos + 3, \strlen($sHeaderValuePart) - $iPos - 5));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
@ -719,7 +600,7 @@ END;
|
|
|
|
|
if (0 < \strlen($aTempArr[0]))
|
|
|
|
|
{
|
|
|
|
|
$sCharset = 0 === \strlen($sForcedIncomingCharset) ? $aTempArr[0] : $sForcedIncomingCharset;
|
|
|
|
|
$sCharset = \MailSo\Base\Utils::NormalizeCharset($sCharset, true);
|
|
|
|
|
$sCharset = static::NormalizeCharset($sCharset, true);
|
|
|
|
|
|
|
|
|
|
if ('' === $sMainCharset)
|
|
|
|
|
{
|
|
|
|
|
@ -748,18 +629,18 @@ END;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$aParts[$iIndex][2] = \MailSo\Base\Utils::NormalizeCharsetByValue($aParts[$iIndex][2], $aParts[$iIndex][1]);
|
|
|
|
|
$aParts[$iIndex][2] = static::NormalizeCharsetByValue($aParts[$iIndex][2], $aParts[$iIndex][1]);
|
|
|
|
|
|
|
|
|
|
$sValue = \str_replace($aParts[$iIndex][0],
|
|
|
|
|
\MailSo\Base\Utils::ConvertEncoding($aParts[$iIndex][1], $aParts[$iIndex][2], \MailSo\Base\Enumerations\Charset::UTF_8),
|
|
|
|
|
static::ConvertEncoding($aParts[$iIndex][1], $aParts[$iIndex][2], \MailSo\Base\Enumerations\Charset::UTF_8),
|
|
|
|
|
$sValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($bOneCharset && 0 < \strlen($sMainCharset))
|
|
|
|
|
{
|
|
|
|
|
$sMainCharset = \MailSo\Base\Utils::NormalizeCharsetByValue($sMainCharset, $sValue);
|
|
|
|
|
$sValue = \MailSo\Base\Utils::ConvertEncoding($sValue, $sMainCharset, \MailSo\Base\Enumerations\Charset::UTF_8);
|
|
|
|
|
$sMainCharset = static::NormalizeCharsetByValue($sMainCharset, $sValue);
|
|
|
|
|
$sValue = static::ConvertEncoding($sValue, $sMainCharset, \MailSo\Base\Enumerations\Charset::UTF_8);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $sValue;
|
|
|
|
|
@ -832,7 +713,7 @@ END;
|
|
|
|
|
public static function EncodeUnencodedValue($sEncodeType, $sValue)
|
|
|
|
|
{
|
|
|
|
|
$sValue = \trim($sValue);
|
|
|
|
|
if (0 < \strlen($sValue) && !\MailSo\Base\Utils::IsAscii($sValue))
|
|
|
|
|
if (0 < \strlen($sValue) && !static::IsAscii($sValue))
|
|
|
|
|
{
|
|
|
|
|
switch (\strtoupper($sEncodeType))
|
|
|
|
|
{
|
|
|
|
|
@ -864,7 +745,7 @@ END;
|
|
|
|
|
public static function EncodeHeaderValue($sEncodeType, $sEncodeCharset, $sValue)
|
|
|
|
|
{
|
|
|
|
|
$sValue = \trim($sValue);
|
|
|
|
|
if (0 < \strlen($sValue) && !\MailSo\Base\Utils::IsAscii($sValue))
|
|
|
|
|
if (0 < \strlen($sValue) && !static::IsAscii($sValue))
|
|
|
|
|
{
|
|
|
|
|
switch (\strtoupper($sEncodeType))
|
|
|
|
|
{
|
|
|
|
|
@ -936,7 +817,7 @@ END;
|
|
|
|
|
$sAttrName = \trim($sAttrName);
|
|
|
|
|
$sValue = \trim($sValue);
|
|
|
|
|
|
|
|
|
|
if (0 < \strlen($sValue) && !\MailSo\Base\Utils::IsAscii($sValue))
|
|
|
|
|
if (0 < \strlen($sValue) && !static::IsAscii($sValue))
|
|
|
|
|
{
|
|
|
|
|
if (!empty($_SERVER['HTTP_USER_AGENT']) && 0 < \strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE'))
|
|
|
|
|
{
|
|
|
|
|
@ -944,7 +825,7 @@ END;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$sValue = \MailSo\Base\Utils::AttributeRfc2231Encode($sAttrName, $sValue);
|
|
|
|
|
$sValue = static::AttributeRfc2231Encode($sAttrName, $sValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
@ -1195,7 +1076,7 @@ END;
|
|
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$sExt = \MailSo\Base\Utils::GetFileExtension($sFileName);
|
|
|
|
|
$sExt = static::GetFileExtension($sFileName);
|
|
|
|
|
if (0 < \strlen($sExt) && isset($aMimeTypes[$sExt]))
|
|
|
|
|
{
|
|
|
|
|
$sResult = $aMimeTypes[$sExt];
|
|
|
|
|
@ -1253,7 +1134,7 @@ END;
|
|
|
|
|
|
|
|
|
|
if ('' === $sResult)
|
|
|
|
|
{
|
|
|
|
|
switch (\strtolower(\MailSo\Base\Utils::GetFileExtension($sFileName)))
|
|
|
|
|
switch (\strtolower(static::GetFileExtension($sFileName)))
|
|
|
|
|
{
|
|
|
|
|
case 'zip':
|
|
|
|
|
case '7z':
|
|
|
|
|
@ -1294,7 +1175,7 @@ END;
|
|
|
|
|
$sSafeMode = \strtolower(\trim(@\ini_get('safe_mode')));
|
|
|
|
|
$bSafeMode = 'on' === $sSafeMode || '1' === $sSafeMode || 'true' === $sSafeMode;
|
|
|
|
|
|
|
|
|
|
$bValidateAction = !$bSafeMode && \MailSo\Base\Utils::FunctionExistsAndEnabled('set_time_limit');
|
|
|
|
|
$bValidateAction = !$bSafeMode && static::FunctionExistsAndEnabled('set_time_limit');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($bValidateAction && $iTimeToReset < $iTime - $iResetTimer)
|
|
|
|
|
@ -1339,11 +1220,11 @@ END;
|
|
|
|
|
{
|
|
|
|
|
if (\is_string($mItem))
|
|
|
|
|
{
|
|
|
|
|
$aInput[$mKey] = \MailSo\Base\Utils::Utf8Clear($mItem);
|
|
|
|
|
$aInput[$mKey] = static::Utf8Clear($mItem);
|
|
|
|
|
}
|
|
|
|
|
else if (\is_array($mItem))
|
|
|
|
|
{
|
|
|
|
|
\MailSo\Base\Utils::ClearArrayUtf8Values($mItem);
|
|
|
|
|
static::ClearArrayUtf8Values($mItem);
|
|
|
|
|
$aInput[$mKey] = $mItem;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -1380,8 +1261,8 @@ END;
|
|
|
|
|
if ($oLogger)
|
|
|
|
|
{
|
|
|
|
|
$oLogger->Write('json_encode: '.\trim(
|
|
|
|
|
(\MailSo\Base\Utils::FunctionExistsAndEnabled('json_last_error') ? ' [Error Code: '.\json_last_error().']' : '').
|
|
|
|
|
(\MailSo\Base\Utils::FunctionExistsAndEnabled('json_last_error_msg') ? ' [Error Message: '.\json_last_error_msg().']' : '')
|
|
|
|
|
(static::FunctionExistsAndEnabled('json_last_error') ? ' [Error Code: '.\json_last_error().']' : '').
|
|
|
|
|
(static::FunctionExistsAndEnabled('json_last_error_msg') ? ' [Error Message: '.\json_last_error_msg().']' : '')
|
|
|
|
|
), \MailSo\Log\Enumerations\Type::WARNING, 'JSON'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
@ -1394,7 +1275,7 @@ END;
|
|
|
|
|
$oLogger->Write('Trying to clear Utf8 before json_encode', \MailSo\Log\Enumerations\Type::INFO, 'JSON');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
\MailSo\Base\Utils::ClearArrayUtf8Values($mInput);
|
|
|
|
|
static::ClearArrayUtf8Values($mInput);
|
|
|
|
|
$sResult = @\json_encode($mInput, $iOpt);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -1409,8 +1290,8 @@ END;
|
|
|
|
|
*/
|
|
|
|
|
public static function ClearFileName($sFileName)
|
|
|
|
|
{
|
|
|
|
|
return \MailSo\Base\Utils::Trim(\MailSo\Base\Utils::ClearNullBite(
|
|
|
|
|
\MailSo\Base\Utils::StripSpaces(
|
|
|
|
|
return static::Trim(static::ClearNullBite(
|
|
|
|
|
static::StripSpaces(
|
|
|
|
|
\str_replace(array('"', '/', '\\', '*', '?', '<', '>', '|', ':'), ' ', $sFileName))));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -1421,7 +1302,7 @@ END;
|
|
|
|
|
*/
|
|
|
|
|
public static function ClearXss($sValue)
|
|
|
|
|
{
|
|
|
|
|
return \MailSo\Base\Utils::Trim(\MailSo\Base\Utils::ClearNullBite(
|
|
|
|
|
return static::Trim(static::ClearNullBite(
|
|
|
|
|
\str_replace(array('"', '/', '\\', '*', '?', '<', '>', '|', ':'), ' ', $sValue)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -1494,7 +1375,7 @@ END;
|
|
|
|
|
$sPathDir = $sSource.'/'.$sRead;
|
|
|
|
|
if (\is_dir($sPathDir))
|
|
|
|
|
{
|
|
|
|
|
\MailSo\Base\Utils::CopyDir($sPathDir, $sDestination.'/'.$sRead);
|
|
|
|
|
static::CopyDir($sPathDir, $sDestination.'/'.$sRead);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -1530,7 +1411,7 @@ END;
|
|
|
|
|
{
|
|
|
|
|
if (@\is_dir($sTempPath.'/'.$sFile))
|
|
|
|
|
{
|
|
|
|
|
if (!\MailSo\Base\Utils::RecTimeDirRemove($sTempPath.'/'.$sFile, $iTime2Kill, $iNow))
|
|
|
|
|
if (!static::RecTimeDirRemove($sTempPath.'/'.$sFile, $iTime2Kill, $iNow))
|
|
|
|
|
{
|
|
|
|
|
$bRemoveAllDirs = false;
|
|
|
|
|
}
|
|
|
|
|
@ -1547,7 +1428,7 @@ END;
|
|
|
|
|
|
|
|
|
|
if ($iFileCount > 0)
|
|
|
|
|
{
|
|
|
|
|
if (\MailSo\Base\Utils::TimeFilesRemove($sTempPath, $iTime2Kill, $iNow))
|
|
|
|
|
if (static::TimeFilesRemove($sTempPath, $iTime2Kill, $iNow))
|
|
|
|
|
{
|
|
|
|
|
return @\rmdir($sTempPath);
|
|
|
|
|
}
|
|
|
|
|
@ -1639,7 +1520,7 @@ END;
|
|
|
|
|
return $sUtfString;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$sUtfString = \preg_replace(\MailSo\Base\Utils::$sValidUtf8Regexp, '$1', $sUtfString);
|
|
|
|
|
$sUtfString = \preg_replace(static::$sValidUtf8Regexp, '$1', $sUtfString);
|
|
|
|
|
|
|
|
|
|
$sUtfString = \preg_replace(
|
|
|
|
|
'/\xE0[\x80-\x9F][\x80-\xBF]'.
|
|
|
|
|
@ -1648,16 +1529,7 @@ END;
|
|
|
|
|
|
|
|
|
|
$sUtfString = \preg_replace('/\xEF\xBF\xBD/', '?', $sUtfString);
|
|
|
|
|
|
|
|
|
|
$sNewUtfString = false;
|
|
|
|
|
if (false === $sNewUtfString && \MailSo\Base\Utils::IsMbStringSupported())
|
|
|
|
|
{
|
|
|
|
|
$sNewUtfString = \MailSo\Base\Utils::MbConvertEncoding($sUtfString, 'UTF-8', 'UTF-8');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (false === $sNewUtfString && \MailSo\Base\Utils::IsIconvSupported())
|
|
|
|
|
{
|
|
|
|
|
$sNewUtfString = \MailSo\Base\Utils::IconvConvertEncoding($sUtfString, 'UTF-8', 'UTF-8');
|
|
|
|
|
}
|
|
|
|
|
$sNewUtfString = static::MbConvertEncoding($sUtfString, 'UTF-8', 'UTF-8');
|
|
|
|
|
|
|
|
|
|
if (false !== $sNewUtfString)
|
|
|
|
|
{
|
|
|
|
|
@ -1733,7 +1605,7 @@ END;
|
|
|
|
|
public static function UrlSafeBase64Decode($sValue)
|
|
|
|
|
{
|
|
|
|
|
$sValue = \rtrim(\strtr($sValue, '-_.', '+/='), '=');
|
|
|
|
|
return \MailSo\Base\Utils::Base64Decode(\str_pad($sValue, \strlen($sValue) + (\strlen($sValue) % 4), '=', STR_PAD_RIGHT));
|
|
|
|
|
return static::Base64Decode(\str_pad($sValue, \strlen($sValue) + (\strlen($sValue) % 4), '=', STR_PAD_RIGHT));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -1838,7 +1710,7 @@ END;
|
|
|
|
|
if (false !== $sBuffer)
|
|
|
|
|
{
|
|
|
|
|
echo $sBuffer;
|
|
|
|
|
\MailSo\Base\Utils::ResetTimeLimit();
|
|
|
|
|
static::ResetTimeLimit();
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -1900,7 +1772,7 @@ END;
|
|
|
|
|
|
|
|
|
|
if ($bResetTimeLimit)
|
|
|
|
|
{
|
|
|
|
|
\MailSo\Base\Utils::ResetTimeLimit();
|
|
|
|
|
static::ResetTimeLimit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -2228,7 +2100,7 @@ END;
|
|
|
|
|
{
|
|
|
|
|
foreach ($mFunctionNameOrNames as $sFunctionName)
|
|
|
|
|
{
|
|
|
|
|
if (!\MailSo\Base\Utils::FunctionExistsAndEnabled($sFunctionName))
|
|
|
|
|
if (!static::FunctionExistsAndEnabled($sFunctionName))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
@ -2295,13 +2167,13 @@ END;
|
|
|
|
|
|
|
|
|
|
if (!$bIsMagicQuotesOn)
|
|
|
|
|
{
|
|
|
|
|
return $bClearNullBite && \is_string($mValue) ? \MailSo\Base\Utils::ClearNullBite($mValue) : $mValue;
|
|
|
|
|
return $bClearNullBite && \is_string($mValue) ? static::ClearNullBite($mValue) : $mValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$sType = \gettype($mValue);
|
|
|
|
|
if ('string' === $sType)
|
|
|
|
|
{
|
|
|
|
|
return \stripslashes($bClearNullBite ? \MailSo\Base\Utils::ClearNullBite($mValue) : $mValue);
|
|
|
|
|
return \stripslashes($bClearNullBite ? static::ClearNullBite($mValue) : $mValue);
|
|
|
|
|
}
|
|
|
|
|
else if ('array' === $sType)
|
|
|
|
|
{
|
|
|
|
|
@ -2309,7 +2181,7 @@ END;
|
|
|
|
|
$mValueKeys = \array_keys($mValue);
|
|
|
|
|
foreach ($mValueKeys as $sKey)
|
|
|
|
|
{
|
|
|
|
|
$aReturnValue[$sKey] = \MailSo\Base\Utils::StripSlashesValue($mValue[$sKey], $bClearNullBite);
|
|
|
|
|
$aReturnValue[$sKey] = static::StripSlashesValue($mValue[$sKey], $bClearNullBite);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $aReturnValue;
|
|
|
|
|
@ -2326,16 +2198,9 @@ END;
|
|
|
|
|
public static function CharsetDetect($sStr)
|
|
|
|
|
{
|
|
|
|
|
$mResult = '';
|
|
|
|
|
if (!\MailSo\Base\Utils::IsAscii($sStr))
|
|
|
|
|
if (!static::IsAscii($sStr))
|
|
|
|
|
{
|
|
|
|
|
$mResult = \MailSo\Base\Utils::IsMbStringSupported() &&
|
|
|
|
|
\MailSo\Base\Utils::FunctionExistsAndEnabled('mb_detect_encoding') ?
|
|
|
|
|
@\mb_detect_encoding($sStr, 'auto', true) : false;
|
|
|
|
|
|
|
|
|
|
if (false === $mResult && \MailSo\Base\Utils::IsIconvSupported())
|
|
|
|
|
{
|
|
|
|
|
$mResult = \md5(@\iconv('utf-8', 'utf-8//IGNORE', $sStr)) === \md5($sStr) ? 'utf-8' : '';
|
|
|
|
|
}
|
|
|
|
|
$mResult = \mb_detect_encoding($sStr, 'auto', true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return \is_string($mResult) && 0 < \strlen($mResult) ? $mResult : '';
|
|
|
|
|
@ -2427,7 +2292,7 @@ END;
|
|
|
|
|
static $oIdn = null;
|
|
|
|
|
if (null === $oIdn)
|
|
|
|
|
{
|
|
|
|
|
include_once MAILSO_LIBRARY_ROOT_PATH.'Vendors/Net/IDNA2.php';
|
|
|
|
|
include_once dirname(__DIR__).'/Vendors/Net/IDNA2.php';
|
|
|
|
|
$oIdn = new \Net_IDNA2();
|
|
|
|
|
$oIdn->setParams('utf8', true);
|
|
|
|
|
}
|
|
|
|
|
@ -2452,7 +2317,7 @@ END;
|
|
|
|
|
catch (\Exception $oException) {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $bLowerIfAscii ? \MailSo\Base\Utils::StrMailDomainToLowerIfAscii($sStr) : $sStr;
|
|
|
|
|
return $bLowerIfAscii ? static::StrMailDomainToLowerIfAscii($sStr) : $sStr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -2463,14 +2328,14 @@ END;
|
|
|
|
|
*/
|
|
|
|
|
public static function IdnToAscii($sStr, $bLowerIfAscii = false)
|
|
|
|
|
{
|
|
|
|
|
$sStr = $bLowerIfAscii ? \MailSo\Base\Utils::StrMailDomainToLowerIfAscii($sStr) : $sStr;
|
|
|
|
|
$sStr = $bLowerIfAscii ? static::StrMailDomainToLowerIfAscii($sStr) : $sStr;
|
|
|
|
|
|
|
|
|
|
$sUser = '';
|
|
|
|
|
$sDomain = $sStr;
|
|
|
|
|
if (false !== \strpos($sStr, '@'))
|
|
|
|
|
{
|
|
|
|
|
$sUser = \MailSo\Base\Utils::GetAccountNameFromEmail($sStr);
|
|
|
|
|
$sDomain = \MailSo\Base\Utils::GetDomainFromEmail($sStr);
|
|
|
|
|
$sUser = static::GetAccountNameFromEmail($sStr);
|
|
|
|
|
$sDomain = static::GetDomainFromEmail($sStr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (0 < \strlen($sDomain) && \preg_match('/[^\x20-\x7E]/', $sDomain))
|
|
|
|
|
|