4 * attachment_common.php
6 * Copyright (c) 1999-2002 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.
14 global $attachment_common_show_images_list;
15 $attachment_common_show_images_list = array();
17 global $FileExtensionToMimeType, $attachment_common_types;
18 $FileExtensionToMimeType = array('bmp' => 'image/x-bitmap',
21 'html' => 'text/html',
22 'jpg' => 'image/jpeg',
23 'jpeg' => 'image/jpeg',
24 'php' => 'text/plain',
26 'rtf' => 'text/richtext',
27 'txt' => 'text/plain',
28 'vcf' => 'text/x-vcard');
30 /* Register browser-supported image types */
31 if (isset($attachment_common_types)) {
32 /* Don't run this before being logged in. That may happen
33 when plugins include mime.php */
34 foreach ($attachment_common_types as $val => $v) {
35 if ($val == 'image/gif')
36 register_attachment_common('image/gif', 'link_image');
37 elseif (($val == 'image/jpeg' ||
$val == 'image/pjpeg') and
38 (!isset($jpeg_done))) {
40 register_attachment_common('image/jpeg', 'link_image');
41 register_attachment_common('image/pjpeg', 'link_image');
43 elseif ($val == 'image/png')
44 register_attachment_common('image/png', 'link_image');
45 elseif ($val == 'image/x-xbitmap')
46 register_attachment_common('image/x-xbitmap', 'link_image');
51 /* Register text-type attachments */
52 //register_attachment_common('message/rfc822', 'link_text');
53 register_attachment_common('message/rfc822', 'link_message');
54 register_attachment_common('text/plain', 'link_text');
55 register_attachment_common('text/richtext', 'link_text');
58 register_attachment_common('text/html', 'link_html');
62 register_attachment_common('text/x-vcard', 'link_vcard');
64 /* Register rules for general types.
65 * These will be used if there isn't a more specific rule available. */
66 register_attachment_common('text/*', 'link_text');
67 register_attachment_common('message/*', 'link_text');
69 /* Register "unknown" attachments */
70 register_attachment_common('application/octet-stream', 'octet_stream');
73 /* Function which optimizes readability of the above code */
75 function register_attachment_common($type, $func) {
76 global $squirrelmail_plugin_hooks;
77 $squirrelmail_plugin_hooks['attachment ' . $type]['attachment_common'] =
78 'attachment_common_' . $func;
82 function attachment_common_link_text(&$Args)
84 /* If there is a text attachment, we would like to create a 'view' button
85 that links to the text attachment viewer.
87 $Args[1] = the array of actions
89 Use our plugin name for adding an action
90 $Args[1]['attachment_common'] = array for href and text
92 $Args[1]['attachment_common']['text'] = What is displayed
93 $Args[1]['attachment_common']['href'] = Where it links to
95 This sets the 'href' of this plugin for a new link. */
98 $Args[1]['attachment_common']['href'] = '../src/view_text.php?'. $QUERY_STRING;
101 /* The link that we created needs a name. "view" will be displayed for
102 all text attachments handled by this plugin. */
103 $Args[1]['attachment_common']['text'] = _("view");
105 /* Each attachment has a filename on the left, which is a link.
106 Where that link points to can be changed. Just in case the link above
107 for viewing text attachments is not the same as the default link for
108 this file, we'll change it.
110 This is a lot better in the image links, since the defaultLink will just
111 download the image, but the one that we set it to will format the page
112 to have an image tag in the center (looking a lot like this text viewer) */
113 $Args[6] = $Args[1]['attachment_common']['href'];
117 function attachment_common_link_message(&$Args)
119 $Args[1]['attachment_common']['href'] = '../src/read_body.php?startMessage=' .
120 $Args[2] . '&passed_id=' . $Args[3] . '&mailbox=' . $Args[4] .
121 '&passed_ent_id=' . $Args[5] . '&override_type0=message&override_type1=rfc822';
122 /* The link that we created needs a name. "view" will be displayed for
123 all text attachments handled by this plugin. */
124 $Args[1]['attachment_common']['text'] = _("view");
126 $Args[6] = $Args[1]['attachment_common']['href'];
130 function attachment_common_link_html(&$Args)
132 $Args[1]['attachment_common']['href'] = '../src/download.php?startMessage=' .
133 $Args[2] . '&passed_id=' . $Args[3] . '&mailbox=' . $Args[4] .
134 '&passed_ent_id=' . $Args[5] . '&override_type0=text&override_type1=html';
136 if ($Args[8] && $Args[9]) {
137 $Args[1]['attachment_common']['href'] .= '&where=' .
138 urlencode($Args[8]) . '&what=' . urlencode($Args[9]);
141 $Args[1]['attachment_common']['text'] = _("view");
143 $Args[6] = $Args[1]['attachment_common']['href'];
147 function attachment_common_link_image(&$Args)
149 global $attachment_common_show_images, $attachment_common_show_images_list;
151 $info['passed_id'] = $Args[3];
152 $info['mailbox'] = $Args[4];
153 $info['ent_id'] = $Args[5];
155 $attachment_common_show_images_list[] = $info;
157 $Args[1]['attachment_common']['href'] = '../src/image.php?startMessage=' .
158 $Args[2] . '&passed_id=' . $Args[3] . '&mailbox=' . $Args[4] .
159 '&passed_ent_id=' . $Args[5];
161 if ($Args[8] && $Args[9]) {
162 $Args[1]['attachment_common']['href'] .= '&where=' .
163 urlencode($Args[8]) . '&what=' . urlencode($Args[9]);
166 $Args[1]['attachment_common']['text'] = _("view");
168 $Args[6] = $Args[1]['attachment_common']['href'];
173 function attachment_common_link_vcard(&$Args)
175 $Args[1]['attachment_common']['href'] = '../src/vcard.php?startMessage=' .
176 $Args[2] . '&passed_id=' . $Args[3] . '&mailbox=' . $Args[4] .
177 '&passed_ent_id=' . $Args[5];
179 if (isset($where) && isset($what))
180 $Args[1]['attachment_common']['href'] .= '&where=' .
181 urlencode($Args[8]) . '&what=' . urlencode($Args[9]);
183 $Args[1]['attachment_common']['text'] = _("Business Card");
185 $Args[6] = $Args[1]['attachment_common']['href'];
189 function attachment_common_octet_stream(&$Args)
191 global $FileExtensionToMimeType;
193 do_hook('attachment_common-load_mime_types');
195 ereg('\\.([^\\.]+)$', $Args[7], $Regs);
197 $Ext = strtolower($Regs[1]);
199 if ($Ext == '' ||
! isset($FileExtensionToMimeType[$Ext]))
202 $Ret = do_hook('attachment ' . $FileExtensionToMimeType[$Ext],
203 $Args[1], $Args[2], $Args[3], $Args[4], $Args[5], $Args[6],
204 $Args[7], $Args[8], $Args[9]);
206 foreach ($Ret as $a => $b) {