removed $_ variables.
[squirrelmail.git] / plugins / filters / spamoptions.php
1 <?php
2 /**
3 * Message and Spam Filter Plugin
4 *
5 * Copyright (c) 1999-2004 The SquirrelMail Project Team
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 * @version $Id$
25 * @package plugins
26 * @subpackage filters
27 */
28
29 /**
30 * Path for SquirrelMail required files.
31 * @ignore
32 */
33 define('SM_PATH','../../');
34
35 /* SquirrelMail required files. */
36 require_once(SM_PATH . 'include/validate.php');
37 require_once(SM_PATH . 'functions/page_header.php');
38 require_once(SM_PATH . 'functions/imap.php');
39 require_once(SM_PATH . 'include/load_prefs.php');
40 require_once(SM_PATH . 'functions/html.php');
41 require_once(SM_PATH . 'plugins/filters/filters.php');
42 global $AllowSpamFilters;
43
44 /* get globals */
45 sqgetGlobalVar('username', $username, SQ_SESSION);
46 sqgetGlobalVar('key', $key, SQ_COOKIE);
47 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
48 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
49
50 sqgetGlobalVar('action', $action, SQ_GET);
51 /* end globals */
52
53 displayPageHeader($color, 'None');
54
55 if (sqgetGlobalVar('spam_submit',$spam_submit,SQ_POST)) {
56 $spam_filters = load_spam_filters();
57
58 // setting spam folder
59 sqgetGlobalVar('filters_spam_folder_set',$filters_spam_folder_set,SQ_POST);
60 if (isset($filters_spam_folder_set)) {
61 setPref($data_dir, $username, 'filters_spam_folder', $filters_spam_folder_set);
62 } else {
63 echo _("You must select spam folder.");
64 }
65
66 // setting scan type
67 sqgetGlobalVar('filters_spam_scan_set',$filters_spam_scan_set,SQ_POST);
68 if (isset($filters_spam_scan_set)) {
69 setPref($data_dir, $username, 'filters_spam_scan', $filters_spam_scan_set);
70 } else {
71 echo _("You must select scan type.");
72 }
73
74 foreach ($spam_filters as $Key => $Value) {
75 $input = $spam_filters[$Key]['prefname'] . '_set';
76 if ( sqgetGlobalVar($input,$input_key,SQ_POST) ) {
77 setPref( $data_dir, $username, $spam_filters[$Key]['prefname'],$input_key);
78 } else {
79 removePref($data_dir, $username, $spam_filters[$Key]['prefname']);
80 }
81 }
82 }
83
84 $filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder');
85 $filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan');
86 $filters = load_filters();
87
88 echo html_tag( 'table',
89 html_tag( 'tr',
90 html_tag( 'th', _("Spam Filtering"), 'center' )
91 ) ,
92 'center', $color[0], 'width="95%" border="0" cellpadding="2" cellspacing="0"' );
93
94 if ($SpamFilters_YourHop == ' ') {
95 echo '<br />' .
96 html_tag( 'div', '<b>' .
97 sprintf(_("WARNING! Tell your admin to set the %s variable"),'SpamFilters_YourHop') .
98 '</b>' ,
99 'center' ) .
100 '<br />';
101 }
102
103
104 if (isset($action) && $action == 'spam') {
105 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
106 $boxes = sqimap_mailbox_list($imapConnection);
107 sqimap_logout($imapConnection);
108 $numboxes = count($boxes);
109
110 for ($i = 0; $i < $numboxes && $filters_spam_folder == ''; $i++) {
111 if ((isset($boxes[$i]['flags'][0]) && $boxes[$i]['flags'][0] != 'noselect') &&
112 (isset($boxes[$i]['flags'][1]) && $boxes[$i]['flags'][1] != 'noselect') &&
113 (isset($boxes[$i]['flags'][2]) && $boxes[$i]['flags'][2] != 'noselect')) {
114 $filters_spam_folder = $boxes[$i]['unformatted'];
115 }
116 }
117
118 echo '<form method="post" action="spamoptions.php">'.
119 '<center>'.
120 html_tag( 'table', '', '', '', 'width="85%" border="0" cellpadding="2" cellspacing="0"' ) .
121 html_tag( 'tr' ) .
122 html_tag( 'th', _("Move spam to:"), 'right', '', 'nowrap' ) .
123 html_tag( 'td', '', 'left' ) .
124 '<select name="filters_spam_folder_set">';
125
126 $selected = 0;
127 if ( isset($filters_spam_folder) )
128 $selected = array(strtolower($filters_spam_folder));
129 echo sqimap_mailbox_option_list(0, $selected, 0, $boxes);
130 echo '</select>'.
131 '</td>'.
132 '</tr>'.
133 html_tag( 'tr',
134 html_tag( 'td', '&nbsp;' ) .
135 html_tag( 'td',
136 _("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.") ,
137 'left' )
138 ) .
139 html_tag( 'tr' ) .
140 html_tag( 'th', _("What to Scan:"), 'right', '', 'nowrap' ) .
141 html_tag( 'td' ) .
142 '<select name="filters_spam_scan_set">'.
143 '<option value=""';
144 if ($filters_spam_scan == '') {
145 echo ' selected';
146 }
147 echo '>' . _("All messages") . '</option>'.
148 '<option value="new"';
149 if ($filters_spam_scan == 'new') {
150 echo ' selected';
151 }
152 echo '>' . _("Only unread messages") . '</option>' .
153 '</select>'.
154 '</td>'.
155 '</tr>'.
156 html_tag( 'tr',
157 html_tag( 'td', '&nbsp;' ) .
158 html_tag( 'td',
159 _("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.") ,
160 'left' )
161 );
162
163 $spam_filters = load_spam_filters();
164
165 foreach ($spam_filters as $Key => $Value) {
166 echo html_tag( 'tr' ) .
167 html_tag( 'th', $Key, 'right', '', 'nowrap' ) ."\n" .
168 html_tag( 'td' ) .
169 '<input type="checkbox" name="' .
170 $spam_filters[$Key]['prefname'] .
171 '_set"';
172 if ($spam_filters[$Key]['enabled']) {
173 echo ' checked';
174 }
175 echo ' /> - ';
176 if ($spam_filters[$Key]['link']) {
177 echo '<a href="' .
178 $spam_filters[$Key]['link'] .
179 '" target="_blank">';
180 }
181 echo $spam_filters[$Key]['name'];
182 if ($spam_filters[$Key]['link']) {
183 echo '</a>';
184 }
185 echo '</td></tr>' .
186 html_tag( 'tr',
187 html_tag( 'td', '&nbsp;' ) .
188 html_tag( 'td', $spam_filters[$Key]['comment'], 'left' )
189 ) . "\n";
190
191 }
192 echo html_tag( 'tr',
193 html_tag( 'td', '<input type="submit" name="spam_submit" value="' . _("Save") . '" />', 'center', '', 'colspan="2"' )
194 ) . "\n" .
195 '</table>'.
196 '</center>'.
197 '</form>';
198 } else {
199 // action is not set or action is not spam
200 echo html_tag( 'p', '', 'center' ) .
201 '[<a href="spamoptions.php?action=spam">' . _("Edit") . '</a>]' .
202 ' - [<a href="../../src/options.php">' . _("Done") . '</a>]</center><br /><br />';
203 printf( _("Spam is sent to %s"), ($filters_spam_folder?'<b>'.imap_utf7_decode_local($filters_spam_folder).'</b>':'[<i>'._("not set yet").'</i>]' ) );
204 echo '<br>';
205 printf( _("Spam scan is limited to <b>%s</b>"), (($filters_spam_scan == 'new')?_("New Messages Only"):_("All Messages") ) );
206 echo '</p>'.
207 '<table border="0" cellpadding="3" cellspacing="0" align="center" bgcolor="' . $color[0] . "\">\n";
208
209 $spam_filters = load_spam_filters();
210
211 foreach ($spam_filters as $Key => $Value) {
212 echo html_tag( 'tr' ) .
213 html_tag( 'th', '', 'center' );
214
215 if ($spam_filters[$Key]['enabled']) {
216 echo _("ON");
217 } else {
218 echo _("OFF");
219 }
220
221 echo '</th>' .
222 html_tag( 'td', '&nbsp;-&nbsp;', 'left' ) .
223 html_tag( 'td', '', 'left' );
224
225 if ($spam_filters[$Key]['link']) {
226 echo '<a href="' .
227 $spam_filters[$Key]['link'] .
228 '" target="_blank">';
229 }
230
231 echo $spam_filters[$Key]['name'];
232 if ($spam_filters[$Key]['link']) {
233 echo '</a>';
234 }
235 echo "</td></tr>\n";
236 }
237 echo '</table>';
238 }
239 ?>
240 </body></html>