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