Index: sandbox/2.2.0.2/expressoMail1_2/inc/get_archive.php
===================================================================
--- sandbox/2.2.0.2/expressoMail1_2/inc/get_archive.php	(revision 4415)
+++ sandbox/2.2.0.2/expressoMail1_2/inc/get_archive.php	(revision 4415)
@@ -0,0 +1,248 @@
+<?php
+/*
+ * Definitions
+ */
+if(!isset($GLOBALS['phpgw_info']))
+{
+    $GLOBALS['phpgw_info']['flags'] = array(
+            'currentapp' => 'expressoMail1_2',
+            'nonavbar'   => true,
+            'noheader'   => true
+    );
+}
+
+$GLOBALS['phpgw_info']['server']['download_temp_dir'] = '/tmp';
+//-----------------------//
+
+/*
+ * Requires
+ */
+require_once 'class.attachment.inc.php';
+require_once '../../header.inc.php';
+//-----------------------//
+
+/*
+ * Get variables
+ */
+$newFilename = urldecode($_GET['newFilename']);
+$indexFile = $_GET['idx_file'];
+$indexPart = $_GET['indexPart'];
+$msgNumber = $_GET['msgNumber'];
+$msgFolder = $_GET['msgFolder'];
+//----------------------------------------------//
+
+/*
+ * Functions
+ */
+function downloadFile($strFileType, $strFileName, $newFileName, $fileContent) {
+
+        $ContentType = "application/octet-stream";
+
+        if ($strFileType == ".asf")
+                $ContentType = "video/x-ms-asf";
+        if ($strFileType == ".avi")
+                $ContentType = "video/avi";
+        if ($strFileType == ".doc")
+                $ContentType = "application/msword";
+        if ($strFileType == ".zip")
+                $ContentType = "application/zip";
+        if ($strFileType == ".xls")
+                $ContentType = "application/vnd.ms-excel";
+        if ($strFileType == ".gif")
+                $ContentType = "image/gif";
+        if ($strFileType == ".jpg" || $strFileType == "jpeg")
+                $ContentType = "image/jpeg";
+        if ($strFileType == ".wav")
+                $ContentType = "audio/wav";
+        if ($strFileType == ".mp3")
+                $ContentType = "audio/mpeg3";
+        if ($strFileType == ".mpg" || $strFileType == "mpeg")
+                $ContentType = "video/mpeg";
+        if ($strFileType == ".rtf")
+                $ContentType = "application/rtf";
+        if ($strFileType == ".htm" || $strFileType == "html")
+                $ContentType = "text/html";
+        if ($strFileType == ".xml")
+                $ContentType = "text/xml";
+        if ($strFileType == ".xsl")
+                $ContentType = "text/xsl";
+        if ($strFileType == ".css")
+                $ContentType = "text/css";
+        if ($strFileType == ".php")
+                $ContentType = "text/php";
+        if ($strFileType == ".asp")
+                $ContentType = "text/asp";
+        if ($strFileType == ".pdf")
+                $ContentType = "application/pdf";
+        if ($strFileType == ".txt")
+                $ContentType = "text/plain";
+        if ($strFileType == ".log")
+                $ContentType = "text/plain";
+        if ($strFileType == ".wmv")
+                $ContentType = "video/x-ms-wmv";
+        if ($strFileType == ".sxc")
+                $ContentType = "application/vnd.sun.xml.calc";
+        if ($strFileType == ".odt")
+                $ContentType = "application/vnd.oasis.opendocument.text";
+        if ($strFileType == ".stc")
+                $ContentType = "application/vnd.sun.xml.calc.template";
+        if ($strFileType == ".sxd")
+                $ContentType = "application/vnd.sun.xml.draw";
+        if ($strFileType == ".std")
+                $ContentType = "application/vnd.sun.xml.draw.template";
+        if ($strFileType == ".sxi")
+                $ContentType = "application/vnd.sun.xml.impress";
+        if ($strFileType == ".sti")
+                $ContentType = "application/vnd.sun.xml.impress.template";
+        if ($strFileType == ".sxm")
+                $ContentType = "application/vnd.sun.xml.math";
+        if ($strFileType == ".sxw")
+                $ContentType = "application/vnd.sun.xml.writer";
+        if ($strFileType == ".sxq")
+                $ContentType = "application/vnd.sun.xml.writer.global";
+        if ($strFileType == ".stw")
+                $ContentType = "application/vnd.sun.xml.writer.template";
+        if ($strFileType == ".ps")
+                $ContentType = "application/postscript";
+        if ($strFileType == ".pps")
+                $ContentType = "application/vnd.ms-powerpoint";
+        if ($strFileType == ".odt")
+                $ContentType = "application/vnd.oasis.opendocument.text";
+        if ($strFileType == ".ott")
+                $ContentType = "application/vnd.oasis.opendocument.text-template";
+        if ($strFileType == ".oth")
+                $ContentType = "application/vnd.oasis.opendocument.text-web";
+        if ($strFileType == ".odm")
+                $ContentType = "application/vnd.oasis.opendocument.text-master";
+        if ($strFileType == ".odg")
+                $ContentType = "application/vnd.oasis.opendocument.graphics";
+        if ($strFileType == ".otg")
+                $ContentType = "application/vnd.oasis.opendocument.graphics-template";
+        if ($strFileType == ".odp")
+                $ContentType = "application/vnd.oasis.opendocument.presentation";
+        if ($strFileType == ".otp")
+                $ContentType = "application/vnd.oasis.opendocument.presentation-template";
+        if ($strFileType == ".ods")
+                $ContentType = "application/vnd.oasis.opendocument.spreadsheet";
+        if ($strFileType == ".ots")
+                $ContentType = "application/vnd.oasis.opendocument.spreadsheet-template";
+        if ($strFileType == ".odc")
+                $ContentType = "application/vnd.oasis.opendocument.chart";
+        if ($strFileType == ".odf")
+                $ContentType = "application/vnd.oasis.opendocument.formula";
+        if ($strFileType == ".odi")
+                $ContentType = "application/vnd.oasis.opendocument.image";
+        if ($strFileType == ".ndl")
+                $ContentType = "application/vnd.lotus-notes";
+        if ($strFileType == ".eml")
+                $ContentType = "text/plain";
+
+        header ("Content-Type: $ContentType");
+        header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
+        header("Pragma: public");
+        header("Expires: 0"); // set expiration time
+        header ("Content-Disposition: attachment; filename=\"". addslashes($newFileName)."\"");
+
+        if($fileContent)
+        {
+          echo $fileContent;
+        }
+        else
+        {
+                $tempDir = $GLOBALS['phpgw_info']['server']['download_temp_dir'];
+                if (preg_match("#^".$tempDir."/(".$GLOBALS['phpgw']->session->sessionid."/)*[A-z0-9_]+_".$GLOBALS['phpgw']->session->sessionid."[A-z0-9]*(\.[A-z]{3,4})?$#",$strFileName))
+                {
+                //avoid stuck request
+                        session_write_close();
+
+                        //reset time limit for big files
+                        set_time_limit(0);
+                        ob_end_flush();
+
+                        if ($fp = fopen ($strFileName, 'rb'))
+                        {
+                                $bufferSize=1024;
+                                for ($i=$bufferSize; $i<=(filesize($strFileName)+$bufferSize); $i+=$bufferSize)
+                                {
+                                        echo fread($fp, $i);
+                                        flush();
+                                }
+                                fclose ($fp);
+                        }
+
+                        //removendo pelo php, garante a suportabilidade cross-platform
+                        cleanup( dirname( $strFileName ) );
+
+                }
+                else
+                {
+                        if (preg_match("#^".dirname( __FILE__ ) . '/../tmpLclAtt'."/source_#",$strFileName)) {
+                                readfile($strFileName);
+                        }
+                }
+        }
+}
+/**
+ * Delete Diretorio
+ * @param string $dir 
+ */
+function cleanup( $dir )
+{
+    if ( is_dir( $dir ) )
+    {
+        $files = scandir($dir);
+
+        foreach( $files as $file )
+            if( $file != "." && $file != ".." )
+                cleanup( $dir.'/'.$file );
+
+        reset( $files ); //?
+        
+        if(!rmdir( $dir ))
+            return;
+    }
+    else
+    {
+        if(!unlink( $dir ))
+        return;
+    }
+
+}
+//-----------------------//
+
+/*
+ * Main
+ */
+
+
+if($msgNumber != 'null' && $indexPart !== null && $msgFolder)
+{
+
+    $attachment = new attachment(PHPGW_INCLUDE_ROOT);
+    $attachment->setStructureFromMail($msgFolder, $msgNumber);
+    $fileContent = $attachment->getAttachment($indexPart);
+
+    if($newFilename)
+        $filename = $newFilename;
+    else
+    {
+        $info = $attachment->getAttachmentInfo($indexPart);
+        $filename = $info['name'];
+    }
+
+
+}
+else
+    $filename = $indexFile;
+
+
+$filename 	 = $filename 	? $filename 	: "attachment.bin";
+$newFilename = $newFilename ? $newFilename 	: $filename;
+
+
+$strFileType = strrev(substr(strrev(strtolower($filename)),0,4));
+
+downloadFile($strFileType,  $filename, $newFilename, $fileContent)
+//-----------------------//
+
+?>
