phpdoc blocks and one more string
[squirrelmail.git] / plugins / spamcop / setup.php
CommitLineData
772be735 1<?php
04f6008a 2 /**
3 ** setup.php -- SpamCop plugin
4 **
82d304a0 5 ** Copyright (c) 1999-2004 The SquirrelMail development team
04f6008a 6 ** Licensed under the GNU GPL. For full terms see the file COPYING.
7 **
ea5f4b8e 8 ** $Id$
9 * @package plugins
10 * @subpackage spamcop
04f6008a 11 **/
772be735 12
ea5f4b8e 13/** @ignore */
0dabfa7f 14require_once(SM_PATH . 'functions/global.php');
15
057e9d6e 16/** Disable Quick Reporting by default */
17$spamcop_quick_report = false;
0dabfa7f 18
ea5f4b8e 19/** Initialize the plugin */
772be735 20function 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';
04f6008a 30
3267e4d8 31 sqgetGlobalVar('spamcop_is_composing' , $spamcop_is_composing);
772be735 32
33 if (isset($spamcop_is_composing)) {
34 $squirrelmail_plugin_hooks['compose_send']['spamcop'] =
35 'spamcop_while_sending';
36 }
37}
38
39
9a422982 40/**
41 * Loads spamcop settings and validates some of values (make '' into 'default', etc.)
42 */
772be735 43function spamcop_load() {
44 global $username, $data_dir, $spamcop_enabled, $spamcop_delete,
9a422982 45 $spamcop_method, $spamcop_id, $spamcop_quick_report, $spamcop_type;
772be735 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');
9a422982 50 $spamcop_type = getPref($data_dir, $username, 'spamcop_type');
772be735 51 $spamcop_id = getPref($data_dir, $username, 'spamcop_id');
057e9d6e 52 if ($spamcop_method == '') {
9a422982 53 // Default to web_form. It is faster.
057e9d6e 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);
772be735 60 }
9a422982 61 if ($spamcop_type == '') {
62 $spamcop_type = 'free';
63 setPref($data_dir, $username, 'spamcop_type', $spamcop_type);
64 }
772be735 65 if ($spamcop_id == '')
66 $spamcop_enabled = 0;
67}
68
69
9a422982 70/**
71 * Shows spamcop link on the read-a-message screen
72 */
772be735 73function spamcop_show_link() {
9a422982 74 global $spamcop_enabled, $spamcop_method, $spamcop_quick_report,$javascript_on;
772be735 75
76 if (! $spamcop_enabled)
77 return;
78
04f6008a 79 /* GLOBALS */
555d97ec 80 sqgetGlobalVar('passed_id', $passed_id, SQ_FORM);
9a422982 81 sqgetGlobalVar('passed_ent_id',$passed_ent_id,SQ_FORM);
555d97ec 82 sqgetGlobalVar('mailbox', $mailbox, SQ_FORM);
83 sqgetGlobalVar('startMessage', $startMessage, SQ_FORM);
04f6008a 84 /* END GLOBALS */
85
9a422982 86 // catch unset passed_ent_id
87 if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_FORM) ) {
88 $passed_ent_id = 0;
89 }
90
772be735 91 echo "<br>\n";
057e9d6e 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 }
772be735 101
9a422982 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) {
8ddc4111 105?><script language="javascript" type="text/javascript">
9a422982 106document.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">');
772be735 107document.write("<?PHP echo _("Report as Spam"); ?>");
108document.write("</a>");
9a422982 109</script><?PHP
772be735 110 } else {
9a422982 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); ?>">
2bd52bbe 112<?PHP echo _("Report as Spam"); ?></a>
113<?PHP
772be735 114 }
115}
116
9a422982 117/**
118 * Show spamcop options block
119 */
772be735 120function 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
9a422982 133/**
134 * When we send the email, we optionally trash it then too
135 */
772be735 136function 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
057e9d6e 152?>