0613a87b991ac71502b72fdf0f02250ba6870e4e
[squirrelmail.git] / plugins / spamcop / setup.php
1 <?php
2 /**
3 ** setup.php -- SpamCop plugin
4 **
5 ** Copyright (c) 1999-2004 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 /**
41 * Loads spamcop settings and validates some of values (make '' into 'default', etc.)
42 */
43 function spamcop_load() {
44 global $username, $data_dir, $spamcop_enabled, $spamcop_delete,
45 $spamcop_method, $spamcop_id, $spamcop_quick_report, $spamcop_type;
46
47 $spamcop_enabled = getPref($data_dir, $username, 'spamcop_enabled');
48 $spamcop_delete = getPref($data_dir, $username, 'spamcop_delete');
49 $spamcop_method = getPref($data_dir, $username, 'spamcop_method');
50 $spamcop_type = getPref($data_dir, $username, 'spamcop_type');
51 $spamcop_id = getPref($data_dir, $username, 'spamcop_id');
52 if ($spamcop_method == '') {
53 // Default to web_form. It is faster.
54 $spamcop_method = 'web_form';
55 setPref($data_dir, $username, 'spamcop_method', $spamcop_method);
56 }
57 if (! $spamcop_quick_report && $spamcop_method=='quick_email') {
58 $spamcop_method = 'web_form';
59 setPref($data_dir, $username, 'spamcop_method', $spamcop_method);
60 }
61 if ($spamcop_type == '') {
62 $spamcop_type = 'free';
63 setPref($data_dir, $username, 'spamcop_type', $spamcop_type);
64 }
65 if ($spamcop_id == '')
66 $spamcop_enabled = 0;
67 }
68
69
70 /**
71 * Shows spamcop link on the read-a-message screen
72 */
73 function spamcop_show_link() {
74 global $spamcop_enabled, $spamcop_method, $spamcop_quick_report,$javascript_on;
75
76 if (! $spamcop_enabled)
77 return;
78
79 /* GLOBALS */
80 sqgetGlobalVar('passed_id', $passed_id, SQ_FORM);
81 sqgetGlobalVar('passed_ent_id',$passed_ent_id,SQ_FORM);
82 sqgetGlobalVar('mailbox', $mailbox, SQ_FORM);
83 sqgetGlobalVar('startMessage', $startMessage, SQ_FORM);
84 /* END GLOBALS */
85
86 // catch unset passed_ent_id
87 if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_FORM) ) {
88 $passed_ent_id = 0;
89 }
90
91 echo "<br>\n";
92
93 /*
94 Catch situation when user use quick_email and does not update
95 preferences. User gets web_form link. If prefs are set to
96 quick_email format - they will be updated after clicking the link
97 */
98 if (! $spamcop_quick_report && $spamcop_method=='quick_email') {
99 $spamcop_method = 'web_form';
100 }
101
102 // Javascript is used only in web based reporting
103 // don't insert javascript if javascript is disabled
104 if ($spamcop_method == 'web_form' && $javascript_on) {
105 ?><script language="javascript" type="text/javascript">
106 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">');
107 document.write("<?PHP echo _("Report as Spam"); ?>");
108 document.write("</a>");
109 </script><?PHP
110 } else {
111 ?><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); ?>">
112 <?PHP echo _("Report as Spam"); ?></a>
113 <?PHP
114 }
115 }
116
117 /**
118 * Show spamcop options block
119 */
120 function spamcop_options()
121 {
122 global $optpage_blocks;
123
124 $optpage_blocks[] = array(
125 'name' => _("SpamCop - Spam Reporting"),
126 'url' => '../plugins/spamcop/options.php',
127 '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."),
128 'js' => false
129 );
130 }
131
132
133 /**
134 * When we send the email, we optionally trash it then too
135 */
136 function spamcop_while_sending()
137 {
138 global $mailbox, $spamcop_delete, $spamcop_is_composing, $auto_expunge,
139 $username, $key, $imapServerAddress, $imapPort;
140
141 if ($spamcop_delete) {
142 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
143 $imapPort, 0);
144 sqimap_mailbox_select($imapConnection, $mailbox);
145 sqimap_messages_delete($imapConnection, $spamcop_is_composing,
146 $spamcop_is_composing, $mailbox);
147 if ($auto_expunge)
148 sqimap_mailbox_expunge($imapConnection, $mailbox, true);
149 }
150 }
151
152 ?>