Skip to content

Commit

Permalink
Catch mb_convert_encoding() error on fetching - closes #4051
Browse files Browse the repository at this point in the history
  • Loading branch information
freescout-help-desk committed Jun 1, 2024
1 parent a93cc2a commit d402dd5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/Misc/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1969,6 +1969,7 @@ public static function checkRequiredFunctions()
'proc_open (PHP)' => function_exists('proc_open'),
'fpassthru (PHP)' => function_exists('fpassthru'),
'symlink (PHP)' => function_exists('symlink'),
'iconv (PHP)' => function_exists('iconv'),
'pcntl_signal (console PHP)' => function_exists('shell_exec') ? (int)\Helper::shellExec('php -r "echo (int)function_exists(\'pcntl_signal\');"') : false,
'ps (shell)' => function_exists('shell_exec') ? \Helper::shellExec('ps') : false,
];
Expand Down
20 changes: 14 additions & 6 deletions overrides/webklex/php-imap/src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -741,13 +741,21 @@ public function convertEncoding($str, string $from = "ISO-8859-2", string $to =
// In some cases iconv can't decode the string and returns:
// Detected an illegal character in input string.
// https://github.com/freescout-helpdesk/freescout/issues/3089
if (!$result) {
if (!$from) {
return mb_convert_encoding($str, $to);

// Use try...catch to avoid:
// mb_convert_encoding(): Argument #3 ($from_encoding) contains invalid encoding "windows-1257"
// https://github.com/freescout-helpdesk/freescout/issues/4051
try {
if (!$result) {
if (!$from) {
return mb_convert_encoding($str, $to);
}
return mb_convert_encoding($str, $to, $from);
} else {
return $result;
}
return mb_convert_encoding($str, $to, $from);
} else {
return $result;
} catch (\Exception $e) {
return $str;
}
}

Expand Down

0 comments on commit d402dd5

Please sign in to comment.