[prev in list] [next in list] [prev in thread] [next in thread] 

List:       squirrelmail-users
Subject:    [SM-USERS] Re: Attachments problem : Solved with a trick
From:       "Dipartimento ICT, Jobiz.com" <ict () jobiz ! com>
Date:       2004-11-29 8:57:46
Message-ID: 41AAE48A.5090406 () jobiz ! com
[Download RAW message or body]

Hi
As you suggestion i write the diff files of "patch" and publish it on 
this ML ....

As you say "How can you guarantee that you are only stripping off the 
correct number of newlines? "
the solution is simple: I wrote an autogenerating php page "on the fly" 
with download informations only, after, i redirect SM on it,in this 
manner, i precisely define the content i write on download channel and 
avoid strange "unpredictable" behaviours that can come out from other 
sections of program ( plugins, etc ... ). At the end of download 
temporary files are removed in order to avoid to fill directory with 
useless files.In this manner, IMHO, SM appear to be less prone to these 
"side effects" and, think, this patch to be considered as "version 
independent" if you consider that it creates and destroy itself without 
involve any part of SM.
Don't worry for multi user environment : temporary files are named with 
session cookie value so, think, they are uniques  and don't conflict 
with various users downloads.Multiple download from same user  
generating, of course, the same file name, but this isn't a problem: 
user can download one file at once ...

WARNING !!! : In a very ugly manner i've 'Hard coded' ( is a nightly 
build ... ) a path to a directory that contains temporary working  files 
the path for my installation is '/var/www/webmail/data' so you MUST 
change this with your own directory were squirrel user can write/read ( 
for me user is : nobody/nobody ) this can be solved using a global 
variable ....

Thanks to you and other people that have send kindly suggestions to me...

With regards
Mariano

["mime.diff" (text/x-patch)]

--- mime.php	2004-11-23 15:52:04.000000000 +0000
+++ mime.php	2004-11-25 08:41:55.000000000 +0000
@@ -153,19 +153,13 @@
     return $ret;
 }
 
+
 function mime_print_body_lines ($imap_stream, $id, $ent_id=1, $encoding) {
     global $uid_support;
-
-    /* Don't kill the connection if the browser is over a dialup
-     * and it would take over 30 seconds to download it.
-     * Donīt call set_time_limit in safe mode.
-     */
-
+    global $username;
     if (!ini_get('safe_mode')) {
         set_time_limit(0);
     }
-   /*  in case of base64 encoded attachments, do not buffer them.
-       Instead, echo the decoded attachment directly to screen */
     if (strtolower($encoding) == 'base64')
        {
         if (!$ent_id)
@@ -177,7 +171,23 @@
            $query = "FETCH $id BODY[$ent_id]";
           }
 
-        sqimap_run_command($imap_stream,$query,true,$response,$message,$uid_support,'sqimap_base64_decode','php://stdout',true);
 +	/* Code Patched 19/11/2004 by Mariano Mancini  
+	 * Extract SQMSESSID in order to use it as filename
+	 */
+        sqgetGlobalVar('SQMSESSID',  $thisSession,     SQ_COOKIE);
+
+	/* Change th path /var/www/webmail/data with one valid to your installation
+	 * To be clean : this path can be register as a session variable ( in future patch \
... ) +	 */
+	 
+	$myhnd = fopen("/var/www/webmail/data/at-".$thisSession,"a");
+	// original one, some people say 'writing on php://stdout contain a failure, it's \
not really a file stream' +	// I don't know if it's real but in case ....
+       // sqimap_run_command($imap_stream,$query,true,$response,$message,$uid_support,'sqimap_base64_decode','php://stdout',true);
 +        sqimap_run_command($imap_stream,$query,true,$response,$message,$uid_support,'sqimap_base64_decode',$myhnd,true);
 +	fclose($myhnd);
+	/* End of patch */
+	
        }
      else
        {
@@ -188,11 +198,9 @@
 }
 
 function sqimap_base64_decode(&$string) {
-
-    //$string = base64_decode($string);
-    //$string = str_replace("\r\n", "\n", $string);
+    $string = str_replace("\r\n", "\n", $string);
     $string = base64_decode($string);
-
+    return $string;
 }
 
 


["download.diff" (text/x-patch)]

--- download.php	2003-09-12 00:06:50.000000000 +0000
+++ download.php	2004-11-25 08:54:54.000000000 +0000
@@ -20,11 +20,20 @@
 require_once(SM_PATH . 'functions/imap.php');
 require_once(SM_PATH . 'functions/mime.php');
 
-header('Pragma: ');
-header('Cache-Control: cache');
+//header('Pragma: ');
+//header('Cache-Control: cache');
 
 /* globals */
 sqgetGlobalVar('key',        $key,          SQ_COOKIE);
+
+/* Code Patched by Mariano Mancini
+ * Using SQMSESSID to compose filenames for the patch ....
+ * so i extract it ... Excuse for the variable name $sessione i use it in Italian to \
avoid to overlap English + * variable with same name 
+ */
+ 
+sqgetGlobalVar('SQMSESSID',  $sessione,     SQ_COOKIE);
+
 sqgetGlobalVar('username',   $username,     SQ_SESSION);
 sqgetGlobalVar('onetimepad', $onetimepad,   SQ_SESSION);
 sqgetGlobalVar('messages',   $messages,     SQ_SESSION);
@@ -37,6 +46,74 @@
 
 /* end globals */
 
+/*
+ * This function is verified to work with Netscape and the *very latest*
+ * version of IE.  I don't know if it works with Opera, but it should now.
+ */
+function DumpHeaders($type0, $type1, $filename, $force) {
+    global $languages, $squirrelmail_language;
+    $isIE = $isIE6 = 0;
+
+    sqgetGlobalVar('HTTP_USER_AGENT', $HTTP_USER_AGENT, SQ_SERVER);
+
+    if (strstr($HTTP_USER_AGENT, 'compatible; MSIE ') !== false &&
+        strstr($HTTP_USER_AGENT, 'Opera') === false) {
+        $isIE = 1;
+    }
+
+    if (strstr($HTTP_USER_AGENT, 'compatible; MSIE 6') !== false &&
+        strstr($HTTP_USER_AGENT, 'Opera') === false) {
+        $isIE6 = 1;
+    }
+
+    if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
+        function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
+        $filename =
+            $languages[$squirrelmail_language]['XTRA_CODE']('downloadfilename', \
$filename, $HTTP_USER_AGENT); +    } else {
+       $filename = ereg_replace('[\\/:\*\?"<>\|;]', '_', str_replace('&nbsp;', ' ', \
$filename)); +    }
+
+    // A Pox on Microsoft and it's Office!
+    if (!$force) {
+        // Try to show in browser window
+        header("Content-Disposition: inline; filename=\"$filename\"");
+        header("Content-Type: $type0/$type1; name=\"$filename\"");
+    } else {
+        // Try to pop up the "save as" box
+        // IE makes this hard.  It pops up 2 save boxes, or none.
+        // http://support.microsoft.com/support/kb/articles/Q238/5/88.ASP
+        // But, accordint to Microsoft, it is "RFC compliant but doesn't
+        // take into account some deviations that allowed within the
+        // specification."  Doesn't that mean RFC non-compliant?
+        // http://support.microsoft.com/support/kb/articles/Q258/4/52.ASP
+        //
+        // The best thing you can do for IE is to upgrade to the latest
+        // version
+        if ($isIE && !$isIE6) {
+            // http://support.microsoft.com/support/kb/articles/Q182/3/15.asp
+            // Do not have quotes around filename, but that applied to
+            // "attachment"... does it apply to inline too?
+            //
+            // This combination seems to work mostly.  IE 5.5 SP 1 has
+            // known issues (see the Microsoft Knowledge Base)
+            header("Content-Disposition: inline; filename=$filename");
+            // This works for most types, but doesn't work with Word files
+            header("Content-Type: application/download; name=\"$filename\"");
+
+            // These are spares, just in case.  :-)
+            //header("Content-Type: $type0/$type1; name=\"$filename\"");
+            //header("Content-Type: application/x-msdownload; name=\"$filename\"");
+            //header("Content-Type: application/octet-stream; name=\"$filename\"");
+        } else {
+            header("Content-Disposition: attachment; filename=\"$filename\"");
+            // application/octet-stream forces download for Netscape
+            header("Content-Type: application/octet-stream; name=\"$filename\"");
+        }
+    }
+}
+
+
 global $uid_support;
 
 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
@@ -91,8 +168,9 @@
 } else {
     $filename = $header->getParameter('name');
 }
-
-$filename = decodeHeader($filename);
+// To avoid strange filenames in download e.g. : 'File&nbspDownload' instead of  \
'File Download' +// locking the decodeHeader
+//$filename = decodeHeader($filename);
 if (strlen($filename) < 1) {
     if ($type1 == 'plain' && $type0 == 'text') {
         $suffix = 'txt';
@@ -132,79 +210,38 @@
  *    viewer (built in to squirrelmail).  Otherwise, it sets the
  *    content-type as application/octet-stream
  */
-if (isset($absolute_dl) && $absolute_dl) {
+/*if (isset($absolute_dl) && $absolute_dl) {
     DumpHeaders($type0, $type1, $filename, 1);
 } else {
     DumpHeaders($type0, $type1, $filename, 0);
-}
-/* be aware that any warning caused by download.php will corrupt the
- * attachment in case of ERROR reporting = E_ALL and the output is the screen */
+}*/
 mime_print_body_lines ($imapConnection, $passed_id, $ent_id, $encoding);
 
-/*
- * This function is verified to work with Netscape and the *very latest*
- * version of IE.  I don't know if it works with Opera, but it should now.
- */
-function DumpHeaders($type0, $type1, $filename, $force) {
-    global $languages, $squirrelmail_language;
-    $isIE = $isIE6 = 0;
-
-    sqgetGlobalVar('HTTP_USER_AGENT', $HTTP_USER_AGENT, SQ_SERVER);
 
-    if (strstr($HTTP_USER_AGENT, 'compatible; MSIE ') !== false &&
-        strstr($HTTP_USER_AGENT, 'Opera') === false) {
-        $isIE = 1;
-    }
+/* Code Patched 19/11/2004 by Mariano Mancini 
+ * Little trick : header statements  send 8 LF along the download channel
+ * So i create a single php page with instructions to download file, after
+ * i destroy files ( download instructions & downloaded file )  to make clean
+ * the directory and don't waste space on disk with useless files.
+ *
+ * WARNING: It's a old dirty trick i hope that SM staff remove this bug quickly ....
+ * Excuse me for the 'Hard Path' but i nightly developed this snippet
+ *
+ * Mariano
+ */
 
-    if (strstr($HTTP_USER_AGENT, 'compatible; MSIE 6') !== false &&
-        strstr($HTTP_USER_AGENT, 'Opera') === false) {
-        $isIE6 = 1;
-    }
+$dwname = "dw-".$sessione.".php";
+$dwunit = "/var/www/webmail/data/dw-".$sessione.".php";
+$atunit = "/var/www/webmail/data/at-".$sessione;
+$myhnd = fopen( $dwunit ,"w");
+fwrite( $myhnd,'<?php');
+fwrite( $myhnd,' ');
+fwrite( $myhnd,'header("Content-Disposition: inline; filename=\"'.$filename.'\" "); \
'   ); +fwrite( $myhnd,'header("Content-Type: application/download; \
name=\"'.$filename.'\" "); '   ); +fwrite( $myhnd,'readfile("'.$atunit.'"); ');
+fwrite( $myhnd,'unlink("'.$dwunit.'"); unlink("'.$atunit.'"); ' );
+fwrite( $myhnd,' ?>');
+fclose( $myhnd);
 
-    if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
-        function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
-        $filename = 
-            $languages[$squirrelmail_language]['XTRA_CODE']('downloadfilename', \
                $filename, $HTTP_USER_AGENT);
-    } else {
-       $filename = ereg_replace('[\\/:\*\?"<>\|;]', '_', str_replace('&nbsp;', ' ', \
                $filename));
-    }
-
-    // A Pox on Microsoft and it's Office!
-    if (!$force) {
-        // Try to show in browser window
-        header("Content-Disposition: inline; filename=\"$filename\"");
-        header("Content-Type: $type0/$type1; name=\"$filename\"");
-    } else {
-        // Try to pop up the "save as" box
-        // IE makes this hard.  It pops up 2 save boxes, or none.
-        // http://support.microsoft.com/support/kb/articles/Q238/5/88.ASP
-        // But, accordint to Microsoft, it is "RFC compliant but doesn't
-        // take into account some deviations that allowed within the
-        // specification."  Doesn't that mean RFC non-compliant?
-        // http://support.microsoft.com/support/kb/articles/Q258/4/52.ASP
-        //
-        // The best thing you can do for IE is to upgrade to the latest
-        // version
-        if ($isIE && !$isIE6) {
-            // http://support.microsoft.com/support/kb/articles/Q182/3/15.asp
-            // Do not have quotes around filename, but that applied to
-            // "attachment"... does it apply to inline too?
-            //
-            // This combination seems to work mostly.  IE 5.5 SP 1 has
-            // known issues (see the Microsoft Knowledge Base)
-            header("Content-Disposition: inline; filename=$filename");
-            // This works for most types, but doesn't work with Word files
-            header("Content-Type: application/download; name=\"$filename\"");
-
-            // These are spares, just in case.  :-)
-            //header("Content-Type: $type0/$type1; name=\"$filename\"");
-            //header("Content-Type: application/x-msdownload; name=\"$filename\"");
-            //header("Content-Type: application/octet-stream; name=\"$filename\"");
-        } else {
-            header("Content-Disposition: attachment; filename=\"$filename\"");
-            // application/octet-stream forces download for Netscape
-            header("Content-Type: application/octet-stream; name=\"$filename\"");
-        }
-    }
-}
+header("Location: ../data/".$dwname);
 ?>


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/
--
squirrelmail-users mailing list
Posting Guidelines: http://squirrelmail.org/wiki/wiki.php?MailingListPostingGuidelines
List Address: squirrelmail-users@lists.sourceforge.net
List Archives: http://news.gmane.org/thread.php?group=gmane.mail.squirrelmail.user
List Archives:  http://sourceforge.net/mailarchive/forum.php?forum_id=2995
List Info: https://lists.sourceforge.net/lists/listinfo/squirrelmail-users

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic