Skip to content

Commit

Permalink
Handled unsupported charsets on mb_convert_encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
josaphatim committed Aug 2, 2023
1 parent aeb9b75 commit 23cd9cd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"ext-openssl": "*",
"ext-session": "*",
"ext-fileinfo": "*",
"ext-iconv": "*",
"webklex/composer-info": "^0.0.1",
"composer" : "^2.0.0",
"zbateson/mail-mime-parser": "^2.4"
Expand Down
14 changes: 12 additions & 2 deletions modules/core/message_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,17 +403,27 @@ function decode_fld($string) {
$encoding = $fld[0];
$fld = substr($fld, (strpos($fld, '?') + 1));
if (strtoupper($encoding) == 'B') {
$fld = mb_convert_encoding(base64_decode($fld), 'UTF-8', $charset);
$fld = convert_to_utf8(base64_decode($fld), $charset);
}
elseif (strtoupper($encoding) == 'Q') {
$fld = mb_convert_encoding(quoted_printable_decode(str_replace('_', ' ', $fld)), 'UTF-8', $charset);
$fld = convert_to_utf8(quoted_printable_decode(str_replace('_', ' ', $fld)), $charset);
}
$string = str_replace($v, $fld, $string);
}
}
return trim($string);
}}

if (!hm_exists('convert_to_utf8')) {
function convert_to_utf8($data, $from_encoding) {
try {
$data = mb_convert_encoding($data, 'UTF-8', $from_encoding);
} catch (ValueError $e) {
$data = iconv($from_encoding, 'UTF-8', $data);
}
return $data;
}}

/**
* @subpackage core/class
*/
Expand Down

0 comments on commit 23cd9cd

Please sign in to comment.