4 +-----------------------------------------------------------------------+
5 | program/steps/mail/get.inc |
7 | This file is part of the RoundCube Webmail client |
8 | Copyright (C) 2005-2009, RoundCube Dev. - Switzerland |
9 | Licensed under the GNU GPL |
12 | Delivering a specific part of a mail message |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com> |
16 +-----------------------------------------------------------------------+
18 $Id: get.inc 2282 2009-02-08 20:38:54Z thomasb $
24 if (!empty($_GET['_preload'])) {
25 $url = str_replace('&_preload=1', '', $_SERVER['REQUEST_URI']);
26 $message = rcube_label('loadingdata');
28 print "<html>\n<head>\n" .
29 '<meta http-equiv="refresh" content="0; url='.Q($url).'">' .
37 // similar code as in program/steps/mail/show.inc
38 if (!empty($_GET['_uid'])) {
39 $RCMAIL->config->set('prefer_html', true);
40 $MESSAGE = new rcube_message(get_input_value('_uid', RCUBE_INPUT_GET));
45 if (!empty($_GET['_frame'])) {
46 $OUTPUT->send('messagepart');
50 else if ($pid = get_input_value('_part', RCUBE_INPUT_GET)) {
51 // TNEF encoded attachment part
52 if (preg_match('/^winmail\.([0-9.]+)\.([0-9]+)$/', $pid, $nt)) {
53 $pid = $nt[1]; $i = $nt[2];
54 if ($part = $MESSAGE->mime_parts[$pid]) {
55 $tnef_arr = $IMAP->tnef_decode($part, $MESSAGE->uid);
56 if (is_a($tnef_arr[$i], 'rcube_message_part'))
57 $MESSAGE->mime_parts[$pid] = $tnef_arr[$i];
61 if ($part = $MESSAGE->mime_parts[$pid]) {
62 $ctype_primary = strtolower($part->ctype_primary);
63 $ctype_secondary = strtolower($part->ctype_secondary);
64 $mimetype = sprintf('%s/%s', $ctype_primary, $ctype_secondary);
66 $browser = new rcube_browser;
68 send_nocacheing_headers();
70 // send download headers
71 if ($_GET['_download']) {
72 header("Content-Type: application/octet-stream");
74 header("Content-Type: application/force-download");
76 else if ($ctype_primary == 'text') {
77 header("Content-Type: text/$ctype_secondary; charset=" . ($part->charset ? $part->charset : RCMAIL_CHARSET));
80 header("Content-Type: $mimetype");
81 header("Content-Transfer-Encoding: binary");
84 // deliver part content
85 if ($ctype_primary == 'text' && $ctype_secondary == 'html') {
86 // get part body if not available
88 $part->body = $MESSAGE->get_part_content($part->mime_id);
90 $OUTPUT = new rcube_html_page();
91 $OUTPUT->write(rcmail_print_body($part, array('safe' => $MESSAGE->is_safe, 'inline_html' => false)));
94 // don't kill the connection if download takes more than 30 sec.
95 if (!ini_get('safe_mode')) {
99 $filename = $part->filename ? $part->filename : ($MESSAGE->subject ? $MESSAGE->subject : 'roundcube') . '.'.$ctype_secondary;
101 if ($browser->ie && $browser->ver < 7)
102 $filename = rawurlencode(abbreviate_string($filename, 55));
103 else if ($browser->ie)
104 $filename = rawurlencode($filename);
106 $filename = addcslashes($filename, '"');
108 $disposition = !empty($_GET['_download']) ? 'attachment' : 'inline';
110 header("Content-Disposition: $disposition; filename=\"$filename\"");
112 // turn off output buffering and print part content
116 $IMAP->get_message_part($MESSAGE->uid, $part->mime_id, $part, true);
125 // send correct headers for content type
126 header("Content-Type: text/html");
128 $cont = "<html>\n<head><title></title>\n</head>\n<body>";
129 $cont .= rcmail_message_body(array());
130 $cont .= "\n</body>\n</html>";
132 $OUTPUT = new rcube_html_page();
133 $OUTPUT->write($cont);
139 // if we arrive here, the requested part was not found
140 header('HTTP/1.1 404 Not Found');