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