adding some information about hmailserver
[squirrelmail.git] / functions / attachment_common.php
CommitLineData
7baf86a9 1<?php
7350889b 2
35586184 3/**
4 * attachment_common.php
5 *
35586184 6 * This file provides the handling of often-used attachment types.
7 *
4b4abf93 8 * @copyright &copy; 1999-2005 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
31841a9e 10 * @version $Id$
d6c32258 11 * @package squirrelmail
3169f064 12 * @todo document attachment $type hook arguments
35586184 13 */
7baf86a9 14
3169f064 15/** @ignore */
16if (! defined('SM_PATH')) define('SM_PATH','../');
17
18/** sqgetGlobalVar() */
19include_once(SM_PATH . 'functions/global.php');
20/** sqm_baseuri() */
21include_once(SM_PATH . 'functions/display_messages.php');
cd21d1aa 22
35586184 23global $attachment_common_show_images_list;
24$attachment_common_show_images_list = array();
bbdd6ddb 25
5bc6067b 26global $FileExtensionToMimeType, $attachment_common_types;
4691e788 27/**
28 * Mapping of file extensions to mime types
29 *
30 * Used for application/octet-stream mime type detection.
31 * Supported extensions: bmp, gif, htm, html, jpg, jpeg, php,
32 * png, rtf, txt, patch (since 1.4.2), vcf
33 * @global array $FileExtensionToMimeType
34 */
5bc6067b 35$FileExtensionToMimeType = array('bmp' => 'image/x-bitmap',
36 'gif' => 'image/gif',
37 'htm' => 'text/html',
38 'html' => 'text/html',
39 'jpg' => 'image/jpeg',
40 'jpeg' => 'image/jpeg',
41 'php' => 'text/plain',
42 'png' => 'image/png',
43 'rtf' => 'text/richtext',
44 'txt' => 'text/plain',
ab8b558f 45 'patch'=> 'text/plain',
5bc6067b 46 'vcf' => 'text/x-vcard');
47
48/* Register browser-supported image types */
b455793d 49sqgetGlobalVar('attachment_common_types', $attachment_common_types);
4691e788 50// FIXME: do we use $attachment_common_types that is not extracted by sqgetGlobalVar() ?
5bc6067b 51if (isset($attachment_common_types)) {
4691e788 52 // var is used to detect activation of jpeg image types
53 unset($jpeg_done);
5bc6067b 54 /* Don't run this before being logged in. That may happen
55 when plugins include mime.php */
56 foreach ($attachment_common_types as $val => $v) {
7baf86a9 57 if ($val == 'image/gif')
5bc6067b 58 register_attachment_common('image/gif', 'link_image');
7baf86a9 59 elseif (($val == 'image/jpeg' || $val == 'image/pjpeg') and
60 (!isset($jpeg_done))) {
5bc6067b 61 $jpeg_done = 1;
62 register_attachment_common('image/jpeg', 'link_image');
63 register_attachment_common('image/pjpeg', 'link_image');
4691e788 64 // register_attachment_common('image/jpg', 'link_image');
7baf86a9 65 }
66 elseif ($val == 'image/png')
5bc6067b 67 register_attachment_common('image/png', 'link_image');
7baf86a9 68 elseif ($val == 'image/x-xbitmap')
5bc6067b 69 register_attachment_common('image/x-xbitmap', 'link_image');
4691e788 70 elseif ($val == '*/*' || $val == 'image/*') {
71 /**
72 * browser (Firefox) declared that anything is acceptable.
73 * Lets register some common image types.
74 */
75 if (! isset($jpeg_done)) {
76 $jpeg_done = 1;
77 register_attachment_common('image/jpeg', 'link_image');
78 register_attachment_common('image/pjpeg', 'link_image');
79 // register_attachment_common('image/jpg', 'link_image');
80 }
81 register_attachment_common('image/gif', 'link_image');
82 register_attachment_common('image/png', 'link_image');
83 register_attachment_common('image/x-xbitmap', 'link_image');
84 // register_attachment_common('image/x-ico', 'link_image');
85 // register_attachment_common('image/x-icon', 'link_image');
86 // register_attachment_common('image/bmp', 'link_image');
87 // register_attachment_common('image/x-ms-bmp', 'link_image');
88 }
5bc6067b 89 }
90 unset($jpeg_done);
91}
7baf86a9 92
5bc6067b 93/* Register text-type attachments */
679f13b7 94register_attachment_common('message/rfc822', 'link_message');
5bc6067b 95register_attachment_common('text/plain', 'link_text');
96register_attachment_common('text/richtext', 'link_text');
7baf86a9 97
5bc6067b 98/* Register HTML */
99register_attachment_common('text/html', 'link_html');
7baf86a9 100
5bc6067b 101/* Register vcards */
102register_attachment_common('text/x-vcard', 'link_vcard');
35036cf9 103register_attachment_common('text/directory', 'link_vcard');
7baf86a9 104
ae2f65a9 105/* Register rules for general types.
106 * These will be used if there isn't a more specific rule available. */
107register_attachment_common('text/*', 'link_text');
108register_attachment_common('message/*', 'link_text');
109
5bc6067b 110/* Register "unknown" attachments */
111register_attachment_common('application/octet-stream', 'octet_stream');
7baf86a9 112
113
3169f064 114/**
115 * Function which optimizes readability of the above code
116 * Registers 'attachment $type' hooks.
117 * @param string $type attachment type
118 * @param string $func suffix of attachment_common_* function, which handles $type attachments.
119 * @since 1.2.0
120 */
7baf86a9 121function register_attachment_common($type, $func) {
5bc6067b 122 global $squirrelmail_plugin_hooks;
123 $squirrelmail_plugin_hooks['attachment ' . $type]['attachment_common'] =
7baf86a9 124 'attachment_common_' . $func;
125}
126
3169f064 127/**
128 * Adds href and text keys to attachment_common array for text attachments
129 * @param array $Args attachment $type hook arguments
130 * @since 1.2.0
131 */
21dab2dc 132function attachment_common_link_text(&$Args) {
133 /* If there is a text attachment, we would like to create a "View" button
5bc6067b 134 that links to the text attachment viewer.
62f7daa5 135
5bc6067b 136 $Args[1] = the array of actions
62f7daa5 137
21dab2dc 138 Use the name of this file for adding an action
139 $Args[1]['attachment_common'] = Array for href and text
62f7daa5 140
5bc6067b 141 $Args[1]['attachment_common']['text'] = What is displayed
21dab2dc 142 $Args[1]['attachment_common']['href'] = Where it links to */
961ca3d8 143 sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
846a3a21 144
3169f064 145 // if htmlspecialchars() breaks something - find other way to encode & in url.
146 $Args[1]['attachment_common']['href'] = sqm_baseuri() . 'src/view_text.php?'. htmlspecialchars($QUERY_STRING);
98eb617f 147 $Args[1]['attachment_common']['href'] =
62f7daa5 148 set_url_var($Args[1]['attachment_common']['href'],
21dab2dc 149 'ent_id',$Args[5]);
62f7daa5 150
21dab2dc 151 /* The link that we created needs a name. */
152 $Args[1]['attachment_common']['text'] = _("View");
679f13b7 153
5bc6067b 154 /* Each attachment has a filename on the left, which is a link.
155 Where that link points to can be changed. Just in case the link above
156 for viewing text attachments is not the same as the default link for
157 this file, we'll change it.
62f7daa5 158
5bc6067b 159 This is a lot better in the image links, since the defaultLink will just
160 download the image, but the one that we set it to will format the page
161 to have an image tag in the center (looking a lot like this text viewer) */
162 $Args[6] = $Args[1]['attachment_common']['href'];
7baf86a9 163}
164
3169f064 165/**
166 * Adds href and text keys to attachment_common array for rfc822 attachments
167 * @param array $Args attachment $type hook arguments
168 * @since 1.2.6
169 */
21dab2dc 170function attachment_common_link_message(&$Args) {
3169f064 171 $Args[1]['attachment_common']['href'] = sqm_baseuri() . 'src/read_body.php?startMessage=' .
679f13b7 172 $Args[2] . '&amp;passed_id=' . $Args[3] . '&amp;mailbox=' . $Args[4] .
173 '&amp;passed_ent_id=' . $Args[5] . '&amp;override_type0=message&amp;override_type1=rfc822';
21dab2dc 174
175 $Args[1]['attachment_common']['text'] = _("View");
f4c8a5ab 176
62f7daa5 177 $Args[6] = $Args[1]['attachment_common']['href'];
679f13b7 178}
179
3169f064 180/**
181 * Adds href and text keys to attachment_common array for html attachments
182 * @param array $Args attachment $type hook arguments
183 * @since 1.2.0
184 */
21dab2dc 185function attachment_common_link_html(&$Args) {
961ca3d8 186 sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
846a3a21 187
3169f064 188 $Args[1]['attachment_common']['href'] = sqm_baseuri() . 'src/view_text.php?'. htmlspecialchars($QUERY_STRING).
189 /* why use the overridetype? can this be removed */
190 /* override_type might be needed only when we want view other type of messages as html */
47f9a69d 191 '&amp;override_type0=text&amp;override_type1=html';
192 $Args[1]['attachment_common']['href'] =
62f7daa5 193 set_url_var($Args[1]['attachment_common']['href'],
21dab2dc 194 'ent_id',$Args[5]);
5bc6067b 195
21dab2dc 196 $Args[1]['attachment_common']['text'] = _("View");
5bc6067b 197
198 $Args[6] = $Args[1]['attachment_common']['href'];
7baf86a9 199}
200
3169f064 201/**
f8a1ed5a 202 * Adds href and text keys to attachment_common array for image attachments
3169f064 203 * @param array $Args attachment $type hook arguments
204 * @since 1.2.0
205 */
21dab2dc 206function attachment_common_link_image(&$Args) {
ce68b76b 207 global $attachment_common_show_images_list;
846a3a21 208
961ca3d8 209 sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
62f7daa5 210
5bc6067b 211 $info['passed_id'] = $Args[3];
212 $info['mailbox'] = $Args[4];
213 $info['ent_id'] = $Args[5];
62f7daa5 214
5bc6067b 215 $attachment_common_show_images_list[] = $info;
62f7daa5 216
3169f064 217 $Args[1]['attachment_common']['href'] = sqm_baseuri() . 'src/image.php?'. htmlspecialchars($QUERY_STRING);
ff9d4297 218 $Args[1]['attachment_common']['href'] =
62f7daa5 219 set_url_var($Args[1]['attachment_common']['href'],
21dab2dc 220 'ent_id',$Args[5]);
62f7daa5 221
21dab2dc 222 $Args[1]['attachment_common']['text'] = _("View");
62f7daa5 223
5bc6067b 224 $Args[6] = $Args[1]['attachment_common']['href'];
7baf86a9 225}
226
3169f064 227/**
f8a1ed5a 228 * Adds href and text keys to attachment_common array for vcard attachments
3169f064 229 * @param array $Args attachment $type hook arguments
230 * @since 1.2.0
231 */
21dab2dc 232function attachment_common_link_vcard(&$Args) {
961ca3d8 233 sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
62f7daa5 234
3169f064 235 $Args[1]['attachment_common']['href'] = sqm_baseuri() . 'src/vcard.php?'. htmlspecialchars($QUERY_STRING);
ff9d4297 236 $Args[1]['attachment_common']['href'] =
62f7daa5 237 set_url_var($Args[1]['attachment_common']['href'],
21dab2dc 238 'ent_id',$Args[5]);
62f7daa5 239
c9fec394 240 $Args[1]['attachment_common']['text'] = _("View Business Card");
62f7daa5 241
5bc6067b 242 $Args[6] = $Args[1]['attachment_common']['href'];
7baf86a9 243}
244
3169f064 245/**
246 * Processes octet-stream attachments.
f8a1ed5a 247 * Calls attachment_common-load_mime_types and attachment $type hooks.
3169f064 248 * @param array $Args attachment $type hook arguments
249 * @since 1.2.0
250 */
21dab2dc 251function attachment_common_octet_stream(&$Args) {
5bc6067b 252 global $FileExtensionToMimeType;
62f7daa5 253
5bc6067b 254 do_hook('attachment_common-load_mime_types');
62f7daa5 255
5bc6067b 256 ereg('\\.([^\\.]+)$', $Args[7], $Regs);
62f7daa5 257
5bc6067b 258 $Ext = strtolower($Regs[1]);
62f7daa5 259
5bc6067b 260 if ($Ext == '' || ! isset($FileExtensionToMimeType[$Ext]))
62f7daa5 261 return;
262
263 $Ret = do_hook('attachment ' . $FileExtensionToMimeType[$Ext],
264 $Args[1], $Args[2], $Args[3], $Args[4], $Args[5], $Args[6],
5bc6067b 265 $Args[7], $Args[8], $Args[9]);
62f7daa5 266
5bc6067b 267 foreach ($Ret as $a => $b) {
268 $Args[$a] = $b;
269 }
7baf86a9 270}
271
62f7daa5 272?>