Bugfix by "Chiu Wai Pun" <pun@alumni.ust.hk>
[squirrelmail.git] / plugins / filters / filters.php
CommitLineData
849bdf42 1<?php
4eee5968 2
15e6162e 3/**
4 * Message and Spam Filter Plugin
5 *
6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This plugin filters your inbox into different folders based upon given
10 * criteria. It is most useful for people who are subscibed to mailing lists
11 * to help organize their messages. The argument stands that filtering is
12 * not the place of the client, which is why this has been made a plugin for
13 * SquirrelMail. You may be better off using products such as Sieve or
14 * Procmail to do your filtering so it happens even when SquirrelMail isn't
15 * running.
16 *
17 * If you need help with this, or see improvements that can be made, please
18 * email me directly at the address above. I definately welcome suggestions
19 * and comments. This plugin, as is the case with all SquirrelMail plugins,
20 * is not directly supported by the developers. Please come to me off the
21 * mailing list if you have trouble with it.
22 *
23 * Also view plugins/README.plugins for more information.
24 *
25 * $Id$
26 */
4eee5968 27
a2a566eb 28function filters_SaveCache () {
29 global $data_dir, $SpamFilters_DNScache;
30
31 if (file_exists($data_dir . "/dnscache")) {
32 $fp = fopen($data_dir . "/dnscache", "r");
33 } else {
34 $fp = false;
35 }
36 if ($fp) {
37 flock($fp,LOCK_EX);
38 } else {
39 $fp = fopen($data_dir . "/dnscache", "w+");
40 fclose($fp);
41 $fp = fopen($data_dir . "/dnscache", "r");
42 flock($fp,LOCK_EX);
43 }
44 $fp1=fopen($data_dir . "/dnscache", "w+");
45
46 foreach ($SpamFilters_DNScache as $Key=> $Value) {
47 $tstr = $Key . ',' . $Value['L'] . ',' . $Value['T'] . "\n";
48 fputs ($fp1, $tstr);
49 }
50 fclose($fp1);
51 flock($fp,LOCK_UN);
52 fclose($fp);
53}
54
55
56function filters_LoadCache () {
57 global $data_dir, $SpamFilters_DNScache;
58
59 if (file_exists($data_dir . "/dnscache")) {
6ade76e0 60 $SpamFilters_DNScache = array();
a2a566eb 61 if ($fp = fopen ($data_dir . "/dnscache", "r")) {
62 flock($fp,LOCK_SH);
63 while ($data=fgetcsv($fp,1024)) {
64 if ($data[2] > time()) {
65 $SpamFilters_DNScache[$data[0]]['L'] = $data[1];
66 $SpamFilters_DNScache[$data[0]]['T'] = $data[2];
67 }
68 }
69
70 flock($fp,LOCK_UN);
71 }
72 }
73}
74
75function filters_bulkquery($filters_spam_scan, $filters, $read) {
76 global $SpamFilters_YourHop, $attachment_dir, $username,
6ade76e0 77 $SpamFilters_DNScache, $SpamFilters_BulkQuery,
78 $SpamFilters_CacheTTL;
a2a566eb 79
80 $IPs = array();
81 $i = 0;
82 while ($i < count($read)) {
83 // EIMS will give funky results
84 $Chunks = explode(' ', $read[$i]);
85 if ($Chunks[0] != '*') {
86 $i ++;
87 continue;
88 }
89 $MsgNum = $Chunks[1];
90
91 $i ++;
a2a566eb 92
93 // Look through all of the Received headers for IP addresses
94 // Stop when I get ")" on a line
95 // Stop if I get "*" on a line (don't advance)
96 // and above all, stop if $i is bigger than the total # of lines
97 while (($i < count($read)) &&
98 ($read[$i][0] != ')' && $read[$i][0] != '*' &&
99 $read[$i][0] != "\n")) {
100 // Check to see if this line is the right "Received from" line
101 // to check
102 if (is_int(strpos($read[$i], $SpamFilters_YourHop))) {
c8a2c24d 103 $read[$i] = ereg_replace('[^0-9\.]', ' ', $read[$i]);
104 $elements = explode(' ', $read[$i]);
105 foreach ($elements as $value) {
106 if ($value != '' &&
107 ereg('[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}',
108 $value, $regs)) {
109 $Chunks = explode('.', $value);
110 $IP = $Chunks[3] . '.' . $Chunks[2] . '.' .
111 $Chunks[1] . '.' . $Chunks[0];
112 foreach ($filters as $key => $value) {
113 if ($filters[$key]['enabled'] &&
114 $filters[$key]['dns']) {
115 if (strlen($SpamFilters_DNScache[$IP.'.'.$filters[$key]['dns']]) == 0) {
116 $IPs[$IP] = true;
117 break;
a2a566eb 118 }
119 }
c8a2c24d 120 }
121 // If we've checked one IP and YourHop is
122 // just a space
123 if ($SpamFilters_YourHop == ' ') {
124 break; // don't check any more
a2a566eb 125 }
126 }
127 }
128 }
129 $i ++;
130 }
131 }
132
133 if (count($IPs) > 0) {
134 $rbls = array();
135 foreach ($filters as $key => $value) {
136 if ($filters[$key]['enabled']) {
137 if ($filters[$key]['dns']) {
138 $rbls[$filters[$key]['dns']] = true;
139 }
140 }
141 }
142
143 $bqfil = $attachment_dir . $username . "-bq.in";
144 $fp = fopen($bqfil, "w");
6ade76e0 145 fputs ($fp, $SpamFilters_CacheTTL . "\n");
a2a566eb 146 foreach ($rbls as $key => $value) {
147 fputs ($fp, "." . $key . "\n");
148 }
149 fputs ($fp, "----------\n");
150 foreach ($IPs as $key => $value) {
151 fputs ($fp, $key . "\n");
152 }
153 fclose ($fp);
154 $bqout = array();
155 exec ($SpamFilters_BulkQuery . " < " . $bqfil, $bqout);
156 foreach ($bqout as $value) {
157 $Chunks = explode(',', $value);
158 $SpamFilters_DNScache[$Chunks[0]]['L'] = $Chunks[1];
159 $SpamFilters_DNScache[$Chunks[0]]['T'] = $Chunks[2] + time();
160 }
161 unlink($bqfil);
162 }
163}
164
165
10a26cea 166function filters_sqimap_read_data ($imap_stream, $pre, $handle_errors, &$response, &$message) {
167 global $color, $squirrelmail_language, $imap_general_debug;
4eee5968 168
10a26cea 169 $data = array();
170 $size = 0;
4eee5968 171
10a26cea 172 do {
173 $read = fgets($imap_stream, 9096);
174 if (ereg("^$pre (OK|BAD|NO)(.*)$", $read, $regs)) {
175 break; // found end of reply
176 }
4eee5968 177
10a26cea 178 // Continue if needed for this single line
179 while (strpos($read, "\n") === false) {
180 $read .= fgets($imap_stream, 9096);
181 }
4eee5968 182
10a26cea 183 $data[] = $read;
4eee5968 184
10a26cea 185 if (ereg("^\\* [0-9]+ FETCH.*\\{([0-9]+)\\}", $read, $regs)) {
186 $size = $regs[1];
4eee5968 187 if ($imap_general_debug) {
10a26cea 188 echo "<small><tt><font color=\"#CC0000\">Size is $size</font></tt></small><br>\n";
4eee5968 189 }
4eee5968 190
10a26cea 191 $total_size = 0;
192 do {
193 $read = fgets($imap_stream, 9096);
194 if ($imap_general_debug) {
195 echo "<small><tt><font color=\"#CC0000\">$read</font></tt></small><br>\n";
196 flush();
197 }
198 $data[] = $read;
199 $total_size += strlen($read);
200 } while ($total_size < $size);
4eee5968 201
10a26cea 202 $size = 0;
203 }
204 // For debugging purposes
ae840cbb 205 if ($imap_general_debug) {
10a26cea 206 echo "<small><tt><font color=\"#CC0000\">$read</font></tt></small><br>\n";
207 flush();
ae840cbb 208 }
10a26cea 209 } while (true);
4eee5968 210
10a26cea 211 $response = $regs[1];
212 $message = trim($regs[2]);
4eee5968 213
10a26cea 214 if ($imap_general_debug) {
215 echo '--<br>';
216 }
217
218 if (!$handle_errors) {
219 return $data;
220 }
221
222 if ($response == 'NO') {
223 // ignore this error from m$ exchange, it is not fatal (aka bug)
224 if (strstr($message, 'command resulted in') === false) {
4eee5968 225 set_up_language($squirrelmail_language);
10a26cea 226 echo "<br><b><font color=$color[2]>\n" .
227 _("ERROR : Could not complete request.") .
228 "</b><br>\n" .
229 _("Reason Given: ") .
230 $message . "</font><br>\n";
4eee5968 231 exit;
232 }
10a26cea 233 } else if ($response == 'BAD') {
234 set_up_language($squirrelmail_language);
235 echo "<br><b><font color=$color[2]>\n" .
236 _("ERROR : Bad or malformed request.") .
237 "</b><br>\n" .
238 _("Server responded: ") .
239 $message . "</font><br>\n";
240 exit;
4eee5968 241 }
242
10a26cea 243 return $data;
244}
245
246
247function start_filters() {
248 global $mailbox, $username, $key, $imapServerAddress, $imapPort, $imap,
249 $imap_general, $filters, $imap_stream, $imapConnection,
250 $UseSeparateImapConnection, $AllowSpamFilters;
251
d9a8ac55 252# if ($mailbox == 'INBOX') {
10a26cea 253 // Detect if we have already connected to IMAP or not.
254 // Also check if we are forced to use a separate IMAP connection
255 if ((!isset($imap_stream) && !isset($imapConnection)) ||
256 $UseSeparateImapConnection) {
257 $stream = sqimap_login($username, $key, $imapServerAddress,
258 $imapPort, 10);
259 $previously_connected = false;
260 } elseif (isset($imapConnection)) {
261 $stream = $imapConnection;
262 $previously_connected = true;
263 } else {
264 $previously_connected = true;
265 $stream = $imap_stream;
266 }
4eee5968 267
10a26cea 268 if (sqimap_get_num_messages($stream, 'INBOX') > 0) {
269 // Filter spam from inbox before we sort them into folders
270 if ($AllowSpamFilters) {
271 spam_filters($stream);
4eee5968 272 }
273
10a26cea 274 // Sort into folders
275 user_filters($stream);
276 }
4eee5968 277
10a26cea 278 if (!$previously_connected) {
279 sqimap_logout($stream);
4eee5968 280 }
d9a8ac55 281# }
10a26cea 282}
283
284
285function user_filters($imap_stream) {
c8a2c24d 286 global $data_dir, $username;
10a26cea 287 $filters = load_filters();
288 if (! $filters) return;
c8a2c24d 289 $filters_user_scan = getPref($data_dir, $username, 'filters_user_scan');
10a26cea 290
291 sqimap_mailbox_select($imap_stream, 'INBOX');
292
293 // For every rule
294 for ($i=0; $i < count($filters); $i++) {
295 // If it is the "combo" rule
296 if ($filters[$i]['where'] == 'To or Cc') {
297 /*
298 * If it's "TO OR CC", we have to do two searches, one for TO
299 * and the other for CC.
300 */
301 filter_search_and_delete($imap_stream, 'TO',
c8a2c24d 302 $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan);
10a26cea 303 filter_search_and_delete($imap_stream, 'CC',
c8a2c24d 304 $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan);
10a26cea 305 } else {
306 /*
307 * If it's a normal TO, CC, SUBJECT, or FROM, then handle it
308 * normally.
309 */
310 filter_search_and_delete($imap_stream, $filters[$i]['where'],
c8a2c24d 311 $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan);
4eee5968 312 }
4eee5968 313 }
10a26cea 314 // Clean out the mailbox whether or not auto_expunge is on
315 // That way it looks like it was redirected properly
316 sqimap_mailbox_expunge($imap_stream, 'INBOX');
317}
318
c8a2c24d 319function filter_search_and_delete($imap, $where, $what, $where_to, $user_scan) {
65ffb3ce 320 global $languages, $squirrelmail_language, $allow_charset_search;
c8a2c24d 321 if ($user_scan == 'new') {
322 $category = 'UNSEEN';
323 } else {
324 $category = 'ALL';
325 }
326
65ffb3ce 327 if ($allow_charset_search && isset($languages[$squirrelmail_language]['CHARSET']) &&
f9ca4be0 328 $languages[$squirrelmail_language]['CHARSET']) {
329 $search_str = "SEARCH CHARSET "
330 . strtoupper($languages[$squirrelmail_language]['CHARSET'])
c8a2c24d 331 . ' ' . $category . ' ';
f9ca4be0 332 } else {
c8a2c24d 333 $search_str = 'SEARCH CHARSET US-ASCII ' . $category . ' ';
f9ca4be0 334 }
9da6bdde 335 if ($where == "Header") {
336 $what = explode(':', $what);
337 $where = trim($where . ' ' . $what[0]);
338 $what = addslashes(trim($what[1]));
339 }
f9ca4be0 340 $search_str .= $where . ' {' . strlen($what) . "}\r\n" . $what . "\r\n";
341
58235ee5 342 fputs ($imap, "a001 $search_str");
10a26cea 343 $read = filters_sqimap_read_data ($imap, 'a001', true, $response, $message);
344
345 // This may have problems with EIMS due to it being goofy
346
347 for ($r=0; $r < count($read) &&
348 substr($read[$r], 0, 8) != '* SEARCH'; $r++) {}
349 if ($response == 'OK') {
350 $ids = explode(' ', $read[$r]);
351 if (sqimap_mailbox_exists($imap, $where_to)) {
352 for ($j=2; $j < count($ids); $j++) {
353 $id = trim($ids[$j]);
354 sqimap_messages_copy ($imap, $id, $id, $where_to);
355 sqimap_messages_flag ($imap, $id, $id, 'Deleted');
4eee5968 356 }
357 }
358 }
10a26cea 359}
4eee5968 360
10a26cea 361// These are the spam filters
362function spam_filters($imap_stream) {
363 global $data_dir, $username;
364 global $SpamFilters_YourHop;
365 global $SpamFilters_DNScache;
a2a566eb 366 global $SpamFilters_SharedCache;
367 global $SpamFilters_BulkQuery;
4eee5968 368
10a26cea 369 $filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan');
370 $filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder');
371 $filters = load_spam_filters();
4eee5968 372
a2a566eb 373 if ($SpamFilters_SharedCache) {
374 filters_LoadCache();
375 }
376
10a26cea 377 $run = 0;
4eee5968 378
10a26cea 379 foreach ($filters as $Key=> $Value) {
380 if ($Value['enabled']) {
381 $run ++;
4eee5968 382 }
10a26cea 383 }
4eee5968 384
10a26cea 385 // short-circuit
386 if ($run == 0) {
387 return;
388 }
4eee5968 389
10a26cea 390 sqimap_mailbox_select($imap_stream, 'INBOX');
4eee5968 391
10a26cea 392 // Ask for a big list of all "Received" headers in the inbox with
393 // flags for each message. Kinda big.
c8a2c24d 394 //fputs($imap_stream, 'A3999 FETCH 1:* (FLAGS BODY.PEEK[HEADER.FIELDS ' .
395 // "(RECEIVED)])\r\n");
396 $sid = sqimap_session_id();
397 if ($filters_spam_scan != 'new') {
398 fputs($imap_stream, $sid.' FETCH 1:* (FLAGS BODY.PEEK[HEADER.FIELDS ' .
399 "(RECEIVED)])\r\n");
400 } else {
401 fputs ($imap_stream, $sid.' SEARCH UNSEEN' . "\r\n");
402 $read = filters_sqimap_read_data ($imap_stream, $sid, true,
403 $response, $message);
404 $sid = sqimap_session_id();
405 if ($response != 'OK' || trim($read[0]) == '* SEARCH') {
406 fputs($imap_stream,
407 $sid.' FETCH 1:* (FLAGS BODY.PEEK[HEADER.FIELDS ' .
408 "(RECEIVED)])\r\n");
409 } else {
410 $read[0] = trim($read[0]);
411 $i = 0;
412 $imap_query = $sid.' FETCH ';
413 $Chunks = explode(' ', $read[0]);
414 for ($i=2; $i < (count($Chunks)-1) ; $i++) {
415 $imap_query .= $Chunks[$i].',';
416 }
417 $imap_query .= $Chunks[count($Chunks)-1];
418 $imap_query .= ' (FLAGS BODY.PEEK[HEADER.FIELDS ';
419 $imap_query .= "(RECEIVED)])\r\n";
420 fputs($imap_stream, $imap_query);
421 }
422 }
423
424 $read = filters_sqimap_read_data ($imap_stream, $sid, true,
10a26cea 425 $response, $message);
10a26cea 426 if ($response != 'OK') {
427 return;
428 }
4eee5968 429
a2a566eb 430 if (strlen($SpamFilters_BulkQuery) > 0) {
431 filters_bulkquery($filters_spam_scan, $filters, $read);
432 }
433
10a26cea 434 $i = 0;
435 while ($i < count($read)) {
436 // EIMS will give funky results
437 $Chunks = explode(' ', $read[$i]);
438 if ($Chunks[0] != '*') {
4eee5968 439 $i ++;
10a26cea 440 continue;
441 }
442 $MsgNum = $Chunks[1];
4eee5968 443
10a26cea 444 $IPs = array();
445 $i ++;
446 $IsSpam = 0;
4eee5968 447
10a26cea 448 // Look through all of the Received headers for IP addresses
449 // Stop when I get ")" on a line
450 // Stop if I get "*" on a line (don't advance)
451 // and above all, stop if $i is bigger than the total # of lines
452 while (($i < count($read)) &&
453 ($read[$i][0] != ')' && $read[$i][0] != '*' &&
454 $read[$i][0] != "\n") && (! $IsSpam)) {
455 // Check to see if this line is the right "Received from" line
456 // to check
457 if (is_int(strpos($read[$i], $SpamFilters_YourHop))) {
458
459 // short-circuit and skip work if we don't scan this one
c8a2c24d 460 $read[$i] = ereg_replace('[^0-9\.]', ' ', $read[$i]);
461 $elements = explode(' ', $read[$i]);
462 foreach ($elements as $value) {
463 if ($value != '' &&
464 ereg('[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}',
465 $value, $regs)) {
466 $Chunks = explode('.', $value);
467 if (filters_spam_check_site($Chunks[0],
468 $Chunks[1], $Chunks[2], $Chunks[3],
469 $filters)) {
470 $IsSpam ++;
471 break; // no sense in checking more IPs
472 }
473 // If we've checked one IP and YourHop is
474 // just a space
475 if ($SpamFilters_YourHop == ' ') {
476 break; // don't check any more
a9aa7ab7 477 }
a9aa7ab7 478 }
4eee5968 479 }
4eee5968 480 }
10a26cea 481 $i ++;
482 }
4eee5968 483
10a26cea 484 // Lookie! It's spam! Yum!
485 if ($IsSpam) {
486 if (sqimap_mailbox_exists($imap_stream, $filters_spam_folder)) {
487 sqimap_messages_copy ($imap_stream, $MsgNum, $MsgNum,
488 $filters_spam_folder);
489 sqimap_messages_flag ($imap_stream, $MsgNum, $MsgNum,
490 'Deleted');
4eee5968 491 }
10a26cea 492 } else {
4eee5968 493 }
10a26cea 494 }
4eee5968 495
10a26cea 496 sqimap_mailbox_expunge($imap_stream, 'INBOX');
4eee5968 497
a2a566eb 498 if ($SpamFilters_SharedCache) {
499 filters_SaveCache();
500 } else {
501 session_register('SpamFilters_DNScache');
502 }
10a26cea 503}
4eee5968 504
505
10a26cea 506// Does the loop through each enabled filter for the specified IP address.
507// IP format: $a.$b.$c.$d
508function filters_spam_check_site($a, $b, $c, $d, &$filters) {
a2a566eb 509 global $SpamFilters_DNScache, $SpamFilters_CacheTTL;
10a26cea 510 foreach ($filters as $key => $value) {
511 if ($filters[$key]['enabled']) {
512 if ($filters[$key]['dns']) {
513 $filter_revip = $d . '.' . $c . '.' . $b . '.' . $a . '.' .
514 $filters[$key]['dns'];
a7cd90dd 515 if (strlen($SpamFilters_DNScache[$filter_revip]['L']) == 0) {
516 $SpamFilters_DNScache[$filter_revip]['L'] =
517 gethostbyname($filter_revip);
518 $SpamFilters_DNScache[$filter_revip]['T'] =
519 time() + $SpamFilters_CacheTTL;
520 }
521 if ($SpamFilters_DNScache[$filter_revip]['L'] ==
522 $filters[$key]['result']) {
523 return 1;
4eee5968 524 }
525 }
526 }
4eee5968 527 }
10a26cea 528 return 0;
529}
530
531function load_filters() {
532 global $data_dir, $username;
c8a2c24d 533
10a26cea 534 $filters = array();
535 for ($i=0; $fltr = getPref($data_dir, $username, 'filter' . $i); $i++) {
536 $ary = explode(',', $fltr);
537 $filters[$i]['where'] = $ary[0];
538 $filters[$i]['what'] = $ary[1];
539 $filters[$i]['folder'] = $ary[2];
4eee5968 540 }
10a26cea 541 return $filters;
542}
543
544function load_spam_filters() {
51199e7a 545 global $data_dir, $username, $SpamFilters_ShowCommercial;
546
547 if ($SpamFilters_ShowCommercial) {
548 $filters['MAPS RBL']['prefname'] = 'filters_spam_maps_rbl';
549 $filters['MAPS RBL']['name'] = 'MAPS Realtime Blackhole List';
550 $filters['MAPS RBL']['link'] = 'http://www.mail-abuse.org/rbl/';
551 $filters['MAPS RBL']['dns'] = 'blackholes.mail-abuse.org';
552 $filters['MAPS RBL']['result'] = '127.0.0.2';
553 $filters['MAPS RBL']['comment'] =
554 _("COMMERCIAL - This list contains servers that are verified spam senders. It is a pretty reliable list to scan spam from.");
555
556 $filters['MAPS RSS']['prefname'] = 'filters_spam_maps_rss';
557 $filters['MAPS RSS']['name'] = 'MAPS Relay Spam Stopper';
558 $filters['MAPS RSS']['link'] = 'http://www.mail-abuse.org/rss/';
559 $filters['MAPS RSS']['dns'] = 'relays.mail-abuse.org';
560 $filters['MAPS RSS']['result'] = '127.0.0.2';
561 $filters['MAPS RSS']['comment'] =
562 _("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.");
563
564 $filters['MAPS DUL']['prefname'] = 'filters_spam_maps_dul';
565 $filters['MAPS DUL']['name'] = 'MAPS Dial-Up List';
566 $filters['MAPS DUL']['link'] = 'http://www.mail-abuse.org/dul/';
567 $filters['MAPS DUL']['dns'] = 'dialups.mail-abuse.org';
568 $filters['MAPS DUL']['result'] = '127.0.0.3';
569 $filters['MAPS DUL']['comment'] =
570 _("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.");
571
572 $filters['MAPS RBLplus-RBL']['prefname'] = 'filters_spam_maps_rblplus_rbl';
573 $filters['MAPS RBLplus-RBL']['name'] = 'MAPS RBL+ RBL List';
574 $filters['MAPS RBLplus-RBL']['link'] = 'http://www.mail-abuse.org/';
575 $filters['MAPS RBLplus-RBL']['dns'] = 'rbl-plus.mail-abuse.org';
576 $filters['MAPS RBLplus-RBL']['result'] = '127.0.0.2';
577 $filters['MAPS RBLplus-RBL']['comment'] =
578 _("COMMERCIAL - RBL+ Blackhole entries.");
579
580 $filters['MAPS RBLplus-RSS']['prefname'] = 'filters_spam_maps_rblplus_rss';
581 $filters['MAPS RBLplus-RSS']['name'] = 'MAPS RBL+ List RSS entries';
582 $filters['MAPS RBLplus-RSS']['link'] = 'http://www.mail-abuse.org/';
583 $filters['MAPS RBLplus-RSS']['dns'] = 'rbl-plus.mail-abuse.org';
584 $filters['MAPS RBLplus-RSS']['result'] = '127.0.0.2';
585 $filters['MAPS RBLplus-RSS']['comment'] =
586 _("COMMERCIAL - RBL+ OpenRelay entries.");
587
588 $filters['MAPS RBLplus-DUL']['prefname'] = 'filters_spam_maps_rblplus_dul';
589 $filters['MAPS RBLplus-DUL']['name'] = 'MAPS RBL+ List DUL entries';
590 $filters['MAPS RBLplus-DUL']['link'] = 'http://www.mail-abuse.org/';
591 $filters['MAPS RBLplus-DUL']['dns'] = 'rbl-plus.mail-abuse.org';
592 $filters['MAPS RBLplus-DUL']['result'] = '127.0.0.3';
593 $filters['MAPS RBLplus-DUL']['comment'] =
594 _("COMMERCIAL - RBL+ Dial-up entries.");
595 }
10a26cea 596
597 $filters['Osirusoft Relays']['prefname'] = 'filters_spam_maps_osirusoft_relay';
598 $filters['Osirusoft Relays']['name'] = 'Osirusoft Relay List';
599 $filters['Osirusoft Relays']['link'] = 'http://relays.osirusoft.com/';
600 $filters['Osirusoft Relays']['dns'] = 'relays.osirusoft.com';
601 $filters['Osirusoft Relays']['result'] = '127.0.0.2';
602 $filters['Osirusoft Relays']['comment'] =
603 _("FREE - Osirusoft Relays - Osirusofts list of verified open relays. Seems to include servers used by abuse@uunet.net auto-replies too.");
604
605 $filters['Osirusoft DUL']['prefname'] = 'filters_spam_maps_osirusoft_dul';
606 $filters['Osirusoft DUL']['name'] = 'Osirusoft Dialup List';
607 $filters['Osirusoft DUL']['link'] = 'http://relays.osirusoft.com/';
608 $filters['Osirusoft DUL']['dns'] = 'relays.osirusoft.com';
609 $filters['Osirusoft DUL']['result'] = '127.0.0.3';
610 $filters['Osirusoft DUL']['comment'] =
611 _("FREE - Osirusoft Dialups - Osirusofts Dialup Spam Source list.");
612
613 $filters['Osirusoft Spam Source']['prefname'] = 'filters_spam_maps_osirusoft_rc';
614 $filters['Osirusoft Spam Source']['name'] = 'Osirusoft Confirmed Spam Source List';
615 $filters['Osirusoft Spam Source']['link'] = 'http://relays.osirusoft.com/';
616 $filters['Osirusoft Spam Source']['dns'] = 'relays.osirusoft.com';
617 $filters['Osirusoft Spam Source']['result'] = '127.0.0.4';
618 $filters['Osirusoft Spam Source']['comment'] =
619 _("FREE - Osirusoft Confirmed Spam Source - Sites that continually spam and have been manually added after multiple nominations. Use with caution. Seems to catch abuse auto-replies from some ISPs.");
620
621 $filters['Osirusoft Smart Host']['prefname'] = 'filters_spam_maps_osirusoft_sh';
622 $filters['Osirusoft Smart Host']['name'] = 'Osirusoft Smart Host List';
623 $filters['Osirusoft Smart Host']['link'] = 'http://relays.osirusoft.com/';
624 $filters['Osirusoft Smart Host']['dns'] = 'relays.osirusoft.com';
625 $filters['Osirusoft Smart Host']['result'] = '127.0.0.5';
626 $filters['Osirusoft Smart Host']['comment'] =
627 _("FREE - Osirusoft Smart Hosts - List of hosts that are secure but relay for other mail servers that are not secure.");
628
629 $filters['Osirusoft SPAMware']['prefname'] = 'filters_spam_maps_osirusoft_ss';
630 $filters['Osirusoft SPAMware']['name'] = 'Osirusoft Spamware Developers List';
631 $filters['Osirusoft SPAMware']['link'] = 'http://relays.osirusoft.com/';
632 $filters['Osirusoft SPAMware']['dns'] = 'relays.osirusoft.com';
633 $filters['Osirusoft SPAMware']['result'] = '127.0.0.6';
634 $filters['Osirusoft SPAMware']['comment'] =
635 _("FREE - Osirusoft Spamware Developers - It is believed that these are IP ranges of companies that are known to produce spam software. Seems to catch abuse auto-replies from some ISPs.");
636
637 $filters['Osirusoft Unc. OptIn']['prefname'] = 'filters_spam_maps_osirusoft_sl';
638 $filters['Osirusoft Unc. OptIn']['name'] = 'Osirusoft Unconfirmed OptIn Server List';
639 $filters['Osirusoft Unc. OptIn']['link'] = 'http://relays.osirusoft.com/';
640 $filters['Osirusoft Unc. OptIn']['dns'] = 'relays.osirusoft.com';
641 $filters['Osirusoft Unc. OptIn']['result'] = '127.0.0.7';
642 $filters['Osirusoft Unc. OptIn']['comment'] =
643 _("FREE - Osirusoft Unconfirmed OptIn Servers - List of listservers that opt users in without confirmation.");
644
645 $filters['Osirusoft Insecure Formmail']['prefname'] = 'filters_spam_maps_osirusoft_fm';
646 $filters['Osirusoft Insecure Formmail']['name'] = 'Osirusoft Insecure formmail.cvi Script List';
647 $filters['Osirusoft Insecure Formmail']['link'] = 'http://relays.osirusoft.com/';
648 $filters['Osirusoft Insecure Formmail']['dns'] = 'relays.osirusoft.com';
649 $filters['Osirusoft Insecure Formmail']['result'] = '127.0.0.8';
650 $filters['Osirusoft Insecure Formmail']['comment'] =
651 _("FREE - Osirusoft Insecure formmail.cgi scripts - List of insecure formmail.cgi scripts. (planned).");
652
653 $filters['Osirusoft Open Proxy']['prefname'] = 'filters_spam_maps_osirusoft_op';
654 $filters['Osirusoft Open Proxy']['name'] = 'Osirusoft Open Proxy Server List';
655 $filters['Osirusoft Open Proxy']['link'] = 'http://relays.osirusoft.com/';
656 $filters['Osirusoft Open Proxy']['dns'] = 'relays.osirusoft.com';
657 $filters['Osirusoft Open Proxy']['result'] = '127.0.0.9';
658 $filters['Osirusoft Open Proxy']['comment'] =
659 _("FREE - Osirusoft Open Proxy Servers - List of Open Proxy Servers.");
660
661 $filters['ORDB']['prefname'] = 'filters_spam_ordb';
662 $filters['ORDB']['name'] = 'Open Relay Database List';
663 $filters['ORDB']['link'] = 'http://www.ordb.org/';
664 $filters['ORDB']['dns'] = 'relays.ordb.org';
665 $filters['ORDB']['result'] = '127.0.0.2';
666 $filters['ORDB']['comment'] =
667 _("FREE - ORDB was born when ORBS went off the air. It seems to have fewer false positives than ORBS did though.");
668
10a26cea 669 $filters['FiveTen Direct']['prefname'] = 'filters_spam_fiveten_src';
670 $filters['FiveTen Direct']['name'] = 'Five-Ten-sg.com Direct SPAM Sources';
671 $filters['FiveTen Direct']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
672 $filters['FiveTen Direct']['dns'] = 'blackholes.five-ten-sg.com';
673 $filters['FiveTen Direct']['result'] = '127.0.0.2';
674 $filters['FiveTen Direct']['comment'] =
675 _("FREE - Five-Ten-sg.com - Direct SPAM sources.");
676
677 $filters['FiveTen DUL']['prefname'] = 'filters_spam_fiveten_dul';
678 $filters['FiveTen DUL']['name'] = 'Five-Ten-sg.com DUL Lists';
679 $filters['FiveTen DUL']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
680 $filters['FiveTen DUL']['dns'] = 'blackholes.five-ten-sg.com';
681 $filters['FiveTen DUL']['result'] = '127.0.0.3';
682 $filters['FiveTen DUL']['comment'] =
683 _("FREE - Five-Ten-sg.com - Dial-up lists - includes some DSL IPs.");
684
685 $filters['FiveTen Unc. OptIn']['prefname'] = 'filters_spam_fiveten_oi';
686 $filters['FiveTen Unc. OptIn']['name'] = 'Five-Ten-sg.com Unconfirmed OptIn Lists';
687 $filters['FiveTen Unc. OptIn']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
688 $filters['FiveTen Unc. OptIn']['dns'] = 'blackholes.five-ten-sg.com';
689 $filters['FiveTen Unc. OptIn']['result'] = '127.0.0.4';
690 $filters['FiveTen Unc. OptIn']['comment'] =
691 _("FREE - Five-Ten-sg.com - Bulk mailers that do not use confirmed opt-in.");
692
693 $filters['FiveTen Others']['prefname'] = 'filters_spam_fiveten_oth';
694 $filters['FiveTen Others']['name'] = 'Five-Ten-sg.com Other Misc. Servers';
695 $filters['FiveTen Others']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
696 $filters['FiveTen Others']['dns'] = 'blackholes.five-ten-sg.com';
697 $filters['FiveTen Others']['result'] = '127.0.0.5';
698 $filters['FiveTen Others']['comment'] =
699 _("FREE - Five-Ten-sg.com - Other misc. servers.");
700
701 $filters['FiveTen Single Stage']['prefname'] = 'filters_spam_fiveten_ss';
702 $filters['FiveTen Single Stage']['name'] = 'Five-Ten-sg.com Single Stage Servers';
703 $filters['FiveTen Single Stage']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
704 $filters['FiveTen Single Stage']['dns'] = 'blackholes.five-ten-sg.com';
705 $filters['FiveTen Single Stage']['result'] = '127.0.0.6';
706 $filters['FiveTen Single Stage']['comment'] =
707 _("FREE - Five-Ten-sg.com - Single Stage servers.");
708
709 $filters['FiveTen SPAM Support']['prefname'] = 'filters_spam_fiveten_supp';
710 $filters['FiveTen SPAM Support']['name'] = 'Five-Ten-sg.com SPAM Support Servers';
711 $filters['FiveTen SPAM Support']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
712 $filters['FiveTen SPAM Support']['dns'] = 'blackholes.five-ten-sg.com';
713 $filters['FiveTen SPAM Support']['result'] = '127.0.0.7';
714 $filters['FiveTen SPAM Support']['comment'] =
715 _("FREE - Five-Ten-sg.com - SPAM Support servers.");
716
717 $filters['FiveTen Web forms']['prefname'] = 'filters_spam_fiveten_wf';
718 $filters['FiveTen Web forms']['name'] = 'Five-Ten-sg.com Web Form IPs';
719 $filters['FiveTen Web forms']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
720 $filters['FiveTen Web forms']['dns'] = 'blackholes.five-ten-sg.com';
721 $filters['FiveTen Web forms']['result'] = '127.0.0.8';
722 $filters['FiveTen Web forms']['comment'] =
723 _("FREE - Five-Ten-sg.com - Web Form IPs.");
724
725 $filters['Dorkslayers']['prefname'] = 'filters_spam_dorks';
726 $filters['Dorkslayers']['name'] = 'Dorkslayers Lists';
727 $filters['Dorkslayers']['link'] = 'http://www.dorkslayers.com';
728 $filters['Dorkslayers']['dns'] = 'orbs.dorkslayers.com';
729 $filters['Dorkslayers']['result'] = '127.0.0.2';
730 $filters['Dorkslayers']['comment'] =
731 _("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.");
732
733 $filters['SPAMhaus']['prefname'] = 'filters_spam_spamhaus';
734 $filters['SPAMhaus']['name'] = 'SPAMhaus Lists';
735 $filters['SPAMhaus']['link'] = 'http://www.spamhaus.org';
736 $filters['SPAMhaus']['dns'] = 'sbl.spamhaus.org';
737 $filters['SPAMhaus']['result'] = '127.0.0.6';
738 $filters['SPAMhaus']['comment'] =
739 _("FREE - SPAMhaus - A list of well-known SPAM sources.");
740
741 $filters['SPAMcop']['prefname'] = 'filters_spam_spamcop';
742 $filters['SPAMcop']['name'] = 'SPAM Cop Lists';
743 $filters['SPAMcop']['link'] = 'http://spamcop.net/bl.shtml';
744 $filters['SPAMcop']['dns'] = 'bl.spamcop.net';
745 $filters['SPAMcop']['result'] = '127.0.0.2';
746 $filters['SPAMcop']['comment'] =
747 _("FREE, for now - SPAMCOP - An interesting solution that lists servers that have a very high spam to legit email ratio (85% or more).");
748
46a184ff 749 $filters['dev.null.dk']['prefname'] = 'filters_spam_devnull';
750 $filters['dev.null.dk']['name'] = 'dev.null.dk Lists';
751 $filters['dev.null.dk']['link'] = 'http://dev.null.dk/';
752 $filters['dev.null.dk']['dns'] = 'dev.null.dk';
753 $filters['dev.null.dk']['result'] = '127.0.0.2';
754 $filters['dev.null.dk']['comment'] =
755 _("FREE - dev.null.dk - I don't have any detailed info on this list.");
756
757 $filters['visi.com']['prefname'] = 'filters_spam_visi';
758 $filters['visi.com']['name'] = 'visi.com Relay Stop List';
759 $filters['visi.com']['link'] = 'http://relays.visi.com';
760 $filters['visi.com']['dns'] = 'relays.visi.com';
761 $filters['visi.com']['result'] = '127.0.0.2';
762 $filters['visi.com']['comment'] =
763 _("FREE - visi.com - Relay Stop List. Very conservative OpenRelay List.");
764
765 $filters['2mbit.com Open Relays']['prefname'] = 'filters_spam_2mb_or';
766 $filters['2mbit.com Open Relays']['name'] = '2mbit.com Open Relays List';
767 $filters['2mbit.com Open Relays']['link'] = 'http://www.2mbit.com/sbl.php';
768 $filters['2mbit.com Open Relays']['dns'] = 'blackholes.2mbit.com';
769 $filters['2mbit.com Open Relays']['result'] = '127.0.0.2';
770 $filters['2mbit.com Open Relays']['comment'] =
771 _("FREE - 2mbit.com Open Relays - Another list of Open Relays.");
772
773 $filters['2mbit.com SPAM Source']['prefname'] = 'filters_spam_2mb_ss';
774 $filters['2mbit.com SPAM Source']['name'] = '2mbit.com SPAM Source List';
775 $filters['2mbit.com SPAM Source']['link'] = 'http://www.2mbit.com/sbl.php';
776 $filters['2mbit.com SPAM Source']['dns'] = 'blackholes.2mbit.com';
777 $filters['2mbit.com SPAM Source']['result'] = '127.0.0.4';
778 $filters['2mbit.com SPAM Source']['comment'] =
779 _("FREE - 2mbit.com SPAM Source - List of Direct SPAM Sources.");
780
781 $filters['2mbit.com SPAM ISPs']['prefname'] = 'filters_spam_2mb_isp';
782 $filters['2mbit.com SPAM ISPs']['name'] = '2mbit.com SPAM-friendly ISP List';
783 $filters['2mbit.com SPAM ISPs']['link'] = 'http://www.2mbit.com/sbl.php';
784 $filters['2mbit.com SPAM ISPs']['dns'] = 'blackholes.2mbit.com';
785 $filters['2mbit.com SPAM ISPs']['result'] = '127.0.0.10';
786 $filters['2mbit.com SPAM ISPs']['comment'] =
787 _("FREE - 2mbit.com SPAM ISPs - List of SPAM-friendly ISPs.");
788
789 $filters['Leadmon DUL']['prefname'] = 'filters_spam_lm_dul';
790 $filters['Leadmon DUL']['name'] = 'Leadmon.net DUL List';
791 $filters['Leadmon DUL']['link'] = 'http://www.leadmon.net/spamguard/';
792 $filters['Leadmon DUL']['dns'] = 'spamguard.leadmon.net';
793 $filters['Leadmon DUL']['result'] = '127.0.0.2';
794 $filters['Leadmon DUL']['comment'] =
795 _("FREE - Leadmon DUL - Another list of Dial-up or otherwise dynamically assigned IPs.");
796
797 $filters['Leadmon SPAM Source']['prefname'] = 'filters_spam_lm_ss';
798 $filters['Leadmon SPAM Source']['name'] = 'Leadmon.net SPAM Source List';
799 $filters['Leadmon SPAM Source']['link'] = 'http://www.leadmon.net/spamguard/';
800 $filters['Leadmon SPAM Source']['dns'] = 'spamguard.leadmon.net';
801 $filters['Leadmon SPAM Source']['result'] = '127.0.0.3';
802 $filters['Leadmon SPAM Source']['comment'] =
803 _("FREE - Leadmon SPAM Source - List of IPs Leadmon.net has received SPAM directly from.");
804
805 $filters['Leadmon Bulk Mailers']['prefname'] = 'filters_spam_lm_bm';
806 $filters['Leadmon Bulk Mailers']['name'] = 'Leadmon.net Bulk Mailers List';
807 $filters['Leadmon Bulk Mailers']['link'] = 'http://www.leadmon.net/spamguard/';
808 $filters['Leadmon Bulk Mailers']['dns'] = 'spamguard.leadmon.net';
809 $filters['Leadmon Bulk Mailers']['result'] = '127.0.0.4';
810 $filters['Leadmon Bulk Mailers']['comment'] =
811 _("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.");
812
813 $filters['Leadmon Open Relays']['prefname'] = 'filters_spam_lm_or';
814 $filters['Leadmon Open Relays']['name'] = 'Leadmon.net Open Relays List';
815 $filters['Leadmon Open Relays']['link'] = 'http://www.leadmon.net/spamguard/';
816 $filters['Leadmon Open Relays']['dns'] = 'spamguard.leadmon.net';
817 $filters['Leadmon Open Relays']['result'] = '127.0.0.5';
818 $filters['Leadmon Open Relays']['comment'] =
819 _("FREE - Leadmon Open Relays - Single Stage Open Relays that are not listed on other active RBLs.");
820
821 $filters['Leadmon Multi-stage']['prefname'] = 'filters_spam_lm_ms';
822 $filters['Leadmon Multi-stage']['name'] = 'Leadmon.net Multi-Stage Relay List';
823 $filters['Leadmon Multi-stage']['link'] = 'http://www.leadmon.net/spamguard/';
824 $filters['Leadmon Multi-stage']['dns'] = 'spamguard.leadmon.net';
825 $filters['Leadmon Multi-stage']['result'] = '127.0.0.6';
826 $filters['Leadmon Multi-stage']['comment'] =
827 _("FREE - Leadmon Multi-stage - Multi-Stage Open Relays that are not listed on other active RBLs and that have sent SPAM to Leadmon.net.");
828
829 $filters['Leadmon SpamBlock']['prefname'] = 'filters_spam_lm_sb';
830 $filters['Leadmon SpamBlock']['name'] = 'Leadmon.net SpamBlock Sites List';
831 $filters['Leadmon SpamBlock']['link'] = 'http://www.leadmon.net/spamguard/';
832 $filters['Leadmon SpamBlock']['dns'] = 'spamguard.leadmon.net';
833 $filters['Leadmon SpamBlock']['result'] = '127.0.0.7';
834 $filters['Leadmon SpamBlock']['comment'] =
835 _("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.");
836
837 $filters['NJABL Open Relays']['prefname'] = 'filters_spam_njabl_or';
838 $filters['NJABL Open Relays']['name'] = 'NJABL Open Relay/Direct Spam Source List';
839 $filters['NJABL Open Relays']['link'] = 'http://www.njabl.org/';
840 $filters['NJABL Open Relays']['dns'] = 'dnsbl.njabl.org';
841 $filters['NJABL Open Relays']['result'] = '127.0.0.2';
842 $filters['NJABL Open Relays']['comment'] =
843 _("FREE, for now - Not Just Another Blacklist - Both Open Relays and Direct SPAM Sources.");
844
845 $filters['NJABL DUL']['prefname'] = 'filters_spam_njabl_dul';
846 $filters['NJABL DUL']['name'] = 'NJABL Dial-ups List';
847 $filters['NJABL DUL']['link'] = 'http://www.njabl.org/';
848 $filters['NJABL DUL']['dns'] = 'dnsbl.njabl.org';
849 $filters['NJABL DUL']['result'] = '127.0.0.3';
850 $filters['NJABL DUL']['comment'] =
851 _("FREE, for now - Not Just Another Blacklist - Dial-up IPs.");
852
10a26cea 853 foreach ($filters as $Key => $Value) {
854 $filters[$Key]['enabled'] = getPref($data_dir, $username,
855 $filters[$Key]['prefname']);
4eee5968 856 }
857
10a26cea 858 return $filters;
859}
4eee5968 860
10a26cea 861function remove_filter ($id) {
862 global $data_dir, $username;
4eee5968 863
10a26cea 864 while ($nextFilter = getPref($data_dir, $username, 'filter' .
865 ($id + 1))) {
866 setPref($data_dir, $username, 'filter' . $id, $nextFilter);
867 $id ++;
4eee5968 868 }
869
10a26cea 870 removePref($data_dir, $username, 'filter' . $id);
871}
4eee5968 872
10a26cea 873function filter_swap($id1, $id2) {
874 global $data_dir, $username;
4eee5968 875
10a26cea 876 $FirstFilter = getPref($data_dir, $username, 'filter' . $id1);
877 $SecondFilter = getPref($data_dir, $username, 'filter' . $id2);
878
879 if ($FirstFilter && $SecondFilter) {
880 setPref($data_dir, $username, 'filter' . $id2, $FirstFilter);
881 setPref($data_dir, $username, 'filter' . $id1, $SecondFilter);
4eee5968 882 }
10a26cea 883}
4eec80a7 884
885/* This update the filter rules when
886 renaming or deleting folders */
f5ab1fb9 887function update_for_folder ($args) {
888 $old_folder = $args[0];
a2a566eb 889 $new_folder = $args[2];
890 $action = $args[1];
4eec80a7 891 global $plugins, $data_dir, $username;
892 $filters = array();
893 $filters = load_filters();
894 $filter_count = count($filters);
895 $p = 0;
896 for ($i=0;$i<$filter_count;$i++) {
897 if (!empty($filters)) {
898 if ($old_folder == $filters[$i]['folder']) {
899 if ($action == 'rename') {
900 $filters[$i]['folder'] = $new_folder;
901 setPref($data_dir, $username, 'filter'.$i,
902 $filters[$i]['where'].','.$filters[$i]['what'].','.$new_folder);
903 }
904 elseif ($action == 'delete') {
905 remove_filter($p);
906 $p = $p-1;
907 }
908 }
909 $p++;
910 }
911 }
912}
849bdf42 913?>