private function ConvertCharset($text, $headers, $subj, $def_enc, $post_enc) { if (CF_ENABLE_ICONV && ICONV_VERSION != '') { if ($subj == 1) { $GLOBALS["encod"] = $post_enc; $GLOBALS["def_enc"] = $def_enc; return charset_decode($text, $headers); } else { $cur_charset = $post_enc; if (CF_ENABLE_ICONV && ICONV_VERSION != '') { if (strtolower($cur_charset) != 'utf-8' && $cur_charset != '') return iconv(strtoupper($cur_charset), "UTF-8", $this->ReplaceSpecialChars($text)); else if ($def_enc) return iconv(strtoupper($def_enc), "UTF-8", $this->ReplaceSpecialChars($text)); else return $this->ReplaceSpecialChars($text); } else return $text; } } else return $text; }
$msg_url = set_url_var($msg_url, 'ent_id', 0); $dwnld_url = '../src/download.php?' . $QUERY_STRING . '&absolute_dl=true'; $unsafe_url = 'view_text.php?' . $QUERY_STRING; $unsafe_url = set_url_var($unsafe_url, 'view_unsafe_images', 1); $body = mime_fetch_body($imapConnection, $passed_id, $ent_id); $body = decodeBody($body, $encoding); if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) { if (mb_detect_encoding($body) != 'ASCII') { $body = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $body); } } if ($type1 == 'html' || isset($override_type1) && $override_type1 == 'html') { $ishtml = TRUE; // html attachment with character set information if (!empty($charset)) { $body = charset_decode($charset, $body, false, true); } $body = magicHTML($body, $passed_id, $message, $mailbox); } else { $ishtml = FALSE; translateText($body, $wrap_at, $charset); } displayPageHeader($color, 'None'); ?> <br /><table width="100%" border="0" cellspacing="0" cellpadding="2" align="center"><tr><td bgcolor="<?php echo $color[0]; ?> "> <b><center> <?php echo _("Viewing a text attachment") . ' - ' . '<a href="' . $msg_url . '">' . _("View message") . '</a>';
/** * Decodes headers * * This functions decode strings that is encoded according to * RFC1522 (MIME Part Two: Message Header Extensions for Non-ASCII Text). * Patched by Christian Schmidt <*****@*****.**> 23/03/2002 */ function decodeHeader($string, $utfencode = true, $htmlsave = true, $decide = false) { global $languages, $squirrelmail_language, $default_charset; if (is_array($string)) { $string = implode("\n", $string); } if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) { $string = $languages[$squirrelmail_language]['XTRA_CODE']('decodeheader', $string); // Do we need to return at this point? // return $string; } $i = 0; $iLastMatch = -2; $encoded = false; $aString = explode(' ', $string); $ret = ''; foreach ($aString as $chunk) { if ($encoded && $chunk === '') { continue; } elseif ($chunk === '') { $ret .= ' '; continue; } $encoded = false; /* if encoded words are not separated by a linear-space-white we still catch them */ $j = $i - 1; while ($match = preg_match('/^(.*)=\\?([^?]*)\\?(Q|B)\\?([^?]*)\\?=(.*)$/Ui', $chunk, $res)) { /* if the last chunk isn't an encoded string then put back the space, otherwise don't */ if ($iLastMatch !== $j) { if ($htmlsave) { $ret .= ' '; } else { $ret .= ' '; } } $iLastMatch = $i; $j = $i; if ($htmlsave) { $ret .= htmlspecialchars($res[1]); } else { $ret .= $res[1]; } $encoding = ucfirst($res[3]); /* decide about valid decoding */ if ($decide && is_conversion_safe($res[2])) { $can_be_encoded = true; } else { $can_be_encoded = false; } switch ($encoding) { case 'B': $replace = base64_decode($res[4]); if ($can_be_encoded) { // string is converted from one charset to another. sanitizing depends on $htmlsave $replace = charset_convert($res[2], $replace, $default_charset, $htmlsave); } elseif ($utfencode) { // string is converted to htmlentities and sanitized $replace = charset_decode($res[2], $replace); } elseif ($htmlsave) { // string is not converted, but still sanitized $replace = htmlspecialchars($replace); } $ret .= $replace; break; case 'Q': $replace = str_replace('_', ' ', $res[4]); $replace = preg_replace('/=([0-9a-f]{2})/ie', 'chr(hexdec("\\1"))', $replace); if ($can_be_encoded) { // string is converted from one charset to another. sanitizing depends on $htmlsave $replace = charset_convert($res[2], $replace, $default_charset, $htmlsave); } elseif ($utfencode) { // string is converted to html entities and sanitized $replace = charset_decode($res[2], $replace); } elseif ($htmlsave) { // string is not converted, but still sanizited $replace = htmlspecialchars($replace); } $ret .= $replace; break; default: break; } $chunk = $res[5]; $encoded = true; } if (!$encoded) { if ($htmlsave) { $ret .= ' '; } else { $ret .= ' '; } } if (!$encoded && $htmlsave) { $ret .= htmlspecialchars($chunk); } else { $ret .= $chunk; } ++$i; } /* remove the first added space */ if ($ret) { if ($htmlsave) { $ret = substr($ret, 5); } else { $ret = substr($ret, 1); } } return $ret; }
/** * Combined decoding and encoding functions * * If conversion is done to charset different that utf-8, unsupported symbols * will be replaced with question marks. * @since 1.4.4 and 1.5.1 * @param string $in_charset initial charset * @param string $string string that has to be converted * @param string $out_charset final charset * @param boolean $htmlencode keep htmlspecialchars encoding * @return string converted string */ function charset_convert($in_charset, $string, $out_charset, $htmlencode = true) { $string = charset_decode($in_charset, $string, true); $string = charset_encode($string, $out_charset, $htmlencode); return $string; }
/** * RFC2184 * @param array $aParameters * @return array */ function processParameters($aParameters) { $aResults = array(); $aCharset = array(); // handle multiline parameters foreach ($aParameters as $key => $value) { if ($iPos = strpos($key, '*')) { $sKey = substr($key, 0, $iPos); if (!isset($aResults[$sKey])) { $aResults[$sKey] = $value; if (substr($key, -1) == '*') { // parameter contains language/charset info $aCharset[] = $sKey; } } else { $aResults[$sKey] .= $value; } } else { $aResults[$key] = $value; } } foreach ($aCharset as $key) { $value = $aResults[$key]; // extract the charset & language $charset = substr($value, 0, strpos($value, "'")); $value = substr($value, strlen($charset) + 1); $language = substr($value, 0, strpos($value, "'")); $value = substr($value, strlen($charset) + 1); /* FIXME: What's the status of charset decode with language information ???? * Maybe language information contains only ascii text and charset_decode() * only runs htmlspecialchars() on it. If it contains 8bit information, you * get html encoded text in charset used by selected translation. */ $value = charset_decode($charset, $value); $aResults[$key] = $value; } return $aResults; }
function processParameters($aParameters) { $aResults = array(); $aCharset = array(); // handle multiline parameters foreach ($aParameters as $key => $value) { if ($iPos = strpos($key, '*')) { $sKey = substr($key, 0, $iPos); if (!isset($aResults[$sKey])) { $aResults[$sKey] = $value; if (substr($key, -1) == '*') { // parameter contains language/charset info $aCharset[] = $sKey; } } else { $aResults[$sKey] .= $value; } } else { $aResults[$key] = $value; } } foreach ($aCharset as $key) { $value = $aResults[$key]; // extract the charset & language $charset = substr($value, 0, strpos($value, "'")); $value = substr($value, strlen($charset) + 1); $language = substr($value, 0, strpos($value, "'")); $value = substr($value, strlen($charset) + 1); // FIX ME What's the status of charset decode with language information ???? $value = charset_decode($charset, $value); $aResults[$key] = $value; } return $aResults; }
/** * Decodes headers * * This function decodes strings that are encoded according to * RFC1522 (MIME Part Two: Message Header Extensions for Non-ASCII Text). * Patched by Christian Schmidt <*****@*****.**> 23/03/2002 * * @param string $string header string that has to be made readable * @param boolean $utfencode change message in order to be readable on user's charset. defaults to true * @param boolean $htmlsafe preserve spaces and sanitize html special characters. defaults to true * @param boolean $decide decide if string can be utfencoded. defaults to false * @return string decoded header string */ function decodeHeader($string, $utfencode = true, $htmlsafe = true, $decide = false) { global $languages, $squirrelmail_language, $default_charset; if (is_array($string)) { $string = implode("\n", $string); } if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_decodeheader')) { $string = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_decodeheader', $string); // Do we need to return at this point? // return $string; } $i = 0; $iLastMatch = -2; $encoded = true; // FIXME: spaces are allowed inside quoted-printable encoding, but the following line will bust up any such encoded strings $aString = explode(' ', $string); $ret = ''; foreach ($aString as $chunk) { if ($encoded && $chunk === '') { continue; } elseif ($chunk === '') { $ret .= ' '; continue; } $encoded = false; /* if encoded words are not separated by a linear-space-white we still catch them */ $j = $i - 1; while ($match = preg_match('/^(.*)=\\?([^?]*)\\?(Q|B)\\?([^?]*)\\?=(.*)$/Ui', $chunk, $res)) { /* if the last chunk isn't an encoded string then put back the space, otherwise don't */ if ($iLastMatch !== $j) { if ($htmlsafe) { $ret .= ' '; } else { $ret .= ' '; } } $iLastMatch = $i; $j = $i; if ($htmlsafe) { $ret .= sm_encode_html_special_chars($res[1]); } else { $ret .= $res[1]; } $encoding = ucfirst($res[3]); /* decide about valid decoding */ if ($decide && is_conversion_safe($res[2])) { $utfencode = true; $can_be_encoded = true; } else { $can_be_encoded = false; } switch ($encoding) { case 'B': $replace = base64_decode($res[4]); if ($utfencode) { if ($can_be_encoded) { /* convert string to different charset, * if functions asks for it (usually in compose) */ $ret .= charset_convert($res[2], $replace, $default_charset, $htmlsafe); } else { // convert string to html codes in order to display it $ret .= charset_decode($res[2], $replace); } } else { if ($htmlsafe) { $replace = sm_encode_html_special_chars($replace); } $ret .= $replace; } break; case 'Q': $replace = str_replace('_', ' ', $res[4]); $replace = preg_replace_callback('/=([0-9a-f]{2})/i', create_function('$matches', 'return chr(hexdec($matches[1]));'), $replace); if ($utfencode) { if ($can_be_encoded) { /* convert string to different charset, * if functions asks for it (usually in compose) */ $replace = charset_convert($res[2], $replace, $default_charset, $htmlsafe); } else { // convert string to html codes in order to display it $replace = charset_decode($res[2], $replace); } } else { if ($htmlsafe) { $replace = sm_encode_html_special_chars($replace); } } $ret .= $replace; break; default: break; } $chunk = $res[5]; $encoded = true; } if (!$encoded) { if ($htmlsafe) { $ret .= ' '; } else { $ret .= ' '; } } if (!$encoded && $htmlsafe) { $ret .= sm_encode_html_special_chars($chunk); } else { $ret .= $chunk; } ++$i; } /* remove the first added space */ if ($ret) { if ($htmlsafe) { $ret = substr($ret, 5); } else { $ret = substr($ret, 1); } } return $ret; }
/** * Shows translation box in message display window * @access private */ function translate_read_form_function() { global $color, $translate_server; global $message, $translate_dir; global $translate_show_read; global $imapConnection, $wrap_at, $passed_id, $mailbox; global $translate_gpltrans_url; global $translate_babelfish_enabled, $translate_go_enabled, $translate_dictionary_enabled, $translate_google_enabled, $translate_gpltrans_enabled, $translate_intertran_enabled, $translate_promt_enabled, $translate_otenet_enabled; global $translate_custom_enabled; if (!$translate_show_read) { return; } $translate_server_option = 'translate_' . $translate_server . '_enabled'; if ($translate_server == 'gpltrans' && $translate_gpltrans_url == '' || !${$translate_server_option} || !function_exists('translate_form_' . $translate_server)) { error_box(_("Selected translation engine is disabled. Please update your translation preferences.")); return; } $translate_dir = 'to'; $trans_ar = $message->findDisplayEntity(array(), array('text/plain')); $body = ''; $final_body = ''; if (!empty($trans_ar[0])) { for ($i = 0; $i < count($trans_ar); $i++) { /* reduced version of formatBody and translateText functions */ // get message entity information $body_message = getEntity($message, $trans_ar[$i]); // get message body $body = mime_fetch_body($imapConnection, $passed_id, $trans_ar[$i]); // convert encoded messages $body = decodeBody($body, $body_message->header->encoding); /* * if message part is html formated - convert spaces, html line feeds, * less than and greater than html entities and remove tags */ if ($body_message->header->type1 == 'html') { $entity_conv = array(' ' => ' ', '<p>' => "\n", '<P>' => "\n", '<br>' => "\n", '<BR>' => "\n", '<br />' => "\n", '<BR />' => "\n", '>' => '>', '<' => '<'); $body = strtr($body, $entity_conv); $body = strip_tags($body); } // remove whitespace $body = trim($body); // save processed text and parse other entity $final_body .= charset_decode($body_message->header->getParameter('charset'), $body); } // add form if message is not empty if (!empty($final_body)) { $function = 'translate_form_' . $translate_server; $function($final_body); } } }