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