]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/mail/get.inc
Imported Upstream version 0.1~beta2.2~dfsg
[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, 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 147 2006-02-20 23:29:14Z roundcube $
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
41 // similar code as in program/steps/mail/show.inc
42 if ($_GET['_uid'])
43   {
44   $MESSAGE = array();
45   $MESSAGE['source'] = rcmail_message_source($_GET['_uid']);
46
47   $mmd = new Mail_mimeDecode($MESSAGE['source']);
48   $MESSAGE['structure'] = $mmd->decode(array('include_bodies' => TRUE,
49                                              'decode_headers' => FALSE,
50                                              'decode_bodies' => FALSE));
51
52   $MESSAGE['parts'] = $mmd->getMimeNumbers($MESSAGE['structure']);
53   }
54
55
56
57 // show part page
58 if ($_GET['_frame'])
59   {
60   parse_template('messagepart');
61   exit;
62   }
63
64 else if ($_GET['_part'])
65   {
66   if ($part = $MESSAGE['parts'][$_GET['_part']]);
67     {
68     $ctype_primary = strtolower($part->ctype_primary);
69     $ctype_secondary = strtolower($part->ctype_secondary);
70
71     $mimetype = sprintf('%s/%s', $ctype_primary, $ctype_secondary);
72     $filename = $part->d_parameters['filename'] ? $part->d_parameters['filename'] : $part->ctype_parameters['name'];
73
74     if ($ctype_primary=='text' && $ctype_secondary=='html')
75       {
76       list($MESSAGE['parts']) = rcmail_parse_message($part,
77                                                      array('safe' => (bool)$_GET['_safe'],
78                                                            'prefer_html' => TRUE,
79                                                            'get_url' => $GET_URL.'&_part=%s'));
80
81       $cont = rcmail_print_body($MESSAGE['parts'][0], (bool)$_GET['_safe']);
82       }
83     else
84       $cont = $IMAP->mime_decode($part->body, $part->headers['content-transfer-encoding']);
85
86     // send correct headers for content type and length
87     if ($_GET['_download'])
88       {
89       // send download headers
90       header("Content-Type: application/octet-stream");
91       header(sprintf('Content-Disposition: attachment; filename="%s"',
92                      $filename ? $filename : "roundcube.$ctype_secondary"));
93       }
94     else
95       {
96       header("Content-Type: $mimetype");
97       header(sprintf('Content-Disposition: inline; filename="%s"', $filename));
98       }
99
100     header(sprintf('Content-Length: %d', strlen($cont)));
101
102     // We need to set the following headers to make downloads work using IE in HTTPS mode.
103     if (isset($_SERVER['HTTPS']))
104       {
105       header('Pragma: ');
106       header('Cache-Control: ');
107       }
108
109     // deliver part content
110     echo $cont;
111     exit;
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
130   if ($MESSAGE['parts'] && $ctype_primary=='multipart')
131     {
132     // reset output page
133     $OUTPUT = new rcube_html_page();
134     parse_template('messagepart');
135     exit;
136     }
137   else if ($MESSAGE['parts'][0])
138     {
139     $part = $MESSAGE['parts'][0];
140     $cont = rcmail_print_body($part, (bool)$_GET['_safe']);
141     }
142   else
143     $cont = $IMAP->get_body($_GET['_uid']);
144
145   $OUTPUT = new rcube_html_page();
146   $OUTPUT->write($cont);
147
148 /*
149     if ($mimetype=='text/html')
150       print $cont;
151     else
152       {
153       print "<html>\n<body>\n";
154       print $cont;
155       print "\n</body>\n</html>";
156       }
157 */
158   exit;
159   }
160
161
162 // if we arrive here, the requested part was not found
163 header('HTTP/1.1 404 Not Found');
164 exit;
165
166 ?>