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
13 require_once(SM_PATH
. 'functions/global.php');
15 /** Disable Quick Reporting by default */
16 $spamcop_quick_report = false;
19 * Initialize the plugin
22 function squirrelmail_plugin_init_spamcop() {
23 global $squirrelmail_plugin_hooks, $spamcop_is_composing;
25 $squirrelmail_plugin_hooks['optpage_register_block']['spamcop'] =
27 $squirrelmail_plugin_hooks['loading_prefs']['spamcop'] =
29 $squirrelmail_plugin_hooks['read_body_header_right']['spamcop'] =
32 sqgetGlobalVar('spamcop_is_composing' , $spamcop_is_composing);
34 if (isset($spamcop_is_composing)) {
35 $squirrelmail_plugin_hooks['compose_send']['spamcop'] =
36 'spamcop_while_sending';
42 * Loads spamcop settings and validates some of values (make '' into 'default', etc.)
45 function spamcop_load() {
46 global $username, $data_dir, $spamcop_enabled, $spamcop_delete,
47 $spamcop_method, $spamcop_id, $spamcop_quick_report, $spamcop_type;
49 $spamcop_enabled = getPref($data_dir, $username, 'spamcop_enabled');
50 $spamcop_delete = getPref($data_dir, $username, 'spamcop_delete');
51 $spamcop_method = getPref($data_dir, $username, 'spamcop_method');
52 $spamcop_type = getPref($data_dir, $username, 'spamcop_type');
53 $spamcop_id = getPref($data_dir, $username, 'spamcop_id');
54 if ($spamcop_method == '') {
55 // Default to web_form. It is faster.
56 $spamcop_method = 'web_form';
57 setPref($data_dir, $username, 'spamcop_method', $spamcop_method);
59 if (! $spamcop_quick_report && $spamcop_method=='quick_email') {
60 $spamcop_method = 'web_form';
61 setPref($data_dir, $username, 'spamcop_method', $spamcop_method);
63 if ($spamcop_type == '') {
64 $spamcop_type = 'free';
65 setPref($data_dir, $username, 'spamcop_type', $spamcop_type);
67 if ($spamcop_id == '')
73 * Shows spamcop link on the read-a-message screen
76 function spamcop_show_link() {
77 global $spamcop_enabled, $spamcop_method, $spamcop_quick_report,$javascript_on;
79 if (! $spamcop_enabled)
83 sqgetGlobalVar('passed_id', $passed_id, SQ_FORM
);
84 sqgetGlobalVar('passed_ent_id',$passed_ent_id,SQ_FORM
);
85 sqgetGlobalVar('mailbox', $mailbox, SQ_FORM
);
86 if ( sqgetGlobalVar('startMessage', $startMessage, SQ_FORM
) ) {
87 $startMessage = (int)$startMessage;
91 // catch unset passed_ent_id
92 if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_FORM
) ) {
99 Catch situation when user use quick_email and does not update
100 preferences. User gets web_form link. If prefs are set to
101 quick_email format - they will be updated after clicking the link
103 if (! $spamcop_quick_report && $spamcop_method=='quick_email') {
104 $spamcop_method = 'web_form';
107 // Javascript is used only in web based reporting
108 // don't insert javascript if javascript is disabled
109 if ($spamcop_method == 'web_form' && $javascript_on) {
110 ?
><script language
="javascript" type
="text/javascript">
111 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">');
112 document
.write("<?php echo _("Report
as Spam
"); ?>");
113 document
.write("</a>");
116 ?
><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); ?>">
117 <?php
echo _("Report as Spam"); ?
></a
>
123 * Show spamcop options block
126 function spamcop_options()
128 global $optpage_blocks;
130 $optpage_blocks[] = array(
131 'name' => _("SpamCop - Spam Reporting"),
132 'url' => '../plugins/spamcop/options.php',
133 '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."),
140 * When we send the email, we optionally trash it then too
143 function spamcop_while_sending()
145 global $mailbox, $spamcop_delete, $spamcop_is_composing, $auto_expunge,
146 $username, $key, $imapServerAddress, $imapPort;
148 if ($spamcop_delete) {
149 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
151 sqimap_mailbox_select($imapConnection, $mailbox);
152 sqimap_msgs_list_delete($imapConnection, $mailbox, array($spamcop_is_composing));
154 sqimap_mailbox_expunge($imapConnection, $mailbox, true);