3 ** attachment_common.php
5 ** Copyright (c) 1999-2001 The Squirrelmail Development Team
6 ** Licensed under the GNU GPL. For full terms see the file COPYING.
8 ** This file provides the handling of often-used attachment types.
13 global $attachment_common_show_images_list;
14 $attachment_common_show_images_list = array();
16 global $FileExtensionToMimeType, $attachment_common_types;
17 $FileExtensionToMimeType = array('bmp' => 'image/x-bitmap',
20 'html' => 'text/html',
21 'jpg' => 'image/jpeg',
22 'jpeg' => 'image/jpeg',
23 'php' => 'text/plain',
25 'rtf' => 'text/richtext',
26 'txt' => 'text/plain',
27 'vcf' => 'text/x-vcard');
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))) {
39 register_attachment_common('image/jpeg', 'link_image');
40 register_attachment_common('image/pjpeg', 'link_image');
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');
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');
56 register_attachment_common('text/html', 'link_html');
59 register_attachment_common('text/x-vcard', 'link_vcard');
61 // Register "unknown" attachments
62 register_attachment_common('application/octet-stream', 'octet_stream');
65 /* Function which optimizes readability of the above code */
67 function register_attachment_common($type, $func) {
68 global $squirrelmail_plugin_hooks;
69 $squirrelmail_plugin_hooks['attachment ' . $type]['attachment_common'] =
70 'attachment_common_' . $func;
74 function attachment_common_link_text(&$Args)
76 // If there is a text attachment, we would like to create a 'view' button
77 // that links to the text attachment viewer.
79 // $Args[1] = the array of actions
81 // Use our plugin name for adding an action
82 // $Args[1]['attachment_common'] = array for href and text
84 // $Args[1]['attachment_common']['text'] = What is displayed
85 // $Args[1]['attachment_common']['href'] = Where it links to
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';
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]);
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");
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.
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'];
113 function attachment_common_link_html(&$Args)
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';
119 if ($Args[8] && $Args[9])
120 $Args[1]['attachment_common']['href'] .= '&where=' .
121 urlencode($Args[8]) . '&what=' . urlencode($Args[9]);
123 $Args[1]['attachment_common']['text'] = _("view");
125 $Args[6] = $Args[1]['attachment_common']['href'];
129 function attachment_common_link_image(&$Args)
131 global $attachment_common_show_images, $attachment_common_show_images_list;
133 $info['passed_id'] = $Args[3];
134 $info['mailbox'] = $Args[4];
135 $info['ent_id'] = $Args[5];
137 $attachment_common_show_images_list[] = $info;
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];
143 if ($Args[8] && $Args[9])
144 $Args[1]['attachment_common']['href'] .= '&where=' .
145 urlencode($Args[8]) . '&what=' . urlencode($Args[9]);
147 $Args[1]['attachment_common']['text'] = _("view");
149 $Args[6] = $Args[1]['attachment_common']['href'];
153 function attachment_common_link_vcard(&$Args)
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];
159 if (isset($where) && isset($what))
160 $Args[1]['attachment_common']['href'] .= '&where=' .
161 urlencode($Args[8]) . '&what=' . urlencode($Args[9]);
163 $Args[1]['attachment_common']['text'] = _("Business Card");
165 $Args[6] = $Args[1]['attachment_common']['href'];
169 function attachment_common_octet_stream(&$Args)
171 global $FileExtensionToMimeType;
173 do_hook('attachment_common-load_mime_types');
175 ereg('\\.([^\\.]+)$', $Args[7], $Regs);
177 $Ext = strtolower($Regs[1]);
179 if ($Ext == '' ||
! isset($FileExtensionToMimeType[$Ext]))
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]);
186 foreach ($Ret as $a => $b) {