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