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