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

Revision 63, 6.0 KB checked in by niltonneto, 17 years ago (diff)

* empty log message *

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