]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/mail/get.inc
Imported Upstream version 0.3.1
[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 2979 2009-09-22 07:50:32Z alec $
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       @set_time_limit(0);
97       
98       $filename = $part->filename ? $part->filename : ($MESSAGE->subject ? $MESSAGE->subject : 'roundcube') . '.'.$ctype_secondary;
99       
100       if ($browser->ie && $browser->ver < 7)
101         $filename = rawurlencode(abbreviate_string($filename, 55));
102       else if ($browser->ie)
103         $filename = rawurlencode($filename);
104       else
105         $filename = addcslashes($filename, '"');
106       
107       $disposition = !empty($_GET['_download']) ? 'attachment' : 'inline';
108       
109       header("Content-Disposition: $disposition; filename=\"$filename\"");
110       
111       // turn off output buffering and print part content
112       if ($part->body)
113         echo $part->body;
114       else if ($part->size)
115         $IMAP->get_message_part($MESSAGE->uid, $part->mime_id, $part, true);
116     }
117
118     exit;
119   }
120 }
121
122 // print message
123 else {
124   // send correct headers for content type
125   header("Content-Type: text/html");
126
127   $cont = "<html>\n<head><title></title>\n</head>\n<body>";
128   $cont .= rcmail_message_body(array());
129   $cont .= "\n</body>\n</html>";
130
131   $OUTPUT = new rcube_html_page();
132   $OUTPUT->write($cont);
133
134   exit;
135 }
136
137
138 // if we arrive here, the requested part was not found
139 header('HTTP/1.1 404 Not Found');
140 exit;
141
142 ?>