Cvascript detection was broken when you changed your setting from never
[squirrelmail.git] / functions / mime.php
index 961e7d990394dc03e47112a66c02f6ac0082d6b2..f8eb09b0f2c87be101def705666e22ce2a3b8c7c 100644 (file)
@@ -3,7 +3,7 @@
 /**
  * mime.php
  *
- * Copyright (c) 1999-2004 The SquirrelMail Project Team
+ * Copyright (c) 1999-2005 The SquirrelMail Project Team
  * Licensed under the GNU GPL. For full terms see the file COPYING.
  *
  * This contains the functions necessary to detect and decode MIME
@@ -161,7 +161,7 @@ function mime_print_body_lines ($imap_stream, $id, $ent_id=1, $encoding) {
 
     /* Don't kill the connection if the browser is over a dialup
      * and it would take over 30 seconds to download it.
-     * Dont call set_time_limit in safe mode.
+     * Don't call set_time_limit in safe mode.
      */
 
     if (!ini_get('safe_mode')) {
@@ -341,9 +341,8 @@ function formatBody($imap_stream, $message, $color, $wrap_at, $ent_num, $id, $ma
      * primary message. To add more of them, just put them in the
      * order that is their priority.
      */
-    global $startMessage, $username, $key, $imapServerAddress, $imapPort,
+    global $startMessage, $languages, $squirrelmail_language,
            $show_html_default, $sort, $has_unsafe_images, $passed_ent_id;
-    global $languages, $squirrelmail_language;
 
     if( !sqgetGlobalVar('view_unsafe_images', $view_unsafe_images, SQ_GET) ) {
         $view_unsafe_images = false;
@@ -421,8 +420,7 @@ function formatBody($imap_stream, $message, $color, $wrap_at, $ent_num, $id, $ma
 
 
 function formatAttachments($message, $exclude_id, $mailbox, $id) {
-    global $where, $what, $startMessage, $color;
-    static $ShownHTML = 0;
+    global $where, $what, $startMessage, $color, $passed_ent_id;
 
     $att_ar = $message->getAttachments($exclude_id);
 
@@ -441,7 +439,6 @@ function formatAttachments($message, $exclude_id, $mailbox, $id) {
         $links['download link']['text'] = _("Download");
         $links['download link']['href'] = SM_PATH .
                 "src/download.php?absolute_dl=true&passed_id=$id&mailbox=$urlMailbox&ent_id=$ent";
-        $ImageURL = '';
         if ($type0 =='message' && $type1 == 'rfc822') {
             $default_page = SM_PATH . 'src/read_body.php';
             $rfc822_header = $att->rfc822_header;
@@ -552,18 +549,18 @@ function formatAttachments($message, $exclude_id, $mailbox, $id) {
 
 function sqimap_base64_decode(&$string) {
 
-    // base64 enoded data goes in pairs of 4 bytes. To achieve on the
+    // Base64 encoded data goes in pairs of 4 bytes. To achieve on the
     // fly decoding (to reduce memory usage) you have to check if the
     // data has incomplete pairs
 
-    // remove the noise in order to check if the 4 bytes pairs are complete
+    // Remove the noise in order to check if the 4 bytes pairs are complete
     $string = str_replace(array("\r\n","\n", "\r", " "),array('','','',''),$string);
 
     $sStringRem = '';
     $iMod = strlen($string) % 4;
     if ($iMod) {
         $sStringRem = substr($string,-$iMod);
-        // check if $sStringRem contains padding characters
+        // Check if $sStringRem contains padding characters
         if (substr($sStringRem,-1) != '=') {
             $string = substr($string,0,-$iMod);
         } else {
@@ -659,7 +656,11 @@ function decodeHeader ($string, $utfencode=true,$htmlsave=true,$decide=false) {
             }
             $iLastMatch = $i;
             $j = $i;
-            $ret .= $res[1];
+            if ($htmlsave) {
+                $ret .= htmlspecialchars($res[1]);
+            } else {
+                $ret .= $res[1];
+            }
             $encoding = ucfirst($res[3]);
 
             /* decide about valid decoding */
@@ -673,14 +674,21 @@ function decodeHeader ($string, $utfencode=true,$htmlsave=true,$decide=false) {
             {
             case 'B':
                 $replace = base64_decode($res[4]);
-                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);
+                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);
+                    } else {
+                        // convert string to html codes in order to display it
+                        $ret .= charset_decode($res[2],$replace);
+                    }
                 } else {
-                  // convert string to html codes in order to display it
-                  $ret .= charset_decode($res[2],$replace);
+                    if ($htmlsave) {
+                        $replace = htmlspecialchars($replace);
+                    }
+                    $ret.= $replace;
                 }
                 break;
             case 'Q':
@@ -1116,7 +1124,6 @@ function sq_getnxtag($body, $offset){
             break;
     }
 
-    $tag_start = $pos;
     $tagname = '';
     /**
      * Look for next [\W-_], which will indicate the end of the tag name.
@@ -1176,7 +1183,6 @@ function sq_getnxtag($body, $offset){
      * At this point we loop in order to find all attributes.
      */
     $attname = '';
-    $atttype = false;
     $attary = Array();
 
     while ($pos <= strlen($body)){
@@ -1585,7 +1591,6 @@ function sq_cid2http($message, $id, $cidurl, $mailbox){
 function sq_body2div($attary, $mailbox, $message, $id){
     $me = 'sq_body2div';
     $divattary = Array('class' => "'bodyclass'");
-    $bgcolor = '#ffffff';
     $text = '#000000';
     $has_bgc_stl = $has_txt_stl = false;
     $styledef = '';