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