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