Replaced code with call to function with same purpose. Also, the code didn't
[squirrelmail.git] / functions / mime.php
index e7370aa7bc43bf42e5e6059403fab0a2b3713fc8..d4ac2e735dc1639724de9841082f4e1cec96fdca 100644 (file)
@@ -163,6 +163,10 @@ function mime_print_body_lines ($imap_stream, $id, $ent_id, $encoding) {
        $sid_s = $sid;
     }
 
+    $body = mime_fetch_body ($imap_stream, $id, $ent_id);
+    echo decodeBody($body, $encoding);
+    return;
+/*
     fputs ($imap_stream, "$sid FETCH $id BODY[$ent_id]\r\n");
     $cnt = 0;
     $continue = true;
@@ -172,26 +176,44 @@ function mime_print_body_lines ($imap_stream, $id, $ent_id, $encoding) {
     // This could be bad -- if the section has sqimap_session_id() . ' OK'
     // or similar, it will kill the download.
     while (!ereg("^".$sid_s." (OK|BAD|NO)(.*)$", $read, $regs)) {
-      if (trim($read) == ')==') {
-          $read1 = $read;
-          $read = fgets ($imap_stream,4096);
-          if (ereg("^".$sid." (OK|BAD|NO)(.*)$", $read, $regs)) {
-              return;
-          } else {
-              echo decodeBody($read1, $encoding) .
-                   decodeBody($read, $encoding);
-          }
-      } else if ($cnt) {
-          echo decodeBody($read, $encoding);
-      }
-      $read = fgets ($imap_stream,4096);
-      $cnt++;
+        if (trim($read) == ')==') {
+            $read1 = $read;
+            $read = fgets ($imap_stream,4096);
+            if (ereg("^".$sid." (OK|BAD|NO)(.*)$", $read, $regs)) {
+                return;
+            } else {
+                echo decodeBody($read1, $encoding) .
+                     decodeBody($read, $encoding);
+            }
+        } else if ($cnt) {
+            echo decodeBody($read, $encoding);
+        }
+        $read = fgets ($imap_stream,4096);
+        $cnt++;
 //      break;
     }
+*/
 }
 
 /* -[ END MIME DECODING ]----------------------------------------------------------- */
 
+/* findDisplayEntity
+ * Checks to see if $message contains content of type $type0/$type1
+ * returns the first entity number it finds of that type, or NULL if
+ * none is found.  Takes optional argument $start to allow the caller
+ * to continue where they left off
+ */
+function findDisplayEntity($message, $type0, $type1, $start=0) {
+    if ($message) {
+        for ($i = $start;isset($message->entities[$i]); $i++) {
+            $entity = $message->entities[$i];
+            if ($entity->type0 == $type0 && $entity->type1 == $type1) {
+                return $i;
+            }
+        }
+    }
+    return NULL;
+}
 
 // This is here for debugging purposese.  It will print out a list
 // of all the entity IDs that are in the $message object.
@@ -318,7 +340,6 @@ function formatBody($imap_stream, $message, $color, $wrap_at, $ent_num, $id, $ma
     if (($body_message->header->type0 == 'text') ||
         ($body_message->header->type0 == 'rfc822')) {
        $body = mime_fetch_body ($imap_stream, $id, $ent_num);
-       
         $body = decodeBody($body, $body_message->header->encoding);
         $hookResults = do_hook("message_body", $body);
         $body = $hookResults[1];
@@ -328,12 +349,14 @@ function formatBody($imap_stream, $message, $color, $wrap_at, $ent_num, $id, $ma
         if ($body_message->header->type1 == 'html') {
             if ( $show_html_default <> 1 ) {
                 $body = strip_tags( $body );
-                translateText($body, $wrap_at, $body_message->header->charset);
+                translateText($body, $wrap_at, 
+                 $body_message->header->getParameter['charset']);
             } else {
                 $body = magicHTML( $body, $id, $message, $mailbox );
             }
         } else {
-            translateText($body, $wrap_at, $body_message->header->charset);
+            translateText($body, $wrap_at, 
+              $body_message->header->getParameter('charset'));
         }
 
         if ($has_unsafe_images) {
@@ -357,24 +380,20 @@ function formatAttachments($message, $exclude_id, $mailbox, $id) {
 
     if (!count($att_ar)) return '';
     
-    $attachments = "<TABLE WIDTH=\"100%\" CELLSPACING=0 CELLPADDING=2 BORDER=0 BGCOLOR=\"$color[0]\"><TR>\n" .
-                "<TH ALIGN=\"left\" BGCOLOR=\"$color[9]\"><B>\n" .
-                _("Attachments") . ':' .
-                "</B></TH></TR><TR><TD>\n" .
-                "<TABLE CELLSPACING=0 CELLPADDING=1 BORDER=0>\n";
+    $attachments = '';
    
     $urlMailbox = urlencode($mailbox);
 
     foreach ($att_ar as $att) {
                 
-        $ent = urlencode($att->entity_id);
+        $ent = urldecode($att->entity_id);
        $header = $att->header;
         $type0 = strtolower($header->type0);
         $type1 = strtolower($header->type1);
        $name = '';
        if ($type0 =='message' && $type1 == 'rfc822') {
-
-            $filename = decodeHeader($header->subject);
+           $rfc822_header = $att->rfc822_header;
+            $filename = decodeHeader($rfc822_header->subject);
             $display_filename = $filename;
             
             $DefaultLink =
@@ -401,14 +420,14 @@ function formatAttachments($message, $exclude_id, $mailbox, $id) {
             $Links = $HookResults[1];
             $DefaultLink = $HookResults[6];
 
-            $attachments .= '<TR><TD>&nbsp;&nbsp;</TD><TD>' .
+            $attachments .= '<TR><TD>' .
                         "<A HREF=\"$DefaultLink\">$display_filename</A>&nbsp;</TD>" .
                         '<TD><SMALL><b>' . show_readable_size($header->size) .
                         '</b>&nbsp;&nbsp;</small></TD>' .
                         "<TD><SMALL>[ $type0/$type1 ]&nbsp;</SMALL></TD>" .
                         '<TD><SMALL>';
-           $from_o = $header->from;
-           if (isset($from_o)) {
+           $from_o = $rfc822_header->from;
+           if (is_object($from_o)) {
                $from_name = $from_o->getAddress(false);
            } else {
                $from_name = _("Unknown sender");
@@ -427,9 +446,11 @@ function formatAttachments($message, $exclude_id, $mailbox, $id) {
                 $attachments .= '<a href="' . $Val['href'] . '">' .  $Val['text'] . '</a>';
             }
             unset($Links);
+           $attachments .= "</TD></TR>\n";
         } else {
-            $filename = decodeHeader($header->filename);
+            $filename = decodeHeader($header->getParameter('filename'));
             if (trim($filename) == '') {
+               $name = decodeHeader($header->getParameter('name'));
                 if (trim($name) == '') {
                     if ( trim( $header->id ) == '' )
                         $display_filename = 'untitled-[' . $ent . ']' ;
@@ -468,7 +489,7 @@ function formatAttachments($message, $exclude_id, $mailbox, $id) {
             $Links = $HookResults[1];
             $DefaultLink = $HookResults[6];
 
-            $attachments .= '<TR><TD>&nbsp;&nbsp;</TD><TD>' .
+            $attachments .= '<TR><TD>' .
                         "<A HREF=\"$DefaultLink\">$display_filename</A>&nbsp;</TD>" .
                         '<TD><SMALL><b>' . show_readable_size($header->size) .
                         '</b>&nbsp;&nbsp;</small></TD>' .
@@ -488,14 +509,11 @@ function formatAttachments($message, $exclude_id, $mailbox, $id) {
                 }
                 $attachments .= '<a href="' . $Val['href'] . '">' .  $Val['text'] . '</a>';
             }
-
+            $attachments .= "</TD></TR>\n";
             unset($Links);
        }         
    
-   }
-   $attachments .= "</SMALL></TD></TR>\n";
-   
-   $attachments .= "</TABLE></TD></TR></TABLE>";
+     }
    
    return $attachments;
 }
@@ -1584,4 +1602,4 @@ function magicHTML($body, $id, $message, $mailbox = 'INBOX'){
     return $trusted;
 }
 
-?>
\ No newline at end of file
+?>