setup.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /* Initialize the plugin */
  3. function squirrelmail_plugin_init_spamcop() {
  4. global $squirrelmail_plugin_hooks, $data_dir, $username,
  5. $spamcop_is_composing;
  6. $squirrelmail_plugin_hooks['optpage_register_block']['spamcop'] =
  7. 'spamcop_options';
  8. $squirrelmail_plugin_hooks['loading_prefs']['spamcop'] =
  9. 'spamcop_load';
  10. $squirrelmail_plugin_hooks['read_body_header_right']['spamcop'] =
  11. 'spamcop_show_link';
  12. if (isset($spamcop_is_composing)) {
  13. $squirrelmail_plugin_hooks['compose_send']['spamcop'] =
  14. 'spamcop_while_sending';
  15. }
  16. }
  17. // Load the settings
  18. // Validate some of it (make '' into 'default', etc.)
  19. function spamcop_load() {
  20. global $username, $data_dir, $spamcop_enabled, $spamcop_delete,
  21. $spamcop_method, $spamcop_id;
  22. $spamcop_enabled = getPref($data_dir, $username, 'spamcop_enabled');
  23. $spamcop_delete = getPref($data_dir, $username, 'spamcop_delete');
  24. $spamcop_method = getPref($data_dir, $username, 'spamcop_method');
  25. $spamcop_id = getPref($data_dir, $username, 'spamcop_id');
  26. if ($spamcop_method == '') {
  27. if (getPref($data_dir, $username, 'spamcop_form'))
  28. $spamcop_method = 'web_form';
  29. else
  30. $spamcop_method = 'thorough_email';
  31. setPref($data_dir, $username, 'spamcop_method', $spamcop_method);
  32. }
  33. if ($spamcop_id == '')
  34. $spamcop_enabled = 0;
  35. }
  36. // Show the link on the read-a-message screen
  37. function spamcop_show_link() {
  38. global $passed_id, $mailbox, $ent_num, $spamcop_enabled, $startMessage,
  39. $spamcop_method;
  40. // This was stolen from printer_friendly
  41. // Do I really need/want it?
  42. if (!trim($mailbox))
  43. $mailbox = 'INBOX';
  44. if (! $spamcop_enabled)
  45. return;
  46. echo "<br>\n";
  47. if ($spamcop_method == 'web_form') {
  48. ?><script language=javascript>
  49. document.write('<a href="../plugins/spamcop/spamcop.php?passed_id=<?PHP
  50. echo urlencode($passed_id); ?>&js_web=1&mailbox=<?PHP
  51. echo urlencode($mailbox); ?>" target="_blank">');
  52. document.write("<?PHP echo _("Report as Spam"); ?>");
  53. document.write("</a>");
  54. </script><noscript>
  55. <a href="../plugins/spamcop/spamcop.php?passed_id=<?PHP
  56. echo urlencode($passed_id); ?>&mailbox=<?PHP
  57. echo urlencode($mailbox); ?>&startMessage=<?PHP
  58. echo urlencode($startMessage); ?>"><?PHP
  59. echo _("Report as Spam"); ?></a>
  60. </noscript><?PHP
  61. } else {
  62. ?><a href="../plugins/spamcop/spamcop.php?passed_id=<?PHP
  63. echo urlencode($passed_id); ?>&mailbox=<?PHP
  64. echo urlencode($mailbox); ?>&startMessage=<?PHP
  65. echo urlencode($startMessage); ?>"><?PHP
  66. echo _("Report as Spam"); ?></a><?PHP
  67. }
  68. }
  69. // Show the link to our own custom options page
  70. function spamcop_options()
  71. {
  72. global $optpage_blocks;
  73. $optpage_blocks[] = array(
  74. 'name' => _("SpamCop - Spam Reporting"),
  75. 'url' => '../plugins/spamcop/options.php',
  76. '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."),
  77. 'js' => false
  78. );
  79. }
  80. // When we send the email, we optionally trash it then too
  81. function spamcop_while_sending()
  82. {
  83. global $mailbox, $spamcop_delete, $spamcop_is_composing, $auto_expunge,
  84. $username, $key, $imapServerAddress, $imapPort;
  85. if ($spamcop_delete) {
  86. $imapConnection = sqimap_login($username, $key, $imapServerAddress,
  87. $imapPort, 0);
  88. sqimap_mailbox_select($imapConnection, $mailbox);
  89. sqimap_messages_delete($imapConnection, $spamcop_is_composing,
  90. $spamcop_is_composing, $mailbox);
  91. if ($auto_expunge)
  92. sqimap_mailbox_expunge($imapConnection, $mailbox, true);
  93. }
  94. }
  95. ?>