mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-01-01 12:32:40 +08:00
Replace PHP 8.2.0 deprecated utf8_decode/utf8_encode
This commit is contained in:
parent
897f22ee6e
commit
ba19d4e6b1
6 changed files with 24 additions and 50 deletions
|
@ -75,40 +75,24 @@ abstract class Locale
|
|||
|
||||
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;
|
||||
$sLocale = \strtolower(\trim(\setlocale(LC_ALL, '')));
|
||||
foreach (static::$aLocaleMapping as $sKey => $sValue) {
|
||||
if (\str_contains($sLocale, $sKey) || \str_contains($sLocale, '.'.$sValue)) {
|
||||
return $sValue;
|
||||
}
|
||||
}
|
||||
|
||||
return $sResult;
|
||||
return '';
|
||||
}
|
||||
|
||||
public static function ConvertSystemString(string $sSrt) : string
|
||||
{
|
||||
$sSrt = \trim($sSrt);
|
||||
if (!empty($sSrt) && !Utils::IsUtf8($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);
|
||||
}
|
||||
$sSrt = $sCharset
|
||||
? Utils::ConvertEncoding($sSrt, $sCharset, Enumerations\Charset::UTF_8)
|
||||
: \mb_convert_encoding($sSrt, 'UTF-8', 'ISO-8859-1');
|
||||
}
|
||||
|
||||
return $sSrt;
|
||||
}
|
||||
|
||||
|
|
|
@ -183,22 +183,12 @@ abstract class Utils
|
|||
return $sInputString;
|
||||
}
|
||||
|
||||
if ($sToEncoding === Enumerations\Charset::UTF_8) {
|
||||
if ($sFromEncoding === Enumerations\Charset::ISO_8859_1) {
|
||||
return \utf8_encode($sInputString);
|
||||
}
|
||||
if ($sFromEncoding === 'utf7-imap') {
|
||||
return static::Utf7ModifiedToUtf8($sInputString);
|
||||
}
|
||||
if ($sToEncoding === Enumerations\Charset::UTF_8 && $sFromEncoding === 'utf7-imap') {
|
||||
return static::Utf7ModifiedToUtf8($sInputString);
|
||||
}
|
||||
|
||||
if ($sFromEncoding === Enumerations\Charset::UTF_8) {
|
||||
if ($sToEncoding === Enumerations\Charset::ISO_8859_1) {
|
||||
return \utf8_decode($sInputString);
|
||||
}
|
||||
if ($sToEncoding === 'utf7-imap') {
|
||||
return static::Utf8ToUtf7Modified($sInputString);
|
||||
}
|
||||
if ($sFromEncoding === Enumerations\Charset::UTF_8 && $sToEncoding === 'utf7-imap') {
|
||||
return static::Utf8ToUtf7Modified($sInputString);
|
||||
}
|
||||
|
||||
return static::MbConvertEncoding($sInputString, $sFromEncoding, $sToEncoding);
|
||||
|
@ -1129,9 +1119,10 @@ abstract class Utils
|
|||
{
|
||||
$sResult = \is_callable('imap_mutf7_to_utf8')
|
||||
? \imap_mutf7_to_utf8($sStr)
|
||||
: \mb_convert_encoding($sStr, 'UTF-8', 'UTF7-IMAP');
|
||||
// static::MbConvertEncoding($sStr, 'UTF7-IMAP', 'UTF-8');
|
||||
// $sResult = \UConverter::transcode($sStr, \UConverter::UTF8, \UConverter::IMAP_MAILBOX);
|
||||
// : \mb_convert_encoding($sStr, 'UTF-8', 'UTF7-IMAP');
|
||||
: static::MbConvertEncoding($sStr, 'UTF7-IMAP', 'UTF-8');
|
||||
// ucnv U_FILE_ACCESS_ERROR
|
||||
// $sResult = \UConverter::transcode($sStr, \UConverter::UTF8, \UConverter::IMAP_MAILBOX, ['to_subst' => '<27>']);
|
||||
return (false === $sResult) ? $sStr : $sResult;
|
||||
}
|
||||
|
||||
|
@ -1139,8 +1130,9 @@ abstract class Utils
|
|||
{
|
||||
$sResult = \is_callable('imap_utf8_to_mutf7')
|
||||
? \imap_utf8_to_mutf7($sStr)
|
||||
: \mb_convert_encoding($sStr, 'UTF7-IMAP', 'UTF-8');
|
||||
// static::MbConvertEncoding($sStr, 'UTF-8', 'UTF7-IMAP');
|
||||
// : \mb_convert_encoding($sStr, 'UTF7-IMAP', 'UTF-8');
|
||||
: static::MbConvertEncoding($sStr, 'UTF-8', 'UTF7-IMAP');
|
||||
// ucnv U_FILE_ACCESS_ERROR
|
||||
// $sResult = \UConverter::transcode($sStr, \UConverter::IMAP_MAILBOX, \UConverter::UTF8);
|
||||
return (false === $sResult) ? $sStr : $sResult;
|
||||
}
|
||||
|
|
|
@ -219,7 +219,7 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
}
|
||||
else
|
||||
{
|
||||
$sPassword = $this->EscapeString(\utf8_decode($sPassword));
|
||||
$sPassword = $this->EscapeString(\mb_convert_encoding($sPassword, 'ISO-8859-1', 'UTF-8'));
|
||||
if ($this->oLogger)
|
||||
{
|
||||
$this->oLogger->AddSecret($sPassword);
|
||||
|
|
|
@ -41,7 +41,7 @@ class Legacy
|
|||
$sValue = \trim($oProp);
|
||||
if ($bOldVersion && !isset($oProp->parameters['CHARSET'])) {
|
||||
if (\strlen($sValue)) {
|
||||
$sEncValue = \utf8_encode($sValue);
|
||||
$sEncValue = \mb_convert_encoding($sValue, 'UTF-8', 'ISO-8859-1');
|
||||
if (\strlen($sEncValue)) {
|
||||
$sValue = $sEncValue;
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ class Legacy
|
|||
$sValue = \trim($sValue);
|
||||
if ($bOldVersion && !isset($oVCard->N->parameters['CHARSET'])) {
|
||||
if (\strlen($sValue)) {
|
||||
$sEncValue = \utf8_encode($sValue);
|
||||
$sEncValue = \mb_convert_encoding($sValue, 'UTF-8', 'ISO-8859-1');
|
||||
if (\strlen($sEncValue)) {
|
||||
$sValue = $sEncValue;
|
||||
}
|
||||
|
|
|
@ -1030,7 +1030,7 @@ class PdoAddressBook
|
|||
catch (\Throwable $oException) {
|
||||
$sResult = $oException->getMessage();
|
||||
if (!empty($sResult) && !\MailSo\Base\Utils::IsAscii($sResult) && !\MailSo\Base\Utils::IsUtf8($sResult)) {
|
||||
$sResult = \utf8_encode($sResult);
|
||||
$sResult = \mb_convert_encoding($sResult, 'UTF-8', 'ISO-8859-1');
|
||||
}
|
||||
|
||||
if (!\is_string($sResult) || empty($sResult)) {
|
||||
|
|
|
@ -465,8 +465,6 @@ class MimeDir extends Parser
|
|||
case 'utf-8':
|
||||
break;
|
||||
case 'iso-8859-1':
|
||||
$property['value'] = utf8_encode($property['value']);
|
||||
break;
|
||||
case 'windows-1252':
|
||||
$property['value'] = mb_convert_encoding($property['value'], 'UTF-8', $charset);
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue