Clean up spamcop plugin wrt globals.
[squirrelmail.git] / plugins / filters / spamoptions.php
CommitLineData
63277aaa 1<?php
15e6162e 2/**
3 * Message and Spam Filter Plugin
4 *
76911253 5 * Copyright (c) 1999-2003 The SquirrelMail Project Team
15e6162e 6 * Licensed under the GNU GPL. For full terms see the file COPYING.
7 *
8 * This plugin filters your inbox into different folders based upon given
9 * criteria. It is most useful for people who are subscibed to mailing lists
10 * to help organize their messages. The argument stands that filtering is
11 * not the place of the client, which is why this has been made a plugin for
12 * SquirrelMail. You may be better off using products such as Sieve or
13 * Procmail to do your filtering so it happens even when SquirrelMail isn't
14 * running.
15 *
16 * If you need help with this, or see improvements that can be made, please
17 * email me directly at the address above. I definately welcome suggestions
18 * and comments. This plugin, as is the case with all SquirrelMail plugins,
19 * is not directly supported by the developers. Please come to me off the
20 * mailing list if you have trouble with it.
21 *
22 * Also view plugins/README.plugins for more information.
23 *
24 * $Id$
25 */
63277aaa 26
08185f2a 27/* Path for SquirrelMail required files. */
28define('SM_PATH','../../');
29
30/* SquirrelMail required files. */
fca6d99e 31require_once(SM_PATH . 'include/validate.php');
08185f2a 32require_once(SM_PATH . 'functions/page_header.php');
33require_once(SM_PATH . 'functions/imap.php');
fca6d99e 34require_once(SM_PATH . 'include/load_prefs.php');
08185f2a 35require_once(SM_PATH . 'functions/html.php');
fca6d99e 36require_once(SM_PATH . 'plugins/filters/filters.php');
10a26cea 37global $AllowSpamFilters;
38
41100fce 39$username = $_SESSION['username'];
40$key = $_COOKIE['key'];
41$onetimepad = $_SESSION['onetimepad'];
42$delimiter = $_SESSION['delimiter'];
43
44if (isset($_GET['action'])) {
45 $action = $_GET['action'];
46}
47
10a26cea 48displayPageHeader($color, 'None');
49
41100fce 50if (isset($_POST['spam_submit'])) {
10a26cea 51 $spam_filters = load_spam_filters();
41100fce 52 setPref($data_dir, $username, 'filters_spam_folder', $_POST['filters_spam_folder_set']);
53 setPref($data_dir, $username, 'filters_spam_scan', $_POST['filters_spam_scan_set']);
10a26cea 54 foreach ($spam_filters as $Key => $Value) {
55 $input = $spam_filters[$Key]['prefname'] . '_set';
41100fce 56 if ( isset( $_POST[$input] ) ) {
10a26cea 57 setPref( $data_dir, $username, $spam_filters[$Key]['prefname'],
41100fce 58 $_POST[$input]);
51199e7a 59 } else {
60 removePref($data_dir, $username, $spam_filters[$Key]['prefname']);
10a26cea 61 }
62 }
63}
64
65$filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder');
66$filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan');
67$filters = load_filters();
68
b01b21d0 69echo html_tag( 'table',
70 html_tag( 'tr',
71 html_tag( 'th', _("Spam Filtering"), 'center' )
72 ) ,
73 'center', $color[0], 'width="95%" border="0" cellpadding="2" cellspacing="0"' );
10a26cea 74
75if ($SpamFilters_YourHop == ' ') {
b01b21d0 76 echo '<br>' .
77 html_tag( 'div', '<b>' .
78 _("WARNING! Tell your admin to set the SpamFilters_YourHop variable") .
79 '</b>' ,
80 'center' ) .
81 '<br>';
10a26cea 82}
83
84
85if (isset($action) && $action == 'spam') {
86 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
87 $boxes = sqimap_mailbox_list($imapConnection);
88 sqimap_logout($imapConnection);
ae48f757 89 $numboxes = count($boxes);
90
91 for ($i = 0; $i < $numboxes && $filters_spam_folder == ''; $i++) {
41100fce 92 if ((isset($boxes[$i]['flags'][0]) && $boxes[$i]['flags'][0] != 'noselect') &&
93 (isset($boxes[$i]['flags'][1]) && $boxes[$i]['flags'][1] != 'noselect') &&
94 (isset($boxes[$i]['flags'][2]) && $boxes[$i]['flags'][2] != 'noselect')) {
10a26cea 95 $filters_spam_folder = $boxes[$i]['unformatted'];
96 }
5e2e3895 97 }
98
10a26cea 99 echo '<form method=post action="spamoptions.php">'.
100 '<center>'.
b01b21d0 101 html_tag( 'table', '', '', '', 'width="85%" border="0" cellpadding="2" cellspacing="0"' ) .
102 html_tag( 'tr' ) .
103 html_tag( 'th', _("Move spam to:"), 'right', '', 'nowrap' ) .
104 html_tag( 'td', '', 'left' ) .
105 '<select name="filters_spam_folder_set">';
10a26cea 106
ae8a7931 107 $selected = 0;
108 if ( isset($filters_spam_folder) )
109 $selected = array(strtolower($filters_spam_folder));
110 echo sqimap_mailbox_option_list(0, $selected, 0, $boxes);
10a26cea 111 echo '</select>'.
112 '</td>'.
113 '</tr>'.
b01b21d0 114 html_tag( 'tr',
115 html_tag( 'td', '&nbsp;' ) .
116 html_tag( 'td',
117 _("Moving spam directly to the trash may not be a good idea at first, since messages from friends and mailing lists might accidentally be marked as spam. Whatever folder you set this to, make sure that it gets cleaned out periodically, so that you don't have an excessively large mailbox hanging around.") ,
118 'left' )
119 ) .
120 html_tag( 'tr' ) .
121 html_tag( 'th', _("What to Scan:"), 'right', '', 'nowrap' ) .
122 html_tag( 'td' ) .
123 '<select name="filters_spam_scan_set">'.
10a26cea 124 '<option value=""';
125 if ($filters_spam_scan == '') {
126 echo ' SELECTED';
127 }
128 echo '>' . _("All messages") . '</option>'.
129 '<option value="new"';
130 if ($filters_spam_scan == 'new') {
131 echo ' SELECTED';
132 }
133 echo '>' . _("Only unread messages") . '</option>' .
134 '</select>'.
135 '</td>'.
136 '</tr>'.
b01b21d0 137 html_tag( 'tr',
138 html_tag( 'td', '&nbsp;' ) .
139 html_tag( 'td',
140 _("The more messages you scan, the longer it takes. I would suggest that you scan only new messages. If you make a change to your filters, I would set it to scan all messages, then go view my INBOX, then come back and set it to scan only new messages. That way, your new spam filters will be applied and you'll scan even the spam you read with the new filters.") ,
141 'left' )
142 );
10a26cea 143
144 $spam_filters = load_spam_filters();
145
146 foreach ($spam_filters as $Key => $Value) {
b01b21d0 147 echo html_tag( 'tr' ) .
148 html_tag( 'th', $Key, 'right', '', 'nowrap' ) ."\n" .
149 html_tag( 'td' ) .
150 '<input type=checkbox name="' .
10a26cea 151 $spam_filters[$Key]['prefname'] .
152 '_set"';
153 if ($spam_filters[$Key]['enabled']) {
154 echo ' CHECKED';
155 }
156 echo '> - ';
157 if ($spam_filters[$Key]['link']) {
158 echo '<a href="' .
159 $spam_filters[$Key]['link'] .
160 '" target="_blank">';
161 }
162 echo $spam_filters[$Key]['name'];
163 if ($spam_filters[$Key]['link']) {
164 echo '</a>';
165 }
b01b21d0 166 echo '</td></tr>' .
167 html_tag( 'tr',
168 html_tag( 'td', '&nbsp;' ) .
169 html_tag( 'td', $spam_filters[$Key]['comment'], 'left' )
170 ) . "\n";
171
10a26cea 172 }
b01b21d0 173 echo html_tag( 'tr',
174 html_tag( 'td', '<input type=submit name="spam_submit" value="' . _("Save") . '">', 'center', '', 'colspan="2"' )
175 ) . "\n" .
10a26cea 176 '</table>'.
177 '</center>'.
178 '</form>';
179
180}
181
41100fce 182if (! isset($_GET['action']) || $_GET['action'] != 'spam') {
10a26cea 183
b01b21d0 184 echo html_tag( 'p', '', 'center' ) .
185 '[<a href="spamoptions.php?action=spam">' . _("Edit") . '</a>]' .
10a26cea 186 ' - [<a href="../../src/options.php">' . _("Done") . '</a>]</center><br><br>';
187 printf( _("Spam is sent to <b>%s</b>"), ($filters_spam_folder?$filters_spam_folder:_("[<i>not set yet</i>]") ) );
188 echo '<br>';
189 printf( _("Spam scan is limited to <b>%s</b>"), (($filters_spam_scan == 'new')?_("New Messages Only"):_("All Messages") ) );
190 echo '</p>'.
191 "<table border=0 cellpadding=3 cellspacing=0 align=center bgcolor=\"$color[0]\">";
192
193 $spam_filters = load_spam_filters();
194
195 foreach ($spam_filters as $Key => $Value) {
b01b21d0 196 echo html_tag( 'tr' ) .
197 html_tag( 'th', '', 'center' );
10a26cea 198
199 if ($spam_filters[$Key]['enabled']) {
200 echo _("ON");
201 } else {
202 echo _("OFF");
203 }
204
b01b21d0 205 echo '</th>' .
206 html_tag( 'td', '&nbsp;-&nbsp;', 'left' ) .
207 html_tag( 'td', '', 'left' );
10a26cea 208
209 if ($spam_filters[$Key]['link']) {
210 echo '<a href="' .
211 $spam_filters[$Key]['link'] .
212 '" target="_blank">';
213 }
214
215 echo $spam_filters[$Key]['name'];
216 if ($spam_filters[$Key]['link']) {
217 echo '</a>';
218 }
219 echo "</td></tr>\n";
220 }
221 echo '</table>';
222}
63277aaa 223
51199e7a 224?>