4 * attachment_common.php
6 * Copyright (c) 1999-2005 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * This file provides the handling of often-used attachment types.
12 * @package squirrelmail
13 * @todo document attachment $type hook arguments
17 if (! defined('SM_PATH')) define('SM_PATH','../');
19 /** sqgetGlobalVar() */
20 include_once(SM_PATH
. 'functions/global.php');
22 include_once(SM_PATH
. 'functions/display_messages.php');
24 global $attachment_common_show_images_list;
25 $attachment_common_show_images_list = array();
27 global $FileExtensionToMimeType, $attachment_common_types;
28 $FileExtensionToMimeType = array('bmp' => 'image/x-bitmap',
31 'html' => 'text/html',
32 'jpg' => 'image/jpeg',
33 'jpeg' => 'image/jpeg',
34 'php' => 'text/plain',
36 'rtf' => 'text/richtext',
37 'txt' => 'text/plain',
38 'patch'=> 'text/plain',
39 'vcf' => 'text/x-vcard');
41 /* Register browser-supported image types */
42 sqgetGlobalVar('attachment_common_types', $attachment_common_types);
43 if (isset($attachment_common_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') and
50 (!isset($jpeg_done))) {
52 register_attachment_common('image/jpeg', 'link_image');
53 register_attachment_common('image/pjpeg', 'link_image');
55 elseif ($val == 'image/png')
56 register_attachment_common('image/png', 'link_image');
57 elseif ($val == 'image/x-xbitmap')
58 register_attachment_common('image/x-xbitmap', 'link_image');
63 /* Register text-type attachments */
64 register_attachment_common('message/rfc822', 'link_message');
65 register_attachment_common('text/plain', 'link_text');
66 register_attachment_common('text/richtext', 'link_text');
69 register_attachment_common('text/html', 'link_html');
72 register_attachment_common('text/x-vcard', 'link_vcard');
73 register_attachment_common('text/directory', 'link_vcard');
75 /* Register rules for general types.
76 * These will be used if there isn't a more specific rule available. */
77 register_attachment_common('text/*', 'link_text');
78 register_attachment_common('message/*', 'link_text');
80 /* Register "unknown" attachments */
81 register_attachment_common('application/octet-stream', 'octet_stream');
85 * Function which optimizes readability of the above code
86 * Registers 'attachment $type' hooks.
87 * @param string $type attachment type
88 * @param string $func suffix of attachment_common_* function, which handles $type attachments.
91 function register_attachment_common($type, $func) {
92 global $squirrelmail_plugin_hooks;
93 $squirrelmail_plugin_hooks['attachment ' . $type]['attachment_common'] =
94 'attachment_common_' . $func;
98 * Adds href and text keys to attachment_common array for text attachments
99 * @param array $Args attachment $type hook arguments
102 function attachment_common_link_text(&$Args) {
103 /* If there is a text attachment, we would like to create a "View" button
104 that links to the text attachment viewer.
106 $Args[1] = the array of actions
108 Use the name of this file for adding an action
109 $Args[1]['attachment_common'] = Array for href and text
111 $Args[1]['attachment_common']['text'] = What is displayed
112 $Args[1]['attachment_common']['href'] = Where it links to */
113 sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER
);
115 // if htmlspecialchars() breaks something - find other way to encode & in url.
116 $Args[1]['attachment_common']['href'] = sqm_baseuri() . 'src/view_text.php?'. htmlspecialchars($QUERY_STRING);
117 $Args[1]['attachment_common']['href'] =
118 set_url_var($Args[1]['attachment_common']['href'],
121 /* The link that we created needs a name. */
122 $Args[1]['attachment_common']['text'] = _("View");
124 /* Each attachment has a filename on the left, which is a link.
125 Where that link points to can be changed. Just in case the link above
126 for viewing text attachments is not the same as the default link for
127 this file, we'll change it.
129 This is a lot better in the image links, since the defaultLink will just
130 download the image, but the one that we set it to will format the page
131 to have an image tag in the center (looking a lot like this text viewer) */
132 $Args[6] = $Args[1]['attachment_common']['href'];
136 * Adds href and text keys to attachment_common array for rfc822 attachments
137 * @param array $Args attachment $type hook arguments
140 function attachment_common_link_message(&$Args) {
141 $Args[1]['attachment_common']['href'] = sqm_baseuri() . 'src/read_body.php?startMessage=' .
142 $Args[2] . '&passed_id=' . $Args[3] . '&mailbox=' . $Args[4] .
143 '&passed_ent_id=' . $Args[5] . '&override_type0=message&override_type1=rfc822';
145 $Args[1]['attachment_common']['text'] = _("View");
147 $Args[6] = $Args[1]['attachment_common']['href'];
151 * Adds href and text keys to attachment_common array for html attachments
152 * @param array $Args attachment $type hook arguments
155 function attachment_common_link_html(&$Args) {
156 sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER
);
158 $Args[1]['attachment_common']['href'] = sqm_baseuri() . 'src/view_text.php?'. htmlspecialchars($QUERY_STRING).
159 /* why use the overridetype? can this be removed */
160 /* override_type might be needed only when we want view other type of messages as html */
161 '&override_type0=text&override_type1=html';
162 $Args[1]['attachment_common']['href'] =
163 set_url_var($Args[1]['attachment_common']['href'],
166 $Args[1]['attachment_common']['text'] = _("View");
168 $Args[6] = $Args[1]['attachment_common']['href'];
172 * Adds href and text keys to attachment_common array for image attachments
173 * @param array $Args attachment $type hook arguments
176 function attachment_common_link_image(&$Args) {
177 global $attachment_common_show_images_list;
179 sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER
);
181 $info['passed_id'] = $Args[3];
182 $info['mailbox'] = $Args[4];
183 $info['ent_id'] = $Args[5];
185 $attachment_common_show_images_list[] = $info;
187 $Args[1]['attachment_common']['href'] = sqm_baseuri() . 'src/image.php?'. htmlspecialchars($QUERY_STRING);
188 $Args[1]['attachment_common']['href'] =
189 set_url_var($Args[1]['attachment_common']['href'],
192 $Args[1]['attachment_common']['text'] = _("View");
194 $Args[6] = $Args[1]['attachment_common']['href'];
198 * Adds href and text keys to attachment_common array for vcard attachments
199 * @param array $Args attachment $type hook arguments
202 function attachment_common_link_vcard(&$Args) {
203 sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER
);
205 $Args[1]['attachment_common']['href'] = sqm_baseuri() . 'src/vcard.php?'. htmlspecialchars($QUERY_STRING);
206 $Args[1]['attachment_common']['href'] =
207 set_url_var($Args[1]['attachment_common']['href'],
210 $Args[1]['attachment_common']['text'] = _("View Business Card");
212 $Args[6] = $Args[1]['attachment_common']['href'];
216 * Processes octet-stream attachments.
217 * Calls attachment_common-load_mime_types and attachment $type hooks.
218 * @param array $Args attachment $type hook arguments
221 function attachment_common_octet_stream(&$Args) {
222 global $FileExtensionToMimeType;
224 do_hook('attachment_common-load_mime_types');
226 ereg('\\.([^\\.]+)$', $Args[7], $Regs);
228 $Ext = strtolower($Regs[1]);
230 if ($Ext == '' ||
! isset($FileExtensionToMimeType[$Ext]))
233 $Ret = do_hook('attachment ' . $FileExtensionToMimeType[$Ext],
234 $Args[1], $Args[2], $Args[3], $Args[4], $Args[5], $Args[6],
235 $Args[7], $Args[8], $Args[9]);
237 foreach ($Ret as $a => $b) {