svncommit
2005-10-27 66773789e392305bba4cdf7ed8e6ae3b8380de51
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" .
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')
75       {
76       list($MESSAGE['parts']) = rcmail_parse_message($MESSAGE['structure'],
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     // deliver part content
103     echo $cont;
104     exit;
105     }
106   }
107
108 // print message
109 else
110   {
111   $ctype_primary = strtolower($MESSAGE['structure']->ctype_primary);
112   $ctype_secondary = strtolower($MESSAGE['structure']->ctype_secondary);
113   $mimetype = sprintf('%s/%s', $ctype_primary, $ctype_secondary);
114
115   // send correct headers for content type
116   header("Content-Type: text/html");
117
118   $cont = ''; 
119   list($MESSAGE['parts']) = rcmail_parse_message($MESSAGE['structure'],
120                                                  array('safe' => (bool)$_GET['_safe'],
121                                                  'get_url' => $GET_URL.'&_part=%s'));
122
123   if ($MESSAGE['parts'] && $ctype_primary=='multipart')
124     {
125     // reset output page
126     $OUTPUT = new rcube_html_page();
127     parse_template('messagepart');
128     exit;
129     }
130   else if ($MESSAGE['parts'][0])
131     {
132     $part = $MESSAGE['parts'][0];
133     $cont = rcmail_print_body($part, (bool)$_GET['_safe']);
134     }
135   else
136     $cont = $IMAP->get_body($_GET['_uid']);
137
138   $OUTPUT = new rcube_html_page();
139   $OUTPUT->write($cont);
140
141 /*
142     if ($mimetype=='text/html')
143       print $cont;
144     else
145       {
146       print "<html>\n<body>\n";
147       print $cont;
148       print "\n</body>\n</html>";
149       }
150 */
151   exit;
152   }
153
154
155 // if we arrive here, the requested part was not found
156 header('HTTP/1.1 404 Not Found');
157 exit;
158
159 ?>