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