]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/mail/get.inc
Imported Upstream version 0.3
[roundcube.git] / program / steps / mail / get.inc
1 <?php
2
3 /*
4  +-----------------------------------------------------------------------+
5  | program/steps/mail/get.inc                                            |
6  |                                                                       |
7  | This file is part of the RoundCube Webmail client                     |
8  | Copyright (C) 2005-2009, RoundCube Dev. - Switzerland                 |
9  | Licensed under the GNU GPL                                            |
10  |                                                                       |
11  | PURPOSE:                                                              |
12  |   Delivering a specific part of a mail message                        |
13  |                                                                       |
14  +-----------------------------------------------------------------------+
15  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
16  +-----------------------------------------------------------------------+
17
18  $Id: get.inc 2912 2009-09-04 10:38:18Z thomasb $
19
20 */
21
22
23 // show loading page
24 if (!empty($_GET['_preload'])) {
25   $url = str_replace('&_preload=1', '', $_SERVER['REQUEST_URI']);
26   $message = rcube_label('loadingdata');
27
28   header('Content-Type: text/html; charset=' . RCMAIL_CHARSET);
29   print "<html>\n<head>\n"
30         . '<meta http-equiv="refresh" content="0; url='.Q($url).'">' . "\n"
31         . '<meta http-equiv="content-type" content="text/html; charset='.RCMAIL_CHARSET.'">' . "\n"
32         . "</head>\n<body>\n$message\n</body>\n</html>";
33   exit;
34 }
35
36 ob_end_clean();
37
38 // similar code as in program/steps/mail/show.inc
39 if (!empty($_GET['_uid'])) {
40   $RCMAIL->config->set('prefer_html', true);
41   $MESSAGE = new rcube_message(get_input_value('_uid', RCUBE_INPUT_GET));
42 }
43
44
45 // show part page
46 if (!empty($_GET['_frame'])) {
47   $OUTPUT->send('messagepart');
48   exit;
49 }
50
51 else if ($pid = get_input_value('_part', RCUBE_INPUT_GET)) {
52   // TNEF encoded attachment part
53   if (preg_match('/^winmail\.([0-9.]+)\.([0-9]+)$/', $pid, $nt)) {
54     $pid = $nt[1]; $i = $nt[2];
55     if ($part = $MESSAGE->mime_parts[$pid]) {
56       $tnef_arr = $IMAP->tnef_decode($part, $MESSAGE->uid);
57       if (is_a($tnef_arr[$i], 'rcube_message_part'))
58         $MESSAGE->mime_parts[$pid] = $tnef_arr[$i];
59     }
60   }
61   
62   if ($part = $MESSAGE->mime_parts[$pid]) {
63     $ctype_primary = strtolower($part->ctype_primary);
64     $ctype_secondary = strtolower($part->ctype_secondary);
65     $mimetype = sprintf('%s/%s', $ctype_primary, $ctype_secondary);
66     
67     $browser = new rcube_browser;
68
69     send_nocacheing_headers();
70     
71     // send download headers
72     if ($_GET['_download']) {
73       header("Content-Type: application/octet-stream");
74       if ($browser->ie)
75         header("Content-Type: application/force-download");
76     }
77     else if ($ctype_primary == 'text') {
78       header("Content-Type: text/$ctype_secondary; charset=" . ($part->charset ? $part->charset : RCMAIL_CHARSET));
79     }
80     else {
81       header("Content-Type: $mimetype");
82       header("Content-Transfer-Encoding: binary");
83     }
84
85     // deliver part content
86     if ($ctype_primary == 'text' && $ctype_secondary == 'html') {
87       // get part body if not available
88       if (!$part->body)
89         $part->body = $MESSAGE->get_part_content($part->mime_id);
90
91       $OUTPUT = new rcube_html_page();
92       $OUTPUT->write(rcmail_print_body($part, array('safe' => $MESSAGE->is_safe, 'inline_html' => false)));
93     }
94     else {
95       // don't kill the connection if download takes more than 30 sec.
96       if (!ini_get('safe_mode')) {
97           set_time_limit(0);
98       }
99       
100       $filename = $part->filename ? $part->filename : ($MESSAGE->subject ? $MESSAGE->subject : 'roundcube') . '.'.$ctype_secondary;
101       
102       if ($browser->ie && $browser->ver < 7)
103         $filename = rawurlencode(abbreviate_string($filename, 55));
104       else if ($browser->ie)
105         $filename = rawurlencode($filename);
106       else
107         $filename = addcslashes($filename, '"');
108       
109       $disposition = !empty($_GET['_download']) ? 'attachment' : 'inline';
110       
111       header("Content-Disposition: $disposition; filename=\"$filename\"");
112       
113       // turn off output buffering and print part content
114       if ($part->body)
115         echo $part->body;
116       else if ($part->size)
117         $IMAP->get_message_part($MESSAGE->uid, $part->mime_id, $part, true);
118     }
119
120     exit;
121   }
122 }
123
124 // print message
125 else {
126   // send correct headers for content type
127   header("Content-Type: text/html");
128
129   $cont = "<html>\n<head><title></title>\n</head>\n<body>";
130   $cont .= rcmail_message_body(array());
131   $cont .= "\n</body>\n</html>";
132
133   $OUTPUT = new rcube_html_page();
134   $OUTPUT->write($cont);
135
136   exit;
137 }
138
139
140 // if we arrive here, the requested part was not found
141 header('HTTP/1.1 404 Not Found');
142 exit;
143
144 ?>