alecpl
2008-07-28 3ac95d5a673db544d7ceeaa9e5fca766cb738120
commit | author | age
4e17e6 1 <?php
T 2
3 /*
4  +-----------------------------------------------------------------------+
5  | program/steps/mail/get.inc                                            |
6  |                                                                       |
7  | This file is part of the RoundCube Webmail client                     |
8fa58e 8  | Copyright (C) 2005-2008, RoundCube Dev. - Switzerland                 |
30233b 9  | Licensed under the GNU GPL                                            |
4e17e6 10  |                                                                       |
T 11  | PURPOSE:                                                              |
12  |   Delivering a specific part of a mail message                        |
13  |                                                                       |
14  +-----------------------------------------------------------------------+
15  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
16  +-----------------------------------------------------------------------+
17
18  $Id$
19
20 */
21
22 require_once('Mail/mimeDecode.php');
23
24
25 // show loading page
8fa58e 26 if (!empty($_GET['_preload'])) {
4e17e6 27   $url = str_replace('&_preload=1', '', $_SERVER['REQUEST_URI']);
T 28   $message = rcube_label('loadingdata');
29
30   print "<html>\n<head>\n" .
719a25 31         '<meta http-equiv="refresh" content="0; url='.Q($url).'">' .
4e17e6 32         "\n</head>\n<body>" .
T 33         $message .
34         "\n</body>\n</html>";
35   exit;
8fa58e 36 }
4e17e6 37
T 38
39 // similar code as in program/steps/mail/show.inc
8fa58e 40 if (!empty($_GET['_uid'])) {
T 41   $RCMAIL->config->set('prefer_html', true);
42   $MESSAGE = new rcube_message(get_input_value('_uid', RCUBE_INPUT_GET));
43 }
4e17e6 44
T 45
46 // show part page
8fa58e 47 if (!empty($_GET['_frame'])) {
47124c 48   $OUTPUT->send('messagepart');
4e17e6 49   exit;
8fa58e 50 }
4e17e6 51
8fa58e 52 else if ($pid = get_input_value('_part', RCUBE_INPUT_GET)) {
T 53   if ($part = $MESSAGE->mime_parts[$pid]) {
4e17e6 54     $ctype_primary = strtolower($part->ctype_primary);
T 55     $ctype_secondary = strtolower($part->ctype_secondary);
56     $mimetype = sprintf('%s/%s', $ctype_primary, $ctype_secondary);
57
5a6ad2 58     header("Expires: 0");
T 59     header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
60     header("Cache-Control: private", false);
61     header("Content-Transfer-Encoding: binary");
62
63     // send download headers
8fa58e 64     if ($_GET['_download']) {
5a6ad2 65       header("Cache-Control: private", false);
4e17e6 66       header("Content-Type: application/octet-stream");
8fa58e 67     }
21e724 68     else if ($ctype_primary == 'text')
T 69       header("Content-Type: text/$ctype_secondary; charset=" . RCMAIL_CHARSET);
4e17e6 70     else
T 71       header("Content-Type: $mimetype");
72
4b0f65 73     // We need to set the following headers to make downloads work using IE in HTTPS mode.
8fa58e 74     if (isset($_SERVER['HTTPS'])) {
4b0f65 75       header('Pragma: ');
T 76       header('Cache-Control: ');
8fa58e 77     }
4b0f65 78
4e17e6 79     // deliver part content
8fa58e 80     if ($ctype_primary == 'text' && $ctype_secondary == 'html') {
ea206d 81       // we have to analyze the whole structure again to find inline objects
8fa58e 82       /* what was this good for again ?
bb8562 83       list($new_parts, $new_attachments) =
S 84         rcmail_parse_message($MESSAGE['structure'],
c57996 85                              array('safe' => intval($_GET['_safe']),
bb8562 86                                    'prefer_html' => TRUE,
S 87                                    'get_url' => $GET_URL.'&_part=%s'));
88
89       $all_parts = array_merge($new_parts, $new_attachments);
90       for ($partix = 0; $partix < sizeof($all_parts); $partix++)
91         if ($all_parts[$partix]->mime_id == $pid)
92           $part = &$all_parts[$partix];
8fa58e 93       */
ea206d 94
8d4bcd 95       // get part body if not available
T 96       if (!$part->body)
8fa58e 97         $part->body = $MESSAGE->get_part_content($part->mime_id);
8d4bcd 98
f7bfec 99       $OUTPUT = new rcube_html_page();
21e724 100       $OUTPUT->write(rcmail_print_body($part, array('safe' => $MESSAGE->is_safe, 'inline_html' => false)));
8fa58e 101     }
T 102     else {
5cc4b1 103       header(sprintf('Content-Disposition: %s; filename="%s";',
719a25 104                      $_GET['_download'] ? 'attachment' : 'inline',
6f2f2d 105                      $part->filename ? abbreviate_string($part->filename, 55) : "roundcube.$ctype_secondary"));
5cc4b1 106
8d4bcd 107       // turn off output buffering and print part content
8fa58e 108       $IMAP->get_message_part($MESSAGE->uid, $part->mime_id, $part, true);
T 109     }
8d4bcd 110
4e17e6 111     exit;
T 112   }
8fa58e 113 }
4e17e6 114
T 115 // print message
8fa58e 116 else {
4e17e6 117   // send correct headers for content type
T 118   header("Content-Type: text/html");
119
8d4bcd 120   $cont = "<html>\n<head><title></title>\n</head>\n<body>";
T 121   $cont .= rcmail_message_body(array());
122   $cont .= "\n</body>\n</html>";
4e17e6 123
T 124   $OUTPUT = new rcube_html_page();
125   $OUTPUT->write($cont);
126
127   exit;
8fa58e 128 }
4e17e6 129
T 130
131 // if we arrive here, the requested part was not found
132 header('HTTP/1.1 404 Not Found');
133 exit;
134
5349b7 135 ?>