From 4e51982134a256a0e0193d2a341b88315f28f5f3 Mon Sep 17 00:00:00 2001 From: tokul Date: Sun, 5 Oct 2003 08:16:09 +0000 Subject: [PATCH 1/1] Decoding support added when replying or forwarding message. Original patch was provided by Viktor S. Grishchenko Currently patch works only with utf-8 translations and with Ukrainian/Bulgarian translations if message has similar charset. Patch should not have any effect on other translations and From: and Subject: headers still need to be fixed with some messages. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@5829 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/i18n.php | 71 ++++++++++++++++++++++++++++++++++++++++++++++ src/compose.php | 8 +++++- 2 files changed, 78 insertions(+), 1 deletion(-) diff --git a/functions/i18n.php b/functions/i18n.php index 1208da44..a0e94563 100644 --- a/functions/i18n.php +++ b/functions/i18n.php @@ -852,4 +852,75 @@ endswitch; // return space instead of non-braking space. return str_replace($nbsp,' ',$string); } + +function is_conversion_safe($input_charset) { + global $languages, $sm_notAlias, $default_charset; + + // convert to lower case + $input_charset = strtolower($input_charset); + + // Is user's locale Unicode based ? + if ( $default_charset == "utf-8" ) { + return true; + } + + // Charsets that are similar +switch ($default_charset): +case "windows-1251": + if ( $input_charset == "iso-8859-5" || + $input_charset == "koi8-r" || + $input_charset == "koi8-u" ) { + return true; + } else { + return false; + } +case "windows-1257": + if ( $input_charset == "iso-8859-13" || + $input_charset == "iso-8859-4" ) { + return true; + } else { + return false; + } +case "iso-8859-4": + if ( $input_charset == "iso-8859-13" || + $input_charset == "windows-1257" ) { + return true; + } else { + return false; + } +case "iso-8859-5": + if ( $input_charset == "windows-1251" || + $input_charset == "koi8-r" || + $input_charset == "koi8-u" ) { + return true; + } else { + return false; + } +case "iso-8859-13": + if ( $input_charset == "iso-8859-4" || + $input_charset == "windows-1257" ) { + return true; + } else { + return false; + } +case "koi8-r": + if ( $input_charset == "windows-1251" || + $input_charset == "iso-8859-5" || + $input_charset == "koi8-u" ) { + return true; + } else { + return false; + } +case "koi8-u": + if ( $input_charset == "windows-1251" || + $input_charset == "iso-8859-5" || + $input_charset == "koi8-r" ) { + return true; + } else { + return false; + } +default: + return false; +endswitch; +} ?> diff --git a/src/compose.php b/src/compose.php index f3d50088..8f7393cc 100644 --- a/src/compose.php +++ b/src/compose.php @@ -562,7 +562,7 @@ function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $se $use_signature, $composesession, $data_dir, $username, $username, $key, $imapServerAddress, $imapPort, $compose_messages, $composeMessage; - global $languages, $squirrelmail_language; + global $languages, $squirrelmail_language, $default_charset; $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = ''; $mailprio = 3; @@ -619,6 +619,12 @@ function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $se $bodypart = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $bodypart); } } + + $actual = $body_part_entity->header->parameters['charset']; + if ( $actual && is_conversion_safe($actual) && $actual != $default_charset){ + $bodypart = charset_decode($actual,$bodypart); + } + $body .= $bodypart; } if ($default_use_priority) { -- 2.25.1