Ticket #1485920: get.inc

File get.inc, 4.7 KB (added by rosali, 4 years ago)
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  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
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
44
45// show part page
46if (!empty($_GET['_frame'])) {
47  $OUTPUT->send('messagepart');
48  exit;
49}
50
51else if ($pid = get_input_value('_part', RCUBE_INPUT_GET)) {
52  // TNEF encoded attachment part
53  if (preg_match('/^winmail\.([0-9.]+)\.([0-9]+)$/', $pid, $nt)) {
54    $pid = $nt[1]; $i = $nt[2];
55    if ($part = $MESSAGE->mime_parts[$pid]) {
56      $tnef_arr = $IMAP->tnef_decode($part, $MESSAGE->uid);
57      if (is_a($tnef_arr[$i], 'rcube_message_part'))
58        $MESSAGE->mime_parts[$pid] = $tnef_arr[$i];
59    }
60  }
61 
62  if ($part = $MESSAGE->mime_parts[$pid]) {
63    $ctype_primary = strtolower($part->ctype_primary);
64    $ctype_secondary = strtolower($part->ctype_secondary);
65    $mimetype = sprintf('%s/%s', $ctype_primary, $ctype_secondary);
66   
67    $browser = new rcube_browser;
68
69    send_nocacheing_headers();
70   
71    // send download headers
72    if ($_GET['_download']) {
73      header("Content-Type: application/octet-stream");
74      if ($browser->ie)
75        header("Content-Type: application/force-download");
76    }
77    else if ($ctype_primary == 'text') {
78      header("Content-Type: text/$ctype_secondary; charset=" . ($part->charset ? $part->charset : RCMAIL_CHARSET));
79    }
80    else {
81      header("Content-Type: $mimetype");
82      header("Content-Transfer-Encoding: binary");
83    }
84
85    // deliver part content
86    if ($ctype_primary == 'text' && $ctype_secondary == 'html') {
87      // get part body if not available
88      if (!$part->body)
89        $part->body = $MESSAGE->get_part_content($part->mime_id);
90
91      $OUTPUT = new rcube_html_page();
92      $OUTPUT->write(rcmail_print_body($part, array('safe' => $MESSAGE->is_safe, 'inline_html' => false)));
93    }
94    else {
95      // don't kill the connection if download takes more than 30 sec.
96      if (!ini_get('safe_mode')) {
97          set_time_limit(0);
98      }     
99     
100      // Find me
101      $temparr = explode("name=",$part->headers['content-type']);
102      if(isset($temparr[1])){
103        $part->filename = $IMAP->decode_header(str_replace("\"","",$temparr[1]));
104      }
105      // End Find me
106     
107      $filename = $part->filename ? $part->filename : ($MESSAGE->subject ? $MESSAGE->subject : 'roundcube') . '.'.$ctype_secondary;
108     
109      if ($browser->ie && $browser->ver < 7)
110        $filename = rawurlencode(abbreviate_string($filename, 55));
111      else if ($browser->ie)
112        $filename = rawurlencode($filename);
113      else
114        $filename = addcslashes($filename, '"');
115     
116      $disposition = !empty($_GET['_download']) ? 'attachment' : 'inline';
117     
118      header("Content-Disposition: $disposition; filename=\"$filename\"");
119     
120      // turn off output buffering and print part content
121      if ($part->body)
122        echo $part->body;
123      else
124        $IMAP->get_message_part($MESSAGE->uid, $part->mime_id, $part, true);
125    }
126
127    exit;
128  }
129}
130
131// print message
132else {
133  // send correct headers for content type
134  header("Content-Type: text/html");
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
148header('HTTP/1.1 404 Not Found');
149exit;
150
151?>