4 +-----------------------------------------------------------------------+
5 | program/steps/mail/get.inc |
7 | This file is part of the RoundCube Webmail client |
8 | Copyright (C) 2005-2008, 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 2182 2008-12-19 07:20:50Z alec $
22 require_once('Mail/mimeDecode.php');
26 if (!empty($_GET['_preload'])) {
27 $url = str_replace('&_preload=1', '', $_SERVER['REQUEST_URI']);
28 $message = rcube_label('loadingdata');
30 print "<html>\n<head>\n" .
31 '<meta http-equiv="refresh" content="0; url='.Q($url).'">' .
39 // similar code as in program/steps/mail/show.inc
40 if (!empty($_GET['_uid'])) {
41 $RCMAIL->config->set('prefer_html', true);
42 $MESSAGE = new rcube_message(get_input_value('_uid', RCUBE_INPUT_GET));
47 if (!empty($_GET['_frame'])) {
48 $OUTPUT->send('messagepart');
52 else if ($pid = get_input_value('_part', RCUBE_INPUT_GET)) {
53 if ($part = $MESSAGE->mime_parts[$pid]) {
54 $ctype_primary = strtolower($part->ctype_primary);
55 $ctype_secondary = strtolower($part->ctype_secondary);
56 $mimetype = sprintf('%s/%s', $ctype_primary, $ctype_secondary);
58 $browser = new rcube_browser;
60 send_nocacheing_headers();
62 // send download headers
63 if ($_GET['_download']) {
64 header("Content-Type: application/octet-stream");
66 header("Content-Type: application/force-download");
68 else if ($ctype_primary == 'text') {
69 header("Content-Type: text/$ctype_secondary; charset=" . ($part->charset ? $part->charset : RCMAIL_CHARSET));
72 header("Content-Type: $mimetype");
73 header("Content-Transfer-Encoding: binary");
76 // deliver part content
77 if ($ctype_primary == 'text' && $ctype_secondary == 'html') {
78 // get part body if not available
80 $part->body = $MESSAGE->get_part_content($part->mime_id);
82 $OUTPUT = new rcube_html_page();
83 $OUTPUT->write(rcmail_print_body($part, array('safe' => $MESSAGE->is_safe, 'inline_html' => false)));
86 // don't kill the connection if download takes more than 30 sec.
87 if (!ini_get('safe_mode')) {
91 $filename = $part->filename ? $part->filename : ($MESSAGE->subject ? $MESSAGE->subject : 'roundcube') . '.'.$ctype_secondary;
93 if ($browser->ie && $browser->ver < 7)
94 $filename = rawurlencode(abbreviate_string($filename, 55));
95 else if ($browser->ie)
96 $filename = rawurlencode($filename);
98 $filename = addcslashes($filename, '"');
100 $disposition = !empty($_GET['_download']) ? 'attachment' : 'inline';
102 header("Content-Disposition: $disposition; filename=\"$filename\"");
104 // turn off output buffering and print part content
105 $IMAP->get_message_part($MESSAGE->uid, $part->mime_id, $part, true);
114 // send correct headers for content type
115 header("Content-Type: text/html");
117 $cont = "<html>\n<head><title></title>\n</head>\n<body>";
118 $cont .= rcmail_message_body(array());
119 $cont .= "\n</body>\n</html>";
121 $OUTPUT = new rcube_html_page();
122 $OUTPUT->write($cont);
128 // if we arrive here, the requested part was not found
129 header('HTTP/1.1 404 Not Found');