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

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