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); |
0ced2b
|
57 |
|
T |
58 |
$browser = new rcube_browser; |
4e17e6
|
59 |
|
0dbac3
|
60 |
send_nocacheing_headers(); |
T |
61 |
|
5a6ad2
|
62 |
// send download headers |
8fa58e
|
63 |
if ($_GET['_download']) { |
4e17e6
|
64 |
header("Content-Type: application/octet-stream"); |
0ced2b
|
65 |
if ($browser->ie) |
T |
66 |
header("Content-Type: application/force-download"); |
8fa58e
|
67 |
} |
0dbac3
|
68 |
else if ($ctype_primary == 'text') { |
0ced2b
|
69 |
header("Content-Type: text/$ctype_secondary; charset=" . ($part->charset ? $part->charset : RCMAIL_CHARSET)); |
0dbac3
|
70 |
} |
T |
71 |
else { |
4e17e6
|
72 |
header("Content-Type: $mimetype"); |
0dbac3
|
73 |
header("Content-Transfer-Encoding: binary"); |
8fa58e
|
74 |
} |
4b0f65
|
75 |
|
4e17e6
|
76 |
// deliver part content |
8fa58e
|
77 |
if ($ctype_primary == 'text' && $ctype_secondary == 'html') { |
8d4bcd
|
78 |
// get part body if not available |
T |
79 |
if (!$part->body) |
8fa58e
|
80 |
$part->body = $MESSAGE->get_part_content($part->mime_id); |
8d4bcd
|
81 |
|
f7bfec
|
82 |
$OUTPUT = new rcube_html_page(); |
21e724
|
83 |
$OUTPUT->write(rcmail_print_body($part, array('safe' => $MESSAGE->is_safe, 'inline_html' => false))); |
8fa58e
|
84 |
} |
T |
85 |
else { |
0ced2b
|
86 |
// don't kill the connection if download takes more than 30 sec. |
T |
87 |
if (!ini_get('safe_mode')) { |
|
88 |
set_time_limit(0); |
|
89 |
} |
|
90 |
|
|
91 |
$filename = $part->filename ? $part->filename : ($MESSAGE->subject ? $MESSAGE->subject : 'roundcube') . '.'.$ctype_secondary; |
|
92 |
$filename = abbreviate_string($part->filename, 55); |
|
93 |
$filename = $browser->ie ? rawurlencode($filename) : addslashes($filename); |
|
94 |
$disposition = !empty($_GET['_download']) ? 'attachment' : 'inline'; |
|
95 |
|
|
96 |
header("Content-Disposition: $disposition; filename=\"$filename\""); |
5cc4b1
|
97 |
|
8d4bcd
|
98 |
// turn off output buffering and print part content |
8fa58e
|
99 |
$IMAP->get_message_part($MESSAGE->uid, $part->mime_id, $part, true); |
T |
100 |
} |
8d4bcd
|
101 |
|
4e17e6
|
102 |
exit; |
T |
103 |
} |
8fa58e
|
104 |
} |
4e17e6
|
105 |
|
T |
106 |
// print message |
8fa58e
|
107 |
else { |
4e17e6
|
108 |
// send correct headers for content type |
T |
109 |
header("Content-Type: text/html"); |
|
110 |
|
8d4bcd
|
111 |
$cont = "<html>\n<head><title></title>\n</head>\n<body>"; |
T |
112 |
$cont .= rcmail_message_body(array()); |
|
113 |
$cont .= "\n</body>\n</html>"; |
4e17e6
|
114 |
|
T |
115 |
$OUTPUT = new rcube_html_page(); |
|
116 |
$OUTPUT->write($cont); |
|
117 |
|
|
118 |
exit; |
8fa58e
|
119 |
} |
4e17e6
|
120 |
|
T |
121 |
|
|
122 |
// if we arrive here, the requested part was not found |
|
123 |
header('HTTP/1.1 404 Not Found'); |
|
124 |
exit; |
|
125 |
|
5349b7
|
126 |
?> |