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 4115 2010-10-20 11:41:48Z alec $
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 // Now we need IMAP connection
39 if (!$RCMAIL->imap_connect()) {
40 // Get action is often executed simultanously.
41 // Some servers have MAXPERIP or other limits.
42 // To workaround this we'll wait for some time
43 // and try again (once).
44 // Note: Random sleep interval is used to minimize concurency
45 // in getting message parts
46 if (!isset($_GET['_redirected'])) {
47 usleep(rand(10,30)*100000); // 1-3 sec.
48 header('Location: ' . $_SERVER['REQUEST_URI'] . '&_redirected=1');
52 'code' => 500, 'type' => 'php',
53 'file' => __FILE__, 'line' => __LINE__,
54 'message' => 'Unable to get/display message part. IMAP connection error'),
57 // Don't kill session, just quit (#1486995)
61 // similar code as in program/steps/mail/show.inc
62 if (!empty($_GET['_uid'])) {
63 $RCMAIL->config->set('prefer_html', true);
64 $MESSAGE = new rcube_message(get_input_value('_uid', RCUBE_INPUT_GET));
67 send_nocacheing_headers();
70 if (!empty($_GET['_frame'])) {
71 $OUTPUT->send('messagepart');
75 else if ($pid = get_input_value('_part', RCUBE_INPUT_GET)) {
77 if ($part = $MESSAGE->mime_parts[$pid]) {
78 $ctype_primary = strtolower($part->ctype_primary);
79 $ctype_secondary = strtolower($part->ctype_secondary);
80 $mimetype = sprintf('%s/%s', $ctype_primary, $ctype_secondary);
82 $browser = $RCMAIL->output->browser;
84 // send download headers
85 if ($_GET['_download']) {
86 header("Content-Type: application/octet-stream");
88 header("Content-Type: application/force-download");
90 else if ($ctype_primary == 'text') {
91 header("Content-Type: text/$ctype_secondary; charset=" . ($part->charset ? $part->charset : RCMAIL_CHARSET));
94 $mimetype = rcmail_fix_mimetype($mimetype);
95 header("Content-Type: $mimetype");
96 header("Content-Transfer-Encoding: binary");
99 // deliver part content
100 if ($ctype_primary == 'text' && $ctype_secondary == 'html' && empty($_GET['_download'])) {
101 // get part body if not available
103 $part->body = $MESSAGE->get_part_content($part->mime_id);
105 $OUTPUT = new rcube_html_page();
106 $OUTPUT->write(rcmail_print_body($part, array('safe' => $MESSAGE->is_safe, 'inline_html' => false)));
109 // don't kill the connection if download takes more than 30 sec.
112 $filename = $part->filename ? $part->filename : ($MESSAGE->subject ? $MESSAGE->subject : 'roundcube') . '.'.$ctype_secondary;
113 $filename = preg_replace('[\r\n]', '', $filename);
115 if ($browser->ie && $browser->ver < 7)
116 $filename = rawurlencode(abbreviate_string($filename, 55));
117 else if ($browser->ie)
118 $filename = rawurlencode($filename);
120 $filename = addcslashes($filename, '"');
122 $disposition = !empty($_GET['_download']) ? 'attachment' : 'inline';
124 header("Content-Disposition: $disposition; filename=\"$filename\"");
126 // turn off output buffering and print part content
129 else if ($part->size)
130 $IMAP->get_message_part($MESSAGE->uid, $part->mime_id, $part, true);
139 // send correct headers for content type
140 header("Content-Type: text/html");
142 $cont = "<html>\n<head><title></title>\n</head>\n<body>";
143 $cont .= rcmail_message_body(array());
144 $cont .= "\n</body>\n</html>";
146 $OUTPUT = new rcube_html_page();
147 $OUTPUT->write($cont);
153 // if we arrive here, the requested part was not found
154 header('HTTP/1.1 404 Not Found');