attachment_common.php 6.8 KB

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