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

Revision 1005, 6.3 KB checked in by amuller, 15 years ago (diff)

Ticket #520 - Implementação de redução automática de imagens

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