7d61692555f29a9e299e0db43ea054990c1f4000
[squirrelmail.git] / functions / attachment_common.php
1 <?php
2
3 /**
4 * attachment_common.php
5 *
6 * Copyright (c) 1999-2003 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 sqgetGlobalVar('attachment_common_types', $attachment_common_types);
32 if (isset($attachment_common_types)) {
33 /* Don't run this before being logged in. That may happen
34 when plugins include mime.php */
35 foreach ($attachment_common_types as $val => $v) {
36 if ($val == 'image/gif')
37 register_attachment_common('image/gif', 'link_image');
38 elseif (($val == 'image/jpeg' || $val == 'image/pjpeg') and
39 (!isset($jpeg_done))) {
40 $jpeg_done = 1;
41 register_attachment_common('image/jpeg', 'link_image');
42 register_attachment_common('image/pjpeg', 'link_image');
43 }
44 elseif ($val == 'image/png')
45 register_attachment_common('image/png', 'link_image');
46 elseif ($val == 'image/x-xbitmap')
47 register_attachment_common('image/x-xbitmap', 'link_image');
48 }
49 unset($jpeg_done);
50 }
51
52 /* Register text-type attachments */
53 //register_attachment_common('message/rfc822', 'link_text');
54 register_attachment_common('message/rfc822', 'link_message');
55 register_attachment_common('text/plain', 'link_text');
56 register_attachment_common('text/richtext', 'link_text');
57
58 /* Register HTML */
59 register_attachment_common('text/html', 'link_html');
60
61
62 /* Register vcards */
63 register_attachment_common('text/x-vcard', 'link_vcard');
64 register_attachment_common('text/directory', 'link_vcard');
65
66 /* Register rules for general types.
67 * These will be used if there isn't a more specific rule available. */
68 register_attachment_common('text/*', 'link_text');
69 register_attachment_common('message/*', 'link_text');
70
71 /* Register "unknown" attachments */
72 register_attachment_common('application/octet-stream', 'octet_stream');
73
74
75 /* Function which optimizes readability of the above code */
76
77 function register_attachment_common($type, $func) {
78 global $squirrelmail_plugin_hooks;
79 $squirrelmail_plugin_hooks['attachment ' . $type]['attachment_common'] =
80 'attachment_common_' . $func;
81 }
82
83
84 function attachment_common_link_text(&$Args)
85 {
86 /* If there is a text attachment, we would like to create a 'view' button
87 that links to the text attachment viewer.
88
89 $Args[1] = the array of actions
90
91 Use our plugin name for adding an action
92 $Args[1]['attachment_common'] = array for href and text
93
94 $Args[1]['attachment_common']['text'] = What is displayed
95 $Args[1]['attachment_common']['href'] = Where it links to
96
97 This sets the 'href' of this plugin for a new link. */
98 sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
99
100 $Args[1]['attachment_common']['href'] = SM_PATH . 'src/view_text.php?'. $QUERY_STRING;
101 $Args[1]['attachment_common']['href'] =
102 set_url_var($Args[1]['attachment_common']['href'],
103 'ent_id',$Args[5]);
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 function attachment_common_link_message(&$Args)
121 {
122 $Args[1]['attachment_common']['href'] = SM_PATH . 'src/read_body.php?startMessage=' .
123 $Args[2] . '&amp;passed_id=' . $Args[3] . '&amp;mailbox=' . $Args[4] .
124 '&amp;passed_ent_id=' . $Args[5] . '&amp;override_type0=message&amp;override_type1=rfc822';
125 /* The link that we created needs a name. "view" will be displayed for
126 all text attachments handled by this plugin. */
127 $Args[1]['attachment_common']['text'] = _("view");
128
129 $Args[6] = $Args[1]['attachment_common']['href'];
130 }
131
132
133 function attachment_common_link_html(&$Args)
134 {
135 sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
136
137 $Args[1]['attachment_common']['href'] = SM_PATH . 'src/view_text.php?'. $QUERY_STRING.
138 /* why use the overridetype? can this be removed */
139 '&amp;override_type0=text&amp;override_type1=html';
140 $Args[1]['attachment_common']['href'] =
141 set_url_var($Args[1]['attachment_common']['href'],
142 'ent_id',$Args[5]);
143
144 $Args[1]['attachment_common']['text'] = _("view");
145
146 $Args[6] = $Args[1]['attachment_common']['href'];
147 }
148
149 function attachment_common_link_image(&$Args)
150 {
151 global $attachment_common_show_images, $attachment_common_show_images_list;
152
153 sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
154
155 $info['passed_id'] = $Args[3];
156 $info['mailbox'] = $Args[4];
157 $info['ent_id'] = $Args[5];
158
159 $attachment_common_show_images_list[] = $info;
160
161 $Args[1]['attachment_common']['href'] = SM_PATH . 'src/image.php?'. $QUERY_STRING;
162 $Args[1]['attachment_common']['href'] =
163 set_url_var($Args[1]['attachment_common']['href'],
164 'ent_id',$Args[5]);
165
166 $Args[1]['attachment_common']['text'] = _("view");
167
168 $Args[6] = $Args[1]['attachment_common']['href'];
169
170 }
171
172
173 function attachment_common_link_vcard(&$Args)
174 {
175 sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
176
177 $Args[1]['attachment_common']['href'] = SM_PATH . 'src/vcard.php?'. $QUERY_STRING;
178 $Args[1]['attachment_common']['href'] =
179 set_url_var($Args[1]['attachment_common']['href'],
180 'ent_id',$Args[5]);
181
182 $Args[1]['attachment_common']['text'] = _("Business Card");
183
184 $Args[6] = $Args[1]['attachment_common']['href'];
185 }
186
187
188 function attachment_common_octet_stream(&$Args)
189 {
190 global $FileExtensionToMimeType;
191
192 do_hook('attachment_common-load_mime_types');
193
194 ereg('\\.([^\\.]+)$', $Args[7], $Regs);
195
196 $Ext = strtolower($Regs[1]);
197
198 if ($Ext == '' || ! isset($FileExtensionToMimeType[$Ext]))
199 return;
200
201 $Ret = do_hook('attachment ' . $FileExtensionToMimeType[$Ext],
202 $Args[1], $Args[2], $Args[3], $Args[4], $Args[5], $Args[6],
203 $Args[7], $Args[8], $Args[9]);
204
205 foreach ($Ret as $a => $b) {
206 $Args[$a] = $b;
207 }
208 }
209
210 ?>