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