4 * attachment_common.php
6 * This file provides the handling of often-used attachment types.
8 * @copyright © 1999-2006 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @package squirrelmail
12 * @todo document attachment $type hook arguments
17 * Mapping of file extensions to mime types
19 * Used for application/octet-stream mime type detection.
20 * Supported extensions: bmp, gif, htm, html, jpg, jpeg, php,
21 * png, rtf, txt, patch (since 1.4.2), vcf
22 * @global array $FileExtensionToMimeType
24 $FileExtensionToMimeType = array('bmp' => 'image/x-bitmap',
27 'html' => 'text/html',
28 'jpe' => 'image/jpeg',
29 'jpg' => 'image/jpeg',
30 'jpeg' => 'image/jpeg',
31 'php' => 'text/plain',
33 'rtf' => 'text/richtext',
34 'txt' => 'text/plain',
35 'patch'=> 'text/plain',
36 'vcf' => 'text/x-vcard');
38 /* Register browser-supported image types */
39 sqgetGlobalVar('attachment_common_types', $attachment_common_types);
40 // FIXME: do we use $attachment_common_types that is not extracted by sqgetGlobalVar() ?
41 if (isset($attachment_common_types)) {
42 // var is used to detect activation of jpeg image types
44 /* Don't run this before being logged in. That may happen
45 when plugins include mime.php */
46 foreach ($attachment_common_types as $val => $v) {
47 if ($val == 'image/gif')
48 register_attachment_common('image/gif', 'link_image');
49 elseif (($val == 'image/jpeg' ||
$val == 'image/pjpeg' ||
$val == 'image/jpg') and
50 (!isset($jpeg_done))) {
52 register_attachment_common('image/jpg', 'link_image');
53 register_attachment_common('image/jpeg', 'link_image');
54 register_attachment_common('image/pjpeg', 'link_image');
56 elseif ($val == 'image/png')
57 register_attachment_common('image/png', 'link_image');
58 elseif ($val == 'image/x-xbitmap')
59 register_attachment_common('image/x-xbitmap', 'link_image');
60 elseif ($val == '*/*' ||
$val == 'image/*') {
62 * browser (Firefox) declared that anything is acceptable.
63 * Lets register some common image types.
65 if (! isset($jpeg_done)) {
67 register_attachment_common('image/jpg', 'link_image');
68 register_attachment_common('image/jpeg', 'link_image');
69 register_attachment_common('image/pjpeg', 'link_image');
71 register_attachment_common('image/gif', 'link_image');
72 register_attachment_common('image/png', 'link_image');
73 register_attachment_common('image/x-xbitmap', 'link_image');
74 // register_attachment_common('image/x-ico', 'link_image');
75 // register_attachment_common('image/x-icon', 'link_image');
76 // register_attachment_common('image/bmp', 'link_image');
77 // register_attachment_common('image/x-ms-bmp', 'link_image');
83 /* Register text-type attachments */
84 register_attachment_common('message/rfc822', 'link_message');
85 register_attachment_common('text/plain', 'link_text');
86 register_attachment_common('text/richtext', 'link_text');
89 register_attachment_common('text/html', 'link_html');
92 register_attachment_common('text/x-vcard', 'link_vcard');
93 register_attachment_common('text/directory', 'link_vcard');
95 /* Register rules for general types.
96 * These will be used if there isn't a more specific rule available. */
97 register_attachment_common('text/*', 'link_text');
98 register_attachment_common('message/*', 'link_text');
100 /* Register "unknown" attachments */
101 register_attachment_common('application/octet-stream', 'octet_stream');
105 * Function which optimizes readability of the above code
106 * Registers 'attachment $type' hooks.
107 * @param string $type attachment type
108 * @param string $func suffix of attachment_common_* function, which handles $type attachments.
111 function register_attachment_common($type, $func) {
112 global $squirrelmail_plugin_hooks;
113 $squirrelmail_plugin_hooks['attachment ' . $type]['attachment_common'] =
114 'attachment_common_' . $func;
118 * Adds href and text keys to attachment_common array for text attachments
119 * @param array $Args attachment $type hook arguments
122 function attachment_common_link_text(&$Args) {
124 /* If there is a text attachment, we would like to create a "View" button
125 that links to the text attachment viewer.
127 $Args[1] = the array of actions
129 Use the name of this file for adding an action
130 $Args[1]['attachment_common'] = Array for href and text
132 $Args[1]['attachment_common']['text'] = What is displayed
133 $Args[1]['attachment_common']['href'] = Where it links to */
134 sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER
);
136 // if htmlspecialchars() breaks something - find other way to encode & in url.
137 $Args[1]['attachment_common']['href'] = $base_uri . 'src/view_text.php?'. htmlspecialchars($QUERY_STRING);
138 $Args[1]['attachment_common']['href'] =
139 set_url_var($Args[1]['attachment_common']['href'],
142 /* The link that we created needs a name. */
143 $Args[1]['attachment_common']['text'] = _("View");
145 /* Each attachment has a filename on the left, which is a link.
146 Where that link points to can be changed. Just in case the link above
147 for viewing text attachments is not the same as the default link for
148 this file, we'll change it.
150 This is a lot better in the image links, since the defaultLink will just
151 download the image, but the one that we set it to will format the page
152 to have an image tag in the center (looking a lot like this text viewer) */
153 $Args[6] = $Args[1]['attachment_common']['href'];
157 * Adds href and text keys to attachment_common array for rfc822 attachments
158 * @param array $Args attachment $type hook arguments
161 function attachment_common_link_message(&$Args) {
163 $Args[1]['attachment_common']['href'] = $base_uri . 'src/read_body.php?startMessage=' .
164 $Args[2] . '&passed_id=' . $Args[3] . '&mailbox=' . $Args[4] .
165 '&passed_ent_id=' . $Args[5] . '&override_type0=message&override_type1=rfc822';
167 $Args[1]['attachment_common']['text'] = _("View");
169 $Args[6] = $Args[1]['attachment_common']['href'];
173 * Adds href and text keys to attachment_common array for html attachments
174 * @param array $Args attachment $type hook arguments
177 function attachment_common_link_html(&$Args) {
179 sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER
);
181 $Args[1]['attachment_common']['href'] = $base_uri . 'src/view_text.php?'. htmlspecialchars($QUERY_STRING).
182 /* why use the overridetype? can this be removed */
183 /* override_type might be needed only when we want view other type of messages as html */
184 '&override_type0=text&override_type1=html';
185 $Args[1]['attachment_common']['href'] =
186 set_url_var($Args[1]['attachment_common']['href'],
189 $Args[1]['attachment_common']['text'] = _("View");
191 $Args[6] = $Args[1]['attachment_common']['href'];
195 * Adds href and text keys to attachment_common array for image attachments
196 * @param array $Args attachment $type hook arguments
199 function attachment_common_link_image(&$Args) {
200 global $attachment_common_show_images_list, $base_uri ;
202 sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER
);
204 $info['passed_id'] = $Args[3];
205 $info['mailbox'] = $Args[4];
206 $info['ent_id'] = $Args[5];
208 $attachment_common_show_images_list[] = $info;
210 $Args[1]['attachment_common']['href'] = $base_uri . 'src/image.php?'. htmlspecialchars($QUERY_STRING);
211 $Args[1]['attachment_common']['href'] =
212 set_url_var($Args[1]['attachment_common']['href'],
215 $Args[1]['attachment_common']['text'] = _("View");
217 $Args[6] = $Args[1]['attachment_common']['href'];
221 * Adds href and text keys to attachment_common array for vcard attachments
222 * @param array $Args attachment $type hook arguments
225 function attachment_common_link_vcard(&$Args) {
227 sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER
);
229 $Args[1]['attachment_common']['href'] = $base_uri . 'src/vcard.php?'. htmlspecialchars($QUERY_STRING);
230 $Args[1]['attachment_common']['href'] =
231 set_url_var($Args[1]['attachment_common']['href'],
234 $Args[1]['attachment_common']['text'] = _("View Business Card");
236 $Args[6] = $Args[1]['attachment_common']['href'];
240 * Processes octet-stream attachments.
241 * Calls attachment_common-load_mime_types and attachment $type hooks.
242 * @param array $Args attachment $type hook arguments
245 function attachment_common_octet_stream(&$Args) {
246 global $FileExtensionToMimeType;
248 do_hook('attachment_common-load_mime_types');
250 ereg('\\.([^\\.]+)$', $Args[7], $Regs);
252 $Ext = strtolower($Regs[1]);
254 if ($Ext == '' ||
! isset($FileExtensionToMimeType[$Ext]))
257 $Ret = do_hook('attachment ' . $FileExtensionToMimeType[$Ext],
258 $Args[1], $Args[2], $Args[3], $Args[4], $Args[5], $Args[6],
259 $Args[7], $Args[8], $Args[9]);
261 foreach ($Ret as $a => $b) {