source: github/program/steps/mail/get.inc @ 1097a3c

HEADcourier-fixdev-browser-capabilitiespdorelease-0.6release-0.7release-0.8
Last change on this file since 1097a3c was 1097a3c, checked in by alecpl <alec@…>, 3 years ago
  • don't parse text/html attachment body on download
  • Property mode set to 100644
File size: 4.6 KB
Line 
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$
19
20*/
21
22
23// show loading page
24if (!empty($_GET['_preload'])) {
25  $url = str_replace('&_preload=1', '', $_SERVER['REQUEST_URI']);
26  $message = rcube_label('loadingdata');
27
28  header('Content-Type: text/html; charset=' . RCMAIL_CHARSET);
29  print "<html>\n<head>\n"
30        . '<meta http-equiv="refresh" content="0; url='.Q($url).'">' . "\n"
31        . '<meta http-equiv="content-type" content="text/html; charset='.RCMAIL_CHARSET.'">' . "\n"
32        . "</head>\n<body>\n$message\n</body>\n</html>";
33  exit;
34}
35
36ob_end_clean();
37
38// similar code as in program/steps/mail/show.inc
39if (!empty($_GET['_uid'])) {
40  $RCMAIL->config->set('prefer_html', true);
41  $MESSAGE = new rcube_message(get_input_value('_uid', RCUBE_INPUT_GET));
42}
43
44send_nocacheing_headers();
45
46// show part page
47if (!empty($_GET['_frame'])) {
48  $OUTPUT->send('messagepart');
49  exit;
50}
51
52else if ($pid = get_input_value('_part', RCUBE_INPUT_GET)) {
53  // TNEF encoded attachment part
54  if (preg_match('/^winmail\.([0-9.]+)\.([0-9]+)$/', $pid, $nt)) {
55    $pid = $nt[1]; $i = $nt[2];
56    if ($part = $MESSAGE->mime_parts[$pid]) {
57      $tnef_arr = $IMAP->tnef_decode($part, $MESSAGE->uid);
58      if (is_a($tnef_arr[$i], 'rcube_message_part'))
59        $MESSAGE->mime_parts[$pid] = $tnef_arr[$i];
60    }
61  }
62 
63  if ($part = $MESSAGE->mime_parts[$pid]) {
64    $ctype_primary = strtolower($part->ctype_primary);
65    $ctype_secondary = strtolower($part->ctype_secondary);
66    $mimetype = sprintf('%s/%s', $ctype_primary, $ctype_secondary);
67   
68    $browser = new rcube_browser;
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' && empty($_GET['_download'])) {
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      @set_time_limit(0);
96     
97      $filename = $part->filename ? $part->filename : ($MESSAGE->subject ? $MESSAGE->subject : 'roundcube') . '.'.$ctype_secondary;
98     
99      if ($browser->ie && $browser->ver < 7)
100        $filename = rawurlencode(abbreviate_string($filename, 55));
101      else if ($browser->ie)
102        $filename = rawurlencode($filename);
103      else
104        $filename = addcslashes($filename, '"');
105     
106      $disposition = !empty($_GET['_download']) ? 'attachment' : 'inline';
107     
108      header("Content-Disposition: $disposition; filename=\"$filename\"");
109     
110      // turn off output buffering and print part content
111      if ($part->body)
112        echo $part->body;
113      else if ($part->size)
114        $IMAP->get_message_part($MESSAGE->uid, $part->mime_id, $part, true);
115    }
116
117    exit;
118  }
119}
120
121// print message
122else {
123  // send correct headers for content type
124  header("Content-Type: text/html");
125
126  $cont = "<html>\n<head><title></title>\n</head>\n<body>";
127  $cont .= rcmail_message_body(array());
128  $cont .= "\n</body>\n</html>";
129
130  $OUTPUT = new rcube_html_page();
131  $OUTPUT->write($cont);
132
133  exit;
134}
135
136
137// if we arrive here, the requested part was not found
138header('HTTP/1.1 404 Not Found');
139exit;
140
141?>
Note: See TracBrowser for help on using the repository browser.