06cf3389e18021bda3ed9cc4cd80a3bdece5b9e7
[squirrelmail.git] / plugins / spamcop / setup.php
1 <?php
2 /**
3 ** setup.php -- SpamCop plugin
4 **
5 ** Copyright (c) 1999-2003 The SquirrelMail development team
6 ** Licensed under the GNU GPL. For full terms see the file COPYING.
7 **
8 ** $Id$
9 * @package plugins
10 * @subpackage spamcop
11 **/
12
13 /** @ignore */
14 require_once(SM_PATH . 'functions/global.php');
15
16 /** Disable Quick Reporting by default */
17 $spamcop_quick_report = false;
18
19 /** Initialize the plugin */
20 function squirrelmail_plugin_init_spamcop() {
21 global $squirrelmail_plugin_hooks, $data_dir, $username,
22 $spamcop_is_composing;
23
24 $squirrelmail_plugin_hooks['optpage_register_block']['spamcop'] =
25 'spamcop_options';
26 $squirrelmail_plugin_hooks['loading_prefs']['spamcop'] =
27 'spamcop_load';
28 $squirrelmail_plugin_hooks['read_body_header_right']['spamcop'] =
29 'spamcop_show_link';
30
31 sqgetGlobalVar('spamcop_is_composing' , $spamcop_is_composing);
32
33 if (isset($spamcop_is_composing)) {
34 $squirrelmail_plugin_hooks['compose_send']['spamcop'] =
35 'spamcop_while_sending';
36 }
37 }
38
39
40 // Load the settings
41 // Validate some of it (make '' into 'default', etc.)
42 function spamcop_load() {
43 global $username, $data_dir, $spamcop_enabled, $spamcop_delete,
44 $spamcop_method, $spamcop_id, $spamcop_quick_report;
45
46 $spamcop_enabled = getPref($data_dir, $username, 'spamcop_enabled');
47 $spamcop_delete = getPref($data_dir, $username, 'spamcop_delete');
48 $spamcop_method = getPref($data_dir, $username, 'spamcop_method');
49 $spamcop_id = getPref($data_dir, $username, 'spamcop_id');
50 if ($spamcop_method == '') {
51 // This variable is not used
52 // if (getPref($data_dir, $username, 'spamcop_form'))
53 // $spamcop_method = 'web_form';
54 // else
55
56 // Default to web_form. It is faster.
57 $spamcop_method = 'web_form';
58 setPref($data_dir, $username, 'spamcop_method', $spamcop_method);
59 }
60 if (! $spamcop_quick_report && $spamcop_method=='quick_email') {
61 $spamcop_method = 'web_form';
62 setPref($data_dir, $username, 'spamcop_method', $spamcop_method);
63 }
64 if ($spamcop_id == '')
65 $spamcop_enabled = 0;
66 }
67
68
69 // Show the link on the read-a-message screen
70 function spamcop_show_link() {
71 global $spamcop_enabled, $spamcop_method, $spamcop_quick_report;
72
73 if (! $spamcop_enabled)
74 return;
75
76 /* GLOBALS */
77 sqgetGlobalVar('passed_id', $passed_id, SQ_FORM);
78 sqgetGlobalVar('mailbox', $mailbox, SQ_FORM);
79 sqgetGlobalVar('startMessage', $startMessage, SQ_FORM);
80 /* END GLOBALS */
81
82 echo "<br>\n";
83
84 /*
85 Catch situation when user use quick_email and does not update
86 preferences. User gets web_form link. If prefs are set to
87 quick_email format - they will be updated after clicking the link
88 */
89 if (! $spamcop_quick_report && $spamcop_method=='quick_email') {
90 $spamcop_method = 'web_form';
91 }
92
93 if ($spamcop_method == 'web_form') {
94 ?><script language="javascript" type="text/javascript">
95 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); ?>" target="_blank">');
96 document.write("<?PHP echo _("Report as Spam"); ?>");
97 document.write("</a>");
98 </script><noscript>
99 <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); ?>">
100 <?PHP echo _("Report as Spam"); ?></a>
101 </noscript><?PHP
102 } else {
103 ?><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); ?>">
104 <?PHP echo _("Report as Spam"); ?></a>
105 <?PHP
106 }
107 }
108
109
110 // Show the link to our own custom options page
111 function spamcop_options()
112 {
113 global $optpage_blocks;
114
115 $optpage_blocks[] = array(
116 'name' => _("SpamCop - Spam Reporting"),
117 'url' => '../plugins/spamcop/options.php',
118 '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."),
119 'js' => false
120 );
121 }
122
123
124 // When we send the email, we optionally trash it then too
125 function spamcop_while_sending()
126 {
127 global $mailbox, $spamcop_delete, $spamcop_is_composing, $auto_expunge,
128 $username, $key, $imapServerAddress, $imapPort;
129
130 if ($spamcop_delete) {
131 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
132 $imapPort, 0);
133 sqimap_mailbox_select($imapConnection, $mailbox);
134 sqimap_messages_delete($imapConnection, $spamcop_is_composing,
135 $spamcop_is_composing, $mailbox);
136 if ($auto_expunge)
137 sqimap_mailbox_expunge($imapConnection, $mailbox, true);
138 }
139 }
140
141 ?>