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