attachment_common.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <?php
  2. /**
  3. * attachment_common.php
  4. *
  5. * Copyright (c) 1999-2005 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. * @version $Id$
  11. * @package squirrelmail
  12. */
  13. /**
  14. * FIXME Needs phpDocumentator style documentation
  15. */
  16. require_once(SM_PATH . 'functions/global.php');
  17. global $attachment_common_show_images_list;
  18. $attachment_common_show_images_list = array();
  19. global $FileExtensionToMimeType, $attachment_common_types;
  20. $FileExtensionToMimeType = array('bmp' => 'image/x-bitmap',
  21. 'gif' => 'image/gif',
  22. 'htm' => 'text/html',
  23. 'html' => 'text/html',
  24. 'jpg' => 'image/jpeg',
  25. 'jpeg' => 'image/jpeg',
  26. 'php' => 'text/plain',
  27. 'png' => 'image/png',
  28. 'rtf' => 'text/richtext',
  29. 'txt' => 'text/plain',
  30. 'patch'=> 'text/plain',
  31. 'vcf' => 'text/x-vcard');
  32. /* Register browser-supported image types */
  33. sqgetGlobalVar('attachment_common_types', $attachment_common_types);
  34. if (isset($attachment_common_types)) {
  35. /* Don't run this before being logged in. That may happen
  36. when plugins include mime.php */
  37. foreach ($attachment_common_types as $val => $v) {
  38. if ($val == 'image/gif')
  39. register_attachment_common('image/gif', 'link_image');
  40. elseif (($val == 'image/jpeg' || $val == 'image/pjpeg') and
  41. (!isset($jpeg_done))) {
  42. $jpeg_done = 1;
  43. register_attachment_common('image/jpeg', 'link_image');
  44. register_attachment_common('image/pjpeg', 'link_image');
  45. }
  46. elseif ($val == 'image/png')
  47. register_attachment_common('image/png', 'link_image');
  48. elseif ($val == 'image/x-xbitmap')
  49. register_attachment_common('image/x-xbitmap', 'link_image');
  50. }
  51. unset($jpeg_done);
  52. }
  53. /* Register text-type attachments */
  54. register_attachment_common('message/rfc822', 'link_message');
  55. register_attachment_common('text/plain', 'link_text');
  56. register_attachment_common('text/richtext', 'link_text');
  57. /* Register HTML */
  58. register_attachment_common('text/html', 'link_html');
  59. /* Register vcards */
  60. register_attachment_common('text/x-vcard', 'link_vcard');
  61. register_attachment_common('text/directory', 'link_vcard');
  62. /* Register rules for general types.
  63. * These will be used if there isn't a more specific rule available. */
  64. register_attachment_common('text/*', 'link_text');
  65. register_attachment_common('message/*', 'link_text');
  66. /* Register "unknown" attachments */
  67. register_attachment_common('application/octet-stream', 'octet_stream');
  68. /* Function which optimizes readability of the above code */
  69. function register_attachment_common($type, $func) {
  70. global $squirrelmail_plugin_hooks;
  71. $squirrelmail_plugin_hooks['attachment ' . $type]['attachment_common'] =
  72. 'attachment_common_' . $func;
  73. }
  74. function attachment_common_link_text(&$Args) {
  75. /* If there is a text attachment, we would like to create a "View" button
  76. that links to the text attachment viewer.
  77. $Args[1] = the array of actions
  78. Use the name of this file for adding an action
  79. $Args[1]['attachment_common'] = Array for href and text
  80. $Args[1]['attachment_common']['text'] = What is displayed
  81. $Args[1]['attachment_common']['href'] = Where it links to */
  82. sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
  83. $Args[1]['attachment_common']['href'] = SM_PATH . 'src/view_text.php?'. $QUERY_STRING;
  84. $Args[1]['attachment_common']['href'] =
  85. set_url_var($Args[1]['attachment_common']['href'],
  86. 'ent_id',$Args[5]);
  87. /* The link that we created needs a name. */
  88. $Args[1]['attachment_common']['text'] = _("View");
  89. /* Each attachment has a filename on the left, which is a link.
  90. Where that link points to can be changed. Just in case the link above
  91. for viewing text attachments is not the same as the default link for
  92. this file, we'll change it.
  93. This is a lot better in the image links, since the defaultLink will just
  94. download the image, but the one that we set it to will format the page
  95. to have an image tag in the center (looking a lot like this text viewer) */
  96. $Args[6] = $Args[1]['attachment_common']['href'];
  97. }
  98. function attachment_common_link_message(&$Args) {
  99. $Args[1]['attachment_common']['href'] = SM_PATH . 'src/read_body.php?startMessage=' .
  100. $Args[2] . '&amp;passed_id=' . $Args[3] . '&amp;mailbox=' . $Args[4] .
  101. '&amp;passed_ent_id=' . $Args[5] . '&amp;override_type0=message&amp;override_type1=rfc822';
  102. $Args[1]['attachment_common']['text'] = _("View");
  103. $Args[6] = $Args[1]['attachment_common']['href'];
  104. }
  105. function attachment_common_link_html(&$Args) {
  106. sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
  107. $Args[1]['attachment_common']['href'] = SM_PATH . 'src/view_text.php?'. $QUERY_STRING.
  108. /* why use the overridetype? can this be removed */
  109. '&amp;override_type0=text&amp;override_type1=html';
  110. $Args[1]['attachment_common']['href'] =
  111. set_url_var($Args[1]['attachment_common']['href'],
  112. 'ent_id',$Args[5]);
  113. $Args[1]['attachment_common']['text'] = _("View");
  114. $Args[6] = $Args[1]['attachment_common']['href'];
  115. }
  116. function attachment_common_link_image(&$Args) {
  117. global $attachment_common_show_images_list;
  118. sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
  119. $info['passed_id'] = $Args[3];
  120. $info['mailbox'] = $Args[4];
  121. $info['ent_id'] = $Args[5];
  122. $attachment_common_show_images_list[] = $info;
  123. $Args[1]['attachment_common']['href'] = SM_PATH . 'src/image.php?'. $QUERY_STRING;
  124. $Args[1]['attachment_common']['href'] =
  125. set_url_var($Args[1]['attachment_common']['href'],
  126. 'ent_id',$Args[5]);
  127. $Args[1]['attachment_common']['text'] = _("View");
  128. $Args[6] = $Args[1]['attachment_common']['href'];
  129. }
  130. function attachment_common_link_vcard(&$Args) {
  131. sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
  132. $Args[1]['attachment_common']['href'] = SM_PATH . 'src/vcard.php?'. $QUERY_STRING;
  133. $Args[1]['attachment_common']['href'] =
  134. set_url_var($Args[1]['attachment_common']['href'],
  135. 'ent_id',$Args[5]);
  136. $Args[1]['attachment_common']['text'] = _("View Business Card");
  137. $Args[6] = $Args[1]['attachment_common']['href'];
  138. }
  139. function attachment_common_octet_stream(&$Args) {
  140. global $FileExtensionToMimeType;
  141. do_hook('attachment_common-load_mime_types');
  142. ereg('\\.([^\\.]+)$', $Args[7], $Regs);
  143. $Ext = strtolower($Regs[1]);
  144. if ($Ext == '' || ! isset($FileExtensionToMimeType[$Ext]))
  145. return;
  146. $Ret = do_hook('attachment ' . $FileExtensionToMimeType[$Ext],
  147. $Args[1], $Args[2], $Args[3], $Args[4], $Args[5], $Args[6],
  148. $Args[7], $Args[8], $Args[9]);
  149. foreach ($Ret as $a => $b) {
  150. $Args[$a] = $b;
  151. }
  152. }
  153. ?>