Skip to content

Commit

Permalink
Fix mb_convert_encoding() invalid encoding error on fetching - closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
freescout-help-desk committed Jun 1, 2024
1 parent d402dd5 commit 505db99
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/Console/Commands/TestWebklex.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function handle()
$this->line('In-Reply-To: ');
$this->info($message->getInReplyTo());
$this->line('References: ');
$this->info(json_encode(array_values(array_filter(preg_split('/[, <>]/', $message->getReferences() ?? []))), JSON_UNESCAPED_UNICODE));
$this->info(json_encode(array_values(array_filter(preg_split('/[, <>]/', $message->getReferences() ?? ''))), JSON_UNESCAPED_UNICODE));
$this->line('Subject: ');
$this->info($message->getSubject());
$this->line('Text Body: ');
Expand Down
9 changes: 6 additions & 3 deletions overrides/webklex/php-imap/src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -722,13 +722,16 @@ public function convertEncoding($str, string $from = "ISO-8859-2", string $to =
if (strtolower($from ?? '') == 'us-ascii' && $to == 'UTF-8') {
return $str;
}
if (!$str) {
return $str;
}

$result = '';

if (strtolower($from) == 'iso-2022-jp'){
$from = 'iso-2022-jp-ms';
}

// Try iconv.
if (function_exists('iconv') && $from != 'UTF-7' && $to != 'UTF-7' && $from != 'iso-2022-jp-ms') {
try {
Expand All @@ -742,7 +745,7 @@ public function convertEncoding($str, string $from = "ISO-8859-2", string $to =
// Detected an illegal character in input string.
// https://github.com/freescout-helpdesk/freescout/issues/3089

// Use try...catch to avoid:
// 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 {
Expand All @@ -754,7 +757,7 @@ public function convertEncoding($str, string $from = "ISO-8859-2", string $to =
} else {
return $result;
}
} catch (\Exception $e) {
} catch (\Throwable $e) {
return $str;
}
}
Expand Down

0 comments on commit 505db99

Please sign in to comment.