4 +-----------------------------------------------------------------------+
5 | program/steps/mail/get.inc |
7 | This file is part of the RoundCube Webmail client |
8 | Copyright (C) 2005, 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 147 2006-02-20 23:29:14Z roundcube $
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='.$url.'">' .
41 // similar code as in program/steps/mail/show.inc
45 $MESSAGE['source'] = rcmail_message_source($_GET['_uid']);
47 $mmd = new Mail_mimeDecode($MESSAGE['source']);
48 $MESSAGE['structure'] = $mmd->decode(array('include_bodies' => TRUE,
49 'decode_headers' => FALSE,
50 'decode_bodies' => FALSE));
52 $MESSAGE['parts'] = $mmd->getMimeNumbers($MESSAGE['structure']);
60 parse_template('messagepart');
64 else if ($_GET['_part'])
66 if ($part = $MESSAGE['parts'][$_GET['_part']]);
68 $ctype_primary = strtolower($part->ctype_primary);
69 $ctype_secondary = strtolower($part->ctype_secondary);
71 $mimetype = sprintf('%s/%s', $ctype_primary, $ctype_secondary);
72 $filename = $part->d_parameters['filename'] ? $part->d_parameters['filename'] : $part->ctype_parameters['name'];
74 if ($ctype_primary=='text' && $ctype_secondary=='html')
76 list($MESSAGE['parts']) = rcmail_parse_message($part,
77 array('safe' => (bool)$_GET['_safe'],
78 'prefer_html' => TRUE,
79 'get_url' => $GET_URL.'&_part=%s'));
81 $cont = rcmail_print_body($MESSAGE['parts'][0], (bool)$_GET['_safe']);
84 $cont = $IMAP->mime_decode($part->body, $part->headers['content-transfer-encoding']);
86 // send correct headers for content type and length
87 if ($_GET['_download'])
89 // send download headers
90 header("Content-Type: application/octet-stream");
91 header(sprintf('Content-Disposition: attachment; filename="%s"',
92 $filename ? $filename : "roundcube.$ctype_secondary"));
96 header("Content-Type: $mimetype");
97 header(sprintf('Content-Disposition: inline; filename="%s"', $filename));
100 header(sprintf('Content-Length: %d', strlen($cont)));
102 // We need to set the following headers to make downloads work using IE in HTTPS mode.
103 if (isset($_SERVER['HTTPS']))
106 header('Cache-Control: ');
109 // deliver part content
118 $ctype_primary = strtolower($MESSAGE['structure']->ctype_primary);
119 $ctype_secondary = strtolower($MESSAGE['structure']->ctype_secondary);
120 $mimetype = sprintf('%s/%s', $ctype_primary, $ctype_secondary);
122 // send correct headers for content type
123 header("Content-Type: text/html");
126 list($MESSAGE['parts']) = rcmail_parse_message($MESSAGE['structure'],
127 array('safe' => (bool)$_GET['_safe'],
128 'get_url' => $GET_URL.'&_part=%s'));
130 if ($MESSAGE['parts'] && $ctype_primary=='multipart')
133 $OUTPUT = new rcube_html_page();
134 parse_template('messagepart');
137 else if ($MESSAGE['parts'][0])
139 $part = $MESSAGE['parts'][0];
140 $cont = rcmail_print_body($part, (bool)$_GET['_safe']);
143 $cont = $IMAP->get_body($_GET['_uid']);
145 $OUTPUT = new rcube_html_page();
146 $OUTPUT->write($cont);
149 if ($mimetype=='text/html')
153 print "<html>\n<body>\n";
155 print "\n</body>\n</html>";
162 // if we arrive here, the requested part was not found
163 header('HTTP/1.1 404 Not Found');