source: trunk/expressoMail1_2/inc/gotodownload.php @ 2360

Revision 2360, 8.3 KB checked in by amuller, 14 years ago (diff)

Ticket #1008 - Adicionando informações sobre licenças

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2
3/***************************************************************************
4        * Expresso Livre                                                           *
5        * http://www.expressolivre.org                                             *
6        * --------------------------------------------                             *
7        *  This program is free software; you can redistribute it and/or modify it *
8        *  under the terms of the GNU General Public License as published by the   *
9        *  Free Software Foundation; either version 2 of the License, or (at your  *
10        *  option) any later version.                                              *
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 = urldecode($_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
63        downloadFile($strFileType, $filename, $newfilename, $fileContent, $encoding);
64
65        function downloadFile($strFileType, $strFileName, $newFileName, $fileContent, $encoding) {
66                $ContentType = "application/octet-stream";
67
68                if ($strFileType == ".asf")
69                        $ContentType = "video/x-ms-asf";
70                if ($strFileType == ".avi")
71                        $ContentType = "video/avi";
72                if ($strFileType == ".doc")
73                        $ContentType = "application/msword";
74                if ($strFileType == ".zip")
75                        $ContentType = "application/zip";
76                if ($strFileType == ".xls")
77                        $ContentType = "application/vnd.ms-excel";
78                if ($strFileType == ".gif")
79                        $ContentType = "image/gif";
80                if ($strFileType == ".jpg" || $strFileType == "jpeg")
81                        $ContentType = "image/jpeg";
82                if ($strFileType == ".wav")
83                        $ContentType = "audio/wav";
84                if ($strFileType == ".mp3")
85                        $ContentType = "audio/mpeg3";
86                if ($strFileType == ".mpg" || $strFileType == "mpeg")
87                        $ContentType = "video/mpeg";
88                if ($strFileType == ".rtf")
89                        $ContentType = "application/rtf";
90                if ($strFileType == ".htm" || $strFileType == "html")
91                        $ContentType = "text/html";
92                if ($strFileType == ".xml")
93                        $ContentType = "text/xml";
94                if ($strFileType == ".xsl")
95                        $ContentType = "text/xsl";
96                if ($strFileType == ".css")
97                        $ContentType = "text/css";
98                if ($strFileType == ".php")
99                        $ContentType = "text/php";
100                if ($strFileType == ".asp")
101                        $ContentType = "text/asp";
102                if ($strFileType == ".pdf")
103                        $ContentType = "application/pdf";
104                if ($strFileType == ".txt")
105                        $ContentType = "text/plain";
106                if ($strFileType == ".log")
107                        $ContentType = "text/plain";
108                if ($strFileType == ".wmv")
109                        $ContentType = "video/x-ms-wmv";
110                if ($strFileType == ".sxc")
111                        $ContentType = "application/vnd.sun.xml.calc";
112                if ($strFileType == ".odt")
113                        $ContentType = "application/vnd.oasis.opendocument.text";
114                if ($strFileType == ".stc")
115                        $ContentType = "application/vnd.sun.xml.calc.template";
116                if ($strFileType == ".sxd")
117                        $ContentType = "application/vnd.sun.xml.draw";
118                if ($strFileType == ".std")
119                        $ContentType = "application/vnd.sun.xml.draw.template";
120                if ($strFileType == ".sxi")
121                        $ContentType = "application/vnd.sun.xml.impress";
122                if ($strFileType == ".sti")
123                        $ContentType = "application/vnd.sun.xml.impress.template";
124                if ($strFileType == ".sxm")
125                        $ContentType = "application/vnd.sun.xml.math";
126                if ($strFileType == ".sxw")
127                        $ContentType = "application/vnd.sun.xml.writer";
128                if ($strFileType == ".sxq")
129                        $ContentType = "application/vnd.sun.xml.writer.global";
130                if ($strFileType == ".stw")
131                        $ContentType = "application/vnd.sun.xml.writer.template";
132                if ($strFileType == ".ps")
133                        $ContentType = "application/postscript";
134                if ($strFileType == ".pps")
135                        $ContentType = "application/vnd.ms-powerpoint";
136                if ($strFileType == ".odt")
137                        $ContentType = "application/vnd.oasis.opendocument.text";
138                if ($strFileType == ".ott")
139                        $ContentType = "application/vnd.oasis.opendocument.text-template";
140                if ($strFileType == ".oth")
141                        $ContentType = "application/vnd.oasis.opendocument.text-web";
142                if ($strFileType == ".odm")
143                        $ContentType = "application/vnd.oasis.opendocument.text-master";
144                if ($strFileType == ".odg")
145                        $ContentType = "application/vnd.oasis.opendocument.graphics";
146                if ($strFileType == ".otg")
147                        $ContentType = "application/vnd.oasis.opendocument.graphics-template";
148                if ($strFileType == ".odp")
149                        $ContentType = "application/vnd.oasis.opendocument.presentation";
150                if ($strFileType == ".otp")
151                        $ContentType = "application/vnd.oasis.opendocument.presentation-template";
152                if ($strFileType == ".ods")
153                        $ContentType = "application/vnd.oasis.opendocument.spreadsheet";
154                if ($strFileType == ".ots")
155                        $ContentType = "application/vnd.oasis.opendocument.spreadsheet-template";
156                if ($strFileType == ".odc")
157                        $ContentType = "application/vnd.oasis.opendocument.chart";
158                if ($strFileType == ".odf")
159                        $ContentType = "application/vnd.oasis.opendocument.formula";
160                if ($strFileType == ".odi")
161                        $ContentType = "application/vnd.oasis.opendocument.image";
162                if ($strFileType == ".ndl")
163                        $ContentType = "application/vnd.lotus-notes";
164                if ($strFileType == ".eml")
165                        $ContentType = "text/plain";
166
167                header ("Content-Type: $ContentType");
168                header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
169                header("Pragma: public");
170                header("Expires: 0"); // set expiration time
171                header ("Content-Disposition: attachment; filename=\"". addslashes($newFileName)."\"");         
172                if($fileContent) {
173                        if($encoding == 'base64')
174                                echo imap_base64($fileContent);
175                        else if($encoding == 'quoted-printable')
176                                echo quoted_printable_decode($fileContent);
177                        else
178                                echo $fileContent;
179                }
180                else
181                        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))
182                        {
183                                //avoid stuck request
184                                session_write_close();
185
186                                //reset time limit for big files
187                                set_time_limit(0);
188
189                                if ($fp = fopen ($strFileName, 'rb'))
190                                {
191                                        $bufferSize=1024;
192                                        for ($i=$bufferSize; $i<=filesize($strFileName); $i+=$bufferSize)
193                                        {
194                                                echo fread($fp, $i);
195                                                flush();
196                                                ob_end_flush();
197                                        }
198                                        fclose ($fp);
199                                }
200                                //readfile($strFileName);
201                                exec("rm -f ".escapeshellcmd(escapeshellarg($strFileName)));
202                        }
203                        else
204                                if (preg_match("#^".dirname( __FILE__ ) . '/../tmpLclAtt'."/source_#",$strFileName)) {
205                                        readfile($strFileName);
206                                }
207        }
208?>
Note: See TracBrowser for help on using the repository browser.