Happy New Year
[squirrelmail.git] / functions / attachment_common.php
index a984ed77deb3b50bc6ce13f0fc77fc94f2f26baa..69f3e06e4d3d5d521da7d95780aa4f5e268a1126 100644 (file)
@@ -5,7 +5,7 @@
  *
  * This file provides the handling of often-used attachment types.
  *
- * @copyright © 1999-2007 The SquirrelMail Project Team
+ * @copyright 1999-2021 The SquirrelMail Project Team
  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @package squirrelmail
@@ -93,6 +93,9 @@ register_attachment_common('text/html',      'link_html');
 register_attachment_common('text/x-vcard',   'link_vcard');
 register_attachment_common('text/directory', 'link_vcard');
 
+/* Register ics (calendar) */
+register_attachment_common('application/ics',  'link_text');
+
 /* Register rules for general types.
  * These will be used if there isn't a more specific rule available. */
 register_attachment_common('text/*',  'link_text');
@@ -147,8 +150,8 @@ function attachment_common_link_text(&$Args) {
        $Args[0]['attachment_common']['href'] = Where it links to */
     sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
 
-    // if htmlspecialchars() breaks something - find other way to encode & in url.
-    $Args[0]['attachment_common']['href'] = $base_uri  . 'src/view_text.php?'. htmlspecialchars($QUERY_STRING);
+    // if sm_encode_html_special_chars() breaks something - find other way to encode & in url.
+    $Args[0]['attachment_common']['href'] = $base_uri  . 'src/view_text.php?'. $QUERY_STRING;
     $Args[0]['attachment_common']['href'] =
           set_url_var($Args[0]['attachment_common']['href'],
           'ent_id',$Args[4]);
@@ -164,7 +167,7 @@ function attachment_common_link_text(&$Args) {
        This is a lot better in the image links, since the defaultLink will just
        download the image, but the one that we set it to will format the page
        to have an image tag in the center (looking a lot like this text viewer) */
-    $Args[5] = $Args[1]['attachment_common']['href'];
+    $Args[5] = $Args[0]['attachment_common']['href'];
 }
 
 /**
@@ -192,7 +195,7 @@ function attachment_common_link_html(&$Args) {
     global $base_uri;
     sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
 
-    $Args[0]['attachment_common']['href'] = $base_uri  . 'src/view_text.php?'. htmlspecialchars($QUERY_STRING).
+    $Args[0]['attachment_common']['href'] = $base_uri  . 'src/view_text.php?'. $QUERY_STRING.
         /* why use the overridetype? can this be removed */
         /* override_type might be needed only when we want view other type of messages as html */
        '&override_type0=text&override_type1=html';
@@ -223,7 +226,7 @@ function attachment_common_link_image(&$Args) {
     
     $attachment_common_show_images_list[] = $info;
 
-    $Args[0]['attachment_common']['href'] = $base_uri  . 'src/image.php?'. htmlspecialchars($QUERY_STRING);
+    $Args[0]['attachment_common']['href'] = $base_uri  . 'src/image.php?'. $QUERY_STRING;
     $Args[0]['attachment_common']['href'] =
           set_url_var($Args[0]['attachment_common']['href'],
           'ent_id',$Args[4]);
@@ -242,7 +245,7 @@ function attachment_common_link_vcard(&$Args) {
     global $base_uri;
     sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
 
-    $Args[0]['attachment_common']['href'] = $base_uri  . 'src/vcard.php?'. htmlspecialchars($QUERY_STRING);
+    $Args[0]['attachment_common']['href'] = $base_uri  . 'src/vcard.php?'. $QUERY_STRING;
     $Args[0]['attachment_common']['href'] =
           set_url_var($Args[0]['attachment_common']['href'],
           'ent_id',$Args[4]);
@@ -265,9 +268,12 @@ function attachment_common_octet_stream(&$Args) {
 //FIXME: or at least we can move this hook up to the top of this file where $FileExtensionToMimeType is defined.  What else is this hook here for?  What plugins use it?
     do_hook('attachment_common-load_mime_types', $null);
 
-    ereg('\\.([^\\.]+)$', $Args[6], $Regs);
+    preg_match('/\.([^.]+)$/', $Args[6], $Regs);
 
-    $Ext = strtolower($Regs[1]);
+    $Ext = '';
+    if (is_array($Regs) && isset($Regs[1])) {
+        $Ext = strtolower($Regs[1]);
+    }
 
     if ($Ext == '' || ! isset($FileExtensionToMimeType[$Ext]))
         return;