thomascube
2006-08-23 6c76c91951d259f59b2b7a42b8fe895dcc0ef21b
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                     |
8  | Copyright (C) 2005, 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" .
32         '<meta http-equiv="refresh" content="0; url='.$url.'">' .
33         "\n</head>\n<body>" .
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   {
8d4bcd 58   if ($part = $MESSAGE['parts'][$pid]);
4e17e6 59     {
T 60     $ctype_primary = strtolower($part->ctype_primary);
61     $ctype_secondary = strtolower($part->ctype_secondary);
62
63     $mimetype = sprintf('%s/%s', $ctype_primary, $ctype_secondary);
64     $filename = $part->d_parameters['filename'] ? $part->d_parameters['filename'] : $part->ctype_parameters['name'];
65
66     // send correct headers for content type and length
67     if ($_GET['_download'])
68       {
69       // send download headers
70       header("Content-Type: application/octet-stream");
71       header(sprintf('Content-Disposition: attachment; filename="%s"',
72                      $filename ? $filename : "roundcube.$ctype_secondary"));
73       }
74     else
75       {
76       header("Content-Type: $mimetype");
77       header(sprintf('Content-Disposition: inline; filename="%s"', $filename));
78       }
79
4b0f65 80     // We need to set the following headers to make downloads work using IE in HTTPS mode.
T 81     if (isset($_SERVER['HTTPS']))
82       {
83       header('Pragma: ');
84       header('Cache-Control: ');
85       }
86
4e17e6 87     // deliver part content
8d4bcd 88     if ($ctype_primary=='text' && $ctype_secondary=='html')
T 89       {
90       // get part body if not available
91       if (!$part->body)
92         $part->body = $IMAP->get_message_part($MESSAGE['UID'], $part->mime_id, $part);        
93
94       list($MESSAGE['parts']) = rcmail_parse_message($part,
95                                                      array('safe' => (bool)$_GET['_safe'],
96                                                            'prefer_html' => TRUE,
97                                                            'get_url' => $GET_URL.'&_part=%s'));
98
99       print rcmail_print_body($MESSAGE['parts'][0], (bool)$_GET['_safe']);
100       }
101     else
102       {
103       // turn off output buffering and print part content
104       //@ob_end_clean();
105       $IMAP->get_message_part($MESSAGE['UID'], $part->mime_id, $part->encoding, true);
106       }
107
4e17e6 108     exit;
T 109     }
110   }
111
112 // print message
113 else
114   {
115   $ctype_primary = strtolower($MESSAGE['structure']->ctype_primary);
116   $ctype_secondary = strtolower($MESSAGE['structure']->ctype_secondary);
117   $mimetype = sprintf('%s/%s', $ctype_primary, $ctype_secondary);
118
119   // send correct headers for content type
120   header("Content-Type: text/html");
121
122   $cont = ''; 
123   list($MESSAGE['parts']) = rcmail_parse_message($MESSAGE['structure'],
124                                                  array('safe' => (bool)$_GET['_safe'],
125                                                  'get_url' => $GET_URL.'&_part=%s'));
126
8d4bcd 127   $cont = "<html>\n<head><title></title>\n</head>\n<body>";
T 128   $cont .= rcmail_message_body(array());
129   $cont .= "\n</body>\n</html>";
4e17e6 130
T 131   $OUTPUT = new rcube_html_page();
132   $OUTPUT->write($cont);
133
134   exit;
135   }
136
137
138 // if we arrive here, the requested part was not found
139 header('HTTP/1.1 404 Not Found');
140 exit;
141
142 ?>