]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/mail/get.inc
Imported Upstream version 0.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-2007, 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 1026 2008-02-07 07:50:37Z thomasb $
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='.Q($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   {
43   $MESSAGE = array('UID' => get_input_value('_uid', RCUBE_INPUT_GET));
44   $MESSAGE['structure'] = $IMAP->get_structure($MESSAGE['UID']);
45   $MESSAGE['parts'] = $IMAP->get_mime_numbers($MESSAGE['structure']);
46   }
47
48
49 // show part page
50 if ($_GET['_frame'])
51   {
52   parse_template('messagepart');
53   exit;
54   }
55
56 else if ($pid = get_input_value('_part', RCUBE_INPUT_GET))
57   {
58   if ($part = $MESSAGE['parts'][$pid])
59     {
60     $ctype_primary = strtolower($part->ctype_primary);
61     $ctype_secondary = strtolower($part->ctype_secondary);
62     $mimetype = sprintf('%s/%s', $ctype_primary, $ctype_secondary);
63
64     header("Expires: 0");
65     header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
66     header("Cache-Control: private", false);
67     header("Content-Transfer-Encoding: binary");
68
69     // send download headers
70     if ($_GET['_download'])
71       {
72       header("Cache-Control: private", false);
73       header("Content-Type: application/octet-stream");
74       }
75     else
76       header("Content-Type: $mimetype");
77
78     // We need to set the following headers to make downloads work using IE in HTTPS mode.
79     if (isset($_SERVER['HTTPS']))
80       {
81       header('Pragma: ');
82       header('Cache-Control: ');
83       }
84
85     // deliver part content
86     if ($ctype_primary=='text' && $ctype_secondary=='html')
87       {
88       // we have to analyze the whole structure again to find inline objects
89       list($new_parts, $new_attachments) =
90         rcmail_parse_message($MESSAGE['structure'],
91                              array('safe' => intval($_GET['_safe']),
92                                    'prefer_html' => TRUE,
93                                    'get_url' => $GET_URL.'&_part=%s'));
94
95       $all_parts = array_merge($new_parts, $new_attachments);
96       for ($partix = 0; $partix < sizeof($all_parts); $partix++)
97         if ($all_parts[$partix]->mime_id == $pid)
98           $part = &$all_parts[$partix];
99
100       // get part body if not available
101       if (!$part->body)
102         $part->body = $IMAP->get_message_part($MESSAGE['UID'], $part->mime_id, $part);
103
104       $OUTPUT = new rcube_html_page();
105       $OUTPUT->write(rcmail_print_body($part, intval($_GET['_safe'])));
106       }
107     else
108       {
109       header(sprintf('Content-Disposition: %s; filename="%s";',
110                      $_GET['_download'] ? 'attachment' : 'inline',
111                      $part->filename ? abbreviate_string($part->filename, 55) : "roundcube.$ctype_secondary"));
112
113       // turn off output buffering and print part content
114       $IMAP->get_message_part($MESSAGE['UID'], $part->mime_id, $part, true);
115       }
116
117     exit;
118     }
119   }
120
121 // print message
122 else
123   {
124   $ctype_primary = strtolower($MESSAGE['structure']->ctype_primary);
125   $ctype_secondary = strtolower($MESSAGE['structure']->ctype_secondary);
126   $mimetype = sprintf('%s/%s', $ctype_primary, $ctype_secondary);
127
128   // send correct headers for content type
129   header("Content-Type: text/html");
130
131   $cont = ''; 
132   list($MESSAGE['parts']) = rcmail_parse_message($MESSAGE['structure'],
133                                                  array('safe' => intval($_GET['_safe']),
134                                                  'get_url' => $GET_URL.'&_part=%s'));
135
136   $cont = "<html>\n<head><title></title>\n</head>\n<body>";
137   $cont .= rcmail_message_body(array());
138   $cont .= "\n</body>\n</html>";
139
140   $OUTPUT = new rcube_html_page();
141   $OUTPUT->write($cont);
142
143   exit;
144   }
145
146
147 // if we arrive here, the requested part was not found
148 header('HTTP/1.1 404 Not Found');
149 exit;
150
151 ?>