Added separate iso-8859-*, cp1257 and big5 decoding files
[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
cd21d1aa 14require_once(SM_PATH . 'functions/global.php');
15
35586184 16global $attachment_common_show_images_list;
17$attachment_common_show_images_list = array();
bbdd6ddb 18
5bc6067b 19global $FileExtensionToMimeType, $attachment_common_types;
20$FileExtensionToMimeType = array('bmp' => 'image/x-bitmap',
21 'gif' => 'image/gif',
22 'htm' => 'text/html',
23 'html' => 'text/html',
24 'jpg' => 'image/jpeg',
25 'jpeg' => 'image/jpeg',
26 'php' => 'text/plain',
27 'png' => 'image/png',
28 'rtf' => 'text/richtext',
29 'txt' => 'text/plain',
30 'vcf' => 'text/x-vcard');
31
32/* Register browser-supported image types */
b455793d 33sqgetGlobalVar('attachment_common_types', $attachment_common_types);
5bc6067b 34if (isset($attachment_common_types)) {
35 /* Don't run this before being logged in. That may happen
36 when plugins include mime.php */
37 foreach ($attachment_common_types as $val => $v) {
7baf86a9 38 if ($val == 'image/gif')
5bc6067b 39 register_attachment_common('image/gif', 'link_image');
7baf86a9 40 elseif (($val == 'image/jpeg' || $val == 'image/pjpeg') and
41 (!isset($jpeg_done))) {
5bc6067b 42 $jpeg_done = 1;
43 register_attachment_common('image/jpeg', 'link_image');
44 register_attachment_common('image/pjpeg', 'link_image');
7baf86a9 45 }
46 elseif ($val == 'image/png')
5bc6067b 47 register_attachment_common('image/png', 'link_image');
7baf86a9 48 elseif ($val == 'image/x-xbitmap')
5bc6067b 49 register_attachment_common('image/x-xbitmap', 'link_image');
50 }
51 unset($jpeg_done);
52}
7baf86a9 53
5bc6067b 54/* Register text-type attachments */
679f13b7 55//register_attachment_common('message/rfc822', 'link_text');
56register_attachment_common('message/rfc822', 'link_message');
5bc6067b 57register_attachment_common('text/plain', 'link_text');
58register_attachment_common('text/richtext', 'link_text');
7baf86a9 59
5bc6067b 60/* Register HTML */
61register_attachment_common('text/html', 'link_html');
7baf86a9 62
ae2f65a9 63
5bc6067b 64/* Register vcards */
65register_attachment_common('text/x-vcard', 'link_vcard');
35036cf9 66register_attachment_common('text/directory', 'link_vcard');
7baf86a9 67
ae2f65a9 68/* Register rules for general types.
69 * These will be used if there isn't a more specific rule available. */
70register_attachment_common('text/*', 'link_text');
71register_attachment_common('message/*', 'link_text');
72
5bc6067b 73/* Register "unknown" attachments */
74register_attachment_common('application/octet-stream', 'octet_stream');
7baf86a9 75
76
77/* Function which optimizes readability of the above code */
78
79function register_attachment_common($type, $func) {
5bc6067b 80 global $squirrelmail_plugin_hooks;
81 $squirrelmail_plugin_hooks['attachment ' . $type]['attachment_common'] =
7baf86a9 82 'attachment_common_' . $func;
83}
84
85
86function attachment_common_link_text(&$Args)
87{
5bc6067b 88 /* If there is a text attachment, we would like to create a 'view' button
89 that links to the text attachment viewer.
90
91 $Args[1] = the array of actions
92
93 Use our plugin name for adding an action
94 $Args[1]['attachment_common'] = array for href and text
95
96 $Args[1]['attachment_common']['text'] = What is displayed
97 $Args[1]['attachment_common']['href'] = Where it links to
98
99 This sets the 'href' of this plugin for a new link. */
961ca3d8 100 sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
846a3a21 101
961ca3d8 102 $Args[1]['attachment_common']['href'] = SM_PATH . 'src/view_text.php?'. $QUERY_STRING;
98eb617f 103 $Args[1]['attachment_common']['href'] =
104 set_url_var($Args[1]['attachment_common']['href'],
b854f93a 105 'ent_id',$Args[5]);
7baf86a9 106
5bc6067b 107 /* The link that we created needs a name. "view" will be displayed for
108 all text attachments handled by this plugin. */
109 $Args[1]['attachment_common']['text'] = _("view");
679f13b7 110
5bc6067b 111 /* Each attachment has a filename on the left, which is a link.
112 Where that link points to can be changed. Just in case the link above
113 for viewing text attachments is not the same as the default link for
114 this file, we'll change it.
115
116 This is a lot better in the image links, since the defaultLink will just
117 download the image, but the one that we set it to will format the page
118 to have an image tag in the center (looking a lot like this text viewer) */
119 $Args[6] = $Args[1]['attachment_common']['href'];
7baf86a9 120}
121
679f13b7 122function attachment_common_link_message(&$Args)
123{
961ca3d8 124 $Args[1]['attachment_common']['href'] = SM_PATH . 'src/read_body.php?startMessage=' .
679f13b7 125 $Args[2] . '&amp;passed_id=' . $Args[3] . '&amp;mailbox=' . $Args[4] .
126 '&amp;passed_ent_id=' . $Args[5] . '&amp;override_type0=message&amp;override_type1=rfc822';
127 /* The link that we created needs a name. "view" will be displayed for
128 all text attachments handled by this plugin. */
129 $Args[1]['attachment_common']['text'] = _("view");
f4c8a5ab 130
131 $Args[6] = $Args[1]['attachment_common']['href'];
679f13b7 132}
133
134
846a3a21 135function attachment_common_link_html(&$Args)
7baf86a9 136{
961ca3d8 137 sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
846a3a21 138
961ca3d8 139 $Args[1]['attachment_common']['href'] = SM_PATH . 'src/view_text.php?'. $QUERY_STRING.
47f9a69d 140 /* why use the overridetype? can this be removed */
141 '&amp;override_type0=text&amp;override_type1=html';
142 $Args[1]['attachment_common']['href'] =
143 set_url_var($Args[1]['attachment_common']['href'],
144 'ent_id',$Args[5]);
5bc6067b 145
146 $Args[1]['attachment_common']['text'] = _("view");
147
148 $Args[6] = $Args[1]['attachment_common']['href'];
7baf86a9 149}
150
7baf86a9 151function attachment_common_link_image(&$Args)
152{
5bc6067b 153 global $attachment_common_show_images, $attachment_common_show_images_list;
846a3a21 154
961ca3d8 155 sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
156
5bc6067b 157 $info['passed_id'] = $Args[3];
158 $info['mailbox'] = $Args[4];
159 $info['ent_id'] = $Args[5];
160
161 $attachment_common_show_images_list[] = $info;
162
961ca3d8 163 $Args[1]['attachment_common']['href'] = SM_PATH . 'src/image.php?'. $QUERY_STRING;
ff9d4297 164 $Args[1]['attachment_common']['href'] =
165 set_url_var($Args[1]['attachment_common']['href'],
166 'ent_id',$Args[5]);
cd7b8833 167
5bc6067b 168 $Args[1]['attachment_common']['text'] = _("view");
169
170 $Args[6] = $Args[1]['attachment_common']['href'];
f4c8a5ab 171
7baf86a9 172}
173
174
175function attachment_common_link_vcard(&$Args)
176{
961ca3d8 177 sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
178
179 $Args[1]['attachment_common']['href'] = SM_PATH . 'src/vcard.php?'. $QUERY_STRING;
ff9d4297 180 $Args[1]['attachment_common']['href'] =
181 set_url_var($Args[1]['attachment_common']['href'],
182 'ent_id',$Args[5]);
5bc6067b 183
184 $Args[1]['attachment_common']['text'] = _("Business Card");
185
186 $Args[6] = $Args[1]['attachment_common']['href'];
7baf86a9 187}
188
189
190function attachment_common_octet_stream(&$Args)
191{
5bc6067b 192 global $FileExtensionToMimeType;
7baf86a9 193
5bc6067b 194 do_hook('attachment_common-load_mime_types');
7baf86a9 195
5bc6067b 196 ereg('\\.([^\\.]+)$', $Args[7], $Regs);
7baf86a9 197
5bc6067b 198 $Ext = strtolower($Regs[1]);
7baf86a9 199
5bc6067b 200 if ($Ext == '' || ! isset($FileExtensionToMimeType[$Ext]))
201 return;
7baf86a9 202
5bc6067b 203 $Ret = do_hook('attachment ' . $FileExtensionToMimeType[$Ext],
204 $Args[1], $Args[2], $Args[3], $Args[4], $Args[5], $Args[6],
205 $Args[7], $Args[8], $Args[9]);
7baf86a9 206
5bc6067b 207 foreach ($Ret as $a => $b) {
208 $Args[$a] = $b;
209 }
7baf86a9 210}
211
ae2f65a9 212?>