4 +-----------------------------------------------------------------------+
5 | program/steps/mail/get.inc |
7 | This file is part of the RoundCube Webmail client |
8 | Copyright (C) 2005-2007, 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 1026 2008-02-07 07:50:37Z thomasb $
22 require_once('Mail/mimeDecode.php');
26 if ($_GET['_preload'])
28 $url = str_replace('&_preload=1', '', $_SERVER['REQUEST_URI']);
29 $message = rcube_label('loadingdata');
31 print "<html>\n<head>\n" .
32 '<meta http-equiv="refresh" content="0; url='.Q($url).'">' .
40 // similar code as in program/steps/mail/show.inc
43 $MESSAGE = array('UID' => get_input_value('_uid', RCUBE_INPUT_GET));
44 $MESSAGE['structure'] = $IMAP->get_structure($MESSAGE['UID']);
45 $MESSAGE['parts'] = $IMAP->get_mime_numbers($MESSAGE['structure']);
52 parse_template('messagepart');
56 else if ($pid = get_input_value('_part', RCUBE_INPUT_GET))
58 if ($part = $MESSAGE['parts'][$pid])
60 $ctype_primary = strtolower($part->ctype_primary);
61 $ctype_secondary = strtolower($part->ctype_secondary);
62 $mimetype = sprintf('%s/%s', $ctype_primary, $ctype_secondary);
65 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
66 header("Cache-Control: private", false);
67 header("Content-Transfer-Encoding: binary");
69 // send download headers
70 if ($_GET['_download'])
72 header("Cache-Control: private", false);
73 header("Content-Type: application/octet-stream");
76 header("Content-Type: $mimetype");
78 // We need to set the following headers to make downloads work using IE in HTTPS mode.
79 if (isset($_SERVER['HTTPS']))
82 header('Cache-Control: ');
85 // deliver part content
86 if ($ctype_primary=='text' && $ctype_secondary=='html')
88 // we have to analyze the whole structure again to find inline objects
89 list($new_parts, $new_attachments) =
90 rcmail_parse_message($MESSAGE['structure'],
91 array('safe' => intval($_GET['_safe']),
92 'prefer_html' => TRUE,
93 'get_url' => $GET_URL.'&_part=%s'));
95 $all_parts = array_merge($new_parts, $new_attachments);
96 for ($partix = 0; $partix < sizeof($all_parts); $partix++)
97 if ($all_parts[$partix]->mime_id == $pid)
98 $part = &$all_parts[$partix];
100 // get part body if not available
102 $part->body = $IMAP->get_message_part($MESSAGE['UID'], $part->mime_id, $part);
104 $OUTPUT = new rcube_html_page();
105 $OUTPUT->write(rcmail_print_body($part, intval($_GET['_safe'])));
109 header(sprintf('Content-Disposition: %s; filename="%s";',
110 $_GET['_download'] ? 'attachment' : 'inline',
111 $part->filename ? abbreviate_string($part->filename, 55) : "roundcube.$ctype_secondary"));
113 // turn off output buffering and print part content
114 $IMAP->get_message_part($MESSAGE['UID'], $part->mime_id, $part, true);
124 $ctype_primary = strtolower($MESSAGE['structure']->ctype_primary);
125 $ctype_secondary = strtolower($MESSAGE['structure']->ctype_secondary);
126 $mimetype = sprintf('%s/%s', $ctype_primary, $ctype_secondary);
128 // send correct headers for content type
129 header("Content-Type: text/html");
132 list($MESSAGE['parts']) = rcmail_parse_message($MESSAGE['structure'],
133 array('safe' => intval($_GET['_safe']),
134 'get_url' => $GET_URL.'&_part=%s'));
136 $cont = "<html>\n<head><title></title>\n</head>\n<body>";
137 $cont .= rcmail_message_body(array());
138 $cont .= "\n</body>\n</html>";
140 $OUTPUT = new rcube_html_page();
141 $OUTPUT->write($cont);
147 // if we arrive here, the requested part was not found
148 header('HTTP/1.1 404 Not Found');