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