X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=blobdiff_plain;f=plugins%2Ftranslate%2Ffunctions.php;h=bd7616f2a2e8a66a008b6e3049ddddf1e3ae1749;hp=edde502567051ce5c2f16bb3cfca928aeaacab59;hb=dffb9139475e0b3b78d3d6015d686963bb74b161;hpb=b2e8c7a0f6ef359d6fbd7fc597fb0f728d06a752;ds=inline 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) { - +