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

Revision 2, 5.7 KB checked in by niltonneto, 17 years ago (diff)

Removida todas as tags usadas pelo CVS ($Id, $Source).
Primeira versão no CVS externo.

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