| 1 | <?php |
| 2 | /** |
| 3 | ** setup.php -- SpamCop plugin |
| 4 | ** |
| 5 | ** Copyright (c) 1999-2002 The SquirrelMail development team |
| 6 | ** Licensed under the GNU GPL. For full terms see the file COPYING. |
| 7 | ** |
| 8 | ** $Id$ |
| 9 | **/ |
| 10 | |
| 11 | require_once(SM_PATH . 'functions/global.php'); |
| 12 | |
| 13 | |
| 14 | /* Initialize the plugin */ |
| 15 | function squirrelmail_plugin_init_spamcop() { |
| 16 | global $squirrelmail_plugin_hooks, $data_dir, $username, |
| 17 | $spamcop_is_composing; |
| 18 | |
| 19 | $squirrelmail_plugin_hooks['optpage_register_block']['spamcop'] = |
| 20 | 'spamcop_options'; |
| 21 | $squirrelmail_plugin_hooks['loading_prefs']['spamcop'] = |
| 22 | 'spamcop_load'; |
| 23 | $squirrelmail_plugin_hooks['read_body_header_right']['spamcop'] = |
| 24 | 'spamcop_show_link'; |
| 25 | |
| 26 | sqextractGlobalVar('spamcop_is_composing'); |
| 27 | |
| 28 | if (isset($spamcop_is_composing)) { |
| 29 | $squirrelmail_plugin_hooks['compose_send']['spamcop'] = |
| 30 | 'spamcop_while_sending'; |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | |
| 35 | // Load the settings |
| 36 | // Validate some of it (make '' into 'default', etc.) |
| 37 | function spamcop_load() { |
| 38 | global $username, $data_dir, $spamcop_enabled, $spamcop_delete, |
| 39 | $spamcop_method, $spamcop_id; |
| 40 | |
| 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_id = getPref($data_dir, $username, 'spamcop_id'); |
| 45 | if ($spamcop_method == '') { |
| 46 | if (getPref($data_dir, $username, 'spamcop_form')) |
| 47 | $spamcop_method = 'web_form'; |
| 48 | else |
| 49 | $spamcop_method = 'thorough_email'; |
| 50 | setPref($data_dir, $username, 'spamcop_method', $spamcop_method); |
| 51 | } |
| 52 | if ($spamcop_id == '') |
| 53 | $spamcop_enabled = 0; |
| 54 | } |
| 55 | |
| 56 | |
| 57 | // Show the link on the read-a-message screen |
| 58 | function spamcop_show_link() { |
| 59 | global $spamcop_enabled, $spamcop_method; |
| 60 | |
| 61 | if (! $spamcop_enabled) |
| 62 | return; |
| 63 | |
| 64 | /* GLOBALS */ |
| 65 | $passed_id = $_GET['passed_id']; |
| 66 | $mailbox = $_GET['mailbox']; |
| 67 | $startMessage = $_GET['startMessage']; |
| 68 | /* END GLOBALS */ |
| 69 | |
| 70 | echo "<br>\n"; |
| 71 | |
| 72 | if ($spamcop_method == 'web_form') { |
| 73 | ?><script language=javascript> |
| 74 | document.write('<a href="../plugins/spamcop/spamcop.php?passed_id=<?PHP |
| 75 | echo urlencode($passed_id); ?>&js_web=1&mailbox=<?PHP |
| 76 | echo urlencode($mailbox); ?>" target="_blank">'); |
| 77 | document.write("<?PHP echo _("Report as Spam"); ?>"); |
| 78 | document.write("</a>"); |
| 79 | </script><noscript> |
| 80 | <a href="../plugins/spamcop/spamcop.php?passed_id=<?PHP |
| 81 | echo urlencode($passed_id); ?>&mailbox=<?PHP |
| 82 | echo urlencode($mailbox); ?>&startMessage=<?PHP |
| 83 | echo urlencode($startMessage); ?>"><?PHP |
| 84 | echo _("Report as Spam"); ?></a> |
| 85 | </noscript><?PHP |
| 86 | } else { |
| 87 | ?><a href="../plugins/spamcop/spamcop.php?passed_id=<?PHP |
| 88 | echo urlencode($passed_id); ?>&mailbox=<?PHP |
| 89 | echo urlencode($mailbox); ?>&startMessage=<?PHP |
| 90 | echo urlencode($startMessage); ?>"><?PHP |
| 91 | echo _("Report as Spam"); ?></a><?PHP |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | |
| 96 | // Show the link to our own custom options page |
| 97 | function spamcop_options() |
| 98 | { |
| 99 | global $optpage_blocks; |
| 100 | |
| 101 | $optpage_blocks[] = array( |
| 102 | 'name' => _("SpamCop - Spam Reporting"), |
| 103 | 'url' => '../plugins/spamcop/options.php', |
| 104 | '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."), |
| 105 | 'js' => false |
| 106 | ); |
| 107 | } |
| 108 | |
| 109 | |
| 110 | // When we send the email, we optionally trash it then too |
| 111 | function spamcop_while_sending() |
| 112 | { |
| 113 | global $mailbox, $spamcop_delete, $spamcop_is_composing, $auto_expunge, |
| 114 | $username, $key, $imapServerAddress, $imapPort; |
| 115 | |
| 116 | if ($spamcop_delete) { |
| 117 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, |
| 118 | $imapPort, 0); |
| 119 | sqimap_mailbox_select($imapConnection, $mailbox); |
| 120 | sqimap_messages_delete($imapConnection, $spamcop_is_composing, |
| 121 | $spamcop_is_composing, $mailbox); |
| 122 | if ($auto_expunge) |
| 123 | sqimap_mailbox_expunge($imapConnection, $mailbox, true); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | ?> |