mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-30 20:49:20 +03:00
Header parser fixes (ISO_2022_JP charset probles) (Closes #355)
+ Small fixes
This commit is contained in:
parent
6b0ca800e8
commit
3a9bc849c9
15 changed files with 131 additions and 59 deletions
|
|
@ -33,4 +33,5 @@ class Charset
|
|||
const ISO_8859_1 = 'iso-8859-1';
|
||||
const ISO_8859_8 = 'iso-8859-8';
|
||||
const ISO_8859_8_I = 'iso-8859-8-i';
|
||||
const ISO_2022_JP = 'iso-2022-jp';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -198,6 +198,27 @@ class Utils
|
|||
return $sEncoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sCharset
|
||||
* @param string $sValue
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function NormalizeCharsetByValue($sCharset, $sValue)
|
||||
{
|
||||
$sCharset = \MailSo\Base\Utils::NormalizeCharset($sCharset);
|
||||
|
||||
if (\MailSo\Base\Enumerations\Charset::UTF_8 !== $sCharset &&
|
||||
\MailSo\Base\Utils::IsUtf8($sValue) &&
|
||||
false === \strpos($sCharset, \MailSo\Base\Enumerations\Charset::ISO_2022_JP)
|
||||
)
|
||||
{
|
||||
$sCharset = \MailSo\Base\Enumerations\Charset::UTF_8;
|
||||
}
|
||||
|
||||
return $sCharset;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
|
|
@ -296,14 +317,13 @@ class Utils
|
|||
$mResult = @\iconv(\strtoupper($sInputFromEncoding), \strtoupper($sInputToEncoding).$sIconvOptions, $sInputString);
|
||||
if (false === $mResult)
|
||||
{
|
||||
if (\MailSo\Config::$SystemLogger instanceof \MailSo\Log\Logger)
|
||||
if (\MailSo\Log\Logger::IsSystemEnabled())
|
||||
{
|
||||
$sHex = 500 < \strlen($sInputString) ? '' : \bin2hex($sInputString);
|
||||
\MailSo\Config::$SystemLogger->WriteDump(array(
|
||||
\MailSo\Log\Logger::SystemLog(array(
|
||||
'inc' => \strtoupper($sInputFromEncoding),
|
||||
'out' => \strtoupper($sInputToEncoding).$sIconvOptions,
|
||||
'val' => $sInputString,
|
||||
'hex' => $sHex
|
||||
'val' => 500 < \strlen($sInputString) ? \substr($sInputString, 0, 500) : $sInputString,
|
||||
'hex' => 500 < \strlen($sInputString) ? '-- to long --' : \bin2hex($sInputString)
|
||||
), \MailSo\Log\Enumerations\Type::NOTICE);
|
||||
}
|
||||
|
||||
|
|
@ -471,7 +491,7 @@ class Utils
|
|||
*/
|
||||
public static function IsUtf8($sValue)
|
||||
{
|
||||
return (bool) (\function_exists('mb_check_encoding') ?
|
||||
return (bool) ( \function_exists('mb_check_encoding') ?
|
||||
\mb_check_encoding($sValue, 'UTF-8') : \preg_match('//u', $sValue));
|
||||
}
|
||||
|
||||
|
|
@ -527,10 +547,7 @@ class Utils
|
|||
$sValue = $sEncodedValue;
|
||||
if (0 < \strlen($sIncomingCharset))
|
||||
{
|
||||
if (\MailSo\Base\Enumerations\Charset::UTF_8 !== $sIncomingCharset && \MailSo\Base\Utils::IsUtf8($sValue))
|
||||
{
|
||||
$sIncomingCharset = \MailSo\Base\Enumerations\Charset::UTF_8;
|
||||
}
|
||||
$sIncomingCharset = \MailSo\Base\Utils::NormalizeCharsetByValue($sIncomingCharset, $sValue);
|
||||
|
||||
$sValue = \MailSo\Base\Utils::ConvertEncoding($sValue, $sIncomingCharset,
|
||||
\MailSo\Base\Enumerations\Charset::UTF_8);
|
||||
|
|
@ -620,10 +637,7 @@ class Utils
|
|||
}
|
||||
else
|
||||
{
|
||||
if (\MailSo\Base\Enumerations\Charset::UTF_8 !== $aParts[$iIndex][2] && \MailSo\Base\Utils::IsUtf8($aParts[$iIndex][1]))
|
||||
{
|
||||
$aParts[$iIndex][2] = \MailSo\Base\Enumerations\Charset::UTF_8;
|
||||
}
|
||||
$aParts[$iIndex][2] = \MailSo\Base\Utils::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),
|
||||
|
|
@ -633,11 +647,7 @@ class Utils
|
|||
|
||||
if ($bOneCharset && 0 < \strlen($sMainCharset))
|
||||
{
|
||||
if (\MailSo\Base\Enumerations\Charset::UTF_8 !== $sMainCharset && \MailSo\Base\Utils::IsUtf8($sValue))
|
||||
{
|
||||
$sMainCharset = \MailSo\Base\Enumerations\Charset::UTF_8;
|
||||
}
|
||||
|
||||
$sMainCharset = \MailSo\Base\Utils::NormalizeCharsetByValue($sMainCharset, $sValue);
|
||||
$sValue = \MailSo\Base\Utils::ConvertEncoding($sValue, $sMainCharset, \MailSo\Base\Enumerations\Charset::UTF_8);
|
||||
}
|
||||
|
||||
|
|
@ -1163,12 +1173,17 @@ class Utils
|
|||
$sResult = @\json_encode($mInput, $iOpt);
|
||||
if (!\is_string($sResult) || '' === $sResult)
|
||||
{
|
||||
if (!$oLogger && \MailSo\Config::$SystemLogger instanceof \MailSo\Log\Logger)
|
||||
if (!$oLogger && \MailSo\Log\Logger::IsSystemEnabled())
|
||||
{
|
||||
$oLogger = \MailSo\Config::$SystemLogger;
|
||||
}
|
||||
|
||||
if ($oLogger instanceof \MailSo\Log\Logger)
|
||||
if (!($oLogger instanceof \MailSo\Log\Logger))
|
||||
{
|
||||
$oLogger = null;
|
||||
}
|
||||
|
||||
if ($oLogger)
|
||||
{
|
||||
$oLogger->Write('json_encode: '.\trim(
|
||||
(\MailSo\Base\Utils::FunctionExistsAndEnabled('json_last_error') ? ' [Error Code: '.\json_last_error().']' : '').
|
||||
|
|
@ -1179,7 +1194,7 @@ class Utils
|
|||
|
||||
if (\is_array($mInput))
|
||||
{
|
||||
if ($oLogger instanceof \MailSo\Log\Logger)
|
||||
if ($oLogger)
|
||||
{
|
||||
$oLogger->WriteDump($mInput, \MailSo\Log\Enumerations\Type::INFO, 'JSON');
|
||||
$oLogger->Write('Trying to clear Utf8 before json_encode', \MailSo\Log\Enumerations\Type::INFO, 'JSON');
|
||||
|
|
|
|||
|
|
@ -83,6 +83,26 @@ class Logger extends \MailSo\Base\Collection
|
|||
return $oInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public static function IsSystemEnabled()
|
||||
{
|
||||
return !!(\MailSo\Config::$SystemLogger instanceof \MailSo\Log\Logger);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $mData
|
||||
* @param int $iType = \MailSo\Log\Enumerations\Type::INFO
|
||||
*/
|
||||
public static function SystemLog($mData, $iType = \MailSo\Log\Enumerations\Type::INFO)
|
||||
{
|
||||
if (\MailSo\Config::$SystemLogger instanceof \MailSo\Log\Logger)
|
||||
{
|
||||
\MailSo\Config::$SystemLogger->WriteMixed($mData, $iType);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @staticvar string $sCache;
|
||||
*
|
||||
|
|
|
|||
|
|
@ -279,6 +279,9 @@ abstract class NetClient
|
|||
|
||||
\restore_error_handler();
|
||||
|
||||
$this->writeLog('Connected ('.(\is_resource($this->rConnect) ? 'success' : 'unsuccess').')',
|
||||
\MailSo\Log\Enumerations\Type::NOTE);
|
||||
|
||||
if (!\is_resource($this->rConnect))
|
||||
{
|
||||
$this->writeLogException(
|
||||
|
|
@ -316,7 +319,7 @@ abstract class NetClient
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -676,13 +676,13 @@ class Actions
|
|||
case ('APC' === $sDriver || 'APCU' === $sDriver) &&
|
||||
\MailSo\Base\Utils::FunctionExistsAndEnabled(array(
|
||||
'apc_store', 'apc_fetch', 'apc_delete', 'apc_clear_cache')):
|
||||
|
||||
|
||||
$oDriver = \MailSo\Cache\Drivers\APC::NewInstance();
|
||||
break;
|
||||
|
||||
case ('MEMCACHE' === $sDriver || 'MEMCACHED' === $sDriver) &&
|
||||
\MailSo\Base\Utils::FunctionExistsAndEnabled('memcache_connect'):
|
||||
|
||||
|
||||
$oDriver = \MailSo\Cache\Drivers\Memcache::NewInstance(
|
||||
$this->Config()->Get('labs', 'fast_cache_memcache_host', '127.0.0.1'),
|
||||
(int) $this->Config()->Get('labs', 'fast_cache_memcache_port', 11211)
|
||||
|
|
@ -755,11 +755,11 @@ class Actions
|
|||
$this->oLogger->WriteEmptyLine();
|
||||
|
||||
$oHttp = $this->Http();
|
||||
|
||||
|
||||
$this->oLogger->Write('[DATE:'.\gmdate('d.m.y').'][RL:'.APP_VERSION.'][PHP:'.PHP_VERSION.'][IP:'.
|
||||
$oHttp->GetClientIp().'][PID:'.(\MailSo\Base\Utils::FunctionExistsAndEnabled('getmypid') ? \getmypid() : 'unknown').
|
||||
'][GUID:'.\MailSo\Log\Logger::Guid().']');
|
||||
|
||||
|
||||
$this->oLogger->Write(
|
||||
'[APC:'.(\MailSo\Base\Utils::FunctionExistsAndEnabled('apc_fetch') ? 'on' : 'off').']'.
|
||||
'[MB:'.(\MailSo\Base\Utils::FunctionExistsAndEnabled('mb_convert_encoding') ? 'on' : 'off').']'.
|
||||
|
|
@ -901,7 +901,7 @@ class Actions
|
|||
$oAccount->SetProxyAuthUser($aAccountHash[8]);
|
||||
$oAccount->SetProxyAuthUser($aAccountHash[89]);
|
||||
}
|
||||
|
||||
|
||||
$this->Logger()->AddSecret($oAccount->Password());
|
||||
$this->Logger()->AddSecret($oAccount->ProxyAuthPassword());
|
||||
|
||||
|
|
@ -1489,7 +1489,7 @@ class Actions
|
|||
if (false === \strpos($sEmail, '@') || 0 === \strlen($sPassword))
|
||||
{
|
||||
$this->loginErrorDelay();
|
||||
|
||||
|
||||
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::InvalidInputArgument);
|
||||
}
|
||||
|
||||
|
|
@ -1501,7 +1501,7 @@ class Actions
|
|||
$this->Logger()->AddSecret($sPassword);
|
||||
|
||||
$this->Plugins()->RunHook('event.login-pre-login-provide', array());
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
$oAccount = $this->LoginProvide($sEmail, $sLogin, $sPassword, $sSignMeToken, true);
|
||||
|
|
@ -1540,7 +1540,7 @@ class Actions
|
|||
if (empty($sAdditionalCode))
|
||||
{
|
||||
$this->Logger()->Write('TFA: Required Code for '.$oAccount->ParentEmailHelper().' account.');
|
||||
|
||||
|
||||
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::AccountTwoFactorAuthRequired);
|
||||
}
|
||||
else
|
||||
|
|
@ -4747,7 +4747,7 @@ class Actions
|
|||
{
|
||||
$oSmtpClient->Logout();
|
||||
}
|
||||
|
||||
|
||||
$oSmtpClient->Disconnect();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue