Fixed wrong sqimap_run_command call. The $sid is added inside
[squirrelmail.git] / plugins / filters / filters.php
CommitLineData
849bdf42 1<?php
4eee5968 2
15e6162e 3/**
4 * Message and Spam Filter Plugin
5 *
76911253 6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
15e6162e 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
ae48f757 31 if (file_exists($data_dir . '/dnscache')) {
32 $fp = fopen($data_dir . '/dnscache', 'r');
a2a566eb 33 } else {
34 $fp = false;
35 }
36 if ($fp) {
37 flock($fp,LOCK_EX);
38 } else {
ae48f757 39 $fp = fopen($data_dir . '/dnscache', 'w+');
a2a566eb 40 fclose($fp);
ae48f757 41 $fp = fopen($data_dir . '/dnscache', 'r');
a2a566eb 42 flock($fp,LOCK_EX);
43 }
ae48f757 44 $fp1=fopen($data_dir . '/dnscache', 'w+');
a2a566eb 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
ae48f757 58 if (file_exists($data_dir . '/dnscache')) {
6ade76e0 59 $SpamFilters_DNScache = array();
ae48f757 60 if ($fp = fopen ($data_dir . '/dnscache', 'r')) {
a2a566eb 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
ae48f757 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) {
ae48f757 146 fputs ($fp, '.' . $key . "\n");
a2a566eb 147 }
148 fputs ($fp, "----------\n");
149 foreach ($IPs as $key => $value) {
150 fputs ($fp, $key . "\n");
151 }
152 fclose ($fp);
153 $bqout = array();
ae48f757 154 exec ($SpamFilters_BulkQuery . ' < ' . $bqfil, $bqout);
a2a566eb 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,
3c66c567 167 $UseSeparateImapConnection, $AllowSpamFilters;
41100fce 168
3c66c567 169 sqgetGlobalVar('username', $username, SQ_SESSION);
170 sqgetGlobalVar('key', $key, SQ_COOKIE);
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
ae48f757 213 for ($i=0, $num = count($filters); $i < $num; $i++) {
10a26cea 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 }
ae48f757 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
ae48f757 277 for ($r=0, $num = count($read); $r < $num &&
53fcc494 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)) {
ae48f757 282 for ($j=2, $num = count($ids); $j < $num; $j++) {
10a26cea 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 ' .
4c409e5a 328 '(RECEIVED)])', true, $response, $message, $uid_support);
c8a2c24d 329 } else {
4c409e5a 330 $read = sqimap_run_command($imap_stream, 'SEARCH UNSEEN', true, $response, $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 ' .
4c409e5a 333 '(RECEIVED)])', true, $response, $message, $uid_support);
c8a2c24d 334 } else {
6174dcc7 335 if (isset($read[0])) {
336 if (preg_match("/^\* SEARCH (.+)$/", $read[0], $regs)) {
337 $search_array = preg_split("/ /", trim($regs[1]));
338 }
c8a2c24d 339 }
6174dcc7 340 $msgs_str = sqimap_message_list_squisher($search_array);
341 $imap_query = 'FETCH '.$msgs_str;
c8a2c24d 342 $imap_query .= ' (FLAGS BODY.PEEK[HEADER.FIELDS ';
6174dcc7 343 $imap_query .= '(RECEIVED)])';
4c409e5a 344 $read = sqimap_run_command($imap_stream,$imap_query, true, $response, $message, $uid_support);
c8a2c24d 345 }
346 }
347
53fcc494 348 if (isset($response) && $response != 'OK') {
10a26cea 349 return;
350 }
4eee5968 351
a2a566eb 352 if (strlen($SpamFilters_BulkQuery) > 0) {
353 filters_bulkquery($filters_spam_scan, $filters, $read);
354 }
355
10a26cea 356 $i = 0;
357 while ($i < count($read)) {
358 // EIMS will give funky results
359 $Chunks = explode(' ', $read[$i]);
360 if ($Chunks[0] != '*') {
4eee5968 361 $i ++;
10a26cea 362 continue;
363 }
364 $MsgNum = $Chunks[1];
4eee5968 365
10a26cea 366 $IPs = array();
367 $i ++;
368 $IsSpam = 0;
4eee5968 369
10a26cea 370 // Look through all of the Received headers for IP addresses
371 // Stop when I get ")" on a line
372 // Stop if I get "*" on a line (don't advance)
373 // and above all, stop if $i is bigger than the total # of lines
374 while (($i < count($read)) &&
375 ($read[$i][0] != ')' && $read[$i][0] != '*' &&
376 $read[$i][0] != "\n") && (! $IsSpam)) {
377 // Check to see if this line is the right "Received from" line
378 // to check
379 if (is_int(strpos($read[$i], $SpamFilters_YourHop))) {
380
381 // short-circuit and skip work if we don't scan this one
c8a2c24d 382 $read[$i] = ereg_replace('[^0-9\.]', ' ', $read[$i]);
383 $elements = explode(' ', $read[$i]);
384 foreach ($elements as $value) {
385 if ($value != '' &&
386 ereg('[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}',
387 $value, $regs)) {
388 $Chunks = explode('.', $value);
389 if (filters_spam_check_site($Chunks[0],
390 $Chunks[1], $Chunks[2], $Chunks[3],
391 $filters)) {
392 $IsSpam ++;
393 break; // no sense in checking more IPs
394 }
395 // If we've checked one IP and YourHop is
396 // just a space
397 if ($SpamFilters_YourHop == ' ') {
398 break; // don't check any more
a9aa7ab7 399 }
a9aa7ab7 400 }
4eee5968 401 }
4eee5968 402 }
10a26cea 403 $i ++;
404 }
4eee5968 405
10a26cea 406 // Lookie! It's spam! Yum!
407 if ($IsSpam) {
408 if (sqimap_mailbox_exists($imap_stream, $filters_spam_folder)) {
409 sqimap_messages_copy ($imap_stream, $MsgNum, $MsgNum,
410 $filters_spam_folder);
411 sqimap_messages_flag ($imap_stream, $MsgNum, $MsgNum,
53fcc494 412 'Deleted', false);
4eee5968 413 }
10a26cea 414 } else {
4eee5968 415 }
10a26cea 416 }
4eee5968 417
10a26cea 418 sqimap_mailbox_expunge($imap_stream, 'INBOX');
4eee5968 419
a2a566eb 420 if ($SpamFilters_SharedCache) {
421 filters_SaveCache();
422 } else {
41100fce 423 sqsession_register($SpamFilters_DNScache, 'SpamFilters_DNScache');
a2a566eb 424 }
53fcc494 425
10a26cea 426}
4eee5968 427
10a26cea 428// Does the loop through each enabled filter for the specified IP address.
429// IP format: $a.$b.$c.$d
430function filters_spam_check_site($a, $b, $c, $d, &$filters) {
a2a566eb 431 global $SpamFilters_DNScache, $SpamFilters_CacheTTL;
10a26cea 432 foreach ($filters as $key => $value) {
433 if ($filters[$key]['enabled']) {
434 if ($filters[$key]['dns']) {
435 $filter_revip = $d . '.' . $c . '.' . $b . '.' . $a . '.' .
436 $filters[$key]['dns'];
ae48f757 437
438 if(!isset($SpamFilters_DNScache[$filter_revip]['L']))
439 $SpamFilters_DNScache[$filter_revip]['L'] = '';
440
441 if(!isset($SpamFilters_DNScache[$filter_revip]['T']))
442 $SpamFilters_DNScache[$filter_revip]['T'] = '';
443
a7cd90dd 444 if (strlen($SpamFilters_DNScache[$filter_revip]['L']) == 0) {
445 $SpamFilters_DNScache[$filter_revip]['L'] =
446 gethostbyname($filter_revip);
447 $SpamFilters_DNScache[$filter_revip]['T'] =
448 time() + $SpamFilters_CacheTTL;
449 }
450 if ($SpamFilters_DNScache[$filter_revip]['L'] ==
451 $filters[$key]['result']) {
452 return 1;
4eee5968 453 }
454 }
455 }
4eee5968 456 }
10a26cea 457 return 0;
458}
459
460function load_filters() {
461 global $data_dir, $username;
c8a2c24d 462
10a26cea 463 $filters = array();
464 for ($i=0; $fltr = getPref($data_dir, $username, 'filter' . $i); $i++) {
465 $ary = explode(',', $fltr);
466 $filters[$i]['where'] = $ary[0];
467 $filters[$i]['what'] = $ary[1];
468 $filters[$i]['folder'] = $ary[2];
4eee5968 469 }
10a26cea 470 return $filters;
471}
472
473function load_spam_filters() {
51199e7a 474 global $data_dir, $username, $SpamFilters_ShowCommercial;
475
476 if ($SpamFilters_ShowCommercial) {
477 $filters['MAPS RBL']['prefname'] = 'filters_spam_maps_rbl';
478 $filters['MAPS RBL']['name'] = 'MAPS Realtime Blackhole List';
479 $filters['MAPS RBL']['link'] = 'http://www.mail-abuse.org/rbl/';
480 $filters['MAPS RBL']['dns'] = 'blackholes.mail-abuse.org';
481 $filters['MAPS RBL']['result'] = '127.0.0.2';
482 $filters['MAPS RBL']['comment'] =
483 _("COMMERCIAL - This list contains servers that are verified spam senders. It is a pretty reliable list to scan spam from.");
484
485 $filters['MAPS RSS']['prefname'] = 'filters_spam_maps_rss';
486 $filters['MAPS RSS']['name'] = 'MAPS Relay Spam Stopper';
487 $filters['MAPS RSS']['link'] = 'http://www.mail-abuse.org/rss/';
488 $filters['MAPS RSS']['dns'] = 'relays.mail-abuse.org';
489 $filters['MAPS RSS']['result'] = '127.0.0.2';
490 $filters['MAPS RSS']['comment'] =
491 _("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.");
492
493 $filters['MAPS DUL']['prefname'] = 'filters_spam_maps_dul';
494 $filters['MAPS DUL']['name'] = 'MAPS Dial-Up List';
495 $filters['MAPS DUL']['link'] = 'http://www.mail-abuse.org/dul/';
496 $filters['MAPS DUL']['dns'] = 'dialups.mail-abuse.org';
497 $filters['MAPS DUL']['result'] = '127.0.0.3';
498 $filters['MAPS DUL']['comment'] =
499 _("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.");
500
501 $filters['MAPS RBLplus-RBL']['prefname'] = 'filters_spam_maps_rblplus_rbl';
502 $filters['MAPS RBLplus-RBL']['name'] = 'MAPS RBL+ RBL List';
503 $filters['MAPS RBLplus-RBL']['link'] = 'http://www.mail-abuse.org/';
504 $filters['MAPS RBLplus-RBL']['dns'] = 'rbl-plus.mail-abuse.org';
505 $filters['MAPS RBLplus-RBL']['result'] = '127.0.0.2';
506 $filters['MAPS RBLplus-RBL']['comment'] =
507 _("COMMERCIAL - RBL+ Blackhole entries.");
508
509 $filters['MAPS RBLplus-RSS']['prefname'] = 'filters_spam_maps_rblplus_rss';
510 $filters['MAPS RBLplus-RSS']['name'] = 'MAPS RBL+ List RSS entries';
511 $filters['MAPS RBLplus-RSS']['link'] = 'http://www.mail-abuse.org/';
512 $filters['MAPS RBLplus-RSS']['dns'] = 'rbl-plus.mail-abuse.org';
513 $filters['MAPS RBLplus-RSS']['result'] = '127.0.0.2';
514 $filters['MAPS RBLplus-RSS']['comment'] =
515 _("COMMERCIAL - RBL+ OpenRelay entries.");
516
517 $filters['MAPS RBLplus-DUL']['prefname'] = 'filters_spam_maps_rblplus_dul';
518 $filters['MAPS RBLplus-DUL']['name'] = 'MAPS RBL+ List DUL entries';
519 $filters['MAPS RBLplus-DUL']['link'] = 'http://www.mail-abuse.org/';
520 $filters['MAPS RBLplus-DUL']['dns'] = 'rbl-plus.mail-abuse.org';
521 $filters['MAPS RBLplus-DUL']['result'] = '127.0.0.3';
522 $filters['MAPS RBLplus-DUL']['comment'] =
523 _("COMMERCIAL - RBL+ Dial-up entries.");
524 }
10a26cea 525
526 $filters['Osirusoft Relays']['prefname'] = 'filters_spam_maps_osirusoft_relay';
527 $filters['Osirusoft Relays']['name'] = 'Osirusoft Relay List';
528 $filters['Osirusoft Relays']['link'] = 'http://relays.osirusoft.com/';
529 $filters['Osirusoft Relays']['dns'] = 'relays.osirusoft.com';
530 $filters['Osirusoft Relays']['result'] = '127.0.0.2';
531 $filters['Osirusoft Relays']['comment'] =
532 _("FREE - Osirusoft Relays - Osirusofts list of verified open relays. Seems to include servers used by abuse@uunet.net auto-replies too.");
533
534 $filters['Osirusoft DUL']['prefname'] = 'filters_spam_maps_osirusoft_dul';
535 $filters['Osirusoft DUL']['name'] = 'Osirusoft Dialup List';
536 $filters['Osirusoft DUL']['link'] = 'http://relays.osirusoft.com/';
537 $filters['Osirusoft DUL']['dns'] = 'relays.osirusoft.com';
538 $filters['Osirusoft DUL']['result'] = '127.0.0.3';
539 $filters['Osirusoft DUL']['comment'] =
540 _("FREE - Osirusoft Dialups - Osirusofts Dialup Spam Source list.");
541
542 $filters['Osirusoft Spam Source']['prefname'] = 'filters_spam_maps_osirusoft_rc';
543 $filters['Osirusoft Spam Source']['name'] = 'Osirusoft Confirmed Spam Source List';
544 $filters['Osirusoft Spam Source']['link'] = 'http://relays.osirusoft.com/';
545 $filters['Osirusoft Spam Source']['dns'] = 'relays.osirusoft.com';
546 $filters['Osirusoft Spam Source']['result'] = '127.0.0.4';
547 $filters['Osirusoft Spam Source']['comment'] =
548 _("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.");
549
550 $filters['Osirusoft Smart Host']['prefname'] = 'filters_spam_maps_osirusoft_sh';
551 $filters['Osirusoft Smart Host']['name'] = 'Osirusoft Smart Host List';
552 $filters['Osirusoft Smart Host']['link'] = 'http://relays.osirusoft.com/';
553 $filters['Osirusoft Smart Host']['dns'] = 'relays.osirusoft.com';
554 $filters['Osirusoft Smart Host']['result'] = '127.0.0.5';
555 $filters['Osirusoft Smart Host']['comment'] =
556 _("FREE - Osirusoft Smart Hosts - List of hosts that are secure but relay for other mail servers that are not secure.");
557
558 $filters['Osirusoft SPAMware']['prefname'] = 'filters_spam_maps_osirusoft_ss';
559 $filters['Osirusoft SPAMware']['name'] = 'Osirusoft Spamware Developers List';
560 $filters['Osirusoft SPAMware']['link'] = 'http://relays.osirusoft.com/';
561 $filters['Osirusoft SPAMware']['dns'] = 'relays.osirusoft.com';
562 $filters['Osirusoft SPAMware']['result'] = '127.0.0.6';
563 $filters['Osirusoft SPAMware']['comment'] =
564 _("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.");
565
566 $filters['Osirusoft Unc. OptIn']['prefname'] = 'filters_spam_maps_osirusoft_sl';
567 $filters['Osirusoft Unc. OptIn']['name'] = 'Osirusoft Unconfirmed OptIn Server List';
568 $filters['Osirusoft Unc. OptIn']['link'] = 'http://relays.osirusoft.com/';
569 $filters['Osirusoft Unc. OptIn']['dns'] = 'relays.osirusoft.com';
570 $filters['Osirusoft Unc. OptIn']['result'] = '127.0.0.7';
571 $filters['Osirusoft Unc. OptIn']['comment'] =
572 _("FREE - Osirusoft Unconfirmed OptIn Servers - List of listservers that opt users in without confirmation.");
573
574 $filters['Osirusoft Insecure Formmail']['prefname'] = 'filters_spam_maps_osirusoft_fm';
575 $filters['Osirusoft Insecure Formmail']['name'] = 'Osirusoft Insecure formmail.cvi Script List';
576 $filters['Osirusoft Insecure Formmail']['link'] = 'http://relays.osirusoft.com/';
577 $filters['Osirusoft Insecure Formmail']['dns'] = 'relays.osirusoft.com';
578 $filters['Osirusoft Insecure Formmail']['result'] = '127.0.0.8';
579 $filters['Osirusoft Insecure Formmail']['comment'] =
580 _("FREE - Osirusoft Insecure formmail.cgi scripts - List of insecure formmail.cgi scripts. (planned).");
581
582 $filters['Osirusoft Open Proxy']['prefname'] = 'filters_spam_maps_osirusoft_op';
583 $filters['Osirusoft Open Proxy']['name'] = 'Osirusoft Open Proxy Server List';
584 $filters['Osirusoft Open Proxy']['link'] = 'http://relays.osirusoft.com/';
585 $filters['Osirusoft Open Proxy']['dns'] = 'relays.osirusoft.com';
586 $filters['Osirusoft Open Proxy']['result'] = '127.0.0.9';
587 $filters['Osirusoft Open Proxy']['comment'] =
588 _("FREE - Osirusoft Open Proxy Servers - List of Open Proxy Servers.");
589
590 $filters['ORDB']['prefname'] = 'filters_spam_ordb';
591 $filters['ORDB']['name'] = 'Open Relay Database List';
592 $filters['ORDB']['link'] = 'http://www.ordb.org/';
593 $filters['ORDB']['dns'] = 'relays.ordb.org';
594 $filters['ORDB']['result'] = '127.0.0.2';
595 $filters['ORDB']['comment'] =
596 _("FREE - ORDB was born when ORBS went off the air. It seems to have fewer false positives than ORBS did though.");
597
10a26cea 598 $filters['FiveTen Direct']['prefname'] = 'filters_spam_fiveten_src';
599 $filters['FiveTen Direct']['name'] = 'Five-Ten-sg.com Direct SPAM Sources';
600 $filters['FiveTen Direct']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
601 $filters['FiveTen Direct']['dns'] = 'blackholes.five-ten-sg.com';
602 $filters['FiveTen Direct']['result'] = '127.0.0.2';
603 $filters['FiveTen Direct']['comment'] =
604 _("FREE - Five-Ten-sg.com - Direct SPAM sources.");
605
606 $filters['FiveTen DUL']['prefname'] = 'filters_spam_fiveten_dul';
607 $filters['FiveTen DUL']['name'] = 'Five-Ten-sg.com DUL Lists';
608 $filters['FiveTen DUL']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
609 $filters['FiveTen DUL']['dns'] = 'blackholes.five-ten-sg.com';
610 $filters['FiveTen DUL']['result'] = '127.0.0.3';
611 $filters['FiveTen DUL']['comment'] =
612 _("FREE - Five-Ten-sg.com - Dial-up lists - includes some DSL IPs.");
613
614 $filters['FiveTen Unc. OptIn']['prefname'] = 'filters_spam_fiveten_oi';
615 $filters['FiveTen Unc. OptIn']['name'] = 'Five-Ten-sg.com Unconfirmed OptIn Lists';
616 $filters['FiveTen Unc. OptIn']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
617 $filters['FiveTen Unc. OptIn']['dns'] = 'blackholes.five-ten-sg.com';
618 $filters['FiveTen Unc. OptIn']['result'] = '127.0.0.4';
619 $filters['FiveTen Unc. OptIn']['comment'] =
620 _("FREE - Five-Ten-sg.com - Bulk mailers that do not use confirmed opt-in.");
621
622 $filters['FiveTen Others']['prefname'] = 'filters_spam_fiveten_oth';
623 $filters['FiveTen Others']['name'] = 'Five-Ten-sg.com Other Misc. Servers';
624 $filters['FiveTen Others']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
625 $filters['FiveTen Others']['dns'] = 'blackholes.five-ten-sg.com';
626 $filters['FiveTen Others']['result'] = '127.0.0.5';
627 $filters['FiveTen Others']['comment'] =
628 _("FREE - Five-Ten-sg.com - Other misc. servers.");
629
630 $filters['FiveTen Single Stage']['prefname'] = 'filters_spam_fiveten_ss';
631 $filters['FiveTen Single Stage']['name'] = 'Five-Ten-sg.com Single Stage Servers';
632 $filters['FiveTen Single Stage']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
633 $filters['FiveTen Single Stage']['dns'] = 'blackholes.five-ten-sg.com';
634 $filters['FiveTen Single Stage']['result'] = '127.0.0.6';
635 $filters['FiveTen Single Stage']['comment'] =
636 _("FREE - Five-Ten-sg.com - Single Stage servers.");
637
638 $filters['FiveTen SPAM Support']['prefname'] = 'filters_spam_fiveten_supp';
639 $filters['FiveTen SPAM Support']['name'] = 'Five-Ten-sg.com SPAM Support Servers';
640 $filters['FiveTen SPAM Support']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
641 $filters['FiveTen SPAM Support']['dns'] = 'blackholes.five-ten-sg.com';
642 $filters['FiveTen SPAM Support']['result'] = '127.0.0.7';
643 $filters['FiveTen SPAM Support']['comment'] =
644 _("FREE - Five-Ten-sg.com - SPAM Support servers.");
645
646 $filters['FiveTen Web forms']['prefname'] = 'filters_spam_fiveten_wf';
647 $filters['FiveTen Web forms']['name'] = 'Five-Ten-sg.com Web Form IPs';
648 $filters['FiveTen Web forms']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
649 $filters['FiveTen Web forms']['dns'] = 'blackholes.five-ten-sg.com';
650 $filters['FiveTen Web forms']['result'] = '127.0.0.8';
651 $filters['FiveTen Web forms']['comment'] =
652 _("FREE - Five-Ten-sg.com - Web Form IPs.");
653
654 $filters['Dorkslayers']['prefname'] = 'filters_spam_dorks';
655 $filters['Dorkslayers']['name'] = 'Dorkslayers Lists';
656 $filters['Dorkslayers']['link'] = 'http://www.dorkslayers.com';
657 $filters['Dorkslayers']['dns'] = 'orbs.dorkslayers.com';
658 $filters['Dorkslayers']['result'] = '127.0.0.2';
659 $filters['Dorkslayers']['comment'] =
660 _("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.");
661
662 $filters['SPAMhaus']['prefname'] = 'filters_spam_spamhaus';
663 $filters['SPAMhaus']['name'] = 'SPAMhaus Lists';
664 $filters['SPAMhaus']['link'] = 'http://www.spamhaus.org';
665 $filters['SPAMhaus']['dns'] = 'sbl.spamhaus.org';
666 $filters['SPAMhaus']['result'] = '127.0.0.6';
667 $filters['SPAMhaus']['comment'] =
668 _("FREE - SPAMhaus - A list of well-known SPAM sources.");
669
670 $filters['SPAMcop']['prefname'] = 'filters_spam_spamcop';
671 $filters['SPAMcop']['name'] = 'SPAM Cop Lists';
672 $filters['SPAMcop']['link'] = 'http://spamcop.net/bl.shtml';
673 $filters['SPAMcop']['dns'] = 'bl.spamcop.net';
674 $filters['SPAMcop']['result'] = '127.0.0.2';
675 $filters['SPAMcop']['comment'] =
676 _("FREE, for now - SPAMCOP - An interesting solution that lists servers that have a very high spam to legit email ratio (85% or more).");
677
46a184ff 678 $filters['dev.null.dk']['prefname'] = 'filters_spam_devnull';
679 $filters['dev.null.dk']['name'] = 'dev.null.dk Lists';
680 $filters['dev.null.dk']['link'] = 'http://dev.null.dk/';
681 $filters['dev.null.dk']['dns'] = 'dev.null.dk';
682 $filters['dev.null.dk']['result'] = '127.0.0.2';
683 $filters['dev.null.dk']['comment'] =
684 _("FREE - dev.null.dk - I don't have any detailed info on this list.");
685
686 $filters['visi.com']['prefname'] = 'filters_spam_visi';
687 $filters['visi.com']['name'] = 'visi.com Relay Stop List';
688 $filters['visi.com']['link'] = 'http://relays.visi.com';
689 $filters['visi.com']['dns'] = 'relays.visi.com';
690 $filters['visi.com']['result'] = '127.0.0.2';
691 $filters['visi.com']['comment'] =
692 _("FREE - visi.com - Relay Stop List. Very conservative OpenRelay List.");
693
694 $filters['2mbit.com Open Relays']['prefname'] = 'filters_spam_2mb_or';
695 $filters['2mbit.com Open Relays']['name'] = '2mbit.com Open Relays List';
696 $filters['2mbit.com Open Relays']['link'] = 'http://www.2mbit.com/sbl.php';
697 $filters['2mbit.com Open Relays']['dns'] = 'blackholes.2mbit.com';
698 $filters['2mbit.com Open Relays']['result'] = '127.0.0.2';
699 $filters['2mbit.com Open Relays']['comment'] =
700 _("FREE - 2mbit.com Open Relays - Another list of Open Relays.");
701
702 $filters['2mbit.com SPAM Source']['prefname'] = 'filters_spam_2mb_ss';
703 $filters['2mbit.com SPAM Source']['name'] = '2mbit.com SPAM Source List';
704 $filters['2mbit.com SPAM Source']['link'] = 'http://www.2mbit.com/sbl.php';
705 $filters['2mbit.com SPAM Source']['dns'] = 'blackholes.2mbit.com';
706 $filters['2mbit.com SPAM Source']['result'] = '127.0.0.4';
707 $filters['2mbit.com SPAM Source']['comment'] =
708 _("FREE - 2mbit.com SPAM Source - List of Direct SPAM Sources.");
709
710 $filters['2mbit.com SPAM ISPs']['prefname'] = 'filters_spam_2mb_isp';
711 $filters['2mbit.com SPAM ISPs']['name'] = '2mbit.com SPAM-friendly ISP List';
712 $filters['2mbit.com SPAM ISPs']['link'] = 'http://www.2mbit.com/sbl.php';
713 $filters['2mbit.com SPAM ISPs']['dns'] = 'blackholes.2mbit.com';
714 $filters['2mbit.com SPAM ISPs']['result'] = '127.0.0.10';
715 $filters['2mbit.com SPAM ISPs']['comment'] =
716 _("FREE - 2mbit.com SPAM ISPs - List of SPAM-friendly ISPs.");
717
718 $filters['Leadmon DUL']['prefname'] = 'filters_spam_lm_dul';
719 $filters['Leadmon DUL']['name'] = 'Leadmon.net DUL List';
720 $filters['Leadmon DUL']['link'] = 'http://www.leadmon.net/spamguard/';
721 $filters['Leadmon DUL']['dns'] = 'spamguard.leadmon.net';
722 $filters['Leadmon DUL']['result'] = '127.0.0.2';
723 $filters['Leadmon DUL']['comment'] =
724 _("FREE - Leadmon DUL - Another list of Dial-up or otherwise dynamically assigned IPs.");
725
726 $filters['Leadmon SPAM Source']['prefname'] = 'filters_spam_lm_ss';
727 $filters['Leadmon SPAM Source']['name'] = 'Leadmon.net SPAM Source List';
728 $filters['Leadmon SPAM Source']['link'] = 'http://www.leadmon.net/spamguard/';
729 $filters['Leadmon SPAM Source']['dns'] = 'spamguard.leadmon.net';
730 $filters['Leadmon SPAM Source']['result'] = '127.0.0.3';
731 $filters['Leadmon SPAM Source']['comment'] =
732 _("FREE - Leadmon SPAM Source - List of IPs Leadmon.net has received SPAM directly from.");
733
734 $filters['Leadmon Bulk Mailers']['prefname'] = 'filters_spam_lm_bm';
735 $filters['Leadmon Bulk Mailers']['name'] = 'Leadmon.net Bulk Mailers List';
736 $filters['Leadmon Bulk Mailers']['link'] = 'http://www.leadmon.net/spamguard/';
737 $filters['Leadmon Bulk Mailers']['dns'] = 'spamguard.leadmon.net';
738 $filters['Leadmon Bulk Mailers']['result'] = '127.0.0.4';
739 $filters['Leadmon Bulk Mailers']['comment'] =
740 _("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.");
741
742 $filters['Leadmon Open Relays']['prefname'] = 'filters_spam_lm_or';
743 $filters['Leadmon Open Relays']['name'] = 'Leadmon.net Open Relays List';
744 $filters['Leadmon Open Relays']['link'] = 'http://www.leadmon.net/spamguard/';
745 $filters['Leadmon Open Relays']['dns'] = 'spamguard.leadmon.net';
746 $filters['Leadmon Open Relays']['result'] = '127.0.0.5';
747 $filters['Leadmon Open Relays']['comment'] =
748 _("FREE - Leadmon Open Relays - Single Stage Open Relays that are not listed on other active RBLs.");
749
750 $filters['Leadmon Multi-stage']['prefname'] = 'filters_spam_lm_ms';
751 $filters['Leadmon Multi-stage']['name'] = 'Leadmon.net Multi-Stage Relay List';
752 $filters['Leadmon Multi-stage']['link'] = 'http://www.leadmon.net/spamguard/';
753 $filters['Leadmon Multi-stage']['dns'] = 'spamguard.leadmon.net';
754 $filters['Leadmon Multi-stage']['result'] = '127.0.0.6';
755 $filters['Leadmon Multi-stage']['comment'] =
756 _("FREE - Leadmon Multi-stage - Multi-Stage Open Relays that are not listed on other active RBLs and that have sent SPAM to Leadmon.net.");
757
758 $filters['Leadmon SpamBlock']['prefname'] = 'filters_spam_lm_sb';
759 $filters['Leadmon SpamBlock']['name'] = 'Leadmon.net SpamBlock Sites List';
760 $filters['Leadmon SpamBlock']['link'] = 'http://www.leadmon.net/spamguard/';
761 $filters['Leadmon SpamBlock']['dns'] = 'spamguard.leadmon.net';
762 $filters['Leadmon SpamBlock']['result'] = '127.0.0.7';
763 $filters['Leadmon SpamBlock']['comment'] =
764 _("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.");
765
766 $filters['NJABL Open Relays']['prefname'] = 'filters_spam_njabl_or';
767 $filters['NJABL Open Relays']['name'] = 'NJABL Open Relay/Direct Spam Source List';
768 $filters['NJABL Open Relays']['link'] = 'http://www.njabl.org/';
769 $filters['NJABL Open Relays']['dns'] = 'dnsbl.njabl.org';
770 $filters['NJABL Open Relays']['result'] = '127.0.0.2';
771 $filters['NJABL Open Relays']['comment'] =
772 _("FREE, for now - Not Just Another Blacklist - Both Open Relays and Direct SPAM Sources.");
773
774 $filters['NJABL DUL']['prefname'] = 'filters_spam_njabl_dul';
775 $filters['NJABL DUL']['name'] = 'NJABL Dial-ups List';
776 $filters['NJABL DUL']['link'] = 'http://www.njabl.org/';
777 $filters['NJABL DUL']['dns'] = 'dnsbl.njabl.org';
778 $filters['NJABL DUL']['result'] = '127.0.0.3';
779 $filters['NJABL DUL']['comment'] =
780 _("FREE, for now - Not Just Another Blacklist - Dial-up IPs.");
781
18b078e9 782 $filters['Conf DSBL.ORG Relay']['prefname'] = 'filters_spam_dsbl_conf_ss';
783 $filters['Conf DSBL.ORG Relay']['name'] = 'DSBL.org Confirmed Relay List';
784 $filters['Conf DSBL.ORG Relay']['link'] = 'http://www.dsbl.org/';
785 $filters['Conf DSBL.ORG Relay']['dns'] = 'list.dsbl.org';
786 $filters['Conf DSBL.ORG Relay']['result'] = '127.0.0.2';
787 $filters['Conf DSBL.ORG Relay']['comment'] =
788 _("FREE - Distributed Sender Boycott List - Confirmed Relays");
789
790 $filters['Conf DSBL.ORG Multi-Stage']['prefname'] = 'filters_spam_dsbl_conf_ms';
791 $filters['Conf DSBL.ORG Multi-Stage']['name'] = 'DSBL.org Confirmed Multi-Stage Relay List';
792 $filters['Conf DSBL.ORG Multi-Stage']['link'] = 'http://www.dsbl.org/';
793 $filters['Conf DSBL.ORG Multi-Stage']['dns'] = 'multihop.dsbl.org';
794 $filters['Conf DSBL.ORG Multi-Stage']['result'] = '127.0.0.2';
795 $filters['Conf DSBL.ORG Multi-Stage']['comment'] =
796 _("FREE - Distributed Sender Boycott List - Confirmed Multi-stage Relays");
797
798 $filters['UN-Conf DSBL.ORG']['prefname'] = 'filters_spam_dsbl_unc';
799 $filters['UN-Conf DSBL.ORG']['name'] = 'DSBL.org UN-Confirmed Relay List';
800 $filters['UN-Conf DSBL.ORG']['link'] = 'http://www.dsbl.org/';
801 $filters['UN-Conf DSBL.ORG']['dns'] = 'unconfirmed.dsbl.org';
802 $filters['UN-Conf DSBL.ORG']['result'] = '127.0.0.2';
803 $filters['UN-Conf DSBL.ORG']['comment'] =
804 _("FREE - Distributed Sender Boycott List - UN-Confirmed Relays");
805
10a26cea 806 foreach ($filters as $Key => $Value) {
807 $filters[$Key]['enabled'] = getPref($data_dir, $username,
808 $filters[$Key]['prefname']);
4eee5968 809 }
810
10a26cea 811 return $filters;
812}
4eee5968 813
10a26cea 814function remove_filter ($id) {
815 global $data_dir, $username;
4eee5968 816
10a26cea 817 while ($nextFilter = getPref($data_dir, $username, 'filter' .
818 ($id + 1))) {
819 setPref($data_dir, $username, 'filter' . $id, $nextFilter);
820 $id ++;
4eee5968 821 }
822
10a26cea 823 removePref($data_dir, $username, 'filter' . $id);
824}
4eee5968 825
10a26cea 826function filter_swap($id1, $id2) {
827 global $data_dir, $username;
4eee5968 828
10a26cea 829 $FirstFilter = getPref($data_dir, $username, 'filter' . $id1);
830 $SecondFilter = getPref($data_dir, $username, 'filter' . $id2);
831
832 if ($FirstFilter && $SecondFilter) {
833 setPref($data_dir, $username, 'filter' . $id2, $FirstFilter);
834 setPref($data_dir, $username, 'filter' . $id1, $SecondFilter);
4eee5968 835 }
10a26cea 836}
4eec80a7 837
838/* This update the filter rules when
839 renaming or deleting folders */
f5ab1fb9 840function update_for_folder ($args) {
841 $old_folder = $args[0];
a2a566eb 842 $new_folder = $args[2];
843 $action = $args[1];
4eec80a7 844 global $plugins, $data_dir, $username;
845 $filters = array();
846 $filters = load_filters();
847 $filter_count = count($filters);
848 $p = 0;
849 for ($i=0;$i<$filter_count;$i++) {
850 if (!empty($filters)) {
851 if ($old_folder == $filters[$i]['folder']) {
852 if ($action == 'rename') {
853 $filters[$i]['folder'] = $new_folder;
854 setPref($data_dir, $username, 'filter'.$i,
855 $filters[$i]['where'].','.$filters[$i]['what'].','.$new_folder);
856 }
857 elseif ($action == 'delete') {
858 remove_filter($p);
859 $p = $p-1;
860 }
861 }
862 $p++;
863 }
864 }
865}
849bdf42 866?>