mirror of
https://github.com/retailcrm/Fetch.git
synced 2024-11-22 19:26:01 +03:00
Fix for unsupported encodings
When using mb_convert_encoding, check identified charset against list of available encodings. If none match use US-ASCII if encoding is 7-bit; UTF-8 otherwise. When using iconv, suppress errors and check if the function returns false
This commit is contained in:
parent
ba247b861d
commit
886a1fe82e
@ -480,18 +480,22 @@ class Message
|
||||
if (!empty($parameters['charset']) && $parameters['charset'] !== self::$charset) {
|
||||
$mb_converted = false;
|
||||
if (function_exists('mb_convert_encoding')) {
|
||||
try {
|
||||
$messageBody = mb_convert_encoding($messageBody, self::$charset, $parameters['charset']);
|
||||
$mb_converted = true;
|
||||
} catch (Exception $e) {
|
||||
// @TODO Handle exception
|
||||
if (!in_array($parameters['charset'], mb_list_encodings())) {
|
||||
if ($structure->encoding === 0) {
|
||||
$parameters['charset'] = 'US-ASCII';
|
||||
} else {
|
||||
$parameters['charset'] = 'UTF-8';
|
||||
}
|
||||
}
|
||||
|
||||
$messageBody = @mb_convert_encoding($messageBody, self::$charset, $parameters['charset']);
|
||||
$mb_converted = true;
|
||||
}
|
||||
if (!$mb_converted) {
|
||||
try {
|
||||
$messageBody = iconv($parameters['charset'], self::$charset . self::$charsetFlag, $messageBody);
|
||||
} catch (Exception $e) {
|
||||
// @TODO Handle exception
|
||||
$messageBodyConv = @iconv($parameters['charset'], self::$charset . self::$charsetFlag, $messageBody);
|
||||
|
||||
if ($messageBodyConv !== false) {
|
||||
$messageBody = $messageBodyConv;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user