X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=plugins%2Ftranslate%2Ffunctions.php;h=0d77939d0f0a1ed48be95469b70c444deab1724b;hb=a67cf4877d741cffdf17affd2fae6359921b12ab;hp=edd0233ad47ba242c0db9cdb5ab72870f63e9824;hpb=e50f5ac2682d655013d18d97f9a2aa30b7ed9485;p=squirrelmail.git diff --git a/plugins/translate/functions.php b/plugins/translate/functions.php index edd0233a..0d77939d 100644 --- a/plugins/translate/functions.php +++ b/plugins/translate/functions.php @@ -1,23 +1,23 @@ findDisplayEntity(array(), array('text/plain')); $body = ''; - if ($trans_ar[0] != '') { + $final_body = ''; + if ( !empty($trans_ar[0]) ) { for ($i = 0; $i < count($trans_ar); $i++) { - $body .= formatBody($imapConnection, $message, $color, $wrap_at, $trans_ar[$i], $passed_id, $mailbox); + /* 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;
- $pos = strpos($new_body,
- '">'. _("Download this as a file") . '
');
- if (is_int($pos)) {
- $new_body = substr($new_body, 0, $pos);
+ // add form if message is not empty
+ if (!empty($final_body)) {
+ $function = 'translate_form_' . $translate_server;
+ $function($final_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);
}
/**
@@ -274,7 +284,7 @@ function translate_showtrad() {
'http://www.dictionary.com/translate' );
if ($translate_google_enabled) translate_showtrad_internal( 'Google Translate',
_("No known limits, powered by Systran").
- '
'.sprintf(_("Number of supported language pairs: %s"),'12').' ' ,
+ '
'.sprintf(_("Number of supported language pairs: %s"),'20').' ' ,
'http://www.google.com/translate' );
if ($translate_gpltrans_enabled && $translate_gpltrans_url!='') translate_showtrad_internal( 'GPLTrans',
_("No known limits, powered by GPLTrans (free, open source)").
@@ -424,9 +434,11 @@ function translate_lang_opt($from, $to, $value, $text) {
* Starts translation box
*
* @param string $action url that has to recieve message for translation
+ * @param string $charset (since sm 1.5.1) character set, that should be used
+ * to submit 8bit information.
* @access private
*/
-function translate_new_form($action) {
+function translate_new_form($action,$charset=null) {
global $translate_dir, $translate_location;
global $color, $translate_same_window;
@@ -444,6 +456,9 @@ function translate_new_form($action) {
echo ' target="_blank"';
}
+ if (! is_null($charset))
+ echo ' accept-charset="'.htmlspecialchars($charset).'"';
+
echo ">\n";
?>