removed displaying attachments in case we are dealing with
[squirrelmail.git] / functions / mime.php
index eeff949586c37159528c0c57bd039a4e8c1769f8..61e345741c836eedaf62ebdb31d92f3345288819 100644 (file)
@@ -229,6 +229,21 @@ function mime_get_element (&$structure, $msg, $ent_id) {
            $pos++;
         }
         $structure = substr($structure, strlen($text) + 2);
+     } else if ($char == '{') {
+         /**
+          * loop through until we find the matching quote, 
+          * and return that as a string
+          */
+         $pos = 1;
+         $len = '';
+         while (($char = $structure{$pos}) != '}' 
+                && $pos < strlen($structure)) {
+             $len .= $char;
+             $pos++;
+         }
+         $structure = substr($structure, strlen($len) + 4);
+         $text = substr($structure, 0, $len);
+         $structure = substr($structure, $len + 1);
      } else if ($char == '(') {
         // comment me
         $end = mime_match_parenthesis (0, $structure);
@@ -779,7 +794,7 @@ function formatBody($imap_stream, $message, $color, $wrap_at) {
                 $body = strip_tags( $body );
                 translateText($body, $wrap_at, $body_message->header->charset);
             } else {
-                $body = MagicHTML( $body, $id );
+                $body = MagicHTML( $body, $id, $message );
             }
         } else {
             translateText($body, $wrap_at, $body_message->header->charset);
@@ -796,7 +811,13 @@ function formatBody($imap_stream, $message, $color, $wrap_at) {
 
         /** Display the ATTACHMENTS: message if there's more than one part **/
         if (isset($message->entities[1])) {
-            $body .= formatAttachments ($message, $ent_num, $message->header->mailbox, $id);
+           /* Header-type alternative means we choose the best one to display 
+              so don't show the alternatives as attachment. Header-type related
+              means that the attachments are already part of the related message.
+           */   
+           if ($message->header->type1 !='related' && $message->header->type1 !='alternative') {
+               $body .= formatAttachments ($message, $ent_num, $message->header->mailbox, $id);
+           }
         }
     } else {
         $body = formatAttachments ($message, -1, $message->header->mailbox, $id);
@@ -996,7 +1017,8 @@ function decodeBody($body, $encoding) {
 
   global $show_html_default;
 
-  if ($encoding == 'quoted-printable') {
+  if ($encoding == 'quoted-printable' ||
+      $encoding == 'quoted_printable') {
      $body = quoted_printable_decode($body);
 
 
@@ -1170,8 +1192,6 @@ function sq_skipspace($body, $offset){
     if (sizeof($matches{1})){
         $count = strlen($matches{1});
         $offset += $count;
-        //if ($pos >= strlen($body)){
-        //}
     }
     return $offset;
 }
@@ -1372,18 +1392,16 @@ function sq_getnxtag($body, $offset){
          */
         $matches = Array();
         if (preg_match("%^(\s*)(>|/>)%s", substr($body, $pos), $matches)) {
-           if ($matches{0}){
-               /**
-                * Yep. So we did.
-                */
-               $pos += strlen($matches{1});
-               if ($matches{2} == "/>"){
-                   $tagtype = 3;
-                   $pos++;
-               }
-               return Array($tagname, $attary, $tagtype, $lt, $pos);
-           }
-       }
+            /**
+             * Yep. So we did.
+             */
+            $pos += strlen($matches{1});
+            if ($matches{2} == "/>"){
+                $tagtype = 3;
+                $pos++;
+            }
+            return Array($tagname, $attary, $tagtype, $lt, $pos);
+        }
 
         /**
          * There are several types of attributes, with optional
@@ -1430,7 +1448,7 @@ function sq_getnxtag($body, $offset){
                 $pos++;
                 $tagtype = 3;
             } else {
-                $gt = getnxstr($body, $pos, ">");
+                $gt = sq_findnxstr($body, $pos, ">");
                 $retary = Array(false, false, false, $lt, $gt);
                 return $retary;
             }
@@ -1815,11 +1833,6 @@ function sq_sanitize($body,
              * content before we apply it.
              */
             $free_content = sq_fixstyle($message, $id, $free_content);
-        } else if ($tagname == "body"){
-            $tagname = "div";
-            if ($tagtype == 1){
-                $attary = sq_body2div($attary);
-            }
         }
         if ($skip_content == false){
             $trusted .= $free_content;
@@ -1835,11 +1848,15 @@ function sq_sanitize($body,
                     $skip_content = false;
                 } else {
                     if ($skip_content == false){
-                        if (isset($open_tags{$tagname}) && 
-                            $open_tags{$tagname} > 0){
-                            $open_tags{$tagname}--;
+                        if ($tagname == "body"){
+                            $tagname = "div";
                         } else {
-                            $tagname = false;
+                            if (isset($open_tags{$tagname}) && 
+                                $open_tags{$tagname} > 0){
+                                $open_tags{$tagname}--;
+                            } else {
+                                $tagname = false;
+                            }
                         }
                     } else {
                     }
@@ -1891,6 +1908,13 @@ function sq_sanitize($body,
                                                      $id
                                                      );
                             }
+                            /**
+                             * Convert body into div.
+                             */
+                            if ($tagname == "body"){
+                                $tagname = "div";
+                                $attary = sq_body2div($attary, $message, $id);
+                            }
                         }
                     }
                 } else {
@@ -1924,9 +1948,9 @@ function sq_sanitize($body,
  * @param  $id    the id of the message
  * @return        a string with html safe to display in the browser.
  */
-function magicHTML($body, $id){
+function magicHTML($body, $id, $message){
     global $attachment_common_show_images, $view_unsafe_images,
-        $has_unsafe_images, $message;
+        $has_unsafe_images;
     /**
      * Don't display attached images in HTML mode.
      */