Added a much better fix for the IE/SSL problem. No security hazards
[squirrelmail.git] / src / download.php
index ad291fe6fa43912c0d6e7517dd1c02617cbf2b08..03505fb3c7c28a35c9d7450e771c8a85fdbcb1f9 100644 (file)
    if (!isset($i18n_php))
       include("../functions/i18n.php");
 
+   session_start();
+   header("Pragma: ");
+   header("Cache-Control: cache");
+
    include("../src/load_prefs.php");
 
    function viewText($color, $body, $id, $entid, $mailbox, $type1, $wrap_at) {
@@ -72,7 +76,6 @@
    $message = getEntity($message, $passed_ent_id);
 
    $header = $message->header;
-   $body = mime_fetch_body($imapConnection, $passed_id, $passed_ent_id);
 
    $charset = $header->charset;
    $type0 = $header->type0;
 
    header("Pragma: ");
    header("Content-Description: SquirrelMail Attachment");
-   header("Cache-Control: no-cache, must-revalidate");
    if ($absolute_dl == "true") {
       switch($type0) {
          case "text":
+            $body = mime_fetch_body($imapConnection, $passed_id, $passed_ent_id);
             $body = decodeBody($body, $header->encoding);
-            header("Content-Disposition: attachment; filename=\"$filename\"");
-            header("Content-type: application/octet-stream; name=\"$filename\"");
+            header("Content-Disposition: attachment; filename=$filename");
+            header("Content-type: application/octet-stream; name=$filename");
             set_up_language(getPref($data_dir, $username, "language"));
             if ($type1 == "plain") {
                echo _("Subject") . ": " . decodeHeader(sqStripSlashes($top_header->subject)) . "\n";
             echo trim($body);
             break;
          default:
-            $body = decodeBody($body, $header->encoding);
-            header("Content-Disposition: attachment; filename=\"$filename\"");
-            header("Content-type: application/octet-stream; name=\"$filename\"");
-            echo $body;
+            header("Content-Disposition: attachment; filename=$filename");
+            header("Content-type: application/octet-stream; name=$filename");
+            mime_print_body_lines ($imapConnection, $passed_id, $passed_ent_id, $header->encoding);
             break;
       }
    } else {
       switch ($type0) {
          case "text":
-            $body = decodeBody($body, $header->encoding);
-            include("../functions/page_header.php");
-            viewText($color, $body, $passed_id, $passed_ent_id, $mailbox, $type1, $wrap_at);
+            if ($type1 == "plain" || $type1 == "html") {
+                $body = mime_fetch_body($imapConnection, $passed_id, $passed_ent_id);
+                $body = decodeBody($body, $header->encoding);
+                include("../functions/page_header.php");
+                viewText($color, $body, $passed_id, $passed_ent_id, $mailbox, $type1, $wrap_at);
+            } else {
+                $body = mime_fetch_body($imapConnection, $passed_id, $passed_ent_id);
+                $body = decodeBody($body, $header->encoding);
+                header("Content-type: $type0/$type1; name=$filename");
+                header("Content-Disposition: attachment; filename=$filename");
+                echo $body;
+            }
             break;
          case "message":
+            $body = mime_fetch_body($imapConnection, $passed_id, $passed_ent_id);
             $body = decodeBody($body, $header->encoding);
             include("../functions/page_header.php");
             viewText($color, $body, $passed_id, $passed_ent_id, $mailbox, $type1, $wrap_at);
             break;
          default:
-            $body = decodeBody($body, $header->encoding);
             header("Content-type: $type0/$type1; name=\"$filename\"");
             header("Content-Disposition: attachment; filename=\"$filename\"");
-            echo $body;
+            mime_print_body_lines ($imapConnection, $passed_id, $passed_ent_id, $header->encoding);
             break;
       }
    }    
     
-   sqimap_mailbox_close($imapConnection);
    sqimap_logout($imapConnection);
 ?>