source: companies/celepar/expressoMail1_2/inc/gotodownload.php @ 763

Revision 763, 6.2 KB checked in by niltonneto, 15 years ago (diff)

Importação inicial do Expresso da Celepar

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