alecpl
2008-04-10 3790508c2003255c179b6f4d309d5feeaa2b6299
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                     |
5349b7 8  | Copyright (C) 2005-2007, 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
26 if ($_GET['_preload'])
27   {
28   $url = str_replace('&_preload=1', '', $_SERVER['REQUEST_URI']);
29   $message = rcube_label('loadingdata');
30
31   print "<html>\n<head>\n" .
719a25 32         '<meta http-equiv="refresh" content="0; url='.Q($url).'">' .
4e17e6 33         "\n</head>\n<body>" .
T 34         $message .
35         "\n</body>\n</html>";
36   exit;
37   }
38
39
40 // similar code as in program/steps/mail/show.inc
41 if ($_GET['_uid'])
42   {
8d4bcd 43   $MESSAGE = array('UID' => get_input_value('_uid', RCUBE_INPUT_GET));
T 44   $MESSAGE['structure'] = $IMAP->get_structure($MESSAGE['UID']);
45   $MESSAGE['parts'] = $IMAP->get_mime_numbers($MESSAGE['structure']);
4e17e6 46   }
T 47
48
49 // show part page
50 if ($_GET['_frame'])
51   {
52   parse_template('messagepart');
53   exit;
54   }
55
8d4bcd 56 else if ($pid = get_input_value('_part', RCUBE_INPUT_GET))
4e17e6 57   {
142e5f 58   if ($part = $MESSAGE['parts'][$pid])
4e17e6 59     {
T 60     $ctype_primary = strtolower($part->ctype_primary);
61     $ctype_secondary = strtolower($part->ctype_secondary);
62     $mimetype = sprintf('%s/%s', $ctype_primary, $ctype_secondary);
63
5a6ad2 64     header("Expires: 0");
T 65     header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
66     header("Cache-Control: private", false);
67     header("Content-Transfer-Encoding: binary");
68
69     // send download headers
4e17e6 70     if ($_GET['_download'])
T 71       {
5a6ad2 72       header("Cache-Control: private", false);
4e17e6 73       header("Content-Type: application/octet-stream");
T 74       }
75     else
76       header("Content-Type: $mimetype");
77
4b0f65 78     // We need to set the following headers to make downloads work using IE in HTTPS mode.
T 79     if (isset($_SERVER['HTTPS']))
80       {
81       header('Pragma: ');
82       header('Cache-Control: ');
83       }
84
4e17e6 85     // deliver part content
8d4bcd 86     if ($ctype_primary=='text' && $ctype_secondary=='html')
T 87       {
ea206d 88       // we have to analyze the whole structure again to find inline objects
bb8562 89       list($new_parts, $new_attachments) =
S 90         rcmail_parse_message($MESSAGE['structure'],
c57996 91                              array('safe' => intval($_GET['_safe']),
bb8562 92                                    'prefer_html' => TRUE,
S 93                                    'get_url' => $GET_URL.'&_part=%s'));
94
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];
ea206d 99
8d4bcd 100       // get part body if not available
T 101       if (!$part->body)
bb8562 102         $part->body = $IMAP->get_message_part($MESSAGE['UID'], $part->mime_id, $part);
8d4bcd 103
f7bfec 104       $OUTPUT = new rcube_html_page();
c57996 105       $OUTPUT->write(rcmail_print_body($part, intval($_GET['_safe'])));
8d4bcd 106       }
T 107     else
108       {
5cc4b1 109       header(sprintf('Content-Disposition: %s; filename="%s";',
719a25 110                      $_GET['_download'] ? 'attachment' : 'inline',
6f2f2d 111                      $part->filename ? abbreviate_string($part->filename, 55) : "roundcube.$ctype_secondary"));
5cc4b1 112
8d4bcd 113       // turn off output buffering and print part content
a9cc52 114       $IMAP->get_message_part($MESSAGE['UID'], $part->mime_id, $part, true);
8d4bcd 115       }
T 116
4e17e6 117     exit;
T 118     }
119   }
120
121 // print message
122 else
123   {
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);
127
128   // send correct headers for content type
129   header("Content-Type: text/html");
130
131   $cont = ''; 
132   list($MESSAGE['parts']) = rcmail_parse_message($MESSAGE['structure'],
c57996 133                                                  array('safe' => intval($_GET['_safe']),
4e17e6 134                                                  'get_url' => $GET_URL.'&_part=%s'));
T 135
8d4bcd 136   $cont = "<html>\n<head><title></title>\n</head>\n<body>";
T 137   $cont .= rcmail_message_body(array());
138   $cont .= "\n</body>\n</html>";
4e17e6 139
T 140   $OUTPUT = new rcube_html_page();
141   $OUTPUT->write($cont);
142
143   exit;
144   }
145
146
147 // if we arrive here, the requested part was not found
148 header('HTTP/1.1 404 Not Found');
149 exit;
150
5349b7 151 ?>