]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/mail/get.inc
Imported Upstream version 0.2.1
[roundcube.git] / program / steps / mail / get.inc
1 <?php
2
3 /*
4  +-----------------------------------------------------------------------+
5  | program/steps/mail/get.inc                                            |
6  |                                                                       |
7  | This file is part of the RoundCube Webmail client                     |
8  | Copyright (C) 2005-2009, RoundCube Dev. - Switzerland                 |
9  | Licensed under the GNU GPL                                            |
10  |                                                                       |
11  | PURPOSE:                                                              |
12  |   Delivering a specific part of a mail message                        |
13  |                                                                       |
14  +-----------------------------------------------------------------------+
15  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
16  +-----------------------------------------------------------------------+
17
18  $Id: get.inc 2282 2009-02-08 20:38:54Z thomasb $
19
20 */
21
22
23 // show loading page
24 if (!empty($_GET['_preload'])) {
25   $url = str_replace('&_preload=1', '', $_SERVER['REQUEST_URI']);
26   $message = rcube_label('loadingdata');
27
28   print "<html>\n<head>\n" .
29         '<meta http-equiv="refresh" content="0; url='.Q($url).'">' .
30         "\n</head>\n<body>" .
31         $message .
32         "\n</body>\n</html>";
33   exit;
34 }
35
36
37 // similar code as in program/steps/mail/show.inc
38 if (!empty($_GET['_uid'])) {
39   $RCMAIL->config->set('prefer_html', true);
40   $MESSAGE = new rcube_message(get_input_value('_uid', RCUBE_INPUT_GET));
41 }
42
43
44 // show part page
45 if (!empty($_GET['_frame'])) {
46   $OUTPUT->send('messagepart');
47   exit;
48 }
49
50 else if ($pid = get_input_value('_part', RCUBE_INPUT_GET)) {
51   // TNEF encoded attachment part
52   if (preg_match('/^winmail\.([0-9.]+)\.([0-9]+)$/', $pid, $nt)) {
53     $pid = $nt[1]; $i = $nt[2];
54     if ($part = $MESSAGE->mime_parts[$pid]) {
55       $tnef_arr = $IMAP->tnef_decode($part, $MESSAGE->uid);
56       if (is_a($tnef_arr[$i], 'rcube_message_part'))
57         $MESSAGE->mime_parts[$pid] = $tnef_arr[$i];
58     }
59   }
60   
61   if ($part = $MESSAGE->mime_parts[$pid]) {
62     $ctype_primary = strtolower($part->ctype_primary);
63     $ctype_secondary = strtolower($part->ctype_secondary);
64     $mimetype = sprintf('%s/%s', $ctype_primary, $ctype_secondary);
65     
66     $browser = new rcube_browser;
67
68     send_nocacheing_headers();
69     
70     // send download headers
71     if ($_GET['_download']) {
72       header("Content-Type: application/octet-stream");
73       if ($browser->ie)
74         header("Content-Type: application/force-download");
75     }
76     else if ($ctype_primary == 'text') {
77       header("Content-Type: text/$ctype_secondary; charset=" . ($part->charset ? $part->charset : RCMAIL_CHARSET));
78     }
79     else {
80       header("Content-Type: $mimetype");
81       header("Content-Transfer-Encoding: binary");
82     }
83
84     // deliver part content
85     if ($ctype_primary == 'text' && $ctype_secondary == 'html') {
86       // get part body if not available
87       if (!$part->body)
88         $part->body = $MESSAGE->get_part_content($part->mime_id);
89
90       $OUTPUT = new rcube_html_page();
91       $OUTPUT->write(rcmail_print_body($part, array('safe' => $MESSAGE->is_safe, 'inline_html' => false)));
92     }
93     else {
94       // don't kill the connection if download takes more than 30 sec.
95       if (!ini_get('safe_mode')) {
96           set_time_limit(0);
97       }
98       
99       $filename = $part->filename ? $part->filename : ($MESSAGE->subject ? $MESSAGE->subject : 'roundcube') . '.'.$ctype_secondary;
100       
101       if ($browser->ie && $browser->ver < 7)
102         $filename = rawurlencode(abbreviate_string($filename, 55));
103       else if ($browser->ie)
104         $filename = rawurlencode($filename);
105       else
106         $filename = addcslashes($filename, '"');
107       
108       $disposition = !empty($_GET['_download']) ? 'attachment' : 'inline';
109       
110       header("Content-Disposition: $disposition; filename=\"$filename\"");
111       
112       // turn off output buffering and print part content
113       if ($part->body)
114         echo $part->body;
115       else
116         $IMAP->get_message_part($MESSAGE->uid, $part->mime_id, $part, true);
117     }
118
119     exit;
120   }
121 }
122
123 // print message
124 else {
125   // send correct headers for content type
126   header("Content-Type: text/html");
127
128   $cont = "<html>\n<head><title></title>\n</head>\n<body>";
129   $cont .= rcmail_message_body(array());
130   $cont .= "\n</body>\n</html>";
131
132   $OUTPUT = new rcube_html_page();
133   $OUTPUT->write($cont);
134
135   exit;
136 }
137
138
139 // if we arrive here, the requested part was not found
140 header('HTTP/1.1 404 Not Found');
141 exit;
142
143 ?>