4 * attachment_common.php
6 * This file provides the handling of often-used attachment types.
8 * @copyright © 1999-2005 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
16 if (! defined('SM_PATH')) define('SM_PATH','../');
18 /** sqgetGlobalVar() */
19 include_once(SM_PATH
. 'functions/global.php');
21 include_once(SM_PATH
. 'functions/display_messages.php');
23 global $attachment_common_show_images_list;
24 $attachment_common_show_images_list = array();
26 global $FileExtensionToMimeType, $attachment_common_types;
28 * Mapping of file extensions to mime types
30 * Used for application/octet-stream mime type detection.
31 * Supported extensions: bmp, gif, htm, html, jpg, jpeg, php,
32 * png, rtf, txt, patch (since 1.4.2), vcf
33 * @global array $FileExtensionToMimeType
35 $FileExtensionToMimeType = array('bmp' => 'image/x-bitmap',
38 'html' => 'text/html',
39 'jpg' => 'image/jpeg',
40 'jpeg' => 'image/jpeg',
41 'php' => 'text/plain',
43 'rtf' => 'text/richtext',
44 'txt' => 'text/plain',
45 'patch'=> 'text/plain',
46 'vcf' => 'text/x-vcard');
48 /* Register browser-supported image types */
49 sqgetGlobalVar('attachment_common_types', $attachment_common_types);
50 // FIXME: do we use $attachment_common_types that is not extracted by sqgetGlobalVar() ?
51 if (isset($attachment_common_types)) {
52 // var is used to detect activation of jpeg image types
54 /* Don't run this before being logged in. That may happen
55 when plugins include mime.php */
56 foreach ($attachment_common_types as $val => $v) {
57 if ($val == 'image/gif')
58 register_attachment_common('image/gif', 'link_image');
59 elseif (($val == 'image/jpeg' ||
$val == 'image/pjpeg') and
60 (!isset($jpeg_done))) {
62 register_attachment_common('image/jpeg', 'link_image');
63 register_attachment_common('image/pjpeg', 'link_image');
64 // register_attachment_common('image/jpg', 'link_image');
66 elseif ($val == 'image/png')
67 register_attachment_common('image/png', 'link_image');
68 elseif ($val == 'image/x-xbitmap')
69 register_attachment_common('image/x-xbitmap', 'link_image');
70 elseif ($val == '*/*' ||
$val == 'image/*') {
72 * browser (Firefox) declared that anything is acceptable.
73 * Lets register some common image types.
75 if (! isset($jpeg_done)) {
77 register_attachment_common('image/jpeg', 'link_image');
78 register_attachment_common('image/pjpeg', 'link_image');
79 // register_attachment_common('image/jpg', 'link_image');
81 register_attachment_common('image/gif', 'link_image');
82 register_attachment_common('image/png', 'link_image');
83 register_attachment_common('image/x-xbitmap', 'link_image');
84 // register_attachment_common('image/x-ico', 'link_image');
85 // register_attachment_common('image/x-icon', 'link_image');
86 // register_attachment_common('image/bmp', 'link_image');
87 // register_attachment_common('image/x-ms-bmp', 'link_image');
93 /* Register text-type attachments */
94 register_attachment_common('message/rfc822', 'link_message');
95 register_attachment_common('text/plain', 'link_text');
96 register_attachment_common('text/richtext', 'link_text');
99 register_attachment_common('text/html', 'link_html');
101 /* Register vcards */
102 register_attachment_common('text/x-vcard', 'link_vcard');
103 register_attachment_common('text/directory', 'link_vcard');
105 /* Register rules for general types.
106 * These will be used if there isn't a more specific rule available. */
107 register_attachment_common('text/*', 'link_text');
108 register_attachment_common('message/*', 'link_text');
110 /* Register "unknown" attachments */
111 register_attachment_common('application/octet-stream', 'octet_stream');
115 * Function which optimizes readability of the above code
116 * Registers 'attachment $type' hooks.
117 * @param string $type attachment type
118 * @param string $func suffix of attachment_common_* function, which handles $type attachments.
121 function register_attachment_common($type, $func) {
122 global $squirrelmail_plugin_hooks;
123 $squirrelmail_plugin_hooks['attachment ' . $type]['attachment_common'] =
124 'attachment_common_' . $func;
128 * Adds href and text keys to attachment_common array for text attachments
129 * @param array $Args attachment $type hook arguments
132 function attachment_common_link_text(&$Args) {
133 /* If there is a text attachment, we would like to create a "View" button
134 that links to the text attachment viewer.
136 $Args[1] = the array of actions
138 Use the name of this file for adding an action
139 $Args[1]['attachment_common'] = Array for href and text
141 $Args[1]['attachment_common']['text'] = What is displayed
142 $Args[1]['attachment_common']['href'] = Where it links to */
143 sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER
);
145 // if htmlspecialchars() breaks something - find other way to encode & in url.
146 $Args[1]['attachment_common']['href'] = sqm_baseuri() . 'src/view_text.php?'. htmlspecialchars($QUERY_STRING);
147 $Args[1]['attachment_common']['href'] =
148 set_url_var($Args[1]['attachment_common']['href'],
151 /* The link that we created needs a name. */
152 $Args[1]['attachment_common']['text'] = _("View");
154 /* Each attachment has a filename on the left, which is a link.
155 Where that link points to can be changed. Just in case the link above
156 for viewing text attachments is not the same as the default link for
157 this file, we'll change it.
159 This is a lot better in the image links, since the defaultLink will just
160 download the image, but the one that we set it to will format the page
161 to have an image tag in the center (looking a lot like this text viewer) */
162 $Args[6] = $Args[1]['attachment_common']['href'];
166 * Adds href and text keys to attachment_common array for rfc822 attachments
167 * @param array $Args attachment $type hook arguments
170 function attachment_common_link_message(&$Args) {
171 $Args[1]['attachment_common']['href'] = sqm_baseuri() . 'src/read_body.php?startMessage=' .
172 $Args[2] . '&passed_id=' . $Args[3] . '&mailbox=' . $Args[4] .
173 '&passed_ent_id=' . $Args[5] . '&override_type0=message&override_type1=rfc822';
175 $Args[1]['attachment_common']['text'] = _("View");
177 $Args[6] = $Args[1]['attachment_common']['href'];
181 * Adds href and text keys to attachment_common array for html attachments
182 * @param array $Args attachment $type hook arguments
185 function attachment_common_link_html(&$Args) {
186 sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER
);
188 $Args[1]['attachment_common']['href'] = sqm_baseuri() . 'src/view_text.php?'. htmlspecialchars($QUERY_STRING).
189 /* why use the overridetype? can this be removed */
190 /* override_type might be needed only when we want view other type of messages as html */
191 '&override_type0=text&override_type1=html';
192 $Args[1]['attachment_common']['href'] =
193 set_url_var($Args[1]['attachment_common']['href'],
196 $Args[1]['attachment_common']['text'] = _("View");
198 $Args[6] = $Args[1]['attachment_common']['href'];
202 * Adds href and text keys to attachment_common array for image attachments
203 * @param array $Args attachment $type hook arguments
206 function attachment_common_link_image(&$Args) {
207 global $attachment_common_show_images_list;
209 sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER
);
211 $info['passed_id'] = $Args[3];
212 $info['mailbox'] = $Args[4];
213 $info['ent_id'] = $Args[5];
215 $attachment_common_show_images_list[] = $info;
217 $Args[1]['attachment_common']['href'] = sqm_baseuri() . 'src/image.php?'. htmlspecialchars($QUERY_STRING);
218 $Args[1]['attachment_common']['href'] =
219 set_url_var($Args[1]['attachment_common']['href'],
222 $Args[1]['attachment_common']['text'] = _("View");
224 $Args[6] = $Args[1]['attachment_common']['href'];
228 * Adds href and text keys to attachment_common array for vcard attachments
229 * @param array $Args attachment $type hook arguments
232 function attachment_common_link_vcard(&$Args) {
233 sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER
);
235 $Args[1]['attachment_common']['href'] = sqm_baseuri() . 'src/vcard.php?'. htmlspecialchars($QUERY_STRING);
236 $Args[1]['attachment_common']['href'] =
237 set_url_var($Args[1]['attachment_common']['href'],
240 $Args[1]['attachment_common']['text'] = _("View Business Card");
242 $Args[6] = $Args[1]['attachment_common']['href'];
246 * Processes octet-stream attachments.
247 * Calls attachment_common-load_mime_types and attachment $type hooks.
248 * @param array $Args attachment $type hook arguments
251 function attachment_common_octet_stream(&$Args) {
252 global $FileExtensionToMimeType;
254 do_hook('attachment_common-load_mime_types');
256 ereg('\\.([^\\.]+)$', $Args[7], $Regs);
258 $Ext = strtolower($Regs[1]);
260 if ($Ext == '' ||
! isset($FileExtensionToMimeType[$Ext]))
263 $Ret = do_hook('attachment ' . $FileExtensionToMimeType[$Ext],
264 $Args[1], $Args[2], $Args[3], $Args[4], $Args[5], $Args[6],
265 $Args[7], $Args[8], $Args[9]);
267 foreach ($Ret as $a => $b) {