From dffb9139475e0b3b78d3d6015d686963bb74b161 Mon Sep 17 00:00:00 2001 From: tokul Date: Sun, 19 Mar 2006 10:51:37 +0000 Subject: [PATCH] removed htmlspecialchars applied in wrong place. rewrote message text extraction. Output of formatBody() and translateText() functions depends on user's preferences and can contain html formating. removed message text processing code. conversion of html entities applies only to html special chars and undoes html sanitizing made by charset_decode. It makes message text unsuitable for form input fields. " -> '' and other conversions removed too in order to preserve message format. translate form is displayed only when message body is not empty. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@10994 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- plugins/translate/functions.php | 61 ++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/plugins/translate/functions.php b/plugins/translate/functions.php index edde5025..bd7616f2 100644 --- a/plugins/translate/functions.php +++ b/plugins/translate/functions.php @@ -92,32 +92,47 @@ function translate_read_form_function() { $trans_ar = $message->findDisplayEntity(array(), array('text/plain')); $body = ''; + $final_body = ''; if ($trans_ar[0] != '') { for ($i = 0; $i < count($trans_ar); $i++) { - $body .= formatBody($imapConnection, $message, $color, $wrap_at, $trans_ar[$i], $passed_id, $mailbox, true); + /* 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(' ' => ' ', + '

' => "\n", + '

' => "\n", + '
' => "\n", + '
' => "\n", + '
' => "\n", + '
' => "\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); } - $hookResults = do_hook('message_body', $body); - $body = $hookResults[1]; - } else { - $body = 'Message can\'t be translated'; - } - - $new_body = $body; - - $trans = get_html_translation_table(HTML_ENTITIES); - $trans[' '] = ' '; - $trans = array_flip($trans); - $new_body = strtr($new_body, $trans); - $new_body = urldecode($new_body); - $new_body = strip_tags($new_body); - - /* I really don't like this next part ... */ - $new_body = str_replace('"', "''", $new_body); - $new_body = strtr($new_body, "\n", ' '); - - $function = 'translate_form_' . $translate_server; - $function($new_body); + // add form if message is not empty + if (!empty($final_body)) { + $function = 'translate_form_' . $translate_server; + $function($final_body); + } + } } /** @@ -466,7 +481,7 @@ function translate_form_babelfish($message) { - +