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 2912 2009-09-04 10:38:18Z thomasb $
24 if (!empty($_GET['_preload'])) {
25 $url = str_replace('&_preload=1', '', $_SERVER['REQUEST_URI']);
26 $message = rcube_label('loadingdata');
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>";
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));
46 if (!empty($_GET['_frame'])) {
47 $OUTPUT->send('messagepart');
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];
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);
67 $browser = new rcube_browser;
69 send_nocacheing_headers();
71 // send download headers
72 if ($_GET['_download']) {
73 header("Content-Type: application/octet-stream");
75 header("Content-Type: application/force-download");
77 else if ($ctype_primary == 'text') {
78 header("Content-Type: text/$ctype_secondary; charset=" . ($part->charset ? $part->charset : RCMAIL_CHARSET));
81 header("Content-Type: $mimetype");
82 header("Content-Transfer-Encoding: binary");
85 // deliver part content
86 if ($ctype_primary == 'text' && $ctype_secondary == 'html') {
87 // get part body if not available
89 $part->body = $MESSAGE->get_part_content($part->mime_id);
91 $OUTPUT = new rcube_html_page();
92 $OUTPUT->write(rcmail_print_body($part, array('safe' => $MESSAGE->is_safe, 'inline_html' => false)));
95 // don't kill the connection if download takes more than 30 sec.
96 if (!ini_get('safe_mode')) {
100 $filename = $part->filename ? $part->filename : ($MESSAGE->subject ? $MESSAGE->subject : 'roundcube') . '.'.$ctype_secondary;
102 if ($browser->ie && $browser->ver < 7)
103 $filename = rawurlencode(abbreviate_string($filename, 55));
104 else if ($browser->ie)
105 $filename = rawurlencode($filename);
107 $filename = addcslashes($filename, '"');
109 $disposition = !empty($_GET['_download']) ? 'attachment' : 'inline';
111 header("Content-Disposition: $disposition; filename=\"$filename\"");
113 // turn off output buffering and print part content
116 else if ($part->size)
117 $IMAP->get_message_part($MESSAGE->uid, $part->mime_id, $part, true);
126 // send correct headers for content type
127 header("Content-Type: text/html");
129 $cont = "<html>\n<head><title></title>\n</head>\n<body>";
130 $cont .= rcmail_message_body(array());
131 $cont .= "\n</body>\n</html>";
133 $OUTPUT = new rcube_html_page();
134 $OUTPUT->write($cont);
140 // if we arrive here, the requested part was not found
141 header('HTTP/1.1 404 Not Found');