greatly improved speed and memory management of download of attachments.
authorlkehresman <lkehresman@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Wed, 10 Jan 2001 04:36:00 +0000 (04:36 +0000)
committerlkehresman <lkehresman@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Wed, 10 Jan 2001 04:36:00 +0000 (04:36 +0000)
it doesn't save the file in memory, it now feeds it line-by-line.

git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@921 7612ce4b-ef26-0410-bec9-ea0150e637f0

functions/mime.php
src/download.php

index 823f1b149888698131da2aa685fa4ec4ce6cebd4..7e054d0520a1a1ace7cdfcd2075304051b200ecd 100644 (file)
       return "Body retrival error, please report this bug!\n\nTop line is \"$topline\"\n";
    }
 
+   function mime_print_body_lines ($imap_stream, $id, $ent_id, $encoding) {
+      // do a bit of error correction.  If we couldn't find the entity id, just guess
+      // that it is the first one.  That is usually the case anyway.
+      if (!$ent_id) $ent_id = 1;
+
+      fputs ($imap_stream, "a001 FETCH $id BODY[$ent_id]\r\n");
+         $cnt = 0;
+         $continue = true;
+               $read = fgets ($imap_stream,4096);
+               while (!ereg("^a001 (OK|BAD|NO)(.*)$", $read, $regs)) {
+                       if (trim($read) == ")==") {
+                               $read1 = $read;
+                               $read = fgets ($imap_stream,4096);
+                               if (ereg("^a001 (OK|BAD|NO)(.*)$", $read, $regs)) {
+                                       return;
+                               } else {
+                                       echo decodeBody($read1, $encoding);
+                                       echo decodeBody($read, $encoding);
+                               }
+                       } else if ($cnt) {
+                               echo decodeBody($read, $encoding);
+                       }
+                       $read = fgets ($imap_stream,4096);
+                       $cnt++;
+               }
+   }
+
    /* -[ END MIME DECODING ]----------------------------------------------------------- */
 
 
index 27b4d69caf9eebb591f8f8b61622086c72c52e29..afa21383b0597316897ffaf2648fe1789bec5c1e 100644 (file)
@@ -72,7 +72,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;
    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\"");
             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;
+            mime_print_body_lines ($imapConnection, $passed_id, $passed_ent_id, $header->encoding);
             break;
       }
    } else {
       switch ($type0) {
          case "text":
-                               if ($type1 == "text" || $type1 == "html") {
-                   $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 = decodeBody($body, $header->encoding);
-               header("Content-type: $type0/$type1; name=\"$filename\"");
-               header("Content-Disposition: attachment; filename=\"$filename\"");
-               echo $body;
-                               }
-                               break;
+                $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;
       }
    }