source: sandbox/expressoMail1_2/corretor_ortografico/inc/gotodownload.php @ 2125

Revision 2125, 6.8 KB checked in by eduardoalex, 14 years ago (diff)

Ticket #886 - Adicionado escape no nome do anexo no js e realizado url_decode no php

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2if(!isset($GLOBALS['phpgw_info'])){
3        $GLOBALS['phpgw_info']['flags'] = array(
4                'currentapp' => 'expressoMail1_2',
5                'nonavbar'   => true,
6                'noheader'   => true
7        );
8}
9require_once '../../header.inc.php';
10
11
12        $msg_number = $_GET['msg_number'];
13        $idx_file = $_GET['idx_file'];
14        $newfilename = urldecode($_GET['newfilename']);
15        $msg_part = $_GET['msg_part'];
16        $msg_folder = $_GET['msg_folder'];
17        $msg_folder = mb_convert_encoding($msg_folder,"UTF7-IMAP", mb_detect_encoding($msg_folder, "UTF-8, ISO-8859-1", true));
18
19        $encoding = strtolower($_GET['encoding']);
20        $fileContent = "";
21
22        if($msg_number && $msg_part && $msg_folder && (intval($idx_file == '0' ? '1' : $idx_file))) {
23                $username = $_SESSION['phpgw_info']['expressomail']['user']['userid'];
24                $password = $_SESSION['phpgw_info']['expressomail']['user']['passwd'];
25                $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer'];
26                $imap_port      = $_SESSION['phpgw_info']['expressomail']['email_server']['imapPort'];         
27                if ($_SESSION['phpgw_info']['expressomail']['email_server']['imapTLSEncryption'] == 'yes')
28                {
29                        $imap_options = '/tls/novalidate-cert';
30                }
31                else
32                {
33                        $imap_options = '/notls/novalidate-cert';
34                }
35                $mbox_stream = imap_open("{".$imap_server.":".$imap_port.$imap_options."}".$msg_folder, $username, $password);         
36                $fileContent = imap_fetchbody($mbox_stream, $msg_number, $msg_part, FT_UID);
37                /*
38                 *Removed by Bug #546
39                 *include("class.imap_attachment.inc.php");
40                 *$imap_attachment = new imap_attachment();                     
41                 *$a = $imap_attachment->download_attachment($mbox_stream, $msg_number);
42                 *$filename = $a[$idx_file]['name'];
43                 */
44                $filename = $newfilename;
45        }
46        else
47                $filename = $idx_file;
48
49        $filename        = $filename    ? $filename     : "attachment.bin";
50        $newfilename = $newfilename ? $newfilename      : $filename;
51        $strFileType = strrev(substr(strrev(strtolower($filename)),0,4));
52
53        downloadFile($strFileType, $filename, $newfilename, $fileContent, $encoding);
54
55        function downloadFile($strFileType, $strFileName, $newFileName, $fileContent, $encoding) {
56                $ContentType = "application/octet-stream";
57
58                if ($strFileType == ".asf")
59                        $ContentType = "video/x-ms-asf";
60                if ($strFileType == ".avi")
61                        $ContentType = "video/avi";
62                if ($strFileType == ".doc")
63                        $ContentType = "application/msword";
64                if ($strFileType == ".zip")
65                        $ContentType = "application/zip";
66                if ($strFileType == ".xls")
67                        $ContentType = "application/vnd.ms-excel";
68                if ($strFileType == ".gif")
69                        $ContentType = "image/gif";
70                if ($strFileType == ".jpg" || $strFileType == "jpeg")
71                        $ContentType = "image/jpeg";
72                if ($strFileType == ".wav")
73                        $ContentType = "audio/wav";
74                if ($strFileType == ".mp3")
75                        $ContentType = "audio/mpeg3";
76                if ($strFileType == ".mpg" || $strFileType == "mpeg")
77                        $ContentType = "video/mpeg";
78                if ($strFileType == ".rtf")
79                        $ContentType = "application/rtf";
80                if ($strFileType == ".htm" || $strFileType == "html")
81                        $ContentType = "text/html";
82                if ($strFileType == ".xml")
83                        $ContentType = "text/xml";
84                if ($strFileType == ".xsl")
85                        $ContentType = "text/xsl";
86                if ($strFileType == ".css")
87                        $ContentType = "text/css";
88                if ($strFileType == ".php")
89                        $ContentType = "text/php";
90                if ($strFileType == ".asp")
91                        $ContentType = "text/asp";
92                if ($strFileType == ".pdf")
93                        $ContentType = "application/pdf";
94                if ($strFileType == ".txt")
95                        $ContentType = "text/plain";
96                if ($strFileType == ".log")
97                        $ContentType = "text/plain";
98                if ($strFileType == ".wmv")
99                        $ContentType = "video/x-ms-wmv";
100                if ($strFileType == ".sxc")
101                        $ContentType = "application/vnd.sun.xml.calc";
102                if ($strFileType == ".odt")
103                        $ContentType = "application/vnd.oasis.opendocument.text";
104                if ($strFileType == ".stc")
105                        $ContentType = "application/vnd.sun.xml.calc.template";
106                if ($strFileType == ".sxd")
107                        $ContentType = "application/vnd.sun.xml.draw";
108                if ($strFileType == ".std")
109                        $ContentType = "application/vnd.sun.xml.draw.template";
110                if ($strFileType == ".sxi")
111                        $ContentType = "application/vnd.sun.xml.impress";
112                if ($strFileType == ".sti")
113                        $ContentType = "application/vnd.sun.xml.impress.template";
114                if ($strFileType == ".sxm")
115                        $ContentType = "application/vnd.sun.xml.math";
116                if ($strFileType == ".sxw")
117                        $ContentType = "application/vnd.sun.xml.writer";
118                if ($strFileType == ".sxq")
119                        $ContentType = "application/vnd.sun.xml.writer.global";
120                if ($strFileType == ".stw")
121                        $ContentType = "application/vnd.sun.xml.writer.template";
122                if ($strFileType == ".ps")
123                        $ContentType = "application/postscript";
124                if ($strFileType == ".pps")
125                        $ContentType = "application/vnd.ms-powerpoint";
126                if ($strFileType == ".odt")
127                        $ContentType = "application/vnd.oasis.opendocument.text";
128                if ($strFileType == ".ott")
129                        $ContentType = "application/vnd.oasis.opendocument.text-template";
130                if ($strFileType == ".oth")
131                        $ContentType = "application/vnd.oasis.opendocument.text-web";
132                if ($strFileType == ".odm")
133                        $ContentType = "application/vnd.oasis.opendocument.text-master";
134                if ($strFileType == ".odg")
135                        $ContentType = "application/vnd.oasis.opendocument.graphics";
136                if ($strFileType == ".otg")
137                        $ContentType = "application/vnd.oasis.opendocument.graphics-template";
138                if ($strFileType == ".odp")
139                        $ContentType = "application/vnd.oasis.opendocument.presentation";
140                if ($strFileType == ".otp")
141                        $ContentType = "application/vnd.oasis.opendocument.presentation-template";
142                if ($strFileType == ".ods")
143                        $ContentType = "application/vnd.oasis.opendocument.spreadsheet";
144                if ($strFileType == ".ots")
145                        $ContentType = "application/vnd.oasis.opendocument.spreadsheet-template";
146                if ($strFileType == ".odc")
147                        $ContentType = "application/vnd.oasis.opendocument.chart";
148                if ($strFileType == ".odf")
149                        $ContentType = "application/vnd.oasis.opendocument.formula";
150                if ($strFileType == ".odi")
151                        $ContentType = "application/vnd.oasis.opendocument.image";
152                if ($strFileType == ".ndl")
153                        $ContentType = "application/vnd.lotus-notes";
154                if ($strFileType == ".eml")
155                        $ContentType = "text/plain";
156
157                header ("Content-Type: $ContentType");
158                header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
159                header("Pragma: public");
160                header("Expires: 0"); // set expiration time
161                header ("Content-Disposition: attachment; filename=\"". addslashes($newFileName)."\"");         
162                if($fileContent) {
163                        if($encoding == 'base64')
164                                echo imap_base64($fileContent);
165                        else if($encoding == 'quoted-printable')
166                                echo quoted_printable_decode($fileContent);
167                        else
168                                echo $fileContent;
169                }
170                else
171                        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))
172                        {
173                                readfile($strFileName);
174                                exec("rm -f ".escapeshellcmd(escapeshellarg($strFileName)));
175                        }
176                        else
177                                if (preg_match("#^".dirname( __FILE__ ) . '/../tmpLclAtt'."/source_#",$strFileName)) {
178                                        readfile($strFileName);
179                                }
180        }
181?>
Note: See TracBrowser for help on using the repository browser.