attachment_common.php 7.2 KB

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