7baf86a9 |
1 | <?php |
2ba13803 |
2 | /** |
3 | ** attachment_common.php |
4 | ** |
5 | ** Copyright (c) 1999-2001 The Squirrelmail Development Team |
6 | ** Licensed under the GNU GPL. For full terms see the file COPYING. |
7 | ** |
8 | ** This file provides the handling of often-used attachment types. |
9 | ** |
10 | ** $Id$ |
11 | **/ |
7baf86a9 |
12 | |
13 | global $FileExtensionToMimeType, $attachment_common_types; |
14 | $FileExtensionToMimeType = array('bmp' => 'image/x-bitmap', |
15 | 'gif' => 'image/gif', |
16 | 'htm' => 'text/html', |
17 | 'html' => 'text/html', |
18 | 'jpg' => 'image/jpeg', |
19 | 'jpeg' => 'image/jpeg', |
20 | 'php' => 'text/plain', |
21 | 'png' => 'image/png', |
22 | 'rtf' => 'text/richtext', |
23 | 'txt' => 'text/plain', |
24 | 'vcf' => 'text/x-vcard'); |
25 | |
26 | // Register browser-supported image types |
27 | if (isset($attachment_common_types)) { |
28 | // Don't run this before being logged in. That may happen |
29 | // when plugins include mime.php |
30 | foreach ($attachment_common_types as $val => $v) { |
31 | if ($val == 'image/gif') |
32 | register_attachment_common('image/gif', 'link_image'); |
33 | elseif (($val == 'image/jpeg' || $val == 'image/pjpeg') and |
34 | (!isset($jpeg_done))) { |
35 | $jpeg_done = 1; |
36 | register_attachment_common('image/jpeg', 'link_image'); |
37 | register_attachment_common('image/pjpeg', 'link_image'); |
38 | } |
39 | elseif ($val == 'image/png') |
40 | register_attachment_common('image/png', 'link_image'); |
41 | elseif ($val == 'image/x-xbitmap') |
42 | register_attachment_common('image/x-xbitmap', 'link_image'); |
43 | } |
44 | unset($jpeg_done); |
45 | } |
46 | |
47 | // Register text-type attachments |
48 | register_attachment_common('message/rfc822', 'link_text'); |
49 | register_attachment_common('text/plain', 'link_text'); |
50 | register_attachment_common('text/richtext', 'link_text'); |
51 | |
52 | // Register HTML |
53 | register_attachment_common('text/html', 'link_html'); |
54 | |
55 | // Register vcards |
56 | register_attachment_common('text/x-vcard', 'link_vcard'); |
57 | |
58 | // Register "unknown" attachments |
59 | register_attachment_common('application/octet-stream', 'octet_stream'); |
60 | |
61 | |
62 | /* Function which optimizes readability of the above code */ |
63 | |
64 | function register_attachment_common($type, $func) { |
65 | global $squirrelmail_plugin_hooks; |
66 | $squirrelmail_plugin_hooks['attachment ' . $type]['attachment_common'] = |
67 | 'attachment_common_' . $func; |
68 | } |
69 | |
70 | |
71 | function attachment_common_link_text(&$Args) |
72 | { |
73 | // If there is a text attachment, we would like to create a 'view' button |
74 | // that links to the text attachment viewer. |
75 | // |
76 | // $Args[1] = the array of actions |
77 | // |
78 | // Use our plugin name for adding an action |
79 | // $Args[1]['attachment_common'] = array for href and text |
80 | // |
81 | // $Args[1]['attachment_common']['text'] = What is displayed |
82 | // $Args[1]['attachment_common']['href'] = Where it links to |
83 | // |
84 | // This sets the 'href' of this plugin for a new link. |
85 | $Args[1]['attachment_common']['href'] = '../src/download.php?startMessage=' . |
86 | $Args[2] . '&passed_id=' . $Args[3] . '&mailbox=' . $Args[4] . |
87 | '&passed_ent_id=' . $Args[5] . '&override_type0=text&override_type1=plain'; |
88 | |
89 | // If we got here from a search, we should preserve these variables |
90 | if ($Args[8] && $Args[9]) |
91 | $Args[1]['attachment_common']['href'] .= '&where=' . |
92 | urlencode($Args[8]) . '&what=' . urlencode($Args[9]); |
93 | |
94 | // The link that we created needs a name. "view" will be displayed for |
95 | // all text attachments handled by this plugin. |
96 | $Args[1]['attachment_common']['text'] = _("view"); |
97 | |
98 | // Each attachment has a filename on the left, which is a link. |
99 | // Where that link points to can be changed. Just in case the link above |
100 | // for viewing text attachments is not the same as the default link for |
101 | // this file, we'll change it. |
102 | // |
103 | // This is a lot better in the image links, since the defaultLink will just |
104 | // download the image, but the one that we set it to will format the page |
105 | // to have an image tag in the center (looking a lot like this text viewer) |
106 | $Args[6] = $Args[1]['attachment_common']['href']; |
107 | } |
108 | |
109 | |
110 | function attachment_common_link_html(&$Args) |
111 | { |
112 | $Args[1]['attachment_common']['href'] = '../src/download.php?startMessage=' . |
113 | $Args[2] . '&passed_id=' . $Args[3] . '&mailbox=' . $Args[4] . |
114 | '&passed_ent_id=' . $Args[5] . '&override_type0=text&override_type1=html'; |
115 | |
116 | if ($Args[8] && $Args[9]) |
117 | $Args[1]['attachment_common']['href'] .= '&where=' . |
118 | urlencode($Args[8]) . '&what=' . urlencode($Args[9]); |
119 | |
120 | $Args[1]['attachment_common']['text'] = _("view"); |
121 | |
122 | $Args[6] = $Args[1]['attachment_common']['href']; |
123 | } |
124 | |
125 | |
126 | function attachment_common_link_image(&$Args) |
127 | { |
128 | global $attachment_common_show_images, $attachment_common_show_images_list; |
129 | |
130 | $info['passed_id'] = $Args[3]; |
131 | $info['mailbox'] = $Args[4]; |
132 | $info['ent_id'] = $Args[5]; |
133 | |
134 | $attachment_common_show_images_list[] = $info; |
135 | |
136 | $Args[1]['attachment_common']['href'] = '../src/image.php?startMessage=' . |
137 | $Args[2] . '&passed_id=' . $Args[3] . '&mailbox=' . $Args[4] . |
138 | '&passed_ent_id=' . $Args[5]; |
139 | |
140 | if ($Args[8] && $Args[9]) |
141 | $Args[1]['attachment_common']['href'] .= '&where=' . |
142 | urlencode($Args[8]) . '&what=' . urlencode($Args[9]); |
143 | |
144 | $Args[1]['attachment_common']['text'] = _("view"); |
145 | |
146 | $Args[6] = $Args[1]['attachment_common']['href']; |
147 | } |
148 | |
149 | |
150 | function attachment_common_link_vcard(&$Args) |
151 | { |
152 | $Args[1]['attachment_common']['href'] = '../src/vcard.php?startMessage=' . |
153 | $Args[2] . '&passed_id=' . $Args[3] . '&mailbox=' . $Args[4] . |
154 | '&passed_ent_id=' . $Args[5]; |
155 | |
156 | if (isset($where) && isset($what)) |
157 | $Args[1]['attachment_common']['href'] .= '&where=' . |
158 | urlencode($Args[8]) . '&what=' . urlencode($Args[9]); |
159 | |
160 | $Args[1]['attachment_common']['text'] = _("Business Card"); |
161 | |
162 | $Args[6] = $Args[1]['attachment_common']['href']; |
163 | } |
164 | |
165 | |
166 | function attachment_common_octet_stream(&$Args) |
167 | { |
168 | global $FileExtensionToMimeType; |
169 | |
170 | do_hook('attachment_common-load_mime_types'); |
171 | |
172 | ereg('\\.([^\\.]+)$', $Args[7], $Regs); |
173 | |
174 | $Ext = strtolower($Regs[1]); |
175 | |
176 | if ($Ext == '' || ! isset($FileExtensionToMimeType[$Ext])) |
177 | return; |
178 | |
179 | $Ret = do_hook('attachment ' . $FileExtensionToMimeType[$Ext], |
180 | $Args[1], $Args[2], $Args[3], $Args[4], $Args[5], $Args[6], |
181 | $Args[7], $Args[8], $Args[9]); |
182 | |
183 | foreach ($Ret as $a => $b) { |
184 | $Args[$a] = $b; |
185 | } |
186 | } |
187 | |
188 | ?> |