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" . |
bf0452
|
32 |
'<meta http-equiv="refresh" content="0; url='.htmlspecialchars($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 |
{ |
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"', |
f7bfec
|
72 |
$filename ? rcube_imap::decode_mime_string($filename) : "roundcube.$ctype_secondary")); |
4e17e6
|
73 |
} |
T |
74 |
else |
|
75 |
{ |
|
76 |
header("Content-Type: $mimetype"); |
f7bfec
|
77 |
header(sprintf('Content-Disposition: inline; filename="%s"', rcube_imap::decode_mime_string($filename))); |
4e17e6
|
78 |
} |
T |
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 |
{ |
ea206d
|
90 |
// we have to analyze the whole structure again to find inline objects |
T |
91 |
list($MESSAGE['parts']) = rcmail_parse_message($MESSAGE['structure'], |
|
92 |
array('safe' => (bool)$_GET['_safe'], |
|
93 |
'prefer_html' => TRUE, |
|
94 |
'get_url' => $GET_URL.'&_part=%s')); |
|
95 |
$part = &$MESSAGE['parts'][0]; |
|
96 |
|
8d4bcd
|
97 |
// get part body if not available |
T |
98 |
if (!$part->body) |
f7bfec
|
99 |
$part->body = $IMAP->get_message_part($MESSAGE['UID'], $part->mime_id, $part); |
8d4bcd
|
100 |
|
f7bfec
|
101 |
$OUTPUT = new rcube_html_page(); |
ea206d
|
102 |
$OUTPUT->write(rcmail_print_body($part, (bool)$_GET['_safe'])); |
8d4bcd
|
103 |
} |
T |
104 |
else |
|
105 |
{ |
|
106 |
// turn off output buffering and print part content |
|
107 |
//@ob_end_clean(); |
|
108 |
$IMAP->get_message_part($MESSAGE['UID'], $part->mime_id, $part->encoding, true); |
|
109 |
} |
|
110 |
|
4e17e6
|
111 |
exit; |
T |
112 |
} |
|
113 |
} |
|
114 |
|
|
115 |
// print message |
|
116 |
else |
|
117 |
{ |
|
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); |
|
121 |
|
|
122 |
// send correct headers for content type |
|
123 |
header("Content-Type: text/html"); |
|
124 |
|
|
125 |
$cont = ''; |
|
126 |
list($MESSAGE['parts']) = rcmail_parse_message($MESSAGE['structure'], |
|
127 |
array('safe' => (bool)$_GET['_safe'], |
|
128 |
'get_url' => $GET_URL.'&_part=%s')); |
|
129 |
|
8d4bcd
|
130 |
$cont = "<html>\n<head><title></title>\n</head>\n<body>"; |
T |
131 |
$cont .= rcmail_message_body(array()); |
|
132 |
$cont .= "\n</body>\n</html>"; |
4e17e6
|
133 |
|
T |
134 |
$OUTPUT = new rcube_html_page(); |
|
135 |
$OUTPUT->write($cont); |
|
136 |
|
|
137 |
exit; |
|
138 |
} |
|
139 |
|
|
140 |
|
|
141 |
// if we arrive here, the requested part was not found |
|
142 |
header('HTTP/1.1 404 Not Found'); |
|
143 |
exit; |
|
144 |
|
|
145 |
?> |