added part of new index ordering options
[squirrelmail.git] / functions / mime.php
index 3bae25afc97c7b25fac5f1b746c2161548e2c3b4..a3556f0db8e115065f665bc990662d47c9eeab35 100644 (file)
@@ -61,7 +61,7 @@
       $read = fgets ($imap_stream, 10000);
       $response = substr($read, 0, 4);
       while ($response != "a001") {
-         $bodystructure = $read;
+         $bodystructure .= $read;
          $read = fgets ($imap_stream, 10000);
          $response = substr($read, 0, 4);
       }
       $char = substr($structure, $pos, 1); 
 
       // ignore all extra characters
+      // If inside of a string, skip string -- Boundary IDs and other
+      // things can have ) in them.
       while ($pos < strlen($structure)) {
          $pos++;
          $char = substr($structure, $pos, 1); 
          if ($char == ")") {
             return $pos;
+         } else if ($char == '"') {
+            $pos ++;
+            while (substr($structure, $pos, 1) != '"' && 
+               $pos < strlen($structure)) {
+               $pos ++;
+            }
          } else if ($char == "(") {
             $pos = mime_match_parenthesis ($pos, $structure);
          }
       // Get the right entity and redefine message to be this entity
       $ent_num = findDisplayEntity ($message);
       $body_message = getEntity($message, $ent_num);
-
-      $body = mime_fetch_body ($imap_stream, $id, $ent_num); 
-      $body = decodeBody($body, $body_message->header->encoding);
-
-      // If there are other types that shouldn't be formatted, add
-      // them here 
-      if ($message->header->type1 != "html") {   
-         $body = translateText($body, $wrap_at, $body_message->header->charset);
-      }   
-
-      $body .= "<SMALL><CENTER><A HREF=\"../src/download.php?absolute_dl=true&passed_id=$id&passed_ent_id=$ent_num&mailbox=$urlmailbox\">". _("Download this as a file") ."</A></CENTER><BR></SMALL>";
-
-      /** Display the ATTACHMENTS: message if there's more than one part **/
-      if ($message->entities) {
+      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);
+   
+         // If there are other types that shouldn't be formatted, add
+         // them here 
+         if ($message->header->type1 != "html") {   
+            $body = translateText($body, $wrap_at, $body_message->header->charset);
+         }   
+   
+         $body .= "<SMALL><CENTER><A HREF=\"../src/download.php?absolute_dl=true&passed_id=$id&passed_ent_id=$ent_num&mailbox=$urlmailbox\">". _("Download this as a file") ."</A></CENTER><BR></SMALL>";
+   
+         /** Display the ATTACHMENTS: message if there's more than one part **/
+         if ($message->entities) {
+            $body .= "</TD></TR></TABLE>";
+            $body .= "<TABLE WIDTH=100% CELLSPACING=0 CELLPADDING=4 BORDER=0><TR><TD BGCOLOR=\"$color[0]\">";
+            $body .= "<TT><B>ATTACHMENTS:</B></TT>";
+            $body .= "</TD></TR><TR><TD BGCOLOR=\"$color[0]\">";
+            $num = 0;
+   
+            $body .= formatAttachments ($message, $ent_num, $message->header->mailbox, $id);
+            $body .= "</TD></TR></TABLE>";
+         } else {
+            $body .= "</TD></TR></TABLE>";
+         }
+      } else {
          $body .= "</TD></TR></TABLE>";
          $body .= "<TABLE WIDTH=100% CELLSPACING=0 CELLPADDING=4 BORDER=0><TR><TD BGCOLOR=\"$color[0]\">";
          $body .= "<TT><B>ATTACHMENTS:</B></TT>";
          $body .= "</TD></TR><TR><TD BGCOLOR=\"$color[0]\">";
          $num = 0;
 
-         $body .= formatAttachments ($message, $ent_num, $message->header->mailbox, $id);
-         $body .= "</TD></TR></TABLE>";
-      } else {
+         $body .= formatAttachments ($message, 999999, $message->header->mailbox, $id);
          $body .= "</TD></TR></TABLE>";
       }
       return $body;
                if ($message->header->description)
                   $body .= "&nbsp;&nbsp;<b>" . htmlspecialchars($message->header->description)."</b>";
                $body .= "&nbsp;(<a href=\"../src/download.php?absolute_dl=true&passed_id=$id&mailbox=$urlMailbox&passed_ent_id=$ent\">"._("download")."</a>)\n";     
+               do_hook("attachment $type0/$type1");
                $body .= "</TT><BR>";
                $num++;
             }