A few more unnecessary urldecodes when not needed. Now we can view headers
[squirrelmail.git] / functions / attachment_common.php
CommitLineData
7baf86a9 1<?php
7350889b 2
35586184 3/**
4 * attachment_common.php
5 *
76911253 6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
35586184 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 */
7baf86a9 13
35586184 14global $attachment_common_show_images_list;
15$attachment_common_show_images_list = array();
bbdd6ddb 16
5bc6067b 17global $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 */
b455793d 31sqgetGlobalVar('attachment_common_types', $attachment_common_types);
5bc6067b 32if (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) {
7baf86a9 36 if ($val == 'image/gif')
5bc6067b 37 register_attachment_common('image/gif', 'link_image');
7baf86a9 38 elseif (($val == 'image/jpeg' || $val == 'image/pjpeg') and
39 (!isset($jpeg_done))) {
5bc6067b 40 $jpeg_done = 1;
41 register_attachment_common('image/jpeg', 'link_image');
42 register_attachment_common('image/pjpeg', 'link_image');
7baf86a9 43 }
44 elseif ($val == 'image/png')
5bc6067b 45 register_attachment_common('image/png', 'link_image');
7baf86a9 46 elseif ($val == 'image/x-xbitmap')
5bc6067b 47 register_attachment_common('image/x-xbitmap', 'link_image');
48 }
49 unset($jpeg_done);
50}
7baf86a9 51
5bc6067b 52/* Register text-type attachments */
679f13b7 53//register_attachment_common('message/rfc822', 'link_text');
54register_attachment_common('message/rfc822', 'link_message');
5bc6067b 55register_attachment_common('text/plain', 'link_text');
56register_attachment_common('text/richtext', 'link_text');
7baf86a9 57
5bc6067b 58/* Register HTML */
59register_attachment_common('text/html', 'link_html');
7baf86a9 60
ae2f65a9 61
5bc6067b 62/* Register vcards */
63register_attachment_common('text/x-vcard', 'link_vcard');
35036cf9 64register_attachment_common('text/directory', 'link_vcard');
7baf86a9 65
ae2f65a9 66/* Register rules for general types.
67 * These will be used if there isn't a more specific rule available. */
68register_attachment_common('text/*', 'link_text');
69register_attachment_common('message/*', 'link_text');
70
5bc6067b 71/* Register "unknown" attachments */
72register_attachment_common('application/octet-stream', 'octet_stream');
7baf86a9 73
74
75/* Function which optimizes readability of the above code */
76
77function register_attachment_common($type, $func) {
5bc6067b 78 global $squirrelmail_plugin_hooks;
79 $squirrelmail_plugin_hooks['attachment ' . $type]['attachment_common'] =
7baf86a9 80 'attachment_common_' . $func;
81}
82
83
84function attachment_common_link_text(&$Args)
85{
5bc6067b 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. */
961ca3d8 98 sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
846a3a21 99
961ca3d8 100 $Args[1]['attachment_common']['href'] = SM_PATH . 'src/view_text.php?'. $QUERY_STRING;
98eb617f 101 $Args[1]['attachment_common']['href'] =
102 set_url_var($Args[1]['attachment_common']['href'],
b854f93a 103 'ent_id',$Args[5]);
7baf86a9 104
5bc6067b 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");
679f13b7 108
5bc6067b 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'];
7baf86a9 118}
119
679f13b7 120function attachment_common_link_message(&$Args)
121{
961ca3d8 122 $Args[1]['attachment_common']['href'] = SM_PATH . 'src/read_body.php?startMessage=' .
679f13b7 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");
f4c8a5ab 128
129 $Args[6] = $Args[1]['attachment_common']['href'];
679f13b7 130}
131
132
846a3a21 133function attachment_common_link_html(&$Args)
7baf86a9 134{
961ca3d8 135 sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
846a3a21 136
961ca3d8 137 $Args[1]['attachment_common']['href'] = SM_PATH . 'src/view_text.php?'. $QUERY_STRING.
47f9a69d 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]);
5bc6067b 143
144 $Args[1]['attachment_common']['text'] = _("view");
145
146 $Args[6] = $Args[1]['attachment_common']['href'];
7baf86a9 147}
148
7baf86a9 149function attachment_common_link_image(&$Args)
150{
5bc6067b 151 global $attachment_common_show_images, $attachment_common_show_images_list;
846a3a21 152
961ca3d8 153 sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
154
5bc6067b 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
961ca3d8 161 $Args[1]['attachment_common']['href'] = SM_PATH . 'src/image.php?'. $QUERY_STRING;
ff9d4297 162 $Args[1]['attachment_common']['href'] =
163 set_url_var($Args[1]['attachment_common']['href'],
164 'ent_id',$Args[5]);
cd7b8833 165
5bc6067b 166 $Args[1]['attachment_common']['text'] = _("view");
167
168 $Args[6] = $Args[1]['attachment_common']['href'];
f4c8a5ab 169
7baf86a9 170}
171
172
173function attachment_common_link_vcard(&$Args)
174{
961ca3d8 175 sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
176
177 $Args[1]['attachment_common']['href'] = SM_PATH . 'src/vcard.php?'. $QUERY_STRING;
ff9d4297 178 $Args[1]['attachment_common']['href'] =
179 set_url_var($Args[1]['attachment_common']['href'],
180 'ent_id',$Args[5]);
5bc6067b 181
182 $Args[1]['attachment_common']['text'] = _("Business Card");
183
184 $Args[6] = $Args[1]['attachment_common']['href'];
7baf86a9 185}
186
187
188function attachment_common_octet_stream(&$Args)
189{
5bc6067b 190 global $FileExtensionToMimeType;
7baf86a9 191
5bc6067b 192 do_hook('attachment_common-load_mime_types');
7baf86a9 193
5bc6067b 194 ereg('\\.([^\\.]+)$', $Args[7], $Regs);
7baf86a9 195
5bc6067b 196 $Ext = strtolower($Regs[1]);
7baf86a9 197
5bc6067b 198 if ($Ext == '' || ! isset($FileExtensionToMimeType[$Ext]))
199 return;
7baf86a9 200
5bc6067b 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]);
7baf86a9 204
5bc6067b 205 foreach ($Ret as $a => $b) {
206 $Args[$a] = $b;
207 }
7baf86a9 208}
209
ae2f65a9 210?>