Source for file attachment_common.php

Documentation is available at attachment_common.php

  1. <?php
  2.  
  3. /**
  4.  * attachment_common.php
  5.  *
  6.  * This file provides the handling of often-used attachment types.
  7.  *
  8.  * @copyright 1999-2020 The SquirrelMail Project Team
  9.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10.  * @version $Id: attachment_common.php 14840 2020-01-07 07:42:38Z pdontthink $
  11.  * @package squirrelmail
  12.  */
  13.  
  14. /**
  15.  * FIXME Needs phpDocumentator style documentation
  16.  */
  17. require_once(SM_PATH 'functions/global.php');
  18.  
  19. global $attachment_common_show_images_list;
  20. $attachment_common_show_images_list array();
  21.  
  22. global $FileExtensionToMimeType$attachment_common_types;
  23. $FileExtensionToMimeType array('bmp'  => 'image/x-bitmap',
  24.                                  'gif'  => 'image/gif',
  25.                                  'htm'  => 'text/html',
  26.                                  'html' => 'text/html',
  27.                                  'jpg'  => 'image/jpeg',
  28.                                  'jpeg' => 'image/jpeg',
  29.                                  'php'  => 'text/plain',
  30.                                  'png'  => 'image/png',
  31.                                  'rtf'  => 'text/richtext',
  32.                                  'txt'  => 'text/plain',
  33.                                  'patch'=> 'text/plain',
  34.                                  'vcf'  => 'text/x-vcard');
  35.  
  36. /* Register browser-supported image types */
  37. sqgetGlobalVar('attachment_common_types'$attachment_common_types);
  38. if (isset($attachment_common_types)) {
  39.     // var is used to detect activation of jpeg image types
  40.     unset($jpeg_done);
  41.     /* Don't run this before being logged in. That may happen
  42.        when plugins include mime.php */
  43.     foreach ($attachment_common_types as $val => $v{
  44.         if ($val == 'image/gif')
  45.             register_attachment_common('image/gif',       'link_image');
  46.         elseif (($val == 'image/jpeg' || $val == 'image/pjpeg'and
  47.                 (!isset($jpeg_done))) {
  48.             $jpeg_done 1;
  49.             register_attachment_common('image/jpeg',      'link_image');
  50.             register_attachment_common('image/pjpeg',     'link_image');
  51.         }
  52.         elseif ($val == 'image/png')
  53.             register_attachment_common('image/png',       'link_image');
  54.         elseif ($val == 'image/x-xbitmap')
  55.             register_attachment_common('image/x-xbitmap''link_image');
  56.         elseif ($val == '*/*' || $val == 'image/*'{
  57.             /**
  58.              * browser (Firefox) declared that anything is acceptable.
  59.              * Lets register some common image types.
  60.              */
  61.             if (isset($jpeg_done)) {
  62.                 $jpeg_done 1;
  63.                 register_attachment_common('image/jpeg',  'link_image');
  64.                 register_attachment_common('image/pjpeg''link_image');
  65.             }
  66.             register_attachment_common('image/gif',       'link_image');
  67.             register_attachment_common('image/png',       'link_image');
  68.             register_attachment_common('image/x-xbitmap''link_image');
  69.         }
  70.     }
  71.     unset($jpeg_done);
  72. }
  73.  
  74. /* Register text-type attachments */
  75. register_attachment_common('message/rfc822''link_message');
  76. register_attachment_common('text/plain',     'link_text');
  77. register_attachment_common('text/richtext',  'link_text');
  78.  
  79. /* Register HTML */
  80. register_attachment_common('text/html',      'link_html');
  81.  
  82.  
  83. /* Register vcards */
  84. register_attachment_common('text/x-vcard',   'link_vcard');
  85. register_attachment_common('text/directory''link_vcard');
  86.  
  87. /* Register rules for general types.
  88.  * These will be used if there isn't a more specific rule available. */
  89. register_attachment_common('text/*',  'link_text');
  90. register_attachment_common('message/*',  'link_text');
  91.  
  92. /* Register "unknown" attachments */
  93. register_attachment_common('application/octet-stream''octet_stream');
  94.  
  95.  
  96. /* Function which optimizes readability of the above code */
  97.  
  98. function register_attachment_common($type$func{
  99.     global $squirrelmail_plugin_hooks;
  100.     $squirrelmail_plugin_hooks['attachment ' $type]['attachment_common'=
  101.                       'attachment_common_' $func;
  102. }
  103.  
  104.  
  105. function attachment_common_link_text(&$Args{
  106.  
  107.     global $squirrelmail_attachments_finished_handling;
  108.     // TODO: The two lines below used to only depend on $Args[7] (the so-called "display filename") but that prevents attachments with the same name from having "View" links, which makes no sense.... however, was there originally some use case where this made sense??  For now, I've added the entity ID to make it unique
  109.     if (!empty($squirrelmail_attachments_finished_handling[$Args[7$Args[5]])) return;
  110.     $squirrelmail_attachments_finished_handling[$Args[7$Args[5]] TRUE;
  111.  
  112.     /* If there is a text attachment, we would like to create a "View" button
  113.        that links to the text attachment viewer.
  114.  
  115.        $Args[1] = the array of actions
  116.  
  117.        Use the name of this file for adding an action
  118.        $Args[1]['attachment_common'] = Array for href and text
  119.  
  120.        $Args[1]['attachment_common']['text'] = What is displayed
  121.        $Args[1]['attachment_common']['href'] = Where it links to */
  122.     sqgetGlobalVar('QUERY_STRING'$QUERY_STRINGSQ_SERVER);
  123.  
  124.     $Args[1]['attachment_common']['href'SM_PATH 'src/view_text.php?'$QUERY_STRING;
  125.     $Args[1]['attachment_common']['href'=
  126.           set_url_var($Args[1]['attachment_common']['href'],
  127.           'ent_id',$Args[5]);
  128.  
  129.     /* The link that we created needs a name. */
  130.     $Args[1]['attachment_common']['text'_("View");
  131.  
  132.     /* Each attachment has a filename on the left, which is a link.
  133.        Where that link points to can be changed.  Just in case the link above
  134.        for viewing text attachments is not the same as the default link for
  135.        this file, we'll change it.
  136.  
  137.        This is a lot better in the image links, since the defaultLink will just
  138.        download the image, but the one that we set it to will format the page
  139.        to have an image tag in the center (looking a lot like this text viewer) */
  140.     $Args[6$Args[1]['attachment_common']['href'];
  141. }
  142.  
  143. function attachment_common_link_message(&$Args{
  144.  
  145.     global $squirrelmail_attachments_finished_handling;
  146.     // TODO: The two lines below used to only depend on $Args[7] (the so-called "display filename") but that prevents attachments with the same name from having "View" links, which makes no sense.... however, was there originally some use case where this made sense??  For now, I've added the entity ID to make it unique
  147.     if (!empty($squirrelmail_attachments_finished_handling[$Args[7$Args[5]])) return;
  148.     $squirrelmail_attachments_finished_handling[$Args[7$Args[5]] TRUE;
  149.  
  150.     $Args[1]['attachment_common']['href'SM_PATH 'src/read_body.php?startMessage=' .
  151.         $Args[2'&amp;passed_id=' $Args[3'&amp;mailbox=' $Args[4.
  152.         '&amp;passed_ent_id=' $Args[5'&amp;override_type0=message&amp;override_type1=rfc822';
  153.  
  154.     $Args[1]['attachment_common']['text'_("View");
  155.  
  156.     $Args[6$Args[1]['attachment_common']['href'];
  157. }
  158.  
  159.  
  160. function attachment_common_link_html(&$Args{
  161.  
  162.     global $squirrelmail_attachments_finished_handling;
  163.     // TODO: The two lines below used to only depend on $Args[7] (the so-called "display filename") but that prevents attachments with the same name from having "View" links, which makes no sense.... however, was there originally some use case where this made sense??  For now, I've added the entity ID to make it unique
  164.     if (!empty($squirrelmail_attachments_finished_handling[$Args[7$Args[5]])) return;
  165.     $squirrelmail_attachments_finished_handling[$Args[7$Args[5]] TRUE;
  166.  
  167.     sqgetGlobalVar('QUERY_STRING'$QUERY_STRINGSQ_SERVER);
  168.  
  169.     $Args[1]['attachment_common']['href'SM_PATH 'src/view_text.php?'$QUERY_STRING.
  170.        /* why use the overridetype? can this be removed */
  171.        '&amp;override_type0=text&amp;override_type1=html';
  172.     $Args[1]['attachment_common']['href'=
  173.           set_url_var($Args[1]['attachment_common']['href'],
  174.           'ent_id',$Args[5]);
  175.  
  176.     $Args[1]['attachment_common']['text'_("View");
  177.  
  178.     $Args[6$Args[1]['attachment_common']['href'];
  179. }
  180.  
  181. function attachment_common_link_image(&$Args{
  182.  
  183.     global $squirrelmail_attachments_finished_handling;
  184.     // TODO: The two lines below used to only depend on $Args[7] (the so-called "display filename") but that prevents attachments with the same name from having "View" links, which makes no sense.... however, was there originally some use case where this made sense??  For now, I've added the entity ID to make it unique
  185.     if (!empty($squirrelmail_attachments_finished_handling[$Args[7$Args[5]])) return;
  186.     $squirrelmail_attachments_finished_handling[$Args[7$Args[5]] TRUE;
  187.  
  188.     global $attachment_common_show_images$attachment_common_show_images_list;
  189.  
  190.     sqgetGlobalVar('QUERY_STRING'$QUERY_STRINGSQ_SERVER);
  191.  
  192.     $info['passed_id'$Args[3];
  193.     $info['mailbox'$Args[4];
  194.     $info['ent_id'$Args[5];
  195.  
  196.     $attachment_common_show_images_list[$info;
  197.  
  198.     $Args[1]['attachment_common']['href'SM_PATH 'src/image.php?'$QUERY_STRING;
  199.     $Args[1]['attachment_common']['href'=
  200.           set_url_var($Args[1]['attachment_common']['href'],
  201.           'ent_id',$Args[5]);
  202.  
  203.     $Args[1]['attachment_common']['text'_("View");
  204.  
  205.     $Args[6$Args[1]['attachment_common']['href'];
  206. }
  207.  
  208.  
  209. function attachment_common_link_vcard(&$Args{
  210.  
  211.     global $squirrelmail_attachments_finished_handling;
  212.     // TODO: The two lines below used to only depend on $Args[7] (the so-called "display filename") but that prevents attachments with the same name from having "View" links, which makes no sense.... however, was there originally some use case where this made sense??  For now, I've added the entity ID to make it unique
  213.     if (!empty($squirrelmail_attachments_finished_handling[$Args[7$Args[5]])) return;
  214.     $squirrelmail_attachments_finished_handling[$Args[7$Args[5]] TRUE;
  215.  
  216.     sqgetGlobalVar('QUERY_STRING'$QUERY_STRINGSQ_SERVER);
  217.  
  218.     $Args[1]['attachment_common']['href'SM_PATH 'src/vcard.php?'$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 Business Card");
  224.  
  225.     $Args[6$Args[1]['attachment_common']['href'];
  226. }
  227.  
  228.  
  229. function attachment_common_octet_stream(&$Args{
  230.     global $FileExtensionToMimeType;
  231.  
  232.     do_hook('attachment_common-load_mime_types');
  233.  
  234.     preg_match('/\.([^.]+)$/'$Args[7]$Regs);
  235.  
  236.     $Ext '';
  237.     if (is_array($Regs&& isset($Regs[1])) {
  238.         $Ext $Regs[1];
  239.         $Ext strtolower($Regs[1]);
  240.     }
  241.  
  242.     if ($Ext == '' || isset($FileExtensionToMimeType[$Ext]))
  243.         return;
  244.  
  245.     $Ret do_hook('attachment ' $FileExtensionToMimeType[$Ext],
  246.         $Args[1]$Args[2]$Args[3]$Args[4]$Args[5]$Args[6],
  247.         $Args[7]$Args[8]$Args[9]);
  248.  
  249.     foreach ($Ret as $a => $b{
  250.         $Args[$a$b;
  251.     }
  252. }

Documentation generated on Mon, 13 Jan 2020 04:24:14 +0100 by phpDocumentor 1.4.3