Mercurial > hg > rc2
comparison program/steps/mail/viewsource.inc @ 0:4681f974d28b
vanilla 1.3.3 distro, I hope
author | Charlie Root |
---|---|
date | Thu, 04 Jan 2018 15:52:31 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4681f974d28b |
---|---|
1 <?php | |
2 | |
3 /** | |
4 +-----------------------------------------------------------------------+ | |
5 | program/steps/mail/viewsource.inc | | |
6 | | | |
7 | This file is part of the Roundcube Webmail client | | |
8 | Copyright (C) 2005-2016, The Roundcube Dev Team | | |
9 | | | |
10 | Licensed under the GNU General Public License version 3 or | | |
11 | any later version with exceptions for skins & plugins. | | |
12 | See the README file for a full license statement. | | |
13 | | | |
14 | PURPOSE: | | |
15 | Display a mail message similar as a usual mail application does | | |
16 | | | |
17 +-----------------------------------------------------------------------+ | |
18 | Author: Thomas Bruederli <roundcube@gmail.com> | | |
19 +-----------------------------------------------------------------------+ | |
20 */ | |
21 | |
22 if (!empty($_GET['_save'])) { | |
23 $RCMAIL->request_security_check(rcube_utils::INPUT_GET); | |
24 } | |
25 | |
26 ob_end_clean(); | |
27 | |
28 // similar code as in program/steps/mail/get.inc | |
29 if ($uid = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_GET)) { | |
30 if ($pos = strpos($uid, '.')) { | |
31 $message = new rcube_message($uid); | |
32 $headers = $message->headers; | |
33 $part_id = substr($uid, $pos + 1); | |
34 } | |
35 else { | |
36 $headers = $RCMAIL->storage->get_message_headers($uid); | |
37 } | |
38 | |
39 $charset = $headers->charset ?: $RCMAIL->config->get('default_charset'); | |
40 | |
41 header("Content-Type: text/plain; charset={$charset}"); | |
42 | |
43 if (!empty($_GET['_save'])) { | |
44 $browser = $RCMAIL->output->browser; | |
45 $subject = rcube_mime::decode_header($headers->subject, $headers->charset); | |
46 $filename = rcmail_filename_from_subject(mb_substr($subject, 0, 128)); | |
47 $filename = ($filename ?: $uid) . '.eml'; | |
48 $filename = $browser->ie ? rawurlencode($filename) : addcslashes($filename, '"'); | |
49 | |
50 header("Content-Length: {$headers->size}"); | |
51 header("Content-Disposition: attachment; filename=\"$filename\""); | |
52 } | |
53 | |
54 if (isset($message)) { | |
55 $message->get_part_body($part_id, empty($_GET['_save']), 0, -1); | |
56 } | |
57 else { | |
58 $RCMAIL->storage->print_raw_body($uid, empty($_GET['_save'])); | |
59 } | |
60 } | |
61 else { | |
62 rcube::raise_error(array( | |
63 'code' => 500, | |
64 'type' => 'php', | |
65 'file' => __FILE__, | |
66 'line' => __LINE__, | |
67 'message' => "Message UID $uid not found" | |
68 ), | |
69 true, true); | |
70 } | |
71 | |
72 exit; | |
73 | |
74 | |
75 /** | |
76 * Helper function to convert message subject into filename | |
77 */ | |
78 function rcmail_filename_from_subject($str) | |
79 { | |
80 $str = preg_replace('/[:\t\n\r\0\x0B\/]+\s*/', ' ', $str); | |
81 | |
82 return trim($str, " \t\n\r\0\x0B./_"); | |
83 } |