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

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