Skip to content

Commit

Permalink
Merge pull request #1309 from shawniverson/091424encodingfix
Browse files Browse the repository at this point in the history
Improve utf8 conversion in viewpart.php for ISO character sets
  • Loading branch information
endelwar authored Sep 16, 2024
2 parents 93bc895 + c9a4964 commit 11af50d
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions mailscanner/viewpart.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,12 @@ function decode_structure($structure)
}
*/
if (isset($structure->ctype_parameters['charset'])) {
if ('windows-1255' == strtolower($structure->ctype_parameters['charset'])) {
$structure->body = iconv('ISO-8859-8', 'UTF-8', $structure->body);
} elseif ('utf-8' !== strtolower($structure->ctype_parameters['charset'])) {
$charset = strtoupper($structure->ctype_parameters['charset']);
if ('WINDOWS-1255' === $charset ) {
$structure->body = iconv('ISO-8859-8//TRANSLIT', 'UTF-8', $structure->body);
} elseif ( preg_match('/^ISO-8859-([1-9]|10|1[3-6])$/',$charset)) {
$structure->body = iconv(sprintf('%s//TRANSLIT',$charset), 'UTF-8', $structure->body);
} elseif ('UTF-8' !== $charset) {
$structure->body = getUTF8String($structure->body);
}
}
Expand All @@ -156,9 +159,12 @@ function decode_structure($structure)
case 'text/html':
echo '<!DOCTYPE html>' . "\n";
if (isset($structure->ctype_parameters['charset'])) {
if ('windows-1255' == strtolower($structure->ctype_parameters['charset'])) {
$structure->body = iconv('ISO-8859-8', 'UTF-8', $structure->body);
} elseif ('utf-8' !== strtolower($structure->ctype_parameters['charset'])) {
$charset = strtoupper($structure->ctype_parameters['charset']);
if ('WINDOWS-1255' === $charset ) {
$structure->body = iconv('ISO-8859-8//TRANSLIT', 'UTF-8', $structure->body);
} elseif ( preg_match('/^ISO-8859-([1-9]|10|1[3-6])$/',$charset)) {
$structure->body = iconv(sprintf('%s//TRANSLIT',$charset), 'UTF-8', $structure->body);
} elseif ('UTF-8' !== $charset) {
$structure->body = getUTF8String($structure->body);
}
}
Expand Down

0 comments on commit 11af50d

Please sign in to comment.