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