Increment year in copyright notice.
[squirrelmail.git] / plugins / filters / filters.php
1 <?php
2 /**
3 * Message and Spam Filter Plugin - Filtering Functions
4 *
5 * This plugin filters your inbox into different folders based upon given
6 * criteria. It is most useful for people who are subscibed to mailing lists
7 * to help organize their messages. The argument stands that filtering is
8 * not the place of the client, which is why this has been made a plugin for
9 * SquirrelMail. You may be better off using products such as Sieve or
10 * Procmail to do your filtering so it happens even when SquirrelMail isn't
11 * running.
12 *
13 * If you need help with this, or see improvements that can be made, please
14 * email me directly at the address above. I definately welcome suggestions
15 * and comments. This plugin, as is the case with all SquirrelMail plugins,
16 * is not directly supported by the developers. Please come to me off the
17 * mailing list if you have trouble with it.
18 *
19 * Also view plugins/README.plugins for more information.
20 *
21 * @version $Id$
22 * @copyright (c) 1999-2005 The SquirrelMail Project Team
23 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
24 * @package plugins
25 * @subpackage filters
26 */
27
28 /**
29 * FIXME: Undocumented function
30 * @access private
31 */
32 function filters_SaveCache () {
33 global $data_dir, $SpamFilters_DNScache;
34
35 if (file_exists($data_dir . '/dnscache')) {
36 $fp = fopen($data_dir . '/dnscache', 'r');
37 } else {
38 $fp = false;
39 }
40 if ($fp) {
41 flock($fp,LOCK_EX);
42 } else {
43 $fp = fopen($data_dir . '/dnscache', 'w+');
44 fclose($fp);
45 $fp = fopen($data_dir . '/dnscache', 'r');
46 flock($fp,LOCK_EX);
47 }
48 $fp1=fopen($data_dir . '/dnscache', 'w+');
49
50 foreach ($SpamFilters_DNScache as $Key=> $Value) {
51 $tstr = $Key . ',' . $Value['L'] . ',' . $Value['T'] . "\n";
52 fputs ($fp1, $tstr);
53 }
54 fclose($fp1);
55 flock($fp,LOCK_UN);
56 fclose($fp);
57 }
58
59 /**
60 * FIXME: Undocumented function
61 * @access private
62 */
63 function filters_LoadCache () {
64 global $data_dir, $SpamFilters_DNScache;
65
66 if (file_exists($data_dir . '/dnscache')) {
67 $SpamFilters_DNScache = array();
68 if ($fp = fopen ($data_dir . '/dnscache', 'r')) {
69 flock($fp,LOCK_SH);
70 while ($data=fgetcsv($fp,1024)) {
71 if ($data[2] > time()) {
72 $SpamFilters_DNScache[$data[0]]['L'] = $data[1];
73 $SpamFilters_DNScache[$data[0]]['T'] = $data[2];
74 }
75 }
76
77 flock($fp,LOCK_UN);
78 }
79 }
80 }
81
82 /**
83 * FIXME: Undocumented function
84 * @access private
85 */
86 function filters_bulkquery($filters, $IPs) {
87 global $attachment_dir, $username,
88 $SpamFilters_DNScache, $SpamFilters_BulkQuery,
89 $SpamFilters_CacheTTL;
90
91 if (count($IPs) > 0) {
92 $rbls = array();
93 foreach ($filters as $key => $value) {
94 if ($filters[$key]['enabled']) {
95 if ($filters[$key]['dns']) {
96 $rbls[$filters[$key]['dns']] = true;
97 }
98 }
99 }
100
101 $bqfil = $attachment_dir . $username . '-bq.in';
102 $fp = fopen($bqfil, 'w');
103 fputs ($fp, $SpamFilters_CacheTTL . "\n");
104 foreach ($rbls as $key => $value) {
105 fputs ($fp, '.' . $key . "\n");
106 }
107 fputs ($fp, "----------\n");
108 foreach ($IPs as $key => $value) {
109 fputs ($fp, $key . "\n");
110 }
111 fclose ($fp);
112 $bqout = array();
113 exec ($SpamFilters_BulkQuery . ' < ' . $bqfil, $bqout);
114 foreach ($bqout as $value) {
115 $Chunks = explode(',', $value);
116 $SpamFilters_DNScache[$Chunks[0]]['L'] = $Chunks[1];
117 $SpamFilters_DNScache[$Chunks[0]]['T'] = $Chunks[2] + time();
118 }
119 unlink($bqfil);
120 }
121 }
122
123 /**
124 * FIXME: Undocumented function
125 * @access private
126 */
127 function start_filters() {
128 global $imapServerAddress, $imapPort, $imap_stream, $imapConnection,
129 $UseSeparateImapConnection, $AllowSpamFilters;
130
131 sqgetGlobalVar('username', $username, SQ_SESSION);
132 sqgetGlobalVar('key', $key, SQ_COOKIE);
133
134 // Detect if we have already connected to IMAP or not.
135 // Also check if we are forced to use a separate IMAP connection
136 if ((!isset($imap_stream) && !isset($imapConnection)) ||
137 $UseSeparateImapConnection ) {
138 $stream = sqimap_login($username, $key, $imapServerAddress,
139 $imapPort, 10);
140 $previously_connected = false;
141 } else if (isset($imapConnection)) {
142 $stream = $imapConnection;
143 $previously_connected = true;
144 } else {
145 $previously_connected = true;
146 $stream = $imap_stream;
147 }
148 $aStatus = sqimap_status_messages ($stream, 'INBOX', array('MESSAGES'));
149
150 if ($aStatus['MESSAGES']) {
151 sqimap_mailbox_select($stream, 'INBOX');
152 // Filter spam from inbox before we sort them into folders
153 if ($AllowSpamFilters) {
154 spam_filters($stream);
155 }
156
157 // Sort into folders
158 user_filters($stream);
159 }
160
161 if (!$previously_connected) {
162 sqimap_logout($stream);
163 }
164 }
165
166 /**
167 * FIXME: Undocumented function
168 * @access private
169 */
170 function user_filters($imap_stream) {
171 global $data_dir, $username;
172 $filters = load_filters();
173 if (! $filters) return;
174 $filters_user_scan = getPref($data_dir, $username, 'filters_user_scan');
175
176 $expunge = false;
177 // For every rule
178 for ($i=0, $num = count($filters); $i < $num; $i++) {
179 // If it is the "combo" rule
180 if ($filters[$i]['where'] == 'To or Cc') {
181 /*
182 * If it's "TO OR CC", we have to do two searches, one for TO
183 * and the other for CC.
184 */
185 $expunge = filter_search_and_delete($imap_stream, 'TO',
186 $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge);
187 $expunge = filter_search_and_delete($imap_stream, 'CC',
188 $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge);
189 } else {
190 /*
191 * If it's a normal TO, CC, SUBJECT, or FROM, then handle it
192 * normally.
193 */
194 $expunge = filter_search_and_delete($imap_stream, $filters[$i]['where'],
195 $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge);
196 }
197 }
198 // Clean out the mailbox whether or not auto_expunge is on
199 // That way it looks like it was redirected properly
200 if ($expunge) {
201 sqimap_mailbox_expunge($imap_stream, 'INBOX');
202 }
203 }
204
205 /**
206 * FIXME: Undocumented function
207 * @access private
208 */
209 function filter_search_and_delete($imap_stream, $where, $what, $where_to, $user_scan,
210 $should_expunge) {
211 global $languages, $squirrelmail_language, $allow_charset_search, $imap_server_type;
212
213 if ($user_scan == 'new') {
214 $category = 'UNSEEN';
215 } else {
216 $category = 'ALL';
217 }
218
219 if ($allow_charset_search &&
220 isset($languages[$squirrelmail_language]['CHARSET']) &&
221 $languages[$squirrelmail_language]['CHARSET']) {
222 $search_str = 'SEARCH CHARSET '
223 . strtoupper($languages[$squirrelmail_language]['CHARSET'])
224 . ' ' . $category;
225 } else {
226 $search_str = 'SEARCH CHARSET US-ASCII ' . $category;
227 }
228 if ($where == 'Header') {
229 $what = explode(':', $what);
230 $where = trim($where . ' ' . $what[0]);
231 $what = addslashes(trim($what[1]));
232 }
233
234 if ($imap_server_type == 'macosx') {
235 $search_str .= ' ' . $where . ' ' . $what;
236 } else {
237 $search_str .= ' ' . $where . ' {' . strlen($what) . "}\r\n"
238 . $what . "\r\n";
239 }
240
241 /* read data back from IMAP */
242 $read = sqimap_run_command($imap_stream, $search_str, true, $response, $message, TRUE);
243 if (isset($read[0])) {
244 $ids = array();
245 for ($i=0,$iCnt=count($read);$i<$iCnt;++$i) {
246 if (preg_match("/^\* SEARCH (.+)$/", $read[$i], $regs)) {
247 $ids = preg_split("/ /", trim($regs[1]));
248 break;
249 }
250 }
251 if ($response == 'OK' && count($ids)) {
252 if (sqimap_mailbox_exists($imap_stream, $where_to)) {
253 $should_expunge = true;
254 sqimap_msgs_list_move ($imap_stream, $ids, $where_to);
255 }
256 }
257 }
258 return $should_expunge;
259 }
260
261 /**
262 * FIXME: Undocumented function
263 * @access private
264 */
265 function spam_filters($imap_stream) {
266 global $data_dir, $username;
267 global $SpamFilters_YourHop;
268 global $SpamFilters_DNScache;
269 global $SpamFilters_SharedCache;
270 global $SpamFilters_BulkQuery;
271 global $SpamFilters_CacheTTL;
272
273 $filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan');
274 $filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder');
275 $filters = load_spam_filters();
276
277 if ($SpamFilters_SharedCache) {
278 filters_LoadCache();
279 }
280
281 $run = false;
282
283 foreach ($filters as $Key => $Value) {
284 if ($Value['enabled']) {
285 $run = true;
286 break;
287 }
288 }
289
290 // short-circuit
291 if (!$run) {
292 return;
293 }
294
295 // Ask for a big list of all "Received" headers in the inbox with
296 // flags for each message. Kinda big.
297
298 if ($filters_spam_scan == 'new') {
299 $search_array = array();
300 $read = sqimap_run_command($imap_stream, 'SEARCH UNSEEN', true, $response, $message, TRUE);
301 if (isset($read[0])) {
302 for ($i=0,$iCnt=count($read);$i<$iCnt;++$i) {
303 if (preg_match("/^\* SEARCH (.+)$/", $read[$i], $regs)) {
304 $search_array = preg_split("/ /", trim($regs[1]));
305 break;
306 }
307 }
308 }
309 }
310 if ($filters_spam_scan == 'new' && count($search_array)) {
311 $headers = sqimap_get_small_header_list ($imap_stream, $search_array, array('Received'),array());
312 } else if ($filters_spam_scan != 'new') {
313 $headers = sqimap_get_small_header_list ($imap_stream, null , array('Received'),array());
314 } else {
315 return;
316 }
317 if (!count($headers)) {
318 return;
319 }
320 $bulkquery = (strlen($SpamFilters_BulkQuery) > 0 ? true : false);
321 $IPs = array();
322 $aSpamIds = array();
323 foreach ($headers as $id => $aValue) {
324 if (isset($aValue['UID'])) {
325 $MsgNum = $aValue['UID'];
326 } else {
327 $MsgNum = $id;
328 }
329 // Look through all of the Received headers for IP addresses
330 if (isset($aValue['RECEIVED'])) {
331 foreach ($aValue['RECEIVED'] as $received) {
332 // Check to see if this line is the right "Received from" line
333 // to check
334
335 // $aValue['Received'] is an array with all the received lines.
336 // We should check them from bottom to top and only check the first 2.
337 // Currently we check only the header where $SpamFilters_YourHop in occures
338
339 if (is_int(strpos($received, $SpamFilters_YourHop))) {
340 if (preg_match('/([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/',$received,$aMatch)) {
341 $isspam = false;
342 if (filters_spam_check_site($aMatch[1],$aMatch[2],$aMatch[3],$aMatch[4],$filters)) {
343 $aSpamIds[] = $MsgNum;
344 $isspam = true;
345 }
346 if ($bulkquery) {
347 array_shift($aMatch);
348 $IP = explode('.',$aMatch);
349 foreach ($filters as $key => $value) {
350 if ($filters[$key]['enabled'] && $filters[$key]['dns']) {
351 if (strlen($SpamFilters_DNScache[$IP.'.'.$filters[$key]['dns']]) == 0) {
352 $IPs[$IP] = true;
353 break;
354 }
355 }
356 }
357 }
358 // If we've checked one IP and YourHop is
359 // just a space
360 if ($SpamFilters_YourHop == ' ' || $isspam) {
361 break; // don't check any more
362 }
363 }
364 }
365 }
366 }
367 }
368 // Lookie! It's spam! Yum!
369 if (count($aSpamIds) && sqimap_mailbox_exists($imap_stream, $filters_spam_folder)) {
370 sqimap_msgs_list_move ($imap_stream, $aSpamIds, $filters_spam_folder);
371 sqimap_mailbox_expunge($imap_stream, 'INBOX');
372 }
373
374 if ($bulkquery && count($IPs)) {
375 filters_bulkquery($filters, $IPs);
376 }
377
378 if ($SpamFilters_SharedCache) {
379 filters_SaveCache();
380 } else {
381 sqsession_register($SpamFilters_DNScache, 'SpamFilters_DNScache');
382 }
383 }
384
385 /**
386 * FIXME: Undocumented function
387 * Does the loop through each enabled filter for the specified IP address.
388 * IP format: $a.$b.$c.$d
389 * @access private
390 */
391 function filters_spam_check_site($a, $b, $c, $d, &$filters) {
392 global $SpamFilters_DNScache, $SpamFilters_CacheTTL;
393 foreach ($filters as $key => $value) {
394 if ($filters[$key]['enabled']) {
395 if ($filters[$key]['dns']) {
396 $filter_revip = $d . '.' . $c . '.' . $b . '.' . $a . '.' .
397 $filters[$key]['dns'];
398
399 if(!isset($SpamFilters_DNScache[$filter_revip]['L']))
400 $SpamFilters_DNScache[$filter_revip]['L'] = '';
401
402 if(!isset($SpamFilters_DNScache[$filter_revip]['T']))
403 $SpamFilters_DNScache[$filter_revip]['T'] = '';
404
405 if (strlen($SpamFilters_DNScache[$filter_revip]['L']) == 0) {
406 $SpamFilters_DNScache[$filter_revip]['L'] =
407 gethostbyname($filter_revip);
408 $SpamFilters_DNScache[$filter_revip]['T'] =
409 time() + $SpamFilters_CacheTTL;
410 }
411 if ($SpamFilters_DNScache[$filter_revip]['L'] ==
412 $filters[$key]['result']) {
413 return 1;
414 }
415 }
416 }
417 }
418 return 0;
419 }
420
421 /**
422 * FIXME: Undocumented function
423 * @access private
424 */
425 function load_filters() {
426 global $data_dir, $username;
427
428 $filters = array();
429 for ($i=0; $fltr = getPref($data_dir, $username, 'filter' . $i); $i++) {
430 $ary = explode(',', $fltr);
431 $filters[$i]['where'] = $ary[0];
432 $filters[$i]['what'] = $ary[1];
433 $filters[$i]['folder'] = $ary[2];
434 }
435 return $filters;
436 }
437
438 /**
439 * FIXME: Undocumented function
440 * @access private
441 */
442 function load_spam_filters() {
443 global $data_dir, $username, $SpamFilters_ShowCommercial;
444
445 if ($SpamFilters_ShowCommercial) {
446 $filters['MAPS RBL']['prefname'] = 'filters_spam_maps_rbl';
447 $filters['MAPS RBL']['name'] = 'MAPS Realtime Blackhole List';
448 $filters['MAPS RBL']['link'] = 'http://www.mail-abuse.org/rbl/';
449 $filters['MAPS RBL']['dns'] = 'blackholes.mail-abuse.org';
450 $filters['MAPS RBL']['result'] = '127.0.0.2';
451 $filters['MAPS RBL']['comment'] =
452 _("COMMERCIAL - This list contains servers that are verified spam senders. It is a pretty reliable list to scan spam from.");
453
454 $filters['MAPS RSS']['prefname'] = 'filters_spam_maps_rss';
455 $filters['MAPS RSS']['name'] = 'MAPS Relay Spam Stopper';
456 $filters['MAPS RSS']['link'] = 'http://www.mail-abuse.org/rss/';
457 $filters['MAPS RSS']['dns'] = 'relays.mail-abuse.org';
458 $filters['MAPS RSS']['result'] = '127.0.0.2';
459 $filters['MAPS RSS']['comment'] =
460 _("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.");
461
462 $filters['MAPS DUL']['prefname'] = 'filters_spam_maps_dul';
463 $filters['MAPS DUL']['name'] = 'MAPS Dial-Up List';
464 $filters['MAPS DUL']['link'] = 'http://www.mail-abuse.org/dul/';
465 $filters['MAPS DUL']['dns'] = 'dialups.mail-abuse.org';
466 $filters['MAPS DUL']['result'] = '127.0.0.3';
467 $filters['MAPS DUL']['comment'] =
468 _("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.");
469
470 $filters['MAPS RBLplus-RBL']['prefname'] = 'filters_spam_maps_rblplus_rbl';
471 $filters['MAPS RBLplus-RBL']['name'] = 'MAPS RBL+ RBL List';
472 $filters['MAPS RBLplus-RBL']['link'] = 'http://www.mail-abuse.org/';
473 $filters['MAPS RBLplus-RBL']['dns'] = 'rbl-plus.mail-abuse.org';
474 $filters['MAPS RBLplus-RBL']['result'] = '127.0.0.2';
475 $filters['MAPS RBLplus-RBL']['comment'] =
476 _("COMMERCIAL - RBL+ Blackhole entries.");
477
478 $filters['MAPS RBLplus-RSS']['prefname'] = 'filters_spam_maps_rblplus_rss';
479 $filters['MAPS RBLplus-RSS']['name'] = 'MAPS RBL+ List RSS entries';
480 $filters['MAPS RBLplus-RSS']['link'] = 'http://www.mail-abuse.org/';
481 $filters['MAPS RBLplus-RSS']['dns'] = 'rbl-plus.mail-abuse.org';
482 $filters['MAPS RBLplus-RSS']['result'] = '127.0.0.2';
483 $filters['MAPS RBLplus-RSS']['comment'] =
484 _("COMMERCIAL - RBL+ OpenRelay entries.");
485
486 $filters['MAPS RBLplus-DUL']['prefname'] = 'filters_spam_maps_rblplus_dul';
487 $filters['MAPS RBLplus-DUL']['name'] = 'MAPS RBL+ List DUL entries';
488 $filters['MAPS RBLplus-DUL']['link'] = 'http://www.mail-abuse.org/';
489 $filters['MAPS RBLplus-DUL']['dns'] = 'rbl-plus.mail-abuse.org';
490 $filters['MAPS RBLplus-DUL']['result'] = '127.0.0.3';
491 $filters['MAPS RBLplus-DUL']['comment'] =
492 _("COMMERCIAL - RBL+ Dial-up entries.");
493 }
494
495 $filters['ORDB']['prefname'] = 'filters_spam_ordb';
496 $filters['ORDB']['name'] = 'Open Relay Database List';
497 $filters['ORDB']['link'] = 'http://www.ordb.org/';
498 $filters['ORDB']['dns'] = 'relays.ordb.org';
499 $filters['ORDB']['result'] = '127.0.0.2';
500 $filters['ORDB']['comment'] =
501 _("FREE - ORDB was born when ORBS went off the air. It seems to have fewer false positives than ORBS did though.");
502
503 $filters['FiveTen Direct']['prefname'] = 'filters_spam_fiveten_src';
504 $filters['FiveTen Direct']['name'] = 'Five-Ten-sg.com Direct SPAM Sources';
505 $filters['FiveTen Direct']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
506 $filters['FiveTen Direct']['dns'] = 'blackholes.five-ten-sg.com';
507 $filters['FiveTen Direct']['result'] = '127.0.0.2';
508 $filters['FiveTen Direct']['comment'] =
509 _("FREE - Five-Ten-sg.com - Direct SPAM sources.");
510
511 $filters['FiveTen DUL']['prefname'] = 'filters_spam_fiveten_dul';
512 $filters['FiveTen DUL']['name'] = 'Five-Ten-sg.com DUL Lists';
513 $filters['FiveTen DUL']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
514 $filters['FiveTen DUL']['dns'] = 'blackholes.five-ten-sg.com';
515 $filters['FiveTen DUL']['result'] = '127.0.0.3';
516 $filters['FiveTen DUL']['comment'] =
517 _("FREE - Five-Ten-sg.com - Dial-up lists - includes some DSL IPs.");
518
519 $filters['FiveTen Unc. OptIn']['prefname'] = 'filters_spam_fiveten_oi';
520 $filters['FiveTen Unc. OptIn']['name'] = 'Five-Ten-sg.com Unconfirmed OptIn Lists';
521 $filters['FiveTen Unc. OptIn']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
522 $filters['FiveTen Unc. OptIn']['dns'] = 'blackholes.five-ten-sg.com';
523 $filters['FiveTen Unc. OptIn']['result'] = '127.0.0.4';
524 $filters['FiveTen Unc. OptIn']['comment'] =
525 _("FREE - Five-Ten-sg.com - Bulk mailers that do not use confirmed opt-in.");
526
527 $filters['FiveTen Others']['prefname'] = 'filters_spam_fiveten_oth';
528 $filters['FiveTen Others']['name'] = 'Five-Ten-sg.com Other Misc. Servers';
529 $filters['FiveTen Others']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
530 $filters['FiveTen Others']['dns'] = 'blackholes.five-ten-sg.com';
531 $filters['FiveTen Others']['result'] = '127.0.0.5';
532 $filters['FiveTen Others']['comment'] =
533 _("FREE - Five-Ten-sg.com - Other misc. servers.");
534
535 $filters['FiveTen Single Stage']['prefname'] = 'filters_spam_fiveten_ss';
536 $filters['FiveTen Single Stage']['name'] = 'Five-Ten-sg.com Single Stage Servers';
537 $filters['FiveTen Single Stage']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
538 $filters['FiveTen Single Stage']['dns'] = 'blackholes.five-ten-sg.com';
539 $filters['FiveTen Single Stage']['result'] = '127.0.0.6';
540 $filters['FiveTen Single Stage']['comment'] =
541 _("FREE - Five-Ten-sg.com - Single Stage servers.");
542
543 $filters['FiveTen SPAM Support']['prefname'] = 'filters_spam_fiveten_supp';
544 $filters['FiveTen SPAM Support']['name'] = 'Five-Ten-sg.com SPAM Support Servers';
545 $filters['FiveTen SPAM Support']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
546 $filters['FiveTen SPAM Support']['dns'] = 'blackholes.five-ten-sg.com';
547 $filters['FiveTen SPAM Support']['result'] = '127.0.0.7';
548 $filters['FiveTen SPAM Support']['comment'] =
549 _("FREE - Five-Ten-sg.com - SPAM Support servers.");
550
551 $filters['FiveTen Web forms']['prefname'] = 'filters_spam_fiveten_wf';
552 $filters['FiveTen Web forms']['name'] = 'Five-Ten-sg.com Web Form IPs';
553 $filters['FiveTen Web forms']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
554 $filters['FiveTen Web forms']['dns'] = 'blackholes.five-ten-sg.com';
555 $filters['FiveTen Web forms']['result'] = '127.0.0.8';
556 $filters['FiveTen Web forms']['comment'] =
557 _("FREE - Five-Ten-sg.com - Web Form IPs.");
558
559 $filters['Dorkslayers']['prefname'] = 'filters_spam_dorks';
560 $filters['Dorkslayers']['name'] = 'Dorkslayers Lists';
561 $filters['Dorkslayers']['link'] = 'http://www.dorkslayers.com';
562 $filters['Dorkslayers']['dns'] = 'orbs.dorkslayers.com';
563 $filters['Dorkslayers']['result'] = '127.0.0.2';
564 $filters['Dorkslayers']['comment'] =
565 _("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.");
566
567 $filters['SPAMhaus']['prefname'] = 'filters_spam_spamhaus';
568 $filters['SPAMhaus']['name'] = 'SPAMhaus Lists';
569 $filters['SPAMhaus']['link'] = 'http://www.spamhaus.org';
570 $filters['SPAMhaus']['dns'] = 'sbl.spamhaus.org';
571 $filters['SPAMhaus']['result'] = '127.0.0.6';
572 $filters['SPAMhaus']['comment'] =
573 _("FREE - SPAMhaus - A list of well-known SPAM sources.");
574
575 $filters['SPAMcop']['prefname'] = 'filters_spam_spamcop';
576 $filters['SPAMcop']['name'] = 'SPAM Cop Lists';
577 $filters['SPAMcop']['link'] = 'http://spamcop.net/bl.shtml';
578 $filters['SPAMcop']['dns'] = 'bl.spamcop.net';
579 $filters['SPAMcop']['result'] = '127.0.0.2';
580 $filters['SPAMcop']['comment'] =
581 _("FREE, for now - SpamCop - An interesting solution that lists servers that have a very high spam to legit email ratio (85 percent or more).");
582
583 $filters['dev.null.dk']['prefname'] = 'filters_spam_devnull';
584 $filters['dev.null.dk']['name'] = 'dev.null.dk Lists';
585 $filters['dev.null.dk']['link'] = 'http://dev.null.dk/';
586 $filters['dev.null.dk']['dns'] = 'dev.null.dk';
587 $filters['dev.null.dk']['result'] = '127.0.0.2';
588 $filters['dev.null.dk']['comment'] =
589 _("FREE - dev.null.dk - I don't have any detailed info on this list.");
590
591 $filters['visi.com']['prefname'] = 'filters_spam_visi';
592 $filters['visi.com']['name'] = 'visi.com Relay Stop List';
593 $filters['visi.com']['link'] = 'http://relays.visi.com';
594 $filters['visi.com']['dns'] = 'relays.visi.com';
595 $filters['visi.com']['result'] = '127.0.0.2';
596 $filters['visi.com']['comment'] =
597 _("FREE - visi.com - Relay Stop List. Very conservative OpenRelay List.");
598
599 $filters['ahbl.org Open Relays']['prefname'] = 'filters_spam_2mb_or';
600 $filters['ahbl.org Open Relays']['name'] = 'ahbl.org Open Relays List';
601 $filters['ahbl.org Open Relays']['link'] = 'http://www.ahbl.org/';
602 $filters['ahbl.org Open Relays']['dns'] = 'dnsbl.ahbl.org';
603 $filters['ahbl.org Open Relays']['result'] = '127.0.0.2';
604 $filters['ahbl.org Open Relays']['comment'] =
605 _("FREE - ahbl.org Open Relays - Another list of Open Relays.");
606
607 $filters['ahbl.org SPAM Source']['prefname'] = 'filters_spam_2mb_ss';
608 $filters['ahbl.org SPAM Source']['name'] = 'ahbl.org SPAM Source List';
609 $filters['ahbl.org SPAM Source']['link'] = 'http://www.ahbl.org/';
610 $filters['ahbl.org SPAM Source']['dns'] = 'dnsbl.ahbl.org';
611 $filters['ahbl.org SPAM Source']['result'] = '127.0.0.4';
612 $filters['ahbl.org SPAM Source']['comment'] =
613 _("FREE - ahbl.org SPAM Source - List of Direct SPAM Sources.");
614
615 $filters['ahbl.org SPAM ISPs']['prefname'] = 'filters_spam_2mb_isp';
616 $filters['ahbl.org SPAM ISPs']['name'] = 'ahbl.org SPAM-friendly ISP List';
617 $filters['ahbl.org SPAM ISPs']['link'] = 'http://www.ahbl.org/';
618 $filters['ahbl.org SPAM ISPs']['dns'] = 'dnsbl.ahbl.org';
619 $filters['ahbl.org SPAM ISPs']['result'] = '127.0.0.7';
620 $filters['ahbl.org SPAM ISPs']['comment'] =
621 _("FREE - ahbl.org SPAM ISPs - List of SPAM-friendly ISPs.");
622
623 $filters['Leadmon DUL']['prefname'] = 'filters_spam_lm_dul';
624 $filters['Leadmon DUL']['name'] = 'Leadmon.net DUL List';
625 $filters['Leadmon DUL']['link'] = 'http://www.leadmon.net/spamguard/';
626 $filters['Leadmon DUL']['dns'] = 'spamguard.leadmon.net';
627 $filters['Leadmon DUL']['result'] = '127.0.0.2';
628 $filters['Leadmon DUL']['comment'] =
629 _("FREE - Leadmon DUL - Another list of Dial-up or otherwise dynamically assigned IPs.");
630
631 $filters['Leadmon SPAM Source']['prefname'] = 'filters_spam_lm_ss';
632 $filters['Leadmon SPAM Source']['name'] = 'Leadmon.net SPAM Source List';
633 $filters['Leadmon SPAM Source']['link'] = 'http://www.leadmon.net/spamguard/';
634 $filters['Leadmon SPAM Source']['dns'] = 'spamguard.leadmon.net';
635 $filters['Leadmon SPAM Source']['result'] = '127.0.0.3';
636 $filters['Leadmon SPAM Source']['comment'] =
637 _("FREE - Leadmon SPAM Source - List of IPs Leadmon.net has received SPAM directly from.");
638
639 $filters['Leadmon Bulk Mailers']['prefname'] = 'filters_spam_lm_bm';
640 $filters['Leadmon Bulk Mailers']['name'] = 'Leadmon.net Bulk Mailers List';
641 $filters['Leadmon Bulk Mailers']['link'] = 'http://www.leadmon.net/spamguard/';
642 $filters['Leadmon Bulk Mailers']['dns'] = 'spamguard.leadmon.net';
643 $filters['Leadmon Bulk Mailers']['result'] = '127.0.0.4';
644 $filters['Leadmon Bulk Mailers']['comment'] =
645 _("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.");
646
647 $filters['Leadmon Open Relays']['prefname'] = 'filters_spam_lm_or';
648 $filters['Leadmon Open Relays']['name'] = 'Leadmon.net Open Relays List';
649 $filters['Leadmon Open Relays']['link'] = 'http://www.leadmon.net/spamguard/';
650 $filters['Leadmon Open Relays']['dns'] = 'spamguard.leadmon.net';
651 $filters['Leadmon Open Relays']['result'] = '127.0.0.5';
652 $filters['Leadmon Open Relays']['comment'] =
653 _("FREE - Leadmon Open Relays - Single Stage Open Relays that are not listed on other active RBLs.");
654
655 $filters['Leadmon Multi-stage']['prefname'] = 'filters_spam_lm_ms';
656 $filters['Leadmon Multi-stage']['name'] = 'Leadmon.net Multi-Stage Relay List';
657 $filters['Leadmon Multi-stage']['link'] = 'http://www.leadmon.net/spamguard/';
658 $filters['Leadmon Multi-stage']['dns'] = 'spamguard.leadmon.net';
659 $filters['Leadmon Multi-stage']['result'] = '127.0.0.6';
660 $filters['Leadmon Multi-stage']['comment'] =
661 _("FREE - Leadmon Multi-stage - Multi-Stage Open Relays that are not listed on other active RBLs and that have sent SPAM to Leadmon.net.");
662
663 $filters['Leadmon SpamBlock']['prefname'] = 'filters_spam_lm_sb';
664 $filters['Leadmon SpamBlock']['name'] = 'Leadmon.net SpamBlock Sites List';
665 $filters['Leadmon SpamBlock']['link'] = 'http://www.leadmon.net/spamguard/';
666 $filters['Leadmon SpamBlock']['dns'] = 'spamguard.leadmon.net';
667 $filters['Leadmon SpamBlock']['result'] = '127.0.0.7';
668 $filters['Leadmon SpamBlock']['comment'] =
669 _("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.");
670
671 $filters['NJABL Open Relays']['prefname'] = 'filters_spam_njabl_or';
672 $filters['NJABL Open Relays']['name'] = 'NJABL Open Relay/Direct Spam Source List';
673 $filters['NJABL Open Relays']['link'] = 'http://www.njabl.org/';
674 $filters['NJABL Open Relays']['dns'] = 'dnsbl.njabl.org';
675 $filters['NJABL Open Relays']['result'] = '127.0.0.2';
676 $filters['NJABL Open Relays']['comment'] =
677 _("FREE, for now - Not Just Another Blacklist - Both Open Relays and Direct SPAM Sources.");
678
679 $filters['NJABL DUL']['prefname'] = 'filters_spam_njabl_dul';
680 $filters['NJABL DUL']['name'] = 'NJABL Dial-ups List';
681 $filters['NJABL DUL']['link'] = 'http://www.njabl.org/';
682 $filters['NJABL DUL']['dns'] = 'dnsbl.njabl.org';
683 $filters['NJABL DUL']['result'] = '127.0.0.3';
684 $filters['NJABL DUL']['comment'] =
685 _("FREE, for now - Not Just Another Blacklist - Dial-up IPs.");
686
687 $filters['Conf DSBL.ORG Relay']['prefname'] = 'filters_spam_dsbl_conf_ss';
688 $filters['Conf DSBL.ORG Relay']['name'] = 'DSBL.org Confirmed Relay List';
689 $filters['Conf DSBL.ORG Relay']['link'] = 'http://www.dsbl.org/';
690 $filters['Conf DSBL.ORG Relay']['dns'] = 'list.dsbl.org';
691 $filters['Conf DSBL.ORG Relay']['result'] = '127.0.0.2';
692 $filters['Conf DSBL.ORG Relay']['comment'] =
693 _("FREE - Distributed Sender Boycott List - Confirmed Relays");
694
695 $filters['Conf DSBL.ORG Multi-Stage']['prefname'] = 'filters_spam_dsbl_conf_ms';
696 $filters['Conf DSBL.ORG Multi-Stage']['name'] = 'DSBL.org Confirmed Multi-Stage Relay List';
697 $filters['Conf DSBL.ORG Multi-Stage']['link'] = 'http://www.dsbl.org/';
698 $filters['Conf DSBL.ORG Multi-Stage']['dns'] = 'multihop.dsbl.org';
699 $filters['Conf DSBL.ORG Multi-Stage']['result'] = '127.0.0.2';
700 $filters['Conf DSBL.ORG Multi-Stage']['comment'] =
701 _("FREE - Distributed Sender Boycott List - Confirmed Multi-stage Relays");
702
703 $filters['UN-Conf DSBL.ORG']['prefname'] = 'filters_spam_dsbl_unc';
704 $filters['UN-Conf DSBL.ORG']['name'] = 'DSBL.org UN-Confirmed Relay List';
705 $filters['UN-Conf DSBL.ORG']['link'] = 'http://www.dsbl.org/';
706 $filters['UN-Conf DSBL.ORG']['dns'] = 'unconfirmed.dsbl.org';
707 $filters['UN-Conf DSBL.ORG']['result'] = '127.0.0.2';
708 $filters['UN-Conf DSBL.ORG']['comment'] =
709 _("FREE - Distributed Sender Boycott List - UN-Confirmed Relays");
710
711 foreach ($filters as $Key => $Value) {
712 $filters[$Key]['enabled'] = getPref($data_dir, $username,
713 $filters[$Key]['prefname']);
714 }
715
716 return $filters;
717 }
718
719 /**
720 * FIXME: Undocumented function
721 * @access private
722 */
723 function remove_filter ($id) {
724 global $data_dir, $username;
725
726 while ($nextFilter = getPref($data_dir, $username, 'filter' .
727 ($id + 1))) {
728 setPref($data_dir, $username, 'filter' . $id, $nextFilter);
729 $id ++;
730 }
731
732 removePref($data_dir, $username, 'filter' . $id);
733 }
734
735 /**
736 * FIXME: Undocumented function
737 * @access private
738 */
739 function filter_swap($id1, $id2) {
740 global $data_dir, $username;
741
742 $FirstFilter = getPref($data_dir, $username, 'filter' . $id1);
743 $SecondFilter = getPref($data_dir, $username, 'filter' . $id2);
744
745 if ($FirstFilter && $SecondFilter) {
746 setPref($data_dir, $username, 'filter' . $id2, $FirstFilter);
747 setPref($data_dir, $username, 'filter' . $id1, $SecondFilter);
748 }
749 }
750
751 /**
752 * This update the filter rules when renaming or deleting folders
753 * @param array $args
754 * @access private
755 */
756 function update_for_folder ($args) {
757 $old_folder = $args[0];
758 $new_folder = $args[2];
759 $action = $args[1];
760 global $data_dir, $username;
761 $filters = array();
762 $filters = load_filters();
763 $filter_count = count($filters);
764 $p = 0;
765 for ($i=0;$i<$filter_count;$i++) {
766 if (!empty($filters)) {
767 if ($old_folder == $filters[$i]['folder']) {
768 if ($action == 'rename') {
769 $filters[$i]['folder'] = $new_folder;
770 setPref($data_dir, $username, 'filter'.$i,
771 $filters[$i]['where'].','.$filters[$i]['what'].','.$new_folder);
772 }
773 elseif ($action == 'delete') {
774 remove_filter($p);
775 $p = $p-1;
776 }
777 }
778 $p++;
779 }
780 }
781 }
782
783 /**
784 * Display formated error message
785 * @param string $string text message
786 * @return string html formated text message
787 * @access private
788 */
789 function do_error($string) {
790 global $color;
791 echo "<p align=\"center\"><font color=\"$color[2]\">";
792 echo $string;
793 echo "</font></p>\n";
794 }
795 ?>