3 * setup.php -- SpamCop plugin - setup script
5 * @copyright (c) 1999-2005 The SquirrelMail Project Team
6 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
12 /** Disable Quick Reporting by default */
13 global $spamcop_quick_report;
14 $spamcop_quick_report = false;
17 * Initialize the plugin
20 function squirrelmail_plugin_init_spamcop() {
21 global $squirrelmail_plugin_hooks;
23 $squirrelmail_plugin_hooks['optpage_register_block']['spamcop'] =
25 $squirrelmail_plugin_hooks['loading_prefs']['spamcop'] =
27 $squirrelmail_plugin_hooks['read_body_header_right']['spamcop'] =
29 $squirrelmail_plugin_hooks['compose_send']['spamcop'] =
30 'spamcop_while_sending';
35 * Loads spamcop settings and validates some of values (make '' into 'default', etc.)
38 function spamcop_load() {
39 global $username, $data_dir, $spamcop_enabled, $spamcop_delete, $spamcop_save,
40 $spamcop_method, $spamcop_id, $spamcop_quick_report, $spamcop_type;
42 $spamcop_enabled = getPref($data_dir, $username, 'spamcop_enabled');
43 $spamcop_delete = getPref($data_dir, $username, 'spamcop_delete');
44 $spamcop_save = getPref($data_dir, $username, 'spamcop_save',true);
45 $spamcop_method = getPref($data_dir, $username, 'spamcop_method');
46 $spamcop_type = getPref($data_dir, $username, 'spamcop_type');
47 $spamcop_id = getPref($data_dir, $username, 'spamcop_id');
48 if ($spamcop_method == '') {
49 // Default to web_form. It is faster.
50 $spamcop_method = 'web_form';
51 setPref($data_dir, $username, 'spamcop_method', $spamcop_method);
53 if (! $spamcop_quick_report && $spamcop_method=='quick_email') {
54 $spamcop_method = 'web_form';
55 setPref($data_dir, $username, 'spamcop_method', $spamcop_method);
57 if ($spamcop_type == '') {
58 $spamcop_type = 'free';
59 setPref($data_dir, $username, 'spamcop_type', $spamcop_type);
61 if ($spamcop_id == '')
67 * Shows spamcop link on the read-a-message screen
70 function spamcop_show_link() {
71 global $spamcop_enabled, $spamcop_method, $spamcop_quick_report,$javascript_on;
73 if (! $spamcop_enabled)
77 sqgetGlobalVar('passed_id', $passed_id, SQ_FORM
);
78 sqgetGlobalVar('passed_ent_id',$passed_ent_id,SQ_FORM
);
79 sqgetGlobalVar('mailbox', $mailbox, SQ_FORM
);
80 if ( sqgetGlobalVar('startMessage', $startMessage, SQ_FORM
) ) {
81 $startMessage = (int)$startMessage;
85 // catch unset passed_ent_id
86 if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_FORM
) ) {
93 Catch situation when user uses quick_email and does not update
94 preferences. User gets web_form link. If prefs are set to
95 quick_email format - they will be updated after clicking the link
97 if (! $spamcop_quick_report && $spamcop_method=='quick_email') {
98 $spamcop_method = 'web_form';
101 // Javascript is used only in web based reporting
102 // don't insert javascript if javascript is disabled
103 if ($spamcop_method == 'web_form' && $javascript_on) {
104 ?
><script language
="javascript" type
="text/javascript">
105 document
.write('<a href="../plugins/spamcop/spamcop.php?passed_id=<?php echo urlencode($passed_id); ?>&js_web=1&mailbox=<?php echo urlencode($mailbox); ?>&passed_ent_id=<?php echo urlencode($passed_ent_id); ?>" target="_blank">');
106 document
.write("<?php echo _("Report
as Spam
"); ?>");
107 document
.write("</a>");
110 ?
><a href
="../plugins/spamcop/spamcop.php?passed_id=<?php echo urlencode($passed_id); ?>&mailbox=<?php echo urlencode($mailbox); ?>&startMessage=<?php echo urlencode($startMessage); ?>&passed_ent_id=<?php echo urlencode($passed_ent_id); ?>">
111 <?php
echo _("Report as Spam"); ?
></a
>
117 * Show spamcop options block
120 function spamcop_options() {
121 global $optpage_blocks;
123 $optpage_blocks[] = array(
124 'name' => _("SpamCop - Spam Reporting"),
125 'url' => '../plugins/spamcop/options.php',
126 '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."),
133 * When we send the email, we optionally trash it then too
136 function spamcop_while_sending() {
137 global $mailbox, $spamcop_delete, $spamcop_save, $spamcop_is_composing, $auto_expunge,
138 $username, $key, $imapServerAddress, $imapPort;
140 if (sqgetGlobalVar('spamcop_is_composing' , $spamcop_is_composing)) {
141 // delete spam message
142 if ($spamcop_delete) {
143 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
145 sqimap_mailbox_select($imapConnection, $mailbox);
146 sqimap_msgs_list_delete($imapConnection, $mailbox, array($spamcop_is_composing));
148 sqimap_mailbox_expunge($imapConnection, $mailbox, true);
150 if (! $spamcop_save) {
151 // disable use of send folder.
152 // Temporally override in order to disable saving of 'reply anyway' messages.
153 global $default_move_to_sent;
154 $default_move_to_sent=false;
156 // change default email composition setting. Plugin always operates in right frame.
157 // make sure that compose.php redirects to right page. Temporally override.
158 global $compose_new_win;
159 $compose_new_win = false;