source: sandbox/2.5.0-expresso1/expressoMail1_2/inc/gotodownload.php @ 5509

Revision 5509, 8.8 KB checked in by gustavo, 12 years ago (diff)

Ticket #2488 - Adicionar cabecalho de licenca em arquivos que nao o possuem

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2                /***************************************************************************
3                * Expresso Livre                                                           *
4                * http://www.expressolivre.org                                             *
5                * --------------------------------------------                             *
6                *  This program is free software; you can redistribute it and/or modify it *
7                *  under the terms of the GNU General Public License as published by the   *
8                *  Free Software Foundation; either version 2 of the License, or (at your  *
9                *  option) any later version.                                              *
10                \**************************************************************************/
11               
12if(!isset($GLOBALS['phpgw_info'])){
13        $GLOBALS['phpgw_info']['flags'] = array(
14                'currentapp' => 'expressoMail1_2',
15                'nonavbar'   => true,
16                'noheader'   => true
17        );
18}
19require_once '../../header.inc.php';
20
21
22        $msg_number = $_GET['msg_number'];
23        $idx_file = $_GET['idx_file'];
24        $newfilename = html_entity_decode(rawurldecode($_GET['newfilename']));
25        $msg_part = $_GET['msg_part'];
26        $msg_folder = $_GET['msg_folder'];
27        $msg_folder = mb_convert_encoding($msg_folder,"UTF7-IMAP", mb_detect_encoding($msg_folder, "UTF-8, ISO-8859-1", true));
28
29        $encoding = strtolower($_GET['encoding']);
30        $fileContent = "";
31
32        if($msg_number && $msg_part && $msg_folder && (intval($idx_file == '0' ? '1' : $idx_file))) {
33                $username = $_SESSION['phpgw_info']['expressomail']['user']['userid'];
34                $password = $_SESSION['phpgw_info']['expressomail']['user']['passwd'];
35                $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer'];
36                $imap_port      = $_SESSION['phpgw_info']['expressomail']['email_server']['imapPort'];
37                if ($_SESSION['phpgw_info']['expressomail']['email_server']['imapTLSEncryption'] == 'yes')
38                {
39                        $imap_options = '/tls/novalidate-cert';
40                }
41                else
42                {
43                        $imap_options = '/notls/novalidate-cert';
44                }
45                $mbox_stream = imap_open("{".$imap_server.":".$imap_port.$imap_options."}".$msg_folder, $username, $password);
46                $fileContent = imap_fetchbody($mbox_stream, $msg_number, $msg_part, FT_UID);
47                /*
48                 *Removed by Bug #546
49                 *include("class.imap_attachment.inc.php");
50                 *$imap_attachment = new imap_attachment();
51                 *$a = $imap_attachment->download_attachment($mbox_stream, $msg_number);
52                 *$filename = $a[$idx_file]['name'];
53                 */
54                $filename = $newfilename;
55        }
56        else
57                $filename = $idx_file;
58
59        $filename        = $filename    ? $filename     : "attachment.bin";
60        $newfilename = $newfilename ? $newfilename      : $filename;
61        $strFileType = strrev(substr(strrev(strtolower($filename)),0,4));
62        if(strpos($strFileType ,"." )===false)
63                $strFileType = strrev(substr(strrev(strtolower($newfilename)),0,4));
64
65        downloadFile($strFileType, $filename, $newfilename, $fileContent, $encoding);
66
67        function downloadFile($strFileType, $strFileName, $newFileName, $fileContent, $encoding) {
68                //avoid stuck request
69                session_write_close();
70                $ContentType = "application/octet-stream";
71
72                if ($strFileType == ".asf")
73                        $ContentType = "video/x-ms-asf";
74                if ($strFileType == ".avi")
75                        $ContentType = "video/avi";
76                if ($strFileType == ".doc")
77                        $ContentType = "application/msword";
78                if ($strFileType == ".zip")
79                        $ContentType = "application/zip";
80                if ($strFileType == ".xls")
81                        $ContentType = "application/vnd.ms-excel";
82                if ($strFileType == ".gif")
83                        $ContentType = "image/gif";
84                if ($strFileType == ".jpg" || $strFileType == "jpeg")
85                        $ContentType = "image/jpeg";
86                if ($strFileType == ".wav")
87                        $ContentType = "audio/wav";
88                if ($strFileType == ".mp3")
89                        $ContentType = "audio/mpeg3";
90                if ($strFileType == ".mpg" || $strFileType == "mpeg")
91                        $ContentType = "video/mpeg";
92                if ($strFileType == ".rtf")
93                        $ContentType = "application/rtf";
94                if ($strFileType == ".htm" || $strFileType == "html")
95                        $ContentType = "text/html";
96                if ($strFileType == ".xml")
97                        $ContentType = "text/xml";
98                if ($strFileType == ".xsl")
99                        $ContentType = "text/xsl";
100                if ($strFileType == ".css")
101                        $ContentType = "text/css";
102                if ($strFileType == ".php")
103                        $ContentType = "text/php";
104                if ($strFileType == ".asp")
105                        $ContentType = "text/asp";
106                if ($strFileType == ".pdf")
107                        $ContentType = "application/pdf";
108                if ($strFileType == ".txt")
109                        $ContentType = "text/plain";
110                if ($strFileType == ".log")
111                        $ContentType = "text/plain";
112                if ($strFileType == ".wmv")
113                        $ContentType = "video/x-ms-wmv";
114                if ($strFileType == ".sxc")
115                        $ContentType = "application/vnd.sun.xml.calc";
116                if ($strFileType == ".odt")
117                        $ContentType = "application/vnd.oasis.opendocument.text";
118                if ($strFileType == ".stc")
119                        $ContentType = "application/vnd.sun.xml.calc.template";
120                if ($strFileType == ".sxd")
121                        $ContentType = "application/vnd.sun.xml.draw";
122                if ($strFileType == ".std")
123                        $ContentType = "application/vnd.sun.xml.draw.template";
124                if ($strFileType == ".sxi")
125                        $ContentType = "application/vnd.sun.xml.impress";
126                if ($strFileType == ".sti")
127                        $ContentType = "application/vnd.sun.xml.impress.template";
128                if ($strFileType == ".sxm")
129                        $ContentType = "application/vnd.sun.xml.math";
130                if ($strFileType == ".sxw")
131                        $ContentType = "application/vnd.sun.xml.writer";
132                if ($strFileType == ".sxq")
133                        $ContentType = "application/vnd.sun.xml.writer.global";
134                if ($strFileType == ".stw")
135                        $ContentType = "application/vnd.sun.xml.writer.template";
136                if ($strFileType == ".ps")
137                        $ContentType = "application/postscript";
138                if ($strFileType == ".pps")
139                        $ContentType = "application/vnd.ms-powerpoint";
140                if ($strFileType == ".odt")
141                        $ContentType = "application/vnd.oasis.opendocument.text";
142                if ($strFileType == ".ott")
143                        $ContentType = "application/vnd.oasis.opendocument.text-template";
144                if ($strFileType == ".oth")
145                        $ContentType = "application/vnd.oasis.opendocument.text-web";
146                if ($strFileType == ".odm")
147                        $ContentType = "application/vnd.oasis.opendocument.text-master";
148                if ($strFileType == ".odg")
149                        $ContentType = "application/vnd.oasis.opendocument.graphics";
150                if ($strFileType == ".otg")
151                        $ContentType = "application/vnd.oasis.opendocument.graphics-template";
152                if ($strFileType == ".odp")
153                        $ContentType = "application/vnd.oasis.opendocument.presentation";
154                if ($strFileType == ".otp")
155                        $ContentType = "application/vnd.oasis.opendocument.presentation-template";
156                if ($strFileType == ".ods")
157                        $ContentType = "application/vnd.oasis.opendocument.spreadsheet";
158                if ($strFileType == ".ots")
159                        $ContentType = "application/vnd.oasis.opendocument.spreadsheet-template";
160                if ($strFileType == ".odc")
161                        $ContentType = "application/vnd.oasis.opendocument.chart";
162                if ($strFileType == ".odf")
163                        $ContentType = "application/vnd.oasis.opendocument.formula";
164                if ($strFileType == ".odi")
165                        $ContentType = "application/vnd.oasis.opendocument.image";
166                if ($strFileType == ".ndl")
167                        $ContentType = "application/vnd.lotus-notes";
168                if ($strFileType == ".eml")
169                        $ContentType = "text/plain";
170
171                header ("Content-Type: $ContentType");
172                header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
173                header("Pragma: public");
174                header("Expires: 0"); // set expiration time
175                header ("Content-Disposition: attachment; filename=\"". addslashes($newFileName)."\"");
176                // No IE para que os nomes de arquivos com caracteres especiais no download fiquei corretos o nome deve ser codificado com urlencode.
177                 if (preg_match('/msie/i', $_SERVER['HTTP_USER_AGENT']))
178                        $newFileName=urlencode($newFileName);
179                if($fileContent) {
180                        if($encoding == 'base64')
181                                echo imap_base64($fileContent);
182                        else if($encoding == 'quoted-printable')
183                                echo quoted_printable_decode($fileContent);
184                        else
185                                echo $fileContent;
186                }
187                else
188
189                        if (strstr($strFileName,$GLOBALS['phpgw']->session->sessionid)&&file_exists($strFileName))
190                        {
191                            header("Content-Type: $ContentType");
192                            header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
193                            header("Pragma: public");
194                            header("Expires: 0"); // set expiration time
195                            header ("Content-Disposition: attachment; filename=\"". addslashes($newFileName)."\"");
196                            readfile($strFileName);
197                        }else{
198                            header("HTTP/1.1 404 Not Found");
199                        }
200
201
202                        if (preg_match("#^".ini_get('session.save_path')."/(".$GLOBALS['phpgw']->session->sessionid."/)*[A-z]+_".$GLOBALS['phpgw']->session->sessionid."[A-z0-9]*(\.[A-z]{3,4})?$#",$strFileName))
203                        {
204                                if ( ! preg_match("#^".dirname( __FILE__ ) . '/../tmpLclAtt'."/source_#",$strFileName)) {
205                                        //reset time limit for big files
206                                        set_time_limit(0);
207                                        ob_end_flush();
208
209                                        if ($fp = fopen ($strFileName, 'rb'))
210                                        {
211                                                $bufferSize=1024;
212                                                for ($i=$bufferSize; $i<=(filesize($strFileName)+$bufferSize); $i+=$bufferSize)
213                                                {
214                                                        echo fread($fp, $i);
215                                                        flush();
216                                                }
217                                                fclose ($fp);
218                                        }
219                                        //readfile($strFileName);
220
221                                        exec("rm -f ".escapeshellcmd(escapeshellarg($strFileName)));
222                                }
223                                else
224                                        readfile($strFileName);
225                        }
226        }
227?>
Note: See TracBrowser for help on using the repository browser.