Variable name is misleading, if technically correct. I'd personally eventually like...
[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
9c655416 55/**
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['ORDB']['prefname'] = 'filters_spam_ordb';
653 $filters['ORDB']['name'] = 'Open Relay Database List';
654 $filters['ORDB']['link'] = 'http://www.ordb.org/';
655 $filters['ORDB']['dns'] = 'relays.ordb.org';
656 $filters['ORDB']['result'] = '127.0.0.2';
657 $filters['ORDB']['comment'] =
658 _("FREE - ORDB was born when ORBS went off the air. It seems to have fewer false positives than ORBS did though.");
659
10a26cea 660 $filters['FiveTen Direct']['prefname'] = 'filters_spam_fiveten_src';
661 $filters['FiveTen Direct']['name'] = 'Five-Ten-sg.com Direct SPAM Sources';
662 $filters['FiveTen Direct']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
663 $filters['FiveTen Direct']['dns'] = 'blackholes.five-ten-sg.com';
664 $filters['FiveTen Direct']['result'] = '127.0.0.2';
665 $filters['FiveTen Direct']['comment'] =
666 _("FREE - Five-Ten-sg.com - Direct SPAM sources.");
667
668 $filters['FiveTen DUL']['prefname'] = 'filters_spam_fiveten_dul';
669 $filters['FiveTen DUL']['name'] = 'Five-Ten-sg.com DUL Lists';
670 $filters['FiveTen DUL']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
671 $filters['FiveTen DUL']['dns'] = 'blackholes.five-ten-sg.com';
672 $filters['FiveTen DUL']['result'] = '127.0.0.3';
673 $filters['FiveTen DUL']['comment'] =
674 _("FREE - Five-Ten-sg.com - Dial-up lists - includes some DSL IPs.");
675
676 $filters['FiveTen Unc. OptIn']['prefname'] = 'filters_spam_fiveten_oi';
677 $filters['FiveTen Unc. OptIn']['name'] = 'Five-Ten-sg.com Unconfirmed OptIn Lists';
678 $filters['FiveTen Unc. OptIn']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
679 $filters['FiveTen Unc. OptIn']['dns'] = 'blackholes.five-ten-sg.com';
680 $filters['FiveTen Unc. OptIn']['result'] = '127.0.0.4';
681 $filters['FiveTen Unc. OptIn']['comment'] =
682 _("FREE - Five-Ten-sg.com - Bulk mailers that do not use confirmed opt-in.");
683
684 $filters['FiveTen Others']['prefname'] = 'filters_spam_fiveten_oth';
685 $filters['FiveTen Others']['name'] = 'Five-Ten-sg.com Other Misc. Servers';
686 $filters['FiveTen Others']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
687 $filters['FiveTen Others']['dns'] = 'blackholes.five-ten-sg.com';
688 $filters['FiveTen Others']['result'] = '127.0.0.5';
689 $filters['FiveTen Others']['comment'] =
690 _("FREE - Five-Ten-sg.com - Other misc. servers.");
691
692 $filters['FiveTen Single Stage']['prefname'] = 'filters_spam_fiveten_ss';
693 $filters['FiveTen Single Stage']['name'] = 'Five-Ten-sg.com Single Stage Servers';
694 $filters['FiveTen Single Stage']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
695 $filters['FiveTen Single Stage']['dns'] = 'blackholes.five-ten-sg.com';
696 $filters['FiveTen Single Stage']['result'] = '127.0.0.6';
697 $filters['FiveTen Single Stage']['comment'] =
698 _("FREE - Five-Ten-sg.com - Single Stage servers.");
699
700 $filters['FiveTen SPAM Support']['prefname'] = 'filters_spam_fiveten_supp';
701 $filters['FiveTen SPAM Support']['name'] = 'Five-Ten-sg.com SPAM Support Servers';
702 $filters['FiveTen SPAM Support']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
703 $filters['FiveTen SPAM Support']['dns'] = 'blackholes.five-ten-sg.com';
704 $filters['FiveTen SPAM Support']['result'] = '127.0.0.7';
705 $filters['FiveTen SPAM Support']['comment'] =
706 _("FREE - Five-Ten-sg.com - SPAM Support servers.");
707
708 $filters['FiveTen Web forms']['prefname'] = 'filters_spam_fiveten_wf';
709 $filters['FiveTen Web forms']['name'] = 'Five-Ten-sg.com Web Form IPs';
710 $filters['FiveTen Web forms']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
711 $filters['FiveTen Web forms']['dns'] = 'blackholes.five-ten-sg.com';
712 $filters['FiveTen Web forms']['result'] = '127.0.0.8';
713 $filters['FiveTen Web forms']['comment'] =
714 _("FREE - Five-Ten-sg.com - Web Form IPs.");
715
716 $filters['Dorkslayers']['prefname'] = 'filters_spam_dorks';
717 $filters['Dorkslayers']['name'] = 'Dorkslayers Lists';
718 $filters['Dorkslayers']['link'] = 'http://www.dorkslayers.com';
719 $filters['Dorkslayers']['dns'] = 'orbs.dorkslayers.com';
720 $filters['Dorkslayers']['result'] = '127.0.0.2';
721 $filters['Dorkslayers']['comment'] =
722 _("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.");
723
724 $filters['SPAMhaus']['prefname'] = 'filters_spam_spamhaus';
725 $filters['SPAMhaus']['name'] = 'SPAMhaus Lists';
726 $filters['SPAMhaus']['link'] = 'http://www.spamhaus.org';
727 $filters['SPAMhaus']['dns'] = 'sbl.spamhaus.org';
728 $filters['SPAMhaus']['result'] = '127.0.0.6';
729 $filters['SPAMhaus']['comment'] =
730 _("FREE - SPAMhaus - A list of well-known SPAM sources.");
731
732 $filters['SPAMcop']['prefname'] = 'filters_spam_spamcop';
733 $filters['SPAMcop']['name'] = 'SPAM Cop Lists';
734 $filters['SPAMcop']['link'] = 'http://spamcop.net/bl.shtml';
735 $filters['SPAMcop']['dns'] = 'bl.spamcop.net';
736 $filters['SPAMcop']['result'] = '127.0.0.2';
737 $filters['SPAMcop']['comment'] =
ace4e0d3 738 _("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 739
46a184ff 740 $filters['dev.null.dk']['prefname'] = 'filters_spam_devnull';
741 $filters['dev.null.dk']['name'] = 'dev.null.dk Lists';
742 $filters['dev.null.dk']['link'] = 'http://dev.null.dk/';
743 $filters['dev.null.dk']['dns'] = 'dev.null.dk';
744 $filters['dev.null.dk']['result'] = '127.0.0.2';
745 $filters['dev.null.dk']['comment'] =
746 _("FREE - dev.null.dk - I don't have any detailed info on this list.");
747
748 $filters['visi.com']['prefname'] = 'filters_spam_visi';
749 $filters['visi.com']['name'] = 'visi.com Relay Stop List';
750 $filters['visi.com']['link'] = 'http://relays.visi.com';
751 $filters['visi.com']['dns'] = 'relays.visi.com';
752 $filters['visi.com']['result'] = '127.0.0.2';
753 $filters['visi.com']['comment'] =
754 _("FREE - visi.com - Relay Stop List. Very conservative OpenRelay List.");
755
bd35ab2b 756 $filters['ahbl.org Open Relays']['prefname'] = 'filters_spam_2mb_or';
757 $filters['ahbl.org Open Relays']['name'] = 'ahbl.org Open Relays List';
758 $filters['ahbl.org Open Relays']['link'] = 'http://www.ahbl.org/';
759 $filters['ahbl.org Open Relays']['dns'] = 'dnsbl.ahbl.org';
760 $filters['ahbl.org Open Relays']['result'] = '127.0.0.2';
761 $filters['ahbl.org Open Relays']['comment'] =
762 _("FREE - ahbl.org Open Relays - Another list of Open Relays.");
763
764 $filters['ahbl.org SPAM Source']['prefname'] = 'filters_spam_2mb_ss';
765 $filters['ahbl.org SPAM Source']['name'] = 'ahbl.org SPAM Source List';
766 $filters['ahbl.org SPAM Source']['link'] = 'http://www.ahbl.org/';
767 $filters['ahbl.org SPAM Source']['dns'] = 'dnsbl.ahbl.org';
768 $filters['ahbl.org SPAM Source']['result'] = '127.0.0.4';
769 $filters['ahbl.org SPAM Source']['comment'] =
770 _("FREE - ahbl.org SPAM Source - List of Direct SPAM Sources.");
771
772 $filters['ahbl.org SPAM ISPs']['prefname'] = 'filters_spam_2mb_isp';
773 $filters['ahbl.org SPAM ISPs']['name'] = 'ahbl.org SPAM-friendly ISP List';
774 $filters['ahbl.org SPAM ISPs']['link'] = 'http://www.ahbl.org/';
775 $filters['ahbl.org SPAM ISPs']['dns'] = 'dnsbl.ahbl.org';
776 $filters['ahbl.org SPAM ISPs']['result'] = '127.0.0.7';
777 $filters['ahbl.org SPAM ISPs']['comment'] =
778 _("FREE - ahbl.org SPAM ISPs - List of SPAM-friendly ISPs.");
46a184ff 779
780 $filters['Leadmon DUL']['prefname'] = 'filters_spam_lm_dul';
781 $filters['Leadmon DUL']['name'] = 'Leadmon.net DUL List';
782 $filters['Leadmon DUL']['link'] = 'http://www.leadmon.net/spamguard/';
783 $filters['Leadmon DUL']['dns'] = 'spamguard.leadmon.net';
784 $filters['Leadmon DUL']['result'] = '127.0.0.2';
785 $filters['Leadmon DUL']['comment'] =
786 _("FREE - Leadmon DUL - Another list of Dial-up or otherwise dynamically assigned IPs.");
787
788 $filters['Leadmon SPAM Source']['prefname'] = 'filters_spam_lm_ss';
789 $filters['Leadmon SPAM Source']['name'] = 'Leadmon.net SPAM Source List';
790 $filters['Leadmon SPAM Source']['link'] = 'http://www.leadmon.net/spamguard/';
791 $filters['Leadmon SPAM Source']['dns'] = 'spamguard.leadmon.net';
792 $filters['Leadmon SPAM Source']['result'] = '127.0.0.3';
793 $filters['Leadmon SPAM Source']['comment'] =
794 _("FREE - Leadmon SPAM Source - List of IPs Leadmon.net has received SPAM directly from.");
795
796 $filters['Leadmon Bulk Mailers']['prefname'] = 'filters_spam_lm_bm';
797 $filters['Leadmon Bulk Mailers']['name'] = 'Leadmon.net Bulk Mailers List';
798 $filters['Leadmon Bulk Mailers']['link'] = 'http://www.leadmon.net/spamguard/';
799 $filters['Leadmon Bulk Mailers']['dns'] = 'spamguard.leadmon.net';
800 $filters['Leadmon Bulk Mailers']['result'] = '127.0.0.4';
801 $filters['Leadmon Bulk Mailers']['comment'] =
802 _("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.");
803
804 $filters['Leadmon Open Relays']['prefname'] = 'filters_spam_lm_or';
805 $filters['Leadmon Open Relays']['name'] = 'Leadmon.net Open Relays List';
806 $filters['Leadmon Open Relays']['link'] = 'http://www.leadmon.net/spamguard/';
807 $filters['Leadmon Open Relays']['dns'] = 'spamguard.leadmon.net';
808 $filters['Leadmon Open Relays']['result'] = '127.0.0.5';
809 $filters['Leadmon Open Relays']['comment'] =
810 _("FREE - Leadmon Open Relays - Single Stage Open Relays that are not listed on other active RBLs.");
811
812 $filters['Leadmon Multi-stage']['prefname'] = 'filters_spam_lm_ms';
813 $filters['Leadmon Multi-stage']['name'] = 'Leadmon.net Multi-Stage Relay List';
814 $filters['Leadmon Multi-stage']['link'] = 'http://www.leadmon.net/spamguard/';
815 $filters['Leadmon Multi-stage']['dns'] = 'spamguard.leadmon.net';
816 $filters['Leadmon Multi-stage']['result'] = '127.0.0.6';
817 $filters['Leadmon Multi-stage']['comment'] =
818 _("FREE - Leadmon Multi-stage - Multi-Stage Open Relays that are not listed on other active RBLs and that have sent SPAM to Leadmon.net.");
819
820 $filters['Leadmon SpamBlock']['prefname'] = 'filters_spam_lm_sb';
821 $filters['Leadmon SpamBlock']['name'] = 'Leadmon.net SpamBlock Sites List';
822 $filters['Leadmon SpamBlock']['link'] = 'http://www.leadmon.net/spamguard/';
823 $filters['Leadmon SpamBlock']['dns'] = 'spamguard.leadmon.net';
824 $filters['Leadmon SpamBlock']['result'] = '127.0.0.7';
825 $filters['Leadmon SpamBlock']['comment'] =
826 _("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.");
827
828 $filters['NJABL Open Relays']['prefname'] = 'filters_spam_njabl_or';
829 $filters['NJABL Open Relays']['name'] = 'NJABL Open Relay/Direct Spam Source List';
830 $filters['NJABL Open Relays']['link'] = 'http://www.njabl.org/';
831 $filters['NJABL Open Relays']['dns'] = 'dnsbl.njabl.org';
832 $filters['NJABL Open Relays']['result'] = '127.0.0.2';
833 $filters['NJABL Open Relays']['comment'] =
834 _("FREE, for now - Not Just Another Blacklist - Both Open Relays and Direct SPAM Sources.");
835
836 $filters['NJABL DUL']['prefname'] = 'filters_spam_njabl_dul';
837 $filters['NJABL DUL']['name'] = 'NJABL Dial-ups List';
838 $filters['NJABL DUL']['link'] = 'http://www.njabl.org/';
839 $filters['NJABL DUL']['dns'] = 'dnsbl.njabl.org';
840 $filters['NJABL DUL']['result'] = '127.0.0.3';
841 $filters['NJABL DUL']['comment'] =
842 _("FREE, for now - Not Just Another Blacklist - Dial-up IPs.");
843
18b078e9 844 $filters['Conf DSBL.ORG Relay']['prefname'] = 'filters_spam_dsbl_conf_ss';
845 $filters['Conf DSBL.ORG Relay']['name'] = 'DSBL.org Confirmed Relay List';
846 $filters['Conf DSBL.ORG Relay']['link'] = 'http://www.dsbl.org/';
847 $filters['Conf DSBL.ORG Relay']['dns'] = 'list.dsbl.org';
848 $filters['Conf DSBL.ORG Relay']['result'] = '127.0.0.2';
849 $filters['Conf DSBL.ORG Relay']['comment'] =
850 _("FREE - Distributed Sender Boycott List - Confirmed Relays");
851
852 $filters['Conf DSBL.ORG Multi-Stage']['prefname'] = 'filters_spam_dsbl_conf_ms';
853 $filters['Conf DSBL.ORG Multi-Stage']['name'] = 'DSBL.org Confirmed Multi-Stage Relay List';
854 $filters['Conf DSBL.ORG Multi-Stage']['link'] = 'http://www.dsbl.org/';
855 $filters['Conf DSBL.ORG Multi-Stage']['dns'] = 'multihop.dsbl.org';
856 $filters['Conf DSBL.ORG Multi-Stage']['result'] = '127.0.0.2';
857 $filters['Conf DSBL.ORG Multi-Stage']['comment'] =
858 _("FREE - Distributed Sender Boycott List - Confirmed Multi-stage Relays");
859
860 $filters['UN-Conf DSBL.ORG']['prefname'] = 'filters_spam_dsbl_unc';
861 $filters['UN-Conf DSBL.ORG']['name'] = 'DSBL.org UN-Confirmed Relay List';
862 $filters['UN-Conf DSBL.ORG']['link'] = 'http://www.dsbl.org/';
863 $filters['UN-Conf DSBL.ORG']['dns'] = 'unconfirmed.dsbl.org';
864 $filters['UN-Conf DSBL.ORG']['result'] = '127.0.0.2';
865 $filters['UN-Conf DSBL.ORG']['comment'] =
866 _("FREE - Distributed Sender Boycott List - UN-Confirmed Relays");
867
10a26cea 868 foreach ($filters as $Key => $Value) {
9c655416 869 $filters[$Key]['enabled'] = getPref($data_dir, $username, $filters[$Key]['prefname']);
4eee5968 870 }
871
10a26cea 872 return $filters;
873}
4eee5968 874
0a1dc88e 875/**
9c655416 876 * Removes a User filter
877 * @param int $id ID of the filter to remove
0a1dc88e 878 * @access private
879 */
10a26cea 880function remove_filter ($id) {
881 global $data_dir, $username;
4eee5968 882
9c655416 883 while ($nextFilter = getPref($data_dir, $username, 'filter' . ($id + 1))) {
10a26cea 884 setPref($data_dir, $username, 'filter' . $id, $nextFilter);
885 $id ++;
4eee5968 886 }
887
10a26cea 888 removePref($data_dir, $username, 'filter' . $id);
889}
4eee5968 890
0a1dc88e 891/**
9c655416 892 * Swaps two filters
893 * @param int $id1 ID of first filter to swap
f8a1ed5a 894 * @param int $id2 ID of second filter to swap
0a1dc88e 895 * @access private
896 */
10a26cea 897function filter_swap($id1, $id2) {
898 global $data_dir, $username;
4eee5968 899
10a26cea 900 $FirstFilter = getPref($data_dir, $username, 'filter' . $id1);
901 $SecondFilter = getPref($data_dir, $username, 'filter' . $id2);
902
903 if ($FirstFilter && $SecondFilter) {
904 setPref($data_dir, $username, 'filter' . $id2, $FirstFilter);
905 setPref($data_dir, $username, 'filter' . $id1, $SecondFilter);
4eee5968 906 }
10a26cea 907}
4eec80a7 908
0a1dc88e 909/**
9c655416 910 * This updates the filter rules when renaming or deleting folders
0a1dc88e 911 * @param array $args
b2d8bc6c 912 * @access private
0a1dc88e 913 */
f5ab1fb9 914function update_for_folder ($args) {
9c655416 915
f5ab1fb9 916 $old_folder = $args[0];
9c655416 917 $new_folder = $args[2];
918 $action = $args[1];
ce68b76b 919 global $data_dir, $username;
4eec80a7 920 $filters = array();
921 $filters = load_filters();
922 $filter_count = count($filters);
923 $p = 0;
9c655416 924 for ($i = 0; $i < $filter_count; $i++) {
4eec80a7 925 if (!empty($filters)) {
926 if ($old_folder == $filters[$i]['folder']) {
927 if ($action == 'rename') {
928 $filters[$i]['folder'] = $new_folder;
929 setPref($data_dir, $username, 'filter'.$i,
930 $filters[$i]['where'].','.$filters[$i]['what'].','.$new_folder);
931 }
932 elseif ($action == 'delete') {
933 remove_filter($p);
934 $p = $p-1;
935 }
936 }
937 $p++;
938 }
939 }
940}
0a1dc88e 941
0a1dc88e 942/**
943 * Display formated error message
944 * @param string $string text message
945 * @return string html formated text message
946 * @access private
947 */
948function do_error($string) {
949 global $color;
950 echo "<p align=\"center\"><font color=\"$color[2]\">";
951 echo $string;
952 echo "</font></p>\n";
953}