Просмотр исходного кода

Fixed half implemented feature. Now we provide a stream when calling this
function. This will save memory usage in case we forward from compose and
will stop exhausted memory errors in case of large attachments.

stekkel 20 лет назад
Родитель
Сommit
9efd9d354c
1 измененных файлов с 10 добавлено и 33 удалено
  1. 10 33
      functions/mime.php

+ 10 - 33
functions/mime.php

@@ -159,7 +159,7 @@ function mime_fetch_body($imap_stream, $id, $ent_id=1, $fetch_size=0) {
     return $ret;
     return $ret;
 }
 }
 
 
-function mime_print_body_lines ($imap_stream, $id, $ent_id=1, $encoding) {
+function mime_print_body_lines ($imap_stream, $id, $ent_id=1, $encoding, $rStream) {
 
 
     /* Don't kill the connection if the browser is over a dialup
     /* Don't kill the connection if the browser is over a dialup
     * and it would take over 30 seconds to download it.
     * and it would take over 30 seconds to download it.
@@ -173,14 +173,18 @@ function mime_print_body_lines ($imap_stream, $id, $ent_id=1, $encoding) {
     Instead, echo the decoded attachment directly to screen */
     Instead, echo the decoded attachment directly to screen */
     if (strtolower($encoding) == 'base64') {
     if (strtolower($encoding) == 'base64') {
         if (!$ent_id) {
         if (!$ent_id) {
-        $query = "FETCH $id BODY[]";
+            $query = "FETCH $id BODY[]";
         } else {
         } else {
-        $query = "FETCH $id BODY[$ent_id]";
+            $query = "FETCH $id BODY[$ent_id]";
         }
         }
-        sqimap_run_command($imap_stream,$query,true,$response,$message,TRUE,'sqimap_base64_decode','php://stdout',true);
+        sqimap_run_command($imap_stream,$query,true,$response,$message,TRUE,'sqimap_base64_decode',$rStream,true);
     } else {
     } else {
-    $body = mime_fetch_body ($imap_stream, $id, $ent_id);
-    echo decodeBody($body, $encoding);
+        $body = mime_fetch_body ($imap_stream, $id, $ent_id);
+        if (is_resource($rStream)) {
+            fputs($rStream,decodeBody($body,$encoding));
+        } else {
+            echo decodeBody($body, $encoding);
+        }
     }
     }
 
 
     /*
     /*
@@ -199,33 +203,6 @@ function mime_print_body_lines ($imap_stream, $id, $ent_id=1, $encoding) {
     */
     */
 
 
     return;
     return;
-/*
-    fputs ($imap_stream, "$sid FETCH $id BODY[$ent_id]\r\n");
-    $cnt = 0;
-    $continue = true;
-    $read = fgets ($imap_stream,8192);
-
-
-    // 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++;
-//      break;
-    }
-*/
 }
 }
 
 
 /* -[ END MIME DECODING ]----------------------------------------------------------- */
 /* -[ END MIME DECODING ]----------------------------------------------------------- */