setup.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. /**
  3. * setup.php -- SpamCop plugin - setup script
  4. *
  5. * @copyright (c) 1999-2004 The SquirrelMail development team
  6. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  7. * @version $Id$
  8. * @package plugins
  9. * @subpackage spamcop
  10. */
  11. /** @ignore */
  12. require_once(SM_PATH . 'functions/global.php');
  13. /** Disable Quick Reporting by default */
  14. $spamcop_quick_report = false;
  15. /**
  16. * Initialize the plugin
  17. * @access private
  18. */
  19. function squirrelmail_plugin_init_spamcop() {
  20. global $squirrelmail_plugin_hooks, $data_dir, $username,
  21. $spamcop_is_composing;
  22. $squirrelmail_plugin_hooks['optpage_register_block']['spamcop'] =
  23. 'spamcop_options';
  24. $squirrelmail_plugin_hooks['loading_prefs']['spamcop'] =
  25. 'spamcop_load';
  26. $squirrelmail_plugin_hooks['read_body_header_right']['spamcop'] =
  27. 'spamcop_show_link';
  28. sqgetGlobalVar('spamcop_is_composing' , $spamcop_is_composing);
  29. if (isset($spamcop_is_composing)) {
  30. $squirrelmail_plugin_hooks['compose_send']['spamcop'] =
  31. 'spamcop_while_sending';
  32. }
  33. }
  34. /**
  35. * Loads spamcop settings and validates some of values (make '' into 'default', etc.)
  36. * @access private
  37. */
  38. function spamcop_load() {
  39. global $username, $data_dir, $spamcop_enabled, $spamcop_delete,
  40. $spamcop_method, $spamcop_id, $spamcop_quick_report, $spamcop_type;
  41. $spamcop_enabled = getPref($data_dir, $username, 'spamcop_enabled');
  42. $spamcop_delete = getPref($data_dir, $username, 'spamcop_delete');
  43. $spamcop_method = getPref($data_dir, $username, 'spamcop_method');
  44. $spamcop_type = getPref($data_dir, $username, 'spamcop_type');
  45. $spamcop_id = getPref($data_dir, $username, 'spamcop_id');
  46. if ($spamcop_method == '') {
  47. // Default to web_form. It is faster.
  48. $spamcop_method = 'web_form';
  49. setPref($data_dir, $username, 'spamcop_method', $spamcop_method);
  50. }
  51. if (! $spamcop_quick_report && $spamcop_method=='quick_email') {
  52. $spamcop_method = 'web_form';
  53. setPref($data_dir, $username, 'spamcop_method', $spamcop_method);
  54. }
  55. if ($spamcop_type == '') {
  56. $spamcop_type = 'free';
  57. setPref($data_dir, $username, 'spamcop_type', $spamcop_type);
  58. }
  59. if ($spamcop_id == '')
  60. $spamcop_enabled = 0;
  61. }
  62. /**
  63. * Shows spamcop link on the read-a-message screen
  64. * @access private
  65. */
  66. function spamcop_show_link() {
  67. global $spamcop_enabled, $spamcop_method, $spamcop_quick_report,$javascript_on;
  68. if (! $spamcop_enabled)
  69. return;
  70. /* GLOBALS */
  71. sqgetGlobalVar('passed_id', $passed_id, SQ_FORM);
  72. sqgetGlobalVar('passed_ent_id',$passed_ent_id,SQ_FORM);
  73. sqgetGlobalVar('mailbox', $mailbox, SQ_FORM);
  74. sqgetGlobalVar('startMessage', $startMessage, SQ_FORM);
  75. /* END GLOBALS */
  76. // catch unset passed_ent_id
  77. if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_FORM) ) {
  78. $passed_ent_id = 0;
  79. }
  80. echo "<br>\n";
  81. /*
  82. Catch situation when user use quick_email and does not update
  83. preferences. User gets web_form link. If prefs are set to
  84. quick_email format - they will be updated after clicking the link
  85. */
  86. if (! $spamcop_quick_report && $spamcop_method=='quick_email') {
  87. $spamcop_method = 'web_form';
  88. }
  89. // Javascript is used only in web based reporting
  90. // don't insert javascript if javascript is disabled
  91. if ($spamcop_method == 'web_form' && $javascript_on) {
  92. ?><script language="javascript" type="text/javascript">
  93. document.write('<a href="../plugins/spamcop/spamcop.php?passed_id=<?PHP echo urlencode($passed_id); ?>&amp;js_web=1&amp;mailbox=<?PHP echo urlencode($mailbox); ?>&amp;passed_ent_id=<?PHP echo urlencode($passed_ent_id); ?>" target="_blank">');
  94. document.write("<?PHP echo _("Report as Spam"); ?>");
  95. document.write("</a>");
  96. </script><?PHP
  97. } else {
  98. ?><a href="../plugins/spamcop/spamcop.php?passed_id=<?PHP echo urlencode($passed_id); ?>&amp;mailbox=<?PHP echo urlencode($mailbox); ?>&amp;startMessage=<?PHP echo urlencode($startMessage); ?>&amp;passed_ent_id=<?PHP echo urlencode($passed_ent_id); ?>">
  99. <?PHP echo _("Report as Spam"); ?></a>
  100. <?PHP
  101. }
  102. }
  103. /**
  104. * Show spamcop options block
  105. * @access private
  106. */
  107. function spamcop_options()
  108. {
  109. global $optpage_blocks;
  110. $optpage_blocks[] = array(
  111. 'name' => _("SpamCop - Spam Reporting"),
  112. 'url' => '../plugins/spamcop/options.php',
  113. 'desc' => _("Help fight the battle against unsolicited email. SpamCop reads the spam email and determines the correct addresses to send complaints to. Quite fast, really smart, and easy to use."),
  114. 'js' => false
  115. );
  116. }
  117. /**
  118. * When we send the email, we optionally trash it then too
  119. * @access private
  120. */
  121. function spamcop_while_sending()
  122. {
  123. global $mailbox, $spamcop_delete, $spamcop_is_composing, $auto_expunge,
  124. $username, $key, $imapServerAddress, $imapPort;
  125. if ($spamcop_delete) {
  126. $imapConnection = sqimap_login($username, $key, $imapServerAddress,
  127. $imapPort, 0);
  128. sqimap_mailbox_select($imapConnection, $mailbox);
  129. sqimap_messages_delete($imapConnection, $spamcop_is_composing,
  130. $spamcop_is_composing, $mailbox);
  131. if ($auto_expunge)
  132. sqimap_mailbox_expunge($imapConnection, $mailbox, true);
  133. }
  134. }
  135. ?>