attachment_common.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. /**
  3. * attachment_common.php
  4. *
  5. * Copyright (c) 1999-2002 The SquirrelMail Project Team
  6. * Licensed under the GNU GPL. For full terms see the file COPYING.
  7. *
  8. * This file provides the handling of often-used attachment types.
  9. *
  10. * $Id$
  11. */
  12. /*****************************************************************/
  13. /*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/
  14. /*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/
  15. /*** + Base level indent should begin at left margin, as ***/
  16. /*** the $attachment_common_show_images_list stuff below. ***/
  17. /*** + All identation should consist of four space blocks ***/
  18. /*** + Tab characters are evil. ***/
  19. /*** + all comments should use "slash-star ... star-slash" ***/
  20. /*** style -- no pound characters, no slash-slash style ***/
  21. /*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/
  22. /*** ALWAYS USE { AND } CHARACTERS!!! ***/
  23. /*** + Please use ' instead of ", when possible. Note " ***/
  24. /*** should always be used in _( ) function calls. ***/
  25. /*** Thank you for your help making the SM code more readable. ***/
  26. /*****************************************************************/
  27. global $attachment_common_show_images_list;
  28. $attachment_common_show_images_list = array();
  29. global $FileExtensionToMimeType, $attachment_common_types;
  30. $FileExtensionToMimeType = array('bmp' => 'image/x-bitmap',
  31. 'gif' => 'image/gif',
  32. 'htm' => 'text/html',
  33. 'html' => 'text/html',
  34. 'jpg' => 'image/jpeg',
  35. 'jpeg' => 'image/jpeg',
  36. 'php' => 'text/plain',
  37. 'png' => 'image/png',
  38. 'rtf' => 'text/richtext',
  39. 'txt' => 'text/plain',
  40. 'vcf' => 'text/x-vcard');
  41. // Register browser-supported image types
  42. if (isset($attachment_common_types)) {
  43. // Don't run this before being logged in. That may happen
  44. // when plugins include mime.php
  45. foreach ($attachment_common_types as $val => $v) {
  46. if ($val == 'image/gif')
  47. register_attachment_common('image/gif', 'link_image');
  48. elseif (($val == 'image/jpeg' || $val == 'image/pjpeg') and
  49. (!isset($jpeg_done))) {
  50. $jpeg_done = 1;
  51. register_attachment_common('image/jpeg', 'link_image');
  52. register_attachment_common('image/pjpeg', 'link_image');
  53. }
  54. elseif ($val == 'image/png')
  55. register_attachment_common('image/png', 'link_image');
  56. elseif ($val == 'image/x-xbitmap')
  57. register_attachment_common('image/x-xbitmap', 'link_image');
  58. }
  59. unset($jpeg_done);
  60. }
  61. // Register text-type attachments
  62. register_attachment_common('message/rfc822', 'link_text');
  63. register_attachment_common('text/plain', 'link_text');
  64. register_attachment_common('text/richtext', 'link_text');
  65. // Register HTML
  66. register_attachment_common('text/html', 'link_html');
  67. // Register vcards
  68. register_attachment_common('text/x-vcard', 'link_vcard');
  69. // Register "unknown" attachments
  70. register_attachment_common('application/octet-stream', 'octet_stream');
  71. /* Function which optimizes readability of the above code */
  72. function register_attachment_common($type, $func) {
  73. global $squirrelmail_plugin_hooks;
  74. $squirrelmail_plugin_hooks['attachment ' . $type]['attachment_common'] =
  75. 'attachment_common_' . $func;
  76. }
  77. function attachment_common_link_text(&$Args)
  78. {
  79. // If there is a text attachment, we would like to create a 'view' button
  80. // that links to the text attachment viewer.
  81. //
  82. // $Args[1] = the array of actions
  83. //
  84. // Use our plugin name for adding an action
  85. // $Args[1]['attachment_common'] = array for href and text
  86. //
  87. // $Args[1]['attachment_common']['text'] = What is displayed
  88. // $Args[1]['attachment_common']['href'] = Where it links to
  89. //
  90. // This sets the 'href' of this plugin for a new link.
  91. $Args[1]['attachment_common']['href'] = '../src/download.php?startMessage=' .
  92. $Args[2] . '&passed_id=' . $Args[3] . '&mailbox=' . $Args[4] .
  93. '&passed_ent_id=' . $Args[5] . '&override_type0=text&override_type1=plain';
  94. // If we got here from a search, we should preserve these variables
  95. if ($Args[8] && $Args[9])
  96. $Args[1]['attachment_common']['href'] .= '&where=' .
  97. urlencode($Args[8]) . '&what=' . urlencode($Args[9]);
  98. // The link that we created needs a name. "view" will be displayed for
  99. // all text attachments handled by this plugin.
  100. $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.
  105. //
  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'];
  110. }
  111. function attachment_common_link_html(&$Args)
  112. {
  113. $Args[1]['attachment_common']['href'] = '../src/download.php?startMessage=' .
  114. $Args[2] . '&passed_id=' . $Args[3] . '&mailbox=' . $Args[4] .
  115. '&passed_ent_id=' . $Args[5] . '&override_type0=text&override_type1=html';
  116. if ($Args[8] && $Args[9])
  117. $Args[1]['attachment_common']['href'] .= '&where=' .
  118. urlencode($Args[8]) . '&what=' . urlencode($Args[9]);
  119. $Args[1]['attachment_common']['text'] = _("view");
  120. $Args[6] = $Args[1]['attachment_common']['href'];
  121. }
  122. function attachment_common_link_image(&$Args)
  123. {
  124. global $attachment_common_show_images, $attachment_common_show_images_list;
  125. $info['passed_id'] = $Args[3];
  126. $info['mailbox'] = $Args[4];
  127. $info['ent_id'] = $Args[5];
  128. $attachment_common_show_images_list[] = $info;
  129. $Args[1]['attachment_common']['href'] = '../src/image.php?startMessage=' .
  130. $Args[2] . '&passed_id=' . $Args[3] . '&mailbox=' . $Args[4] .
  131. '&passed_ent_id=' . $Args[5];
  132. if ($Args[8] && $Args[9])
  133. $Args[1]['attachment_common']['href'] .= '&where=' .
  134. urlencode($Args[8]) . '&what=' . urlencode($Args[9]);
  135. $Args[1]['attachment_common']['text'] = _("view");
  136. $Args[6] = $Args[1]['attachment_common']['href'];
  137. }
  138. function attachment_common_link_vcard(&$Args)
  139. {
  140. $Args[1]['attachment_common']['href'] = '../src/vcard.php?startMessage=' .
  141. $Args[2] . '&passed_id=' . $Args[3] . '&mailbox=' . $Args[4] .
  142. '&passed_ent_id=' . $Args[5];
  143. if (isset($where) && isset($what))
  144. $Args[1]['attachment_common']['href'] .= '&where=' .
  145. urlencode($Args[8]) . '&what=' . urlencode($Args[9]);
  146. $Args[1]['attachment_common']['text'] = _("Business Card");
  147. $Args[6] = $Args[1]['attachment_common']['href'];
  148. }
  149. function attachment_common_octet_stream(&$Args)
  150. {
  151. global $FileExtensionToMimeType;
  152. do_hook('attachment_common-load_mime_types');
  153. ereg('\\.([^\\.]+)$', $Args[7], $Regs);
  154. $Ext = strtolower($Regs[1]);
  155. if ($Ext == '' || ! isset($FileExtensionToMimeType[$Ext]))
  156. return;
  157. $Ret = do_hook('attachment ' . $FileExtensionToMimeType[$Ext],
  158. $Args[1], $Args[2], $Args[3], $Args[4], $Args[5], $Args[6],
  159. $Args[7], $Args[8], $Args[9]);
  160. foreach ($Ret as $a => $b) {
  161. $Args[$a] = $b;
  162. }
  163. }
  164. ?>