[imp] Re: Patch for mbox downloads in IMP 3.2.5

Ross Becker ross at rbecker.org
Wed Sep 8 13:50:16 PDT 2004


Here's the text of the patch... forget attachments ;)



--- imp-3.2.5/folders.php	2004-05-28 05:15:03.000000000 -0700
+++ imp/folders.php	2004-09-08 11:19:04.680098952 -0700
@@ -132,11 +132,13 @@
   case DOWNLOAD_FOLDER:
       $download_folders = Horde::getFormData('folder_list');
       if (is_array($download_folders)) {
-         $mbox = IMP_Folder::generateMbox($imp['stream'],
-                                          $download_folders,
-                                          false);
-
-         header('Content-Length: ' . strlen($mbox));
+         $mbfile = IMP_Folder::generateMbox($imp['stream'],
+                                            $download_folders,
+                                            false);
+         fseek( $mbfile, 0, SEEK_END );
+         $mblen =  ftell( $mbfile );
+         fseek( $mbfile, 0, SEEK_SET );
+         header('Content-Length: ' . $mblen );
           header('Content-Type: application/RFC822');

           /* This should force a save file dialog.  According to a note
@@ -155,7 +157,11 @@
              header('Cache-Control: must-revalidate, post-check=0, 
pre-check=0');
              header('Pragma: public');
           }
-         echo $mbox;
+         while ( !feof( $mbfile ) ) {
+            $mbbuf = fread( $mbfile, 8192 );
+            echo $mbbuf;
+         }
+         fclose( $mbfile );
           exit;
       }
       break;
--- imp-3.2.5/lib/Folder.php	2003-11-27 14:38:12.000000000 -0800
+++ imp/lib/Folder.php	2004-09-08 11:08:06.828107656 -0700
@@ -467,12 +467,13 @@
       */
      function generateMbox($stream, $folder_list, $recursive = false)
      {
-        $body = '';
+        $tempf = tmpfile();
          if (is_array($folder_list)) {
              foreach ($folder_list as $folder) {
                  imap_reopen($stream, IMP::serverString() . $folder, 
OP_READONLY);
                  $count = imap_num_msg($stream);
                  for ($i = 1; $i <= $count; $i++) {
+                    $body = '';
                      $h = imap_header($stream, $i);
                      $from = '<>';
                      if (isset($h->from[0])) {
@@ -487,12 +488,13 @@
                      $body .= 'From ' . $from . ' ' . $date . "\n";
                      $body .= imap_fetchheader($stream, $i, 
FT_PREFETCHTEXT);
                      $body .= imap_body($stream, $i) . "\n";
+                    $body = str_replace("\r\n", "\n", $body);
+                    fwrite( $tempf, $body, strlen($body) );
                  }
              }
          }

-        $body = str_replace("\r\n", "\n", $body);
-        return $body;
+        return $tempf;
      }

      /**



More information about the imp mailing list