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