59177427 |
1 | <?php |
895905c0 |
2 | |
35586184 |
3 | /** |
4 | * download.php |
5 | * |
82d304a0 |
6 | * Copyright (c) 1999-2004 The SquirrelMail Project Team |
35586184 |
7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
8 | * |
9 | * Handles attachment downloads to the users computer. |
10 | * Also allows displaying of attachments when possible. |
11 | * |
30967a1e |
12 | * @version $Id$ |
2b646597 |
13 | * @package squirrelmail |
35586184 |
14 | */ |
15 | |
30967a1e |
16 | /** |
17 | * Path for SquirrelMail required files. |
18 | * @ignore |
19 | */ |
86725763 |
20 | define('SM_PATH','../'); |
21 | |
22 | /* SquirrelMail required files. */ |
08185f2a |
23 | require_once(SM_PATH . 'include/validate.php'); |
86725763 |
24 | require_once(SM_PATH . 'functions/imap.php'); |
25 | require_once(SM_PATH . 'functions/mime.php'); |
6b96544a |
26 | |
65c3ec94 |
27 | header('Pragma: '); |
28 | header('Cache-Control: cache'); |
29 | |
0b97a708 |
30 | /* globals */ |
1e12d1ff |
31 | sqgetGlobalVar('key', $key, SQ_COOKIE); |
32 | sqgetGlobalVar('username', $username, SQ_SESSION); |
33 | sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION); |
34 | sqgetGlobalVar('messages', $messages, SQ_SESSION); |
35 | sqgetGlobalVar('mailbox', $mailbox, SQ_GET); |
36 | sqgetGlobalVar('ent_id', $ent_id, SQ_GET); |
37 | sqgetGlobalVar('absolute_dl',$absolute_dl, SQ_GET); |
38 | if ( sqgetGlobalVar('passed_id', $temp, SQ_GET) ) { |
39 | $passed_id = (int) $temp; |
da2415c1 |
40 | } |
1075eaf1 |
41 | |
0b97a708 |
42 | /* end globals */ |
97d7da3b |
43 | |
1e606225 |
44 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
45 | $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox); |
97d7da3b |
46 | |
1e606225 |
47 | $message = &$messages[$mbx_response['UIDVALIDITY']]["$passed_id"]; |
5a1c48cd |
48 | if (!is_object($message)) { |
49 | $message = sqimap_get_message($imapConnection,$passed_id, $mailbox); |
50 | } |
ff9d4297 |
51 | $subject = $message->rfc822_header->subject; |
6914aa18 |
52 | if ($ent_id) { |
53 | $message = &$message->getEntity($ent_id); |
54 | $header = $message->header; |
da2415c1 |
55 | |
6914aa18 |
56 | if ($message->rfc822_header) { |
57 | $subject = $message->rfc822_header->subject; |
6914aa18 |
58 | } else { |
59 | $header = $message->header; |
6914aa18 |
60 | } |
61 | $type0 = $header->type0; |
62 | $type1 = $header->type1; |
63 | $encoding = strtolower($header->encoding); |
ff9d4297 |
64 | } else { |
6914aa18 |
65 | /* raw message */ |
66 | $type0 = 'message'; |
67 | $type1 = 'rfc822'; |
bc5ff7c9 |
68 | $encoding = 'US-ASCII'; |
5d39ca4d |
69 | $header = $message->header; |
ff9d4297 |
70 | } |
97d7da3b |
71 | |
65c3ec94 |
72 | /* |
73 | * lets redefine message as this particular entity that we wish to display. |
74 | * it should hold only the header for this entity. We need to fetch the body |
75 | * yet before we can display anything. |
76 | */ |
65c3ec94 |
77 | |
65c3ec94 |
78 | if (isset($override_type0)) { |
79 | $type0 = $override_type0; |
80 | } |
81 | if (isset($override_type1)) { |
82 | $type1 = $override_type1; |
83 | } |
ff9d4297 |
84 | $filename = ''; |
85 | if (is_object($message->header->disposition)) { |
a91189d6 |
86 | $filename = $header->disposition->getProperty('filename'); |
ff9d4297 |
87 | if (!$filename) { |
708ea172 |
88 | $filename = $header->disposition->getProperty('name'); |
ff9d4297 |
89 | } |
6914aa18 |
90 | if (!$filename) { |
a91189d6 |
91 | $filename = $header->getParameter('name'); |
da2415c1 |
92 | } |
cf22004d |
93 | } else { |
5d39ca4d |
94 | $filename = $header->getParameter('name'); |
65c3ec94 |
95 | } |
bc5ff7c9 |
96 | |
89c7fc5a |
97 | //$filename = decodeHeader($filename, false, false); //Don't want html output nor utf8 because it will return html output |
da2415c1 |
98 | $filename = decodeHeader($filename, true, false); //Don't want html output |
65c3ec94 |
99 | if (strlen($filename) < 1) { |
fd77c331 |
100 | //$filename = decodeHeader($subject, false, false); //Don't want html output nor utf8 because it will return html output |
101 | $filename = decodeHeader($subject, true, false); //Don't want html output |
89c7fc5a |
102 | if ($type1 == 'plain' && $type0 == 'text') |
65c3ec94 |
103 | $suffix = 'txt'; |
89c7fc5a |
104 | else if ($type1 == 'richtext' && $type0 == 'text') |
65c3ec94 |
105 | $suffix = 'rtf'; |
89c7fc5a |
106 | else if ($type1 == 'postscript' && $type0 == 'application') |
65c3ec94 |
107 | $suffix = 'ps'; |
89c7fc5a |
108 | else if ($type1 == 'rfc822' && $type0 == 'message') |
109 | $suffix = 'msg'; |
8e73da2b |
110 | else |
65c3ec94 |
111 | $suffix = $type1; |
8e73da2b |
112 | |
113 | if ($filename == '') |
114 | $filename = 'untitled' . strip_tags($ent_id); |
89c7fc5a |
115 | $filename = $filename . '.' . $suffix; |
65c3ec94 |
116 | } |
117 | |
118 | /* |
119 | * Note: |
120 | * The following sections display the attachment in different |
121 | * ways depending on how they choose. The first way will download |
122 | * under any circumstance. This sets the Content-type to be |
123 | * applicatin/octet-stream, which should be interpreted by the |
124 | * browser as "download me". |
125 | * The second method (view) is used for images or other formats |
126 | * that should be able to be handled by the browser. It will |
127 | * most likely display the attachment inline inside the browser. |
128 | * And finally, the third one will be used by default. If it |
129 | * is displayable (text or html), it will load them up in a text |
130 | * viewer (built in to squirrelmail). Otherwise, it sets the |
131 | * content-type as application/octet-stream |
132 | */ |
88d916ee |
133 | if (isset($absolute_dl) && $absolute_dl) { |
da2415c1 |
134 | SendDownloadHeaders($type0, $type1, $filename, 1); |
65c3ec94 |
135 | } else { |
da2415c1 |
136 | SendDownloadHeaders($type0, $type1, $filename, 0); |
65c3ec94 |
137 | } |
38bca81c |
138 | /* be aware that any warning caused by download.php will corrupt the |
139 | * attachment in case of ERROR reporting = E_ALL and the output is the screen */ |
ff9d4297 |
140 | mime_print_body_lines ($imapConnection, $passed_id, $ent_id, $encoding); |
65c3ec94 |
141 | |
2b646597 |
142 | ?> |