Drop obsolete ORDB RBL from filters plugin, thanks Tomas Kuliavas (#1629398).
[squirrelmail.git] / plugins / filters / filters.php
CommitLineData
849bdf42 1<?php
4b4abf93 2
15e6162e 3/**
0a1dc88e 4 * Message and Spam Filter Plugin - Filtering Functions
15e6162e 5 *
47ccfad4 6 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
b2d8bc6c 7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
4b4abf93 8 * @version $Id$
ea5f4b8e 9 * @package plugins
10 * @subpackage filters
15e6162e 11 */
4eee5968 12
202bcbcc 13/**
14 * do not allow to call this file directly
15 */
24afb0e9 16if ((isset($_SERVER['SCRIPT_FILENAME']) && $_SERVER['SCRIPT_FILENAME'] == __FILE__) ||
17 (isset($HTTP_SERVER_SERVER['SCRIPT_FILENAME']) && $HTTP_SERVER_SERVER['SCRIPT_FILENAME'] == __FILE__) ) {
202bcbcc 18 header("Location: ../../src/login.php");
19 die();
20}
e5c8ec61 21
22/** load globals */
48879ef0 23global $UseSeparateImapConnection,
24 $AllowSpamFilters, $SpamFilters_YourHop, $SpamFilters_ShowCommercial,
25 $SpamFilters_DNScache, $SpamFilters_BulkQuery, $SpamFilters_SharedCache,
e5c8ec61 26 $SpamFilters_CacheTTL;
27
3bde2539 28/**
29 * load required functions. Plugin depends on IMAP functions and they are not
30 * loaded in src/webmail.php
31 */
32include_once (SM_PATH . 'functions/imap.php');
33
e5c8ec61 34/** load default config */
35if (file_exists(SM_PATH . 'plugins/filters/config_default.php')) {
36 include_once (SM_PATH . 'plugins/filters/config_default.php');
37} else {
38 // default config was removed.
39 $UseSeparateImapConnection = false;
40 $AllowSpamFilters = true;
41 $SpamFilters_YourHop = ' ';
42 $SpamFilters_ShowCommercial = false;
43 $SpamFilters_DNScache = array();
44 $SpamFilters_BulkQuery = '';
45 $SpamFilters_SharedCache = true;
46 $SpamFilters_CacheTTL = 7200;
47}
48
49if (file_exists(SM_PATH . 'config/filters_config.php')) {
50 include_once (SM_PATH . 'config/filters_config.php');
51} elseif (file_exists(SM_PATH . 'plugins/filters/config.php')) {
8510adf2 52 include_once (SM_PATH . 'plugins/filters/config.php');
e5c8ec61 53}
9c655416 54
ea5f4b8e 55/**
9c655416 56 * Register option blocks
57 * @access private
58 */
59function filters_optpage_register_block() {
60 global $optpage_blocks, $AllowSpamFilters;
f8a1ed5a 61
9c655416 62 $optpage_blocks[] = array(
63 'name' => _("Message Filters"),
64 'url' => SM_PATH . 'plugins/filters/options.php',
65 'desc' => _("Filtering enables messages with different criteria to be automatically filtered into different folders for easier organization."),
66 'js' => false
67 );
68
69 if ($AllowSpamFilters) {
70 $optpage_blocks[] = array(
71 'name' => _("SPAM Filters"),
72 'url' => SM_PATH . 'plugins/filters/spamoptions.php',
73 'desc' => _("SPAM filters allow you to select from various DNS based blacklists to detect junk email in your INBOX and move it to another folder (like Trash)."),
74 'js' => false
75 );
76 }
77}
78
48879ef0 79/* Receive the status of the folder and do something with it */
80function filters_folder_status($statusarr) {
81
b2f4cdad 82 global $filter_inbox_count;
83 if (empty($filter_inbox_count)) $filter_inbox_count=0;
202bcbcc 84
b2f4cdad 85 if ($statusarr['MAILBOX'] == 'INBOX')
48879ef0 86 {
87 if (!empty($statusarr['MESSAGES'])) $filter_inbox_count=$statusarr['MESSAGES'];
88 }
89}
90
9c655416 91/**
92 * Saves the DNS Cache to disk
0a1dc88e 93 * @access private
5b4ba967 94 */
a2a566eb 95function filters_SaveCache () {
96 global $data_dir, $SpamFilters_DNScache;
97
ae48f757 98 if (file_exists($data_dir . '/dnscache')) {
99 $fp = fopen($data_dir . '/dnscache', 'r');
a2a566eb 100 } else {
101 $fp = false;
102 }
103 if ($fp) {
104 flock($fp,LOCK_EX);
105 } else {
ae48f757 106 $fp = fopen($data_dir . '/dnscache', 'w+');
a2a566eb 107 fclose($fp);
ae48f757 108 $fp = fopen($data_dir . '/dnscache', 'r');
a2a566eb 109 flock($fp,LOCK_EX);
110 }
9c655416 111 $fp1 = fopen($data_dir . '/dnscache', 'w+');
a2a566eb 112
113 foreach ($SpamFilters_DNScache as $Key=> $Value) {
114 $tstr = $Key . ',' . $Value['L'] . ',' . $Value['T'] . "\n";
115 fputs ($fp1, $tstr);
116 }
117 fclose($fp1);
118 flock($fp,LOCK_UN);
119 fclose($fp);
120}
121
0a1dc88e 122/**
9c655416 123 * Loads the DNS Cache from disk
0a1dc88e 124 * @access private
125 */
a2a566eb 126function filters_LoadCache () {
127 global $data_dir, $SpamFilters_DNScache;
128
ae48f757 129 if (file_exists($data_dir . '/dnscache')) {
6ade76e0 130 $SpamFilters_DNScache = array();
ae48f757 131 if ($fp = fopen ($data_dir . '/dnscache', 'r')) {
a2a566eb 132 flock($fp,LOCK_SH);
9c655416 133 while ($data = fgetcsv($fp,1024)) {
a2a566eb 134 if ($data[2] > time()) {
135 $SpamFilters_DNScache[$data[0]]['L'] = $data[1];
136 $SpamFilters_DNScache[$data[0]]['T'] = $data[2];
137 }
138 }
a2a566eb 139 flock($fp,LOCK_UN);
140 }
141 }
142}
143
0a1dc88e 144/**
9c655416 145 * Uses the BulkQuery executable to query all the RBLs at once
146 * @param array $filters Array of SPAM Fitlers
147 * @param array $IPs Array of IP Addresses
0a1dc88e 148 * @access private
149 */
fb577a4d 150function filters_bulkquery($filters, $IPs) {
ce68b76b 151 global $attachment_dir, $username,
6ade76e0 152 $SpamFilters_DNScache, $SpamFilters_BulkQuery,
153 $SpamFilters_CacheTTL;
a2a566eb 154
a2a566eb 155 if (count($IPs) > 0) {
156 $rbls = array();
157 foreach ($filters as $key => $value) {
158 if ($filters[$key]['enabled']) {
159 if ($filters[$key]['dns']) {
160 $rbls[$filters[$key]['dns']] = true;
161 }
162 }
163 }
164
ae48f757 165 $bqfil = $attachment_dir . $username . '-bq.in';
166 $fp = fopen($bqfil, 'w');
6ade76e0 167 fputs ($fp, $SpamFilters_CacheTTL . "\n");
a2a566eb 168 foreach ($rbls as $key => $value) {
ae48f757 169 fputs ($fp, '.' . $key . "\n");
a2a566eb 170 }
171 fputs ($fp, "----------\n");
172 foreach ($IPs as $key => $value) {
173 fputs ($fp, $key . "\n");
174 }
175 fclose ($fp);
176 $bqout = array();
ae48f757 177 exec ($SpamFilters_BulkQuery . ' < ' . $bqfil, $bqout);
a2a566eb 178 foreach ($bqout as $value) {
179 $Chunks = explode(',', $value);
180 $SpamFilters_DNScache[$Chunks[0]]['L'] = $Chunks[1];
181 $SpamFilters_DNScache[$Chunks[0]]['T'] = $Chunks[2] + time();
182 }
183 unlink($bqfil);
184 }
185}
186
0a1dc88e 187/**
9c655416 188 * Starts the filtering process
b2f4cdad 189 * @param array $hook_args (since 1.5.2) do hook arguments. Is used to check
190 * hook name, array key = 0.
0a1dc88e 191 * @access private
192 */
b2f4cdad 193function start_filters($hook_args) {
ce68b76b 194 global $imapServerAddress, $imapPort, $imap_stream, $imapConnection,
2128bbc6 195 $UseSeparateImapConnection, $AllowSpamFilters, $filter_inbox_count,
196 $username;
10a26cea 197
b2f4cdad 198 /**
199 * check hook that calls filtering. If filters are called by right_main_after_header,
200 * do filtering only when we are in INBOX folder.
201 */
202 if ($hook_args[0]=='right_main_after_header' &&
203 (sqgetGlobalVar('mailbox',$mailbox,SQ_FORM) && $mailbox!='INBOX')) {
204 return;
205 }
206
9a43a06b 207 $filters = load_filters();
208
209 // No point running spam filters if there aren't any to run //
210 if ($AllowSpamFilters) {
211 $spamfilters = load_spam_filters();
212
213 $AllowSpamFilters = false;
c02ae58e 214 foreach($spamfilters as $filterskey=>$value) {
9a43a06b 215 if ($value['enabled'] == 'yes') {
216 $AllowSpamFilters = true;
217 break;
218 }
219 }
220 }
221
222 if (!$AllowSpamFilters && empty($filters)) {
223 return;
224 }
225
226
2714d4ff 227 // Detect if we have already connected to IMAP or not.
228 // Also check if we are forced to use a separate IMAP connection
229 if ((!isset($imap_stream) && !isset($imapConnection)) ||
230 $UseSeparateImapConnection ) {
2128bbc6 231 $stream = sqimap_login($username, false, $imapServerAddress,
1320cab5 232 $imapPort, 10);
233 $previously_connected = false;
2714d4ff 234 } else if (isset($imapConnection)) {
235 $stream = $imapConnection;
236 $previously_connected = true;
237 } else {
238 $previously_connected = true;
239 $stream = $imap_stream;
240 }
4eee5968 241
48879ef0 242 if (!isset($filter_inbox_count)) {
243 $aStatus = sqimap_status_messages ($stream, 'INBOX', array('MESSAGES'));
244 if (!empty($aStatus['MESSAGES'])) {
245 $filter_inbox_count=$aStatus['MESSAGES'];
246 } else {
247 $filter_inbox_count=0;
248 }
249 }
250
251 if ($filter_inbox_count > 0) {
2714d4ff 252 sqimap_mailbox_select($stream, 'INBOX');
253 // Filter spam from inbox before we sort them into folders
254 if ($AllowSpamFilters) {
255 spam_filters($stream);
10a26cea 256 }
4eee5968 257
2714d4ff 258 // Sort into folders
259 user_filters($stream);
260 }
261
262 if (!$previously_connected) {
263 sqimap_logout($stream);
264 }
10a26cea 265}
266
0a1dc88e 267/**
9c655416 268 * Does the loop through each filter
269 * @param stream imap_stream the stream to read from
0a1dc88e 270 * @access private
271 */
10a26cea 272function user_filters($imap_stream) {
c8a2c24d 273 global $data_dir, $username;
10a26cea 274 $filters = load_filters();
275 if (! $filters) return;
c8a2c24d 276 $filters_user_scan = getPref($data_dir, $username, 'filters_user_scan');
10a26cea 277
fb577a4d 278 $expunge = false;
53fcc494 279 // For every rule
ae48f757 280 for ($i=0, $num = count($filters); $i < $num; $i++) {
10a26cea 281 // If it is the "combo" rule
282 if ($filters[$i]['where'] == 'To or Cc') {
53fcc494 283 /*
284 * If it's "TO OR CC", we have to do two searches, one for TO
285 * and the other for CC.
286 */
fb577a4d 287 $expunge = filter_search_and_delete($imap_stream, 'TO',
288 $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge);
289 $expunge = filter_search_and_delete($imap_stream, 'CC',
290 $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge);
8a7ccd82 291 } else if ($filters[$i]['where'] == 'Header and Body') {
292 $expunge = filter_search_and_delete($imap_stream, 'TEXT',
293 $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge);
294 } else if ($filters[$i]['where'] == 'Message Body') {
295 $expunge = filter_search_and_delete($imap_stream, 'BODY',
f8a1ed5a 296 $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge);
10a26cea 297 } else {
53fcc494 298 /*
299 * If it's a normal TO, CC, SUBJECT, or FROM, then handle it
300 * normally.
301 */
fb577a4d 302 $expunge = filter_search_and_delete($imap_stream, $filters[$i]['where'],
303 $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge);
4eee5968 304 }
4eee5968 305 }
53fcc494 306 // Clean out the mailbox whether or not auto_expunge is on
307 // That way it looks like it was redirected properly
fb577a4d 308 if ($expunge) {
4f6915b0 309 sqimap_mailbox_expunge($imap_stream, 'INBOX');
53fcc494 310 }
10a26cea 311}
312
0a1dc88e 313/**
9c655416 314 * Creates and runs the IMAP command to filter messages
315 * @param string $where Which part of the message to search (TO, CC, SUBJECT, etc...)
316 * @param string $what String to search for
317 * @param string $where_to Folder it will move to
318 * @param string $user_scan Whether to search all or just unseen
f8a1ed5a 319 * @param string $should_expunge
9c655416 320 * @param boolean $where Which part of location to search
0a1dc88e 321 * @access private
322 */
2714d4ff 323function filter_search_and_delete($imap_stream, $where, $what, $where_to, $user_scan,
fb577a4d 324 $should_expunge) {
6201339c 325 global $languages, $squirrelmail_language, $allow_charset_search, $imap_server_type;
326
1320cab5 327 //TODO: make use of new mailbox cache. See mailbox_display.phpinfo
328
174523e3 329 if (strtolower($where_to) == 'inbox') {
330 return array();
331 }
332
c8a2c24d 333 if ($user_scan == 'new') {
334 $category = 'UNSEEN';
335 } else {
336 $category = 'ALL';
337 }
86e6d79f 338 $category .= ' UNDELETED';
c8a2c24d 339
3eea00ca 340 if ($allow_charset_search &&
341 isset($languages[$squirrelmail_language]['CHARSET']) &&
53fcc494 342 $languages[$squirrelmail_language]['CHARSET']) {
3eea00ca 343 $search_str = 'SEARCH CHARSET '
344 . strtoupper($languages[$squirrelmail_language]['CHARSET'])
345 . ' ' . $category;
f9ca4be0 346 } else {
3eea00ca 347 $search_str = 'SEARCH CHARSET US-ASCII ' . $category;
f9ca4be0 348 }
ae48f757 349 if ($where == 'Header') {
3eea00ca 350 $what = explode(':', $what);
1320cab5 351 $where = strtoupper($where);
3eea00ca 352 $where = trim($where . ' ' . $what[0]);
353 $what = addslashes(trim($what[1]));
9da6bdde 354 }
f18ea37e 355
cf2aa192 356 // see comments in squirrelmail sqimap_search function
357 if ($imap_server_type == 'macosx' || $imap_server_type == 'hmailserver') {
1320cab5 358 $search_str .= ' ' . $where . ' ' . $what;
359 /* read data back from IMAP */
360 $read = sqimap_run_command($imap_stream, $search_str, true, $response, $message, TRUE);
f18ea37e 361 } else {
1320cab5 362 $search_str .= ' ' . $where . ' {' . strlen($what) . "}";
363 $sid = sqimap_session_id(true);
364 fputs ($imap_stream, $sid . ' ' . $search_str . "\r\n");
365 $read2 = sqimap_fgets($imap_stream);
366 # server should respond with Ready for argument, then we will send search text
367 #echo "RR2 $read2<br>";
368 fputs ($imap_stream, "$what\r\n");
369 #echo "SS $what<br>";
370 $read2 = sqimap_fgets($imap_stream);
371 #echo "RR2 $read2<br>";
372 $read[]=$read2;
373 $read3 = sqimap_fgets($imap_stream);
374 #echo "RR3 $read3<br>";
375 list($rtag,$response,$message)=explode(' ',$read3,3);
376## $read2 = sqimap_retrieve_imap_response($imap_stream, $sid, true,
377## $response, $message, $search_str, false, true, false);
378 #echo "RR2 $read2 / RESPONSE $response<br>";
f18ea37e 379 }
10a26cea 380
2714d4ff 381 if (isset($read[0])) {
382 $ids = array();
9c655416 383 for ($i = 0, $iCnt = count($read); $i < $iCnt; ++$i) {
2714d4ff 384 if (preg_match("/^\* SEARCH (.+)$/", $read[$i], $regs)) {
1320cab5 385 $ids += preg_split("/ /", trim($regs[1]));
fb577a4d 386 }
2714d4ff 387 }
388 if ($response == 'OK' && count($ids)) {
389 if (sqimap_mailbox_exists($imap_stream, $where_to)) {
390 $should_expunge = true;
4e6e5d2d 391 sqimap_msgs_list_move ($imap_stream, $ids, $where_to, false);
4eee5968 392 }
1320cab5 393 } elseif ($response != 'OK') {
9cda618e 394 $query = $search_str . "\r\n".$what ."\r\n";
1320cab5 395 if ($response == 'NO') {
1320cab5 396 if (strpos($message,'BADCHARSET') !== false ||
397 strpos($message,'character') !== false) {
398 sqm_trigger_imap_error('SQM_IMAP_BADCHARSET',$query, $response, $message);
399 } else {
400 sqm_trigger_imap_error('SQM_IMAP_ERROR',$query, $response, $message);
401 }
402 } else {
403 sqm_trigger_imap_error('SQM_IMAP_ERROR',$query, $response, $message);
404 }
4eee5968 405 }
406 }
fb577a4d 407 return $should_expunge;
10a26cea 408}
4eee5968 409
0a1dc88e 410/**
9c655416 411 * Loops through all the Received Headers to find IP Addresses
412 * @param stream imap_stream the stream to read from
0a1dc88e 413 * @access private
414 */
10a26cea 415function spam_filters($imap_stream) {
6201339c 416 global $data_dir, $username;
10a26cea 417 global $SpamFilters_YourHop;
418 global $SpamFilters_DNScache;
a2a566eb 419 global $SpamFilters_SharedCache;
420 global $SpamFilters_BulkQuery;
fb577a4d 421 global $SpamFilters_CacheTTL;
4eee5968 422
10a26cea 423 $filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan');
424 $filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder');
425 $filters = load_spam_filters();
4eee5968 426
a2a566eb 427 if ($SpamFilters_SharedCache) {
428 filters_LoadCache();
429 }
430
fb577a4d 431 $run = false;
4eee5968 432
fb577a4d 433 foreach ($filters as $Key => $Value) {
10a26cea 434 if ($Value['enabled']) {
fb577a4d 435 $run = true;
436 break;
4eee5968 437 }
10a26cea 438 }
4eee5968 439
10a26cea 440 // short-circuit
fb577a4d 441 if (!$run) {
10a26cea 442 return;
443 }
4eee5968 444
10a26cea 445 // Ask for a big list of all "Received" headers in the inbox with
446 // flags for each message. Kinda big.
2714d4ff 447
448 if ($filters_spam_scan == 'new') {
449 $search_array = array();
6201339c 450 $read = sqimap_run_command($imap_stream, 'SEARCH UNSEEN', true, $response, $message, TRUE);
2714d4ff 451 if (isset($read[0])) {
9c655416 452 for ($i = 0, $iCnt = count($read); $i < $iCnt; ++$i) {
2714d4ff 453 if (preg_match("/^\* SEARCH (.+)$/", $read[$i], $regs)) {
6174dcc7 454 $search_array = preg_split("/ /", trim($regs[1]));
2714d4ff 455 break;
6174dcc7 456 }
c8a2c24d 457 }
2714d4ff 458 }
c8a2c24d 459 }
2714d4ff 460 if ($filters_spam_scan == 'new' && count($search_array)) {
d3fae94f 461 $headers = sqimap_get_small_header_list ($imap_stream, $search_array, array('Received'),array());
2714d4ff 462 } else if ($filters_spam_scan != 'new') {
d3fae94f 463 $headers = sqimap_get_small_header_list ($imap_stream, null , array('Received'),array());
2714d4ff 464 } else {
465 return;
466 }
467 if (!count($headers)) {
10a26cea 468 return;
469 }
fb577a4d 470 $bulkquery = (strlen($SpamFilters_BulkQuery) > 0 ? true : false);
471 $IPs = array();
472 $aSpamIds = array();
473 foreach ($headers as $id => $aValue) {
2714d4ff 474 if (isset($aValue['UID'])) {
fb577a4d 475 $MsgNum = $aValue['UID'];
476 } else {
477 $MsgNum = $id;
10a26cea 478 }
10a26cea 479 // Look through all of the Received headers for IP addresses
2714d4ff 480 if (isset($aValue['RECEIVED'])) {
481 foreach ($aValue['RECEIVED'] as $received) {
fb577a4d 482 // Check to see if this line is the right "Received from" line
483 // to check
2714d4ff 484
485 // $aValue['Received'] is an array with all the received lines.
fb577a4d 486 // We should check them from bottom to top and only check the first 2.
487 // Currently we check only the header where $SpamFilters_YourHop in occures
2714d4ff 488
fb577a4d 489 if (is_int(strpos($received, $SpamFilters_YourHop))) {
490 if (preg_match('/([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/',$received,$aMatch)) {
491 $isspam = false;
492 if (filters_spam_check_site($aMatch[1],$aMatch[2],$aMatch[3],$aMatch[4],$filters)) {
493 $aSpamIds[] = $MsgNum;
494 $isspam = true;
495 }
496 if ($bulkquery) {
497 array_shift($aMatch);
498 $IP = explode('.',$aMatch);
499 foreach ($filters as $key => $value) {
500 if ($filters[$key]['enabled'] && $filters[$key]['dns']) {
501 if (strlen($SpamFilters_DNScache[$IP.'.'.$filters[$key]['dns']]) == 0) {
502 $IPs[$IP] = true;
503 break;
504 }
505 }
506 }
c8a2c24d 507 }
508 // If we've checked one IP and YourHop is
509 // just a space
fb577a4d 510 if ($SpamFilters_YourHop == ' ' || $isspam) {
c8a2c24d 511 break; // don't check any more
a9aa7ab7 512 }
a9aa7ab7 513 }
4eee5968 514 }
4eee5968 515 }
4eee5968 516 }
10a26cea 517 }
fb577a4d 518 // Lookie! It's spam! Yum!
519 if (count($aSpamIds) && sqimap_mailbox_exists($imap_stream, $filters_spam_folder)) {
520 sqimap_msgs_list_move ($imap_stream, $aSpamIds, $filters_spam_folder);
521 sqimap_mailbox_expunge($imap_stream, 'INBOX');
522 }
4eee5968 523
fb577a4d 524 if ($bulkquery && count($IPs)) {
525 filters_bulkquery($filters, $IPs);
526 }
4eee5968 527
a2a566eb 528 if ($SpamFilters_SharedCache) {
529 filters_SaveCache();
530 } else {
41100fce 531 sqsession_register($SpamFilters_DNScache, 'SpamFilters_DNScache');
a2a566eb 532 }
10a26cea 533}
4eee5968 534
0a1dc88e 535/**
0a1dc88e 536 * Does the loop through each enabled filter for the specified IP address.
537 * IP format: $a.$b.$c.$d
9c655416 538 * @param int $a First subset of IP
539 * @param int $b Second subset of IP
540 * @param int $c Third subset of IP
541 * @param int $d Forth subset of IP
542 * @param array $filters The Spam Filters
543 * @return boolean Whether the IP is Spam
0a1dc88e 544 * @access private
545 */
10a26cea 546function filters_spam_check_site($a, $b, $c, $d, &$filters) {
a2a566eb 547 global $SpamFilters_DNScache, $SpamFilters_CacheTTL;
10a26cea 548 foreach ($filters as $key => $value) {
549 if ($filters[$key]['enabled']) {
550 if ($filters[$key]['dns']) {
551 $filter_revip = $d . '.' . $c . '.' . $b . '.' . $a . '.' .
552 $filters[$key]['dns'];
ae48f757 553
554 if(!isset($SpamFilters_DNScache[$filter_revip]['L']))
555 $SpamFilters_DNScache[$filter_revip]['L'] = '';
556
557 if(!isset($SpamFilters_DNScache[$filter_revip]['T']))
558 $SpamFilters_DNScache[$filter_revip]['T'] = '';
559
a7cd90dd 560 if (strlen($SpamFilters_DNScache[$filter_revip]['L']) == 0) {
561 $SpamFilters_DNScache[$filter_revip]['L'] =
562 gethostbyname($filter_revip);
563 $SpamFilters_DNScache[$filter_revip]['T'] =
564 time() + $SpamFilters_CacheTTL;
565 }
566 if ($SpamFilters_DNScache[$filter_revip]['L'] ==
567 $filters[$key]['result']) {
568 return 1;
4eee5968 569 }
570 }
571 }
4eee5968 572 }
10a26cea 573 return 0;
574}
575
0a1dc88e 576/**
9c655416 577 * Loads the filters from the user preferences
578 * @return array All the user filters
0a1dc88e 579 * @access private
580 */
10a26cea 581function load_filters() {
582 global $data_dir, $username;
c8a2c24d 583
10a26cea 584 $filters = array();
9c655416 585 for ($i = 0; $fltr = getPref($data_dir, $username, 'filter' . $i); $i++) {
10a26cea 586 $ary = explode(',', $fltr);
587 $filters[$i]['where'] = $ary[0];
588 $filters[$i]['what'] = $ary[1];
589 $filters[$i]['folder'] = $ary[2];
4eee5968 590 }
10a26cea 591 return $filters;
592}
593
0a1dc88e 594/**
9c655416 595 * Loads the Spam Filters and checks the preferences for the enabled status
596 * @return array All the spam filters
0a1dc88e 597 * @access private
598 */
10a26cea 599function load_spam_filters() {
51199e7a 600 global $data_dir, $username, $SpamFilters_ShowCommercial;
601
602 if ($SpamFilters_ShowCommercial) {
603 $filters['MAPS RBL']['prefname'] = 'filters_spam_maps_rbl';
604 $filters['MAPS RBL']['name'] = 'MAPS Realtime Blackhole List';
605 $filters['MAPS RBL']['link'] = 'http://www.mail-abuse.org/rbl/';
606 $filters['MAPS RBL']['dns'] = 'blackholes.mail-abuse.org';
607 $filters['MAPS RBL']['result'] = '127.0.0.2';
608 $filters['MAPS RBL']['comment'] =
609 _("COMMERCIAL - This list contains servers that are verified spam senders. It is a pretty reliable list to scan spam from.");
610
611 $filters['MAPS RSS']['prefname'] = 'filters_spam_maps_rss';
612 $filters['MAPS RSS']['name'] = 'MAPS Relay Spam Stopper';
613 $filters['MAPS RSS']['link'] = 'http://www.mail-abuse.org/rss/';
614 $filters['MAPS RSS']['dns'] = 'relays.mail-abuse.org';
615 $filters['MAPS RSS']['result'] = '127.0.0.2';
616 $filters['MAPS RSS']['comment'] =
99aaff8b 617 _("COMMERCIAL - Servers that are configured (or misconfigured) to allow spam to be relayed through their system will be banned with this. Another good one to use.");
51199e7a 618
619 $filters['MAPS DUL']['prefname'] = 'filters_spam_maps_dul';
620 $filters['MAPS DUL']['name'] = 'MAPS Dial-Up List';
621 $filters['MAPS DUL']['link'] = 'http://www.mail-abuse.org/dul/';
622 $filters['MAPS DUL']['dns'] = 'dialups.mail-abuse.org';
623 $filters['MAPS DUL']['result'] = '127.0.0.3';
624 $filters['MAPS DUL']['comment'] =
99aaff8b 625 _("COMMERCIAL - Dial-up users are often filtered out since they should use their ISP's mail servers to send mail. Spammers typically get a dial-up account and send spam directly from there.");
51199e7a 626
627 $filters['MAPS RBLplus-RBL']['prefname'] = 'filters_spam_maps_rblplus_rbl';
628 $filters['MAPS RBLplus-RBL']['name'] = 'MAPS RBL+ RBL List';
629 $filters['MAPS RBLplus-RBL']['link'] = 'http://www.mail-abuse.org/';
630 $filters['MAPS RBLplus-RBL']['dns'] = 'rbl-plus.mail-abuse.org';
631 $filters['MAPS RBLplus-RBL']['result'] = '127.0.0.2';
632 $filters['MAPS RBLplus-RBL']['comment'] =
633 _("COMMERCIAL - RBL+ Blackhole entries.");
634
635 $filters['MAPS RBLplus-RSS']['prefname'] = 'filters_spam_maps_rblplus_rss';
636 $filters['MAPS RBLplus-RSS']['name'] = 'MAPS RBL+ List RSS entries';
637 $filters['MAPS RBLplus-RSS']['link'] = 'http://www.mail-abuse.org/';
638 $filters['MAPS RBLplus-RSS']['dns'] = 'rbl-plus.mail-abuse.org';
639 $filters['MAPS RBLplus-RSS']['result'] = '127.0.0.2';
640 $filters['MAPS RBLplus-RSS']['comment'] =
641 _("COMMERCIAL - RBL+ OpenRelay entries.");
642
643 $filters['MAPS RBLplus-DUL']['prefname'] = 'filters_spam_maps_rblplus_dul';
644 $filters['MAPS RBLplus-DUL']['name'] = 'MAPS RBL+ List DUL entries';
645 $filters['MAPS RBLplus-DUL']['link'] = 'http://www.mail-abuse.org/';
646 $filters['MAPS RBLplus-DUL']['dns'] = 'rbl-plus.mail-abuse.org';
647 $filters['MAPS RBLplus-DUL']['result'] = '127.0.0.3';
648 $filters['MAPS RBLplus-DUL']['comment'] =
649 _("COMMERCIAL - RBL+ Dial-up entries.");
650 }
10a26cea 651
10a26cea 652 $filters['FiveTen Direct']['prefname'] = 'filters_spam_fiveten_src';
653 $filters['FiveTen Direct']['name'] = 'Five-Ten-sg.com Direct SPAM Sources';
654 $filters['FiveTen Direct']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
655 $filters['FiveTen Direct']['dns'] = 'blackholes.five-ten-sg.com';
656 $filters['FiveTen Direct']['result'] = '127.0.0.2';
657 $filters['FiveTen Direct']['comment'] =
658 _("FREE - Five-Ten-sg.com - Direct SPAM sources.");
659
660 $filters['FiveTen DUL']['prefname'] = 'filters_spam_fiveten_dul';
661 $filters['FiveTen DUL']['name'] = 'Five-Ten-sg.com DUL Lists';
662 $filters['FiveTen DUL']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
663 $filters['FiveTen DUL']['dns'] = 'blackholes.five-ten-sg.com';
664 $filters['FiveTen DUL']['result'] = '127.0.0.3';
665 $filters['FiveTen DUL']['comment'] =
666 _("FREE - Five-Ten-sg.com - Dial-up lists - includes some DSL IPs.");
667
668 $filters['FiveTen Unc. OptIn']['prefname'] = 'filters_spam_fiveten_oi';
669 $filters['FiveTen Unc. OptIn']['name'] = 'Five-Ten-sg.com Unconfirmed OptIn Lists';
670 $filters['FiveTen Unc. OptIn']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
671 $filters['FiveTen Unc. OptIn']['dns'] = 'blackholes.five-ten-sg.com';
672 $filters['FiveTen Unc. OptIn']['result'] = '127.0.0.4';
673 $filters['FiveTen Unc. OptIn']['comment'] =
674 _("FREE - Five-Ten-sg.com - Bulk mailers that do not use confirmed opt-in.");
675
676 $filters['FiveTen Others']['prefname'] = 'filters_spam_fiveten_oth';
677 $filters['FiveTen Others']['name'] = 'Five-Ten-sg.com Other Misc. Servers';
678 $filters['FiveTen Others']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
679 $filters['FiveTen Others']['dns'] = 'blackholes.five-ten-sg.com';
680 $filters['FiveTen Others']['result'] = '127.0.0.5';
681 $filters['FiveTen Others']['comment'] =
682 _("FREE - Five-Ten-sg.com - Other misc. servers.");
683
684 $filters['FiveTen Single Stage']['prefname'] = 'filters_spam_fiveten_ss';
685 $filters['FiveTen Single Stage']['name'] = 'Five-Ten-sg.com Single Stage Servers';
686 $filters['FiveTen Single Stage']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
687 $filters['FiveTen Single Stage']['dns'] = 'blackholes.five-ten-sg.com';
688 $filters['FiveTen Single Stage']['result'] = '127.0.0.6';
689 $filters['FiveTen Single Stage']['comment'] =
690 _("FREE - Five-Ten-sg.com - Single Stage servers.");
691
692 $filters['FiveTen SPAM Support']['prefname'] = 'filters_spam_fiveten_supp';
693 $filters['FiveTen SPAM Support']['name'] = 'Five-Ten-sg.com SPAM Support Servers';
694 $filters['FiveTen SPAM Support']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
695 $filters['FiveTen SPAM Support']['dns'] = 'blackholes.five-ten-sg.com';
696 $filters['FiveTen SPAM Support']['result'] = '127.0.0.7';
697 $filters['FiveTen SPAM Support']['comment'] =
698 _("FREE - Five-Ten-sg.com - SPAM Support servers.");
699
700 $filters['FiveTen Web forms']['prefname'] = 'filters_spam_fiveten_wf';
701 $filters['FiveTen Web forms']['name'] = 'Five-Ten-sg.com Web Form IPs';
702 $filters['FiveTen Web forms']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
703 $filters['FiveTen Web forms']['dns'] = 'blackholes.five-ten-sg.com';
704 $filters['FiveTen Web forms']['result'] = '127.0.0.8';
705 $filters['FiveTen Web forms']['comment'] =
706 _("FREE - Five-Ten-sg.com - Web Form IPs.");
707
708 $filters['Dorkslayers']['prefname'] = 'filters_spam_dorks';
709 $filters['Dorkslayers']['name'] = 'Dorkslayers Lists';
710 $filters['Dorkslayers']['link'] = 'http://www.dorkslayers.com';
711 $filters['Dorkslayers']['dns'] = 'orbs.dorkslayers.com';
712 $filters['Dorkslayers']['result'] = '127.0.0.2';
713 $filters['Dorkslayers']['comment'] =
714 _("FREE - Dorkslayers appears to include only really bad open relays outside the US to avoid being sued. Interestingly enough, their website recommends you NOT use their service.");
715
716 $filters['SPAMhaus']['prefname'] = 'filters_spam_spamhaus';
717 $filters['SPAMhaus']['name'] = 'SPAMhaus Lists';
718 $filters['SPAMhaus']['link'] = 'http://www.spamhaus.org';
719 $filters['SPAMhaus']['dns'] = 'sbl.spamhaus.org';
720 $filters['SPAMhaus']['result'] = '127.0.0.6';
721 $filters['SPAMhaus']['comment'] =
722 _("FREE - SPAMhaus - A list of well-known SPAM sources.");
723
724 $filters['SPAMcop']['prefname'] = 'filters_spam_spamcop';
725 $filters['SPAMcop']['name'] = 'SPAM Cop Lists';
726 $filters['SPAMcop']['link'] = 'http://spamcop.net/bl.shtml';
727 $filters['SPAMcop']['dns'] = 'bl.spamcop.net';
728 $filters['SPAMcop']['result'] = '127.0.0.2';
729 $filters['SPAMcop']['comment'] =
ace4e0d3 730 _("FREE, for now - SpamCop - An interesting solution that lists servers that have a very high spam to legit email ratio (85 percent or more).");
10a26cea 731
46a184ff 732 $filters['dev.null.dk']['prefname'] = 'filters_spam_devnull';
733 $filters['dev.null.dk']['name'] = 'dev.null.dk Lists';
734 $filters['dev.null.dk']['link'] = 'http://dev.null.dk/';
735 $filters['dev.null.dk']['dns'] = 'dev.null.dk';
736 $filters['dev.null.dk']['result'] = '127.0.0.2';
737 $filters['dev.null.dk']['comment'] =
738 _("FREE - dev.null.dk - I don't have any detailed info on this list.");
739
740 $filters['visi.com']['prefname'] = 'filters_spam_visi';
741 $filters['visi.com']['name'] = 'visi.com Relay Stop List';
742 $filters['visi.com']['link'] = 'http://relays.visi.com';
743 $filters['visi.com']['dns'] = 'relays.visi.com';
744 $filters['visi.com']['result'] = '127.0.0.2';
745 $filters['visi.com']['comment'] =
746 _("FREE - visi.com - Relay Stop List. Very conservative OpenRelay List.");
747
bd35ab2b 748 $filters['ahbl.org Open Relays']['prefname'] = 'filters_spam_2mb_or';
749 $filters['ahbl.org Open Relays']['name'] = 'ahbl.org Open Relays List';
750 $filters['ahbl.org Open Relays']['link'] = 'http://www.ahbl.org/';
751 $filters['ahbl.org Open Relays']['dns'] = 'dnsbl.ahbl.org';
752 $filters['ahbl.org Open Relays']['result'] = '127.0.0.2';
753 $filters['ahbl.org Open Relays']['comment'] =
754 _("FREE - ahbl.org Open Relays - Another list of Open Relays.");
755
756 $filters['ahbl.org SPAM Source']['prefname'] = 'filters_spam_2mb_ss';
757 $filters['ahbl.org SPAM Source']['name'] = 'ahbl.org SPAM Source List';
758 $filters['ahbl.org SPAM Source']['link'] = 'http://www.ahbl.org/';
759 $filters['ahbl.org SPAM Source']['dns'] = 'dnsbl.ahbl.org';
760 $filters['ahbl.org SPAM Source']['result'] = '127.0.0.4';
761 $filters['ahbl.org SPAM Source']['comment'] =
762 _("FREE - ahbl.org SPAM Source - List of Direct SPAM Sources.");
763
764 $filters['ahbl.org SPAM ISPs']['prefname'] = 'filters_spam_2mb_isp';
765 $filters['ahbl.org SPAM ISPs']['name'] = 'ahbl.org SPAM-friendly ISP List';
766 $filters['ahbl.org SPAM ISPs']['link'] = 'http://www.ahbl.org/';
767 $filters['ahbl.org SPAM ISPs']['dns'] = 'dnsbl.ahbl.org';
768 $filters['ahbl.org SPAM ISPs']['result'] = '127.0.0.7';
769 $filters['ahbl.org SPAM ISPs']['comment'] =
770 _("FREE - ahbl.org SPAM ISPs - List of SPAM-friendly ISPs.");
46a184ff 771
772 $filters['Leadmon DUL']['prefname'] = 'filters_spam_lm_dul';
773 $filters['Leadmon DUL']['name'] = 'Leadmon.net DUL List';
774 $filters['Leadmon DUL']['link'] = 'http://www.leadmon.net/spamguard/';
775 $filters['Leadmon DUL']['dns'] = 'spamguard.leadmon.net';
776 $filters['Leadmon DUL']['result'] = '127.0.0.2';
777 $filters['Leadmon DUL']['comment'] =
778 _("FREE - Leadmon DUL - Another list of Dial-up or otherwise dynamically assigned IPs.");
779
780 $filters['Leadmon SPAM Source']['prefname'] = 'filters_spam_lm_ss';
781 $filters['Leadmon SPAM Source']['name'] = 'Leadmon.net SPAM Source List';
782 $filters['Leadmon SPAM Source']['link'] = 'http://www.leadmon.net/spamguard/';
783 $filters['Leadmon SPAM Source']['dns'] = 'spamguard.leadmon.net';
784 $filters['Leadmon SPAM Source']['result'] = '127.0.0.3';
785 $filters['Leadmon SPAM Source']['comment'] =
786 _("FREE - Leadmon SPAM Source - List of IPs Leadmon.net has received SPAM directly from.");
787
788 $filters['Leadmon Bulk Mailers']['prefname'] = 'filters_spam_lm_bm';
789 $filters['Leadmon Bulk Mailers']['name'] = 'Leadmon.net Bulk Mailers List';
790 $filters['Leadmon Bulk Mailers']['link'] = 'http://www.leadmon.net/spamguard/';
791 $filters['Leadmon Bulk Mailers']['dns'] = 'spamguard.leadmon.net';
792 $filters['Leadmon Bulk Mailers']['result'] = '127.0.0.4';
793 $filters['Leadmon Bulk Mailers']['comment'] =
794 _("FREE - Leadmon Bulk Mailers - Bulk mailers that do not require confirmed opt-in or that have allowed known spammers to become clients and abuse their services.");
795
796 $filters['Leadmon Open Relays']['prefname'] = 'filters_spam_lm_or';
797 $filters['Leadmon Open Relays']['name'] = 'Leadmon.net Open Relays List';
798 $filters['Leadmon Open Relays']['link'] = 'http://www.leadmon.net/spamguard/';
799 $filters['Leadmon Open Relays']['dns'] = 'spamguard.leadmon.net';
800 $filters['Leadmon Open Relays']['result'] = '127.0.0.5';
801 $filters['Leadmon Open Relays']['comment'] =
802 _("FREE - Leadmon Open Relays - Single Stage Open Relays that are not listed on other active RBLs.");
803
804 $filters['Leadmon Multi-stage']['prefname'] = 'filters_spam_lm_ms';
805 $filters['Leadmon Multi-stage']['name'] = 'Leadmon.net Multi-Stage Relay List';
806 $filters['Leadmon Multi-stage']['link'] = 'http://www.leadmon.net/spamguard/';
807 $filters['Leadmon Multi-stage']['dns'] = 'spamguard.leadmon.net';
808 $filters['Leadmon Multi-stage']['result'] = '127.0.0.6';
809 $filters['Leadmon Multi-stage']['comment'] =
810 _("FREE - Leadmon Multi-stage - Multi-Stage Open Relays that are not listed on other active RBLs and that have sent SPAM to Leadmon.net.");
811
812 $filters['Leadmon SpamBlock']['prefname'] = 'filters_spam_lm_sb';
813 $filters['Leadmon SpamBlock']['name'] = 'Leadmon.net SpamBlock Sites List';
814 $filters['Leadmon SpamBlock']['link'] = 'http://www.leadmon.net/spamguard/';
815 $filters['Leadmon SpamBlock']['dns'] = 'spamguard.leadmon.net';
816 $filters['Leadmon SpamBlock']['result'] = '127.0.0.7';
817 $filters['Leadmon SpamBlock']['comment'] =
818 _("FREE - Leadmon SpamBlock - Sites on this listing have sent Leadmon.net direct SPAM from IPs in netblocks where the entire block has no DNS mappings. It's a list of BLOCKS of IPs being used by people who have SPAMmed Leadmon.net.");
819
820 $filters['NJABL Open Relays']['prefname'] = 'filters_spam_njabl_or';
821 $filters['NJABL Open Relays']['name'] = 'NJABL Open Relay/Direct Spam Source List';
822 $filters['NJABL Open Relays']['link'] = 'http://www.njabl.org/';
823 $filters['NJABL Open Relays']['dns'] = 'dnsbl.njabl.org';
824 $filters['NJABL Open Relays']['result'] = '127.0.0.2';
825 $filters['NJABL Open Relays']['comment'] =
826 _("FREE, for now - Not Just Another Blacklist - Both Open Relays and Direct SPAM Sources.");
827
828 $filters['NJABL DUL']['prefname'] = 'filters_spam_njabl_dul';
829 $filters['NJABL DUL']['name'] = 'NJABL Dial-ups List';
830 $filters['NJABL DUL']['link'] = 'http://www.njabl.org/';
831 $filters['NJABL DUL']['dns'] = 'dnsbl.njabl.org';
832 $filters['NJABL DUL']['result'] = '127.0.0.3';
833 $filters['NJABL DUL']['comment'] =
834 _("FREE, for now - Not Just Another Blacklist - Dial-up IPs.");
835
18b078e9 836 $filters['Conf DSBL.ORG Relay']['prefname'] = 'filters_spam_dsbl_conf_ss';
837 $filters['Conf DSBL.ORG Relay']['name'] = 'DSBL.org Confirmed Relay List';
838 $filters['Conf DSBL.ORG Relay']['link'] = 'http://www.dsbl.org/';
839 $filters['Conf DSBL.ORG Relay']['dns'] = 'list.dsbl.org';
840 $filters['Conf DSBL.ORG Relay']['result'] = '127.0.0.2';
841 $filters['Conf DSBL.ORG Relay']['comment'] =
842 _("FREE - Distributed Sender Boycott List - Confirmed Relays");
843
844 $filters['Conf DSBL.ORG Multi-Stage']['prefname'] = 'filters_spam_dsbl_conf_ms';
845 $filters['Conf DSBL.ORG Multi-Stage']['name'] = 'DSBL.org Confirmed Multi-Stage Relay List';
846 $filters['Conf DSBL.ORG Multi-Stage']['link'] = 'http://www.dsbl.org/';
847 $filters['Conf DSBL.ORG Multi-Stage']['dns'] = 'multihop.dsbl.org';
848 $filters['Conf DSBL.ORG Multi-Stage']['result'] = '127.0.0.2';
849 $filters['Conf DSBL.ORG Multi-Stage']['comment'] =
850 _("FREE - Distributed Sender Boycott List - Confirmed Multi-stage Relays");
851
852 $filters['UN-Conf DSBL.ORG']['prefname'] = 'filters_spam_dsbl_unc';
853 $filters['UN-Conf DSBL.ORG']['name'] = 'DSBL.org UN-Confirmed Relay List';
854 $filters['UN-Conf DSBL.ORG']['link'] = 'http://www.dsbl.org/';
855 $filters['UN-Conf DSBL.ORG']['dns'] = 'unconfirmed.dsbl.org';
856 $filters['UN-Conf DSBL.ORG']['result'] = '127.0.0.2';
857 $filters['UN-Conf DSBL.ORG']['comment'] =
858 _("FREE - Distributed Sender Boycott List - UN-Confirmed Relays");
859
10a26cea 860 foreach ($filters as $Key => $Value) {
9c655416 861 $filters[$Key]['enabled'] = getPref($data_dir, $username, $filters[$Key]['prefname']);
4eee5968 862 }
863
10a26cea 864 return $filters;
865}
4eee5968 866
0a1dc88e 867/**
9c655416 868 * Removes a User filter
869 * @param int $id ID of the filter to remove
0a1dc88e 870 * @access private
871 */
10a26cea 872function remove_filter ($id) {
873 global $data_dir, $username;
4eee5968 874
9c655416 875 while ($nextFilter = getPref($data_dir, $username, 'filter' . ($id + 1))) {
10a26cea 876 setPref($data_dir, $username, 'filter' . $id, $nextFilter);
877 $id ++;
4eee5968 878 }
879
10a26cea 880 removePref($data_dir, $username, 'filter' . $id);
881}
4eee5968 882
0a1dc88e 883/**
9c655416 884 * Swaps two filters
885 * @param int $id1 ID of first filter to swap
f8a1ed5a 886 * @param int $id2 ID of second filter to swap
0a1dc88e 887 * @access private
888 */
10a26cea 889function filter_swap($id1, $id2) {
890 global $data_dir, $username;
4eee5968 891
10a26cea 892 $FirstFilter = getPref($data_dir, $username, 'filter' . $id1);
893 $SecondFilter = getPref($data_dir, $username, 'filter' . $id2);
894
895 if ($FirstFilter && $SecondFilter) {
896 setPref($data_dir, $username, 'filter' . $id2, $FirstFilter);
897 setPref($data_dir, $username, 'filter' . $id1, $SecondFilter);
4eee5968 898 }
10a26cea 899}
4eec80a7 900
0a1dc88e 901/**
9c655416 902 * This updates the filter rules when renaming or deleting folders
0a1dc88e 903 * @param array $args
b2d8bc6c 904 * @access private
0a1dc88e 905 */
f5ab1fb9 906function update_for_folder ($args) {
9c655416 907
f5ab1fb9 908 $old_folder = $args[0];
9c655416 909 $new_folder = $args[2];
910 $action = $args[1];
ce68b76b 911 global $data_dir, $username;
4eec80a7 912 $filters = array();
913 $filters = load_filters();
914 $filter_count = count($filters);
915 $p = 0;
9c655416 916 for ($i = 0; $i < $filter_count; $i++) {
4eec80a7 917 if (!empty($filters)) {
918 if ($old_folder == $filters[$i]['folder']) {
919 if ($action == 'rename') {
920 $filters[$i]['folder'] = $new_folder;
921 setPref($data_dir, $username, 'filter'.$i,
922 $filters[$i]['where'].','.$filters[$i]['what'].','.$new_folder);
923 }
924 elseif ($action == 'delete') {
925 remove_filter($p);
926 $p = $p-1;
927 }
928 }
929 $p++;
930 }
931 }
932}
0a1dc88e 933
934/**
0a1dc88e 935 * Display formated error message
936 * @param string $string text message
937 * @return string html formated text message
938 * @access private
939 */
940function do_error($string) {
941 global $color;
942 echo "<p align=\"center\"><font color=\"$color[2]\">";
943 echo $string;
944 echo "</font></p>\n";
945}