From 1b497ae239c810e0c65a1271e6e7767b33f394a0 Mon Sep 17 00:00:00 2001 From: djmaze Date: Tue, 31 Aug 2021 08:12:55 +0200 Subject: [PATCH] Move \MailSo\Base\Utils::ConvertSystemString to \MailSo\Base\Locale::ConvertSystemString --- .../app/libraries/MailSo/Base/Locale.php | 115 ++++++++++++++++++ .../0.0.0/app/libraries/MailSo/Base/Utils.php | 95 --------------- .../app/libraries/MailSo/Net/NetClient.php | 2 +- 3 files changed, 116 insertions(+), 96 deletions(-) create mode 100644 snappymail/v/0.0.0/app/libraries/MailSo/Base/Locale.php diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Base/Locale.php b/snappymail/v/0.0.0/app/libraries/MailSo/Base/Locale.php new file mode 100644 index 000000000..f0a00319d --- /dev/null +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Base/Locale.php @@ -0,0 +1,115 @@ + 'utf-8', + '.20127' => 'iso-8859-1', + + '.1250' => 'windows-1250', + '.cp1250' => 'windows-1250', + '.cp-1250' => 'windows-1250', + '.1251' => 'windows-1251', + '.cp1251' => 'windows-1251', + '.cp-1251' => 'windows-1251', + '.1252' => 'windows-1252', + '.cp1252' => 'windows-1252', + '.cp-1252' => 'windows-1252', + '.1253' => 'windows-1253', + '.cp1253' => 'windows-1253', + '.cp-1253' => 'windows-1253', + '.1254' => 'windows-1254', + '.cp1254' => 'windows-1254', + '.cp-1254' => 'windows-1254', + '.1255' => 'windows-1255', + '.cp1255' => 'windows-1255', + '.cp-1255' => 'windows-1255', + '.1256' => 'windows-1256', + '.cp1256' => 'windows-1256', + '.cp-1256' => 'windows-1256', + '.1257' => 'windows-1257', + '.cp1257' => 'windows-1257', + '.cp-1257' => 'windows-1257', + '.1258' => 'windows-1258', + '.cp1258' => 'windows-1258', + '.cp-1258' => 'windows-1258', + + '.28591' => 'iso-8859-1', + '.28592' => 'iso-8859-2', + '.28593' => 'iso-8859-3', + '.28594' => 'iso-8859-4', + '.28595' => 'iso-8859-5', + '.28596' => 'iso-8859-6', + '.28597' => 'iso-8859-7', + '.28598' => 'iso-8859-8', + '.28599' => 'iso-8859-9', + '.28603' => 'iso-8859-13', + '.28605' => 'iso-8859-15', + + '.1125' => 'cp1125', + '.20866' => 'koi8-r', + '.21866' => 'koi8-u', + '.950' => 'big5', + '.936' => 'euc-cn', + '.20932' => 'euc-js', + '.949' => 'euc-kr', + ); + + public static function DetectSystemCharset() : string + { + $sResult = ''; + $sLocale = \setlocale(LC_ALL, ''); + $sLocaleLower = \strtolower(\trim($sLocale)); + + foreach (static::$aLocaleMapping as $sKey => $sValue) + { + if (false !== \strpos($sLocaleLower, $sKey) || + false !== \strpos($sLocaleLower, '.'.$sValue)) + { + $sResult = $sValue; + break; + } + } + + return $sResult; + } + + public static function ConvertSystemString(string $sSrt) : string + { + $sSrt = \trim($sSrt); + if (!empty($sSrt) && !Utils::IsUtf8($sSrt)) + { + $sCharset = static::DetectSystemCharset(); + if (!empty($sCharset)) + { + $sSrt = Utils::ConvertEncoding( + $sSrt, $sCharset, Enumerations\Charset::UTF_8); + } + else + { + $sSrt = \utf8_encode($sSrt); + } + } + + return $sSrt; + } + +} diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Base/Utils.php b/snappymail/v/0.0.0/app/libraries/MailSo/Base/Utils.php index c308d1469..13f30c1e8 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Base/Utils.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Base/Utils.php @@ -33,101 +33,6 @@ abstract class Utils /x END; - /** - * @var array - */ - public static $aLocaleMapping = array( - '.65001' => 'utf-8', - '.20127' => 'iso-8859-1', - - '.1250' => 'windows-1250', - '.cp1250' => 'windows-1250', - '.cp-1250' => 'windows-1250', - '.1251' => 'windows-1251', - '.cp1251' => 'windows-1251', - '.cp-1251' => 'windows-1251', - '.1252' => 'windows-1252', - '.cp1252' => 'windows-1252', - '.cp-1252' => 'windows-1252', - '.1253' => 'windows-1253', - '.cp1253' => 'windows-1253', - '.cp-1253' => 'windows-1253', - '.1254' => 'windows-1254', - '.cp1254' => 'windows-1254', - '.cp-1254' => 'windows-1254', - '.1255' => 'windows-1255', - '.cp1255' => 'windows-1255', - '.cp-1255' => 'windows-1255', - '.1256' => 'windows-1256', - '.cp1256' => 'windows-1256', - '.cp-1256' => 'windows-1256', - '.1257' => 'windows-1257', - '.cp1257' => 'windows-1257', - '.cp-1257' => 'windows-1257', - '.1258' => 'windows-1258', - '.cp1258' => 'windows-1258', - '.cp-1258' => 'windows-1258', - - '.28591' => 'iso-8859-1', - '.28592' => 'iso-8859-2', - '.28593' => 'iso-8859-3', - '.28594' => 'iso-8859-4', - '.28595' => 'iso-8859-5', - '.28596' => 'iso-8859-6', - '.28597' => 'iso-8859-7', - '.28598' => 'iso-8859-8', - '.28599' => 'iso-8859-9', - '.28603' => 'iso-8859-13', - '.28605' => 'iso-8859-15', - - '.1125' => 'cp1125', - '.20866' => 'koi8-r', - '.21866' => 'koi8-u', - '.950' => 'big5', - '.936' => 'euc-cn', - '.20932' => 'euc-js', - '.949' => 'euc-kr', - ); - - public static function DetectSystemCharset() : string - { - $sResult = ''; - $sLocale = \setlocale(LC_ALL, ''); - $sLocaleLower = \strtolower(\trim($sLocale)); - - foreach (static::$aLocaleMapping as $sKey => $sValue) - { - if (false !== \strpos($sLocaleLower, $sKey) || - false !== \strpos($sLocaleLower, '.'.$sValue)) - { - $sResult = $sValue; - break; - } - } - - return $sResult; - } - - public static function ConvertSystemString(string $sSrt) : string - { - $sSrt = \trim($sSrt); - if (!empty($sSrt) && !static::IsUtf8($sSrt)) - { - $sCharset = static::DetectSystemCharset(); - if (!empty($sCharset)) - { - $sSrt = static::ConvertEncoding( - $sSrt, $sCharset, \MailSo\Base\Enumerations\Charset::UTF_8); - } - else - { - $sSrt = \utf8_encode($sSrt); - } - } - - return $sSrt; - } - public static function NormalizeCharset(string $sEncoding, bool $bAsciAsUtf8 = false) : string { $sEncoding = \strtolower($sEncoding); diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Net/NetClient.php b/snappymail/v/0.0.0/app/libraries/MailSo/Net/NetClient.php index ec34e5232..bb1ebfcc3 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Net/NetClient.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Net/NetClient.php @@ -258,7 +258,7 @@ abstract class NetClient { $this->writeLogException( new Exceptions\SocketCanNotConnectToHostException( - \MailSo\Base\Utils::ConvertSystemString($sErrorStr), (int) $iErrorNo, + \MailSo\Base\Locale::ConvertSystemString($sErrorStr), (int) $iErrorNo, 'Can\'t connect to host "'.$this->sConnectedHost.':'.$this->iConnectedPort.'"' ), \MailSo\Log\Enumerations\Type::NOTICE, true); }