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