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