Adding reminder
[squirrelmail.git] / plugins / spamcop / setup.php
CommitLineData
772be735 1<?php
f3a91d6b 2/**
3 * setup.php -- SpamCop plugin - setup script
4 *
5 * @copyright (c) 1999-2004 The SquirrelMail development team
6 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
7 * @version $Id$
8 * @package plugins
9 * @subpackage spamcop
10 */
772be735 11
ea5f4b8e 12/** @ignore */
0dabfa7f 13require_once(SM_PATH . 'functions/global.php');
14
057e9d6e 15/** Disable Quick Reporting by default */
16$spamcop_quick_report = false;
0dabfa7f 17
f3a91d6b 18/**
19 * Initialize the plugin
20 * @access private
21 */
772be735 22function squirrelmail_plugin_init_spamcop() {
23 global $squirrelmail_plugin_hooks, $data_dir, $username,
24 $spamcop_is_composing;
25
26 $squirrelmail_plugin_hooks['optpage_register_block']['spamcop'] =
27 'spamcop_options';
28 $squirrelmail_plugin_hooks['loading_prefs']['spamcop'] =
29 'spamcop_load';
30 $squirrelmail_plugin_hooks['read_body_header_right']['spamcop'] =
31 'spamcop_show_link';
04f6008a 32
3267e4d8 33 sqgetGlobalVar('spamcop_is_composing' , $spamcop_is_composing);
772be735 34
35 if (isset($spamcop_is_composing)) {
36 $squirrelmail_plugin_hooks['compose_send']['spamcop'] =
37 'spamcop_while_sending';
38 }
39}
40
41
9a422982 42/**
43 * Loads spamcop settings and validates some of values (make '' into 'default', etc.)
f3a91d6b 44 * @access private
9a422982 45 */
772be735 46function spamcop_load() {
47 global $username, $data_dir, $spamcop_enabled, $spamcop_delete,
9a422982 48 $spamcop_method, $spamcop_id, $spamcop_quick_report, $spamcop_type;
772be735 49
50 $spamcop_enabled = getPref($data_dir, $username, 'spamcop_enabled');
51 $spamcop_delete = getPref($data_dir, $username, 'spamcop_delete');
52 $spamcop_method = getPref($data_dir, $username, 'spamcop_method');
9a422982 53 $spamcop_type = getPref($data_dir, $username, 'spamcop_type');
772be735 54 $spamcop_id = getPref($data_dir, $username, 'spamcop_id');
057e9d6e 55 if ($spamcop_method == '') {
9a422982 56 // Default to web_form. It is faster.
057e9d6e 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);
772be735 63 }
9a422982 64 if ($spamcop_type == '') {
65 $spamcop_type = 'free';
66 setPref($data_dir, $username, 'spamcop_type', $spamcop_type);
67 }
772be735 68 if ($spamcop_id == '')
69 $spamcop_enabled = 0;
70}
71
72
9a422982 73/**
74 * Shows spamcop link on the read-a-message screen
f3a91d6b 75 * @access private
9a422982 76 */
772be735 77function spamcop_show_link() {
9a422982 78 global $spamcop_enabled, $spamcop_method, $spamcop_quick_report,$javascript_on;
772be735 79
80 if (! $spamcop_enabled)
81 return;
82
04f6008a 83 /* GLOBALS */
555d97ec 84 sqgetGlobalVar('passed_id', $passed_id, SQ_FORM);
9a422982 85 sqgetGlobalVar('passed_ent_id',$passed_ent_id,SQ_FORM);
555d97ec 86 sqgetGlobalVar('mailbox', $mailbox, SQ_FORM);
87 sqgetGlobalVar('startMessage', $startMessage, SQ_FORM);
04f6008a 88 /* END GLOBALS */
89
9a422982 90 // catch unset passed_ent_id
91 if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_FORM) ) {
92 $passed_ent_id = 0;
93 }
94
6fd95361 95 echo "<br />\n";
057e9d6e 96
97 /*
98 Catch situation when user use quick_email and does not update
99 preferences. User gets web_form link. If prefs are set to
100 quick_email format - they will be updated after clicking the link
101 */
102 if (! $spamcop_quick_report && $spamcop_method=='quick_email') {
103 $spamcop_method = 'web_form';
104 }
772be735 105
9a422982 106 // Javascript is used only in web based reporting
107 // don't insert javascript if javascript is disabled
108 if ($spamcop_method == 'web_form' && $javascript_on) {
8ddc4111 109?><script language="javascript" type="text/javascript">
6fd95361 110document.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">');
111document.write("<?php echo _("Report as Spam"); ?>");
772be735 112document.write("</a>");
6fd95361 113</script><?php
772be735 114 } else {
6fd95361 115?><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); ?>">
116<?php echo _("Report as Spam"); ?></a>
117<?php
772be735 118 }
119}
120
9a422982 121/**
122 * Show spamcop options block
f3a91d6b 123 * @access private
9a422982 124 */
772be735 125function spamcop_options()
126{
127 global $optpage_blocks;
128
129 $optpage_blocks[] = array(
130 'name' => _("SpamCop - Spam Reporting"),
131 'url' => '../plugins/spamcop/options.php',
99aaff8b 132 '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."),
772be735 133 'js' => false
134 );
135}
136
137
9a422982 138/**
139 * When we send the email, we optionally trash it then too
f3a91d6b 140 * @access private
9a422982 141 */
772be735 142function spamcop_while_sending()
143{
144 global $mailbox, $spamcop_delete, $spamcop_is_composing, $auto_expunge,
145 $username, $key, $imapServerAddress, $imapPort;
146
147 if ($spamcop_delete) {
148 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
149 $imapPort, 0);
150 sqimap_mailbox_select($imapConnection, $mailbox);
151 sqimap_messages_delete($imapConnection, $spamcop_is_composing,
152 $spamcop_is_composing, $mailbox);
153 if ($auto_expunge)
154 sqimap_mailbox_expunge($imapConnection, $mailbox, true);
155 }
156}
157
057e9d6e 158?>