4 * Message and Spam Filter Plugin - Filtering Functions
6 * @copyright © 1999-2006 The SquirrelMail Project Team
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
14 if (! defined('SM_PATH')) define('SM_PATH','../../');
17 global $UseSeparateImapConnection,
18 $AllowSpamFilters, $SpamFilters_YourHop, $SpamFilters_ShowCommercial,
19 $SpamFilters_DNScache, $SpamFilters_BulkQuery, $SpamFilters_SharedCache,
20 $SpamFilters_CacheTTL;
22 /** load default config */
23 if (file_exists(SM_PATH
. 'plugins/filters/config_default.php')) {
24 include_once (SM_PATH
. 'plugins/filters/config_default.php');
26 // default config was removed.
27 $UseSeparateImapConnection = false;
28 $AllowSpamFilters = true;
29 $SpamFilters_YourHop = ' ';
30 $SpamFilters_ShowCommercial = false;
31 $SpamFilters_DNScache = array();
32 $SpamFilters_BulkQuery = '';
33 $SpamFilters_SharedCache = true;
34 $SpamFilters_CacheTTL = 7200;
37 if (file_exists(SM_PATH
. 'config/filters_config.php')) {
38 include_once (SM_PATH
. 'config/filters_config.php');
39 } elseif (file_exists(SM_PATH
. 'plugins/filters/config.php')) {
40 include_once (SM_PATH
. 'plugins/filters/config.php');
47 function filters_init_hooks () {
48 global $squirrelmail_plugin_hooks;
50 if (! sqgetGlobalVar('mailbox',$mailbox,SQ_FORM
)) {
54 $squirrelmail_plugin_hooks['left_main_before']['filters'] = 'start_filters_hook';
55 if (isset($mailbox) && $mailbox == 'INBOX') {
56 $squirrelmail_plugin_hooks['right_main_after_header']['filters'] = 'start_filters_hook';
58 $squirrelmail_plugin_hooks['optpage_register_block']['filters'] = 'filters_optpage_register_block_hook';
59 $squirrelmail_plugin_hooks['special_mailbox']['filters'] = 'filters_special_mailbox';
60 $squirrelmail_plugin_hooks['rename_or_delete_folder']['filters'] = 'update_for_folder_hook';
61 $squirrelmail_plugin_hooks['webmail_bottom']['filters'] = 'start_filters_hook';
62 $squirrelmail_plugin_hooks['folder_status']['filters'] = 'filters_folder_status';
66 * Register option blocks
69 function filters_optpage_register_block() {
70 global $optpage_blocks, $AllowSpamFilters;
72 $optpage_blocks[] = array(
73 'name' => _("Message Filters"),
74 'url' => SM_PATH
. 'plugins/filters/options.php',
75 'desc' => _("Filtering enables messages with different criteria to be automatically filtered into different folders for easier organization."),
79 if ($AllowSpamFilters) {
80 $optpage_blocks[] = array(
81 'name' => _("SPAM Filters"),
82 'url' => SM_PATH
. 'plugins/filters/spamoptions.php',
83 'desc' => _("SPAM filters allow you to select from various DNS based blacklists to detect junk email in your INBOX and move it to another folder (like Trash)."),
89 /* Receive the status of the folder and do something with it */
90 function filters_folder_status($statusarr) {
92 global $filter_inbox_count;
93 if (empty($filter_inbox_count)) $filter_inbox_count=0;
95 //echo "GOT HOOK<br><pre>";
96 //var_dump($statusarr);
97 //echo "</pre><br>\n";
99 if ($statusarr['MAILBOX'] == 'INBOX')
101 if (!empty($statusarr['MESSAGES'])) $filter_inbox_count=$statusarr['MESSAGES'];
106 * Saves the DNS Cache to disk
109 function filters_SaveCache () {
110 global $data_dir, $SpamFilters_DNScache;
112 if (file_exists($data_dir . '/dnscache')) {
113 $fp = fopen($data_dir . '/dnscache', 'r');
120 $fp = fopen($data_dir . '/dnscache', 'w+');
122 $fp = fopen($data_dir . '/dnscache', 'r');
125 $fp1 = fopen($data_dir . '/dnscache', 'w+');
127 foreach ($SpamFilters_DNScache as $Key=> $Value) {
128 $tstr = $Key . ',' . $Value['L'] . ',' . $Value['T'] . "\n";
137 * Loads the DNS Cache from disk
140 function filters_LoadCache () {
141 global $data_dir, $SpamFilters_DNScache;
143 if (file_exists($data_dir . '/dnscache')) {
144 $SpamFilters_DNScache = array();
145 if ($fp = fopen ($data_dir . '/dnscache', 'r')) {
147 while ($data = fgetcsv($fp,1024)) {
148 if ($data[2] > time()) {
149 $SpamFilters_DNScache[$data[0]]['L'] = $data[1];
150 $SpamFilters_DNScache[$data[0]]['T'] = $data[2];
159 * Uses the BulkQuery executable to query all the RBLs at once
160 * @param array $filters Array of SPAM Fitlers
161 * @param array $IPs Array of IP Addresses
164 function filters_bulkquery($filters, $IPs) {
165 global $attachment_dir, $username,
166 $SpamFilters_DNScache, $SpamFilters_BulkQuery,
167 $SpamFilters_CacheTTL;
169 if (count($IPs) > 0) {
171 foreach ($filters as $key => $value) {
172 if ($filters[$key]['enabled']) {
173 if ($filters[$key]['dns']) {
174 $rbls[$filters[$key]['dns']] = true;
179 $bqfil = $attachment_dir . $username . '-bq.in';
180 $fp = fopen($bqfil, 'w');
181 fputs ($fp, $SpamFilters_CacheTTL . "\n");
182 foreach ($rbls as $key => $value) {
183 fputs ($fp, '.' . $key . "\n");
185 fputs ($fp, "----------\n");
186 foreach ($IPs as $key => $value) {
187 fputs ($fp, $key . "\n");
191 exec ($SpamFilters_BulkQuery . ' < ' . $bqfil, $bqout);
192 foreach ($bqout as $value) {
193 $Chunks = explode(',', $value);
194 $SpamFilters_DNScache[$Chunks[0]]['L'] = $Chunks[1];
195 $SpamFilters_DNScache[$Chunks[0]]['T'] = $Chunks[2] +
time();
202 * Starts the filtering process
205 function start_filters() {
206 global $imapServerAddress, $imapPort, $imap_stream, $imapConnection,
207 $UseSeparateImapConnection, $AllowSpamFilters, $filter_inbox_count;
209 sqgetGlobalVar('username', $username, SQ_SESSION
);
210 sqgetGlobalVar('key', $key, SQ_COOKIE
);
212 $filters = load_filters();
214 // No point running spam filters if there aren't any to run //
215 if ($AllowSpamFilters) {
216 $spamfilters = load_spam_filters();
218 $AllowSpamFilters = false;
219 foreach($spamfilters as $filterskey=>$value) {
220 if ($value['enabled'] == 'yes') {
221 $AllowSpamFilters = true;
227 if (!$AllowSpamFilters && empty($filters)) {
232 // Detect if we have already connected to IMAP or not.
233 // Also check if we are forced to use a separate IMAP connection
234 if ((!isset($imap_stream) && !isset($imapConnection)) ||
235 $UseSeparateImapConnection ) {
236 $stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10);
237 $previously_connected = false;
238 } else if (isset($imapConnection)) {
239 $stream = $imapConnection;
240 $previously_connected = true;
242 $previously_connected = true;
243 $stream = $imap_stream;
246 if (!isset($filter_inbox_count)) {
247 $aStatus = sqimap_status_messages ($stream, 'INBOX', array('MESSAGES'));
248 if (!empty($aStatus['MESSAGES'])) {
249 $filter_inbox_count=$aStatus['MESSAGES'];
251 $filter_inbox_count=0;
255 if ($filter_inbox_count > 0) {
256 sqimap_mailbox_select($stream, 'INBOX');
257 // Filter spam from inbox before we sort them into folders
258 if ($AllowSpamFilters) {
259 spam_filters($stream);
263 user_filters($stream);
266 if (!$previously_connected) {
267 sqimap_logout($stream);
272 * Does the loop through each filter
273 * @param stream imap_stream the stream to read from
276 function user_filters($imap_stream) {
277 global $data_dir, $username;
278 $filters = load_filters();
279 if (! $filters) return;
280 $filters_user_scan = getPref($data_dir, $username, 'filters_user_scan');
284 for ($i=0, $num = count($filters); $i < $num; $i++
) {
285 // If it is the "combo" rule
286 if ($filters[$i]['where'] == 'To or Cc') {
288 * If it's "TO OR CC", we have to do two searches, one for TO
289 * and the other for CC.
291 $expunge = filter_search_and_delete($imap_stream, 'TO',
292 $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge);
293 $expunge = filter_search_and_delete($imap_stream, 'CC',
294 $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge);
295 } else if ($filters[$i]['where'] == 'Header and Body') {
296 $expunge = filter_search_and_delete($imap_stream, 'TEXT',
297 $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge);
298 } else if ($filters[$i]['where'] == 'Message Body') {
299 $expunge = filter_search_and_delete($imap_stream, 'BODY',
300 $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge);
303 * If it's a normal TO, CC, SUBJECT, or FROM, then handle it
306 $expunge = filter_search_and_delete($imap_stream, $filters[$i]['where'],
307 $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge);
310 // Clean out the mailbox whether or not auto_expunge is on
311 // That way it looks like it was redirected properly
313 sqimap_mailbox_expunge($imap_stream, 'INBOX');
318 * Creates and runs the IMAP command to filter messages
319 * @param string $where Which part of the message to search (TO, CC, SUBJECT, etc...)
320 * @param string $what String to search for
321 * @param string $where_to Folder it will move to
322 * @param string $user_scan Whether to search all or just unseen
323 * @param string $should_expunge
324 * @param boolean $where Which part of location to search
327 function filter_search_and_delete($imap_stream, $where, $what, $where_to, $user_scan,
329 global $languages, $squirrelmail_language, $allow_charset_search, $imap_server_type;
331 if (strtolower($where_to) == 'inbox') {
335 if ($user_scan == 'new') {
336 $category = 'UNSEEN';
340 $category .= ' UNDELETED';
342 if ($allow_charset_search &&
343 isset($languages[$squirrelmail_language]['CHARSET']) &&
344 $languages[$squirrelmail_language]['CHARSET']) {
345 $search_str = 'SEARCH CHARSET '
346 . strtoupper($languages[$squirrelmail_language]['CHARSET'])
349 $search_str = 'SEARCH CHARSET US-ASCII ' . $category;
351 if ($where == 'Header') {
352 $what = explode(':', $what);
353 $where = trim($where . ' ' . $what[0]);
354 $what = addslashes(trim($what[1]));
357 // see comments in squirrelmail sqimap_search function
358 if ($imap_server_type == 'macosx' ||
$imap_server_type == 'hmailserver') {
359 $search_str .= ' ' . $where . ' ' . $what;
361 $search_str .= ' ' . $where . ' {' . strlen($what) . "}\r\n"
365 /* read data back from IMAP */
366 $read = sqimap_run_command($imap_stream, $search_str, true, $response, $message, TRUE);
367 if (isset($read[0])) {
369 for ($i = 0, $iCnt = count($read); $i < $iCnt; ++
$i) {
370 if (preg_match("/^\* SEARCH (.+)$/", $read[$i], $regs)) {
371 $ids = preg_split("/ /", trim($regs[1]));
375 if ($response == 'OK' && count($ids)) {
376 if (sqimap_mailbox_exists($imap_stream, $where_to)) {
377 $should_expunge = true;
378 sqimap_msgs_list_move ($imap_stream, $ids, $where_to, false);
382 return $should_expunge;
386 * Loops through all the Received Headers to find IP Addresses
387 * @param stream imap_stream the stream to read from
390 function spam_filters($imap_stream) {
391 global $data_dir, $username;
392 global $SpamFilters_YourHop;
393 global $SpamFilters_DNScache;
394 global $SpamFilters_SharedCache;
395 global $SpamFilters_BulkQuery;
396 global $SpamFilters_CacheTTL;
398 $filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan');
399 $filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder');
400 $filters = load_spam_filters();
402 if ($SpamFilters_SharedCache) {
408 foreach ($filters as $Key => $Value) {
409 if ($Value['enabled']) {
420 // Ask for a big list of all "Received" headers in the inbox with
421 // flags for each message. Kinda big.
423 if ($filters_spam_scan == 'new') {
424 $search_array = array();
425 $read = sqimap_run_command($imap_stream, 'SEARCH UNSEEN', true, $response, $message, TRUE);
426 if (isset($read[0])) {
427 for ($i = 0, $iCnt = count($read); $i < $iCnt; ++
$i) {
428 if (preg_match("/^\* SEARCH (.+)$/", $read[$i], $regs)) {
429 $search_array = preg_split("/ /", trim($regs[1]));
435 if ($filters_spam_scan == 'new' && count($search_array)) {
436 $headers = sqimap_get_small_header_list ($imap_stream, $search_array, array('Received'),array());
437 } else if ($filters_spam_scan != 'new') {
438 $headers = sqimap_get_small_header_list ($imap_stream, null , array('Received'),array());
442 if (!count($headers)) {
445 $bulkquery = (strlen($SpamFilters_BulkQuery) > 0 ?
true : false);
448 foreach ($headers as $id => $aValue) {
449 if (isset($aValue['UID'])) {
450 $MsgNum = $aValue['UID'];
454 // Look through all of the Received headers for IP addresses
455 if (isset($aValue['RECEIVED'])) {
456 foreach ($aValue['RECEIVED'] as $received) {
457 // Check to see if this line is the right "Received from" line
460 // $aValue['Received'] is an array with all the received lines.
461 // We should check them from bottom to top and only check the first 2.
462 // Currently we check only the header where $SpamFilters_YourHop in occures
464 if (is_int(strpos($received, $SpamFilters_YourHop))) {
465 if (preg_match('/([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/',$received,$aMatch)) {
467 if (filters_spam_check_site($aMatch[1],$aMatch[2],$aMatch[3],$aMatch[4],$filters)) {
468 $aSpamIds[] = $MsgNum;
472 array_shift($aMatch);
473 $IP = explode('.',$aMatch);
474 foreach ($filters as $key => $value) {
475 if ($filters[$key]['enabled'] && $filters[$key]['dns']) {
476 if (strlen($SpamFilters_DNScache[$IP.'.'.$filters[$key]['dns']]) == 0) {
483 // If we've checked one IP and YourHop is
485 if ($SpamFilters_YourHop == ' ' ||
$isspam) {
486 break; // don't check any more
493 // Lookie! It's spam! Yum!
494 if (count($aSpamIds) && sqimap_mailbox_exists($imap_stream, $filters_spam_folder)) {
495 sqimap_msgs_list_move ($imap_stream, $aSpamIds, $filters_spam_folder);
496 sqimap_mailbox_expunge($imap_stream, 'INBOX');
499 if ($bulkquery && count($IPs)) {
500 filters_bulkquery($filters, $IPs);
503 if ($SpamFilters_SharedCache) {
506 sqsession_register($SpamFilters_DNScache, 'SpamFilters_DNScache');
511 * Does the loop through each enabled filter for the specified IP address.
512 * IP format: $a.$b.$c.$d
513 * @param int $a First subset of IP
514 * @param int $b Second subset of IP
515 * @param int $c Third subset of IP
516 * @param int $d Forth subset of IP
517 * @param array $filters The Spam Filters
518 * @return boolean Whether the IP is Spam
521 function filters_spam_check_site($a, $b, $c, $d, &$filters) {
522 global $SpamFilters_DNScache, $SpamFilters_CacheTTL;
523 foreach ($filters as $key => $value) {
524 if ($filters[$key]['enabled']) {
525 if ($filters[$key]['dns']) {
526 $filter_revip = $d . '.' . $c . '.' . $b . '.' . $a . '.' .
527 $filters[$key]['dns'];
529 if(!isset($SpamFilters_DNScache[$filter_revip]['L']))
530 $SpamFilters_DNScache[$filter_revip]['L'] = '';
532 if(!isset($SpamFilters_DNScache[$filter_revip]['T']))
533 $SpamFilters_DNScache[$filter_revip]['T'] = '';
535 if (strlen($SpamFilters_DNScache[$filter_revip]['L']) == 0) {
536 $SpamFilters_DNScache[$filter_revip]['L'] =
537 gethostbyname($filter_revip);
538 $SpamFilters_DNScache[$filter_revip]['T'] =
539 time() +
$SpamFilters_CacheTTL;
541 if ($SpamFilters_DNScache[$filter_revip]['L'] ==
542 $filters[$key]['result']) {
552 * Loads the filters from the user preferences
553 * @return array All the user filters
556 function load_filters() {
557 global $data_dir, $username;
560 for ($i = 0; $fltr = getPref($data_dir, $username, 'filter' . $i); $i++
) {
561 $ary = explode(',', $fltr);
562 $filters[$i]['where'] = $ary[0];
563 $filters[$i]['what'] = $ary[1];
564 $filters[$i]['folder'] = $ary[2];
570 * Loads the Spam Filters and checks the preferences for the enabled status
571 * @return array All the spam filters
574 function load_spam_filters() {
575 global $data_dir, $username, $SpamFilters_ShowCommercial;
577 if ($SpamFilters_ShowCommercial) {
578 $filters['MAPS RBL']['prefname'] = 'filters_spam_maps_rbl';
579 $filters['MAPS RBL']['name'] = 'MAPS Realtime Blackhole List';
580 $filters['MAPS RBL']['link'] = 'http://www.mail-abuse.org/rbl/';
581 $filters['MAPS RBL']['dns'] = 'blackholes.mail-abuse.org';
582 $filters['MAPS RBL']['result'] = '127.0.0.2';
583 $filters['MAPS RBL']['comment'] =
584 _("COMMERCIAL - This list contains servers that are verified spam senders. It is a pretty reliable list to scan spam from.");
586 $filters['MAPS RSS']['prefname'] = 'filters_spam_maps_rss';
587 $filters['MAPS RSS']['name'] = 'MAPS Relay Spam Stopper';
588 $filters['MAPS RSS']['link'] = 'http://www.mail-abuse.org/rss/';
589 $filters['MAPS RSS']['dns'] = 'relays.mail-abuse.org';
590 $filters['MAPS RSS']['result'] = '127.0.0.2';
591 $filters['MAPS RSS']['comment'] =
592 _("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.");
594 $filters['MAPS DUL']['prefname'] = 'filters_spam_maps_dul';
595 $filters['MAPS DUL']['name'] = 'MAPS Dial-Up List';
596 $filters['MAPS DUL']['link'] = 'http://www.mail-abuse.org/dul/';
597 $filters['MAPS DUL']['dns'] = 'dialups.mail-abuse.org';
598 $filters['MAPS DUL']['result'] = '127.0.0.3';
599 $filters['MAPS DUL']['comment'] =
600 _("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.");
602 $filters['MAPS RBLplus-RBL']['prefname'] = 'filters_spam_maps_rblplus_rbl';
603 $filters['MAPS RBLplus-RBL']['name'] = 'MAPS RBL+ RBL List';
604 $filters['MAPS RBLplus-RBL']['link'] = 'http://www.mail-abuse.org/';
605 $filters['MAPS RBLplus-RBL']['dns'] = 'rbl-plus.mail-abuse.org';
606 $filters['MAPS RBLplus-RBL']['result'] = '127.0.0.2';
607 $filters['MAPS RBLplus-RBL']['comment'] =
608 _("COMMERCIAL - RBL+ Blackhole entries.");
610 $filters['MAPS RBLplus-RSS']['prefname'] = 'filters_spam_maps_rblplus_rss';
611 $filters['MAPS RBLplus-RSS']['name'] = 'MAPS RBL+ List RSS entries';
612 $filters['MAPS RBLplus-RSS']['link'] = 'http://www.mail-abuse.org/';
613 $filters['MAPS RBLplus-RSS']['dns'] = 'rbl-plus.mail-abuse.org';
614 $filters['MAPS RBLplus-RSS']['result'] = '127.0.0.2';
615 $filters['MAPS RBLplus-RSS']['comment'] =
616 _("COMMERCIAL - RBL+ OpenRelay entries.");
618 $filters['MAPS RBLplus-DUL']['prefname'] = 'filters_spam_maps_rblplus_dul';
619 $filters['MAPS RBLplus-DUL']['name'] = 'MAPS RBL+ List DUL entries';
620 $filters['MAPS RBLplus-DUL']['link'] = 'http://www.mail-abuse.org/';
621 $filters['MAPS RBLplus-DUL']['dns'] = 'rbl-plus.mail-abuse.org';
622 $filters['MAPS RBLplus-DUL']['result'] = '127.0.0.3';
623 $filters['MAPS RBLplus-DUL']['comment'] =
624 _("COMMERCIAL - RBL+ Dial-up entries.");
627 $filters['ORDB']['prefname'] = 'filters_spam_ordb';
628 $filters['ORDB']['name'] = 'Open Relay Database List';
629 $filters['ORDB']['link'] = 'http://www.ordb.org/';
630 $filters['ORDB']['dns'] = 'relays.ordb.org';
631 $filters['ORDB']['result'] = '127.0.0.2';
632 $filters['ORDB']['comment'] =
633 _("FREE - ORDB was born when ORBS went off the air. It seems to have fewer false positives than ORBS did though.");
635 $filters['FiveTen Direct']['prefname'] = 'filters_spam_fiveten_src';
636 $filters['FiveTen Direct']['name'] = 'Five-Ten-sg.com Direct SPAM Sources';
637 $filters['FiveTen Direct']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
638 $filters['FiveTen Direct']['dns'] = 'blackholes.five-ten-sg.com';
639 $filters['FiveTen Direct']['result'] = '127.0.0.2';
640 $filters['FiveTen Direct']['comment'] =
641 _("FREE - Five-Ten-sg.com - Direct SPAM sources.");
643 $filters['FiveTen DUL']['prefname'] = 'filters_spam_fiveten_dul';
644 $filters['FiveTen DUL']['name'] = 'Five-Ten-sg.com DUL Lists';
645 $filters['FiveTen DUL']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
646 $filters['FiveTen DUL']['dns'] = 'blackholes.five-ten-sg.com';
647 $filters['FiveTen DUL']['result'] = '127.0.0.3';
648 $filters['FiveTen DUL']['comment'] =
649 _("FREE - Five-Ten-sg.com - Dial-up lists - includes some DSL IPs.");
651 $filters['FiveTen Unc. OptIn']['prefname'] = 'filters_spam_fiveten_oi';
652 $filters['FiveTen Unc. OptIn']['name'] = 'Five-Ten-sg.com Unconfirmed OptIn Lists';
653 $filters['FiveTen Unc. OptIn']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
654 $filters['FiveTen Unc. OptIn']['dns'] = 'blackholes.five-ten-sg.com';
655 $filters['FiveTen Unc. OptIn']['result'] = '127.0.0.4';
656 $filters['FiveTen Unc. OptIn']['comment'] =
657 _("FREE - Five-Ten-sg.com - Bulk mailers that do not use confirmed opt-in.");
659 $filters['FiveTen Others']['prefname'] = 'filters_spam_fiveten_oth';
660 $filters['FiveTen Others']['name'] = 'Five-Ten-sg.com Other Misc. Servers';
661 $filters['FiveTen Others']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
662 $filters['FiveTen Others']['dns'] = 'blackholes.five-ten-sg.com';
663 $filters['FiveTen Others']['result'] = '127.0.0.5';
664 $filters['FiveTen Others']['comment'] =
665 _("FREE - Five-Ten-sg.com - Other misc. servers.");
667 $filters['FiveTen Single Stage']['prefname'] = 'filters_spam_fiveten_ss';
668 $filters['FiveTen Single Stage']['name'] = 'Five-Ten-sg.com Single Stage Servers';
669 $filters['FiveTen Single Stage']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
670 $filters['FiveTen Single Stage']['dns'] = 'blackholes.five-ten-sg.com';
671 $filters['FiveTen Single Stage']['result'] = '127.0.0.6';
672 $filters['FiveTen Single Stage']['comment'] =
673 _("FREE - Five-Ten-sg.com - Single Stage servers.");
675 $filters['FiveTen SPAM Support']['prefname'] = 'filters_spam_fiveten_supp';
676 $filters['FiveTen SPAM Support']['name'] = 'Five-Ten-sg.com SPAM Support Servers';
677 $filters['FiveTen SPAM Support']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
678 $filters['FiveTen SPAM Support']['dns'] = 'blackholes.five-ten-sg.com';
679 $filters['FiveTen SPAM Support']['result'] = '127.0.0.7';
680 $filters['FiveTen SPAM Support']['comment'] =
681 _("FREE - Five-Ten-sg.com - SPAM Support servers.");
683 $filters['FiveTen Web forms']['prefname'] = 'filters_spam_fiveten_wf';
684 $filters['FiveTen Web forms']['name'] = 'Five-Ten-sg.com Web Form IPs';
685 $filters['FiveTen Web forms']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
686 $filters['FiveTen Web forms']['dns'] = 'blackholes.five-ten-sg.com';
687 $filters['FiveTen Web forms']['result'] = '127.0.0.8';
688 $filters['FiveTen Web forms']['comment'] =
689 _("FREE - Five-Ten-sg.com - Web Form IPs.");
691 $filters['Dorkslayers']['prefname'] = 'filters_spam_dorks';
692 $filters['Dorkslayers']['name'] = 'Dorkslayers Lists';
693 $filters['Dorkslayers']['link'] = 'http://www.dorkslayers.com';
694 $filters['Dorkslayers']['dns'] = 'orbs.dorkslayers.com';
695 $filters['Dorkslayers']['result'] = '127.0.0.2';
696 $filters['Dorkslayers']['comment'] =
697 _("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.");
699 $filters['SPAMhaus']['prefname'] = 'filters_spam_spamhaus';
700 $filters['SPAMhaus']['name'] = 'SPAMhaus Lists';
701 $filters['SPAMhaus']['link'] = 'http://www.spamhaus.org';
702 $filters['SPAMhaus']['dns'] = 'sbl.spamhaus.org';
703 $filters['SPAMhaus']['result'] = '127.0.0.6';
704 $filters['SPAMhaus']['comment'] =
705 _("FREE - SPAMhaus - A list of well-known SPAM sources.");
707 $filters['SPAMcop']['prefname'] = 'filters_spam_spamcop';
708 $filters['SPAMcop']['name'] = 'SPAM Cop Lists';
709 $filters['SPAMcop']['link'] = 'http://spamcop.net/bl.shtml';
710 $filters['SPAMcop']['dns'] = 'bl.spamcop.net';
711 $filters['SPAMcop']['result'] = '127.0.0.2';
712 $filters['SPAMcop']['comment'] =
713 _("FREE, for now - SpamCop - An interesting solution that lists servers that have a very high spam to legit email ratio (85 percent or more).");
715 $filters['dev.null.dk']['prefname'] = 'filters_spam_devnull';
716 $filters['dev.null.dk']['name'] = 'dev.null.dk Lists';
717 $filters['dev.null.dk']['link'] = 'http://dev.null.dk/';
718 $filters['dev.null.dk']['dns'] = 'dev.null.dk';
719 $filters['dev.null.dk']['result'] = '127.0.0.2';
720 $filters['dev.null.dk']['comment'] =
721 _("FREE - dev.null.dk - I don't have any detailed info on this list.");
723 $filters['visi.com']['prefname'] = 'filters_spam_visi';
724 $filters['visi.com']['name'] = 'visi.com Relay Stop List';
725 $filters['visi.com']['link'] = 'http://relays.visi.com';
726 $filters['visi.com']['dns'] = 'relays.visi.com';
727 $filters['visi.com']['result'] = '127.0.0.2';
728 $filters['visi.com']['comment'] =
729 _("FREE - visi.com - Relay Stop List. Very conservative OpenRelay List.");
731 $filters['ahbl.org Open Relays']['prefname'] = 'filters_spam_2mb_or';
732 $filters['ahbl.org Open Relays']['name'] = 'ahbl.org Open Relays List';
733 $filters['ahbl.org Open Relays']['link'] = 'http://www.ahbl.org/';
734 $filters['ahbl.org Open Relays']['dns'] = 'dnsbl.ahbl.org';
735 $filters['ahbl.org Open Relays']['result'] = '127.0.0.2';
736 $filters['ahbl.org Open Relays']['comment'] =
737 _("FREE - ahbl.org Open Relays - Another list of Open Relays.");
739 $filters['ahbl.org SPAM Source']['prefname'] = 'filters_spam_2mb_ss';
740 $filters['ahbl.org SPAM Source']['name'] = 'ahbl.org SPAM Source List';
741 $filters['ahbl.org SPAM Source']['link'] = 'http://www.ahbl.org/';
742 $filters['ahbl.org SPAM Source']['dns'] = 'dnsbl.ahbl.org';
743 $filters['ahbl.org SPAM Source']['result'] = '127.0.0.4';
744 $filters['ahbl.org SPAM Source']['comment'] =
745 _("FREE - ahbl.org SPAM Source - List of Direct SPAM Sources.");
747 $filters['ahbl.org SPAM ISPs']['prefname'] = 'filters_spam_2mb_isp';
748 $filters['ahbl.org SPAM ISPs']['name'] = 'ahbl.org SPAM-friendly ISP List';
749 $filters['ahbl.org SPAM ISPs']['link'] = 'http://www.ahbl.org/';
750 $filters['ahbl.org SPAM ISPs']['dns'] = 'dnsbl.ahbl.org';
751 $filters['ahbl.org SPAM ISPs']['result'] = '127.0.0.7';
752 $filters['ahbl.org SPAM ISPs']['comment'] =
753 _("FREE - ahbl.org SPAM ISPs - List of SPAM-friendly ISPs.");
755 $filters['Leadmon DUL']['prefname'] = 'filters_spam_lm_dul';
756 $filters['Leadmon DUL']['name'] = 'Leadmon.net DUL List';
757 $filters['Leadmon DUL']['link'] = 'http://www.leadmon.net/spamguard/';
758 $filters['Leadmon DUL']['dns'] = 'spamguard.leadmon.net';
759 $filters['Leadmon DUL']['result'] = '127.0.0.2';
760 $filters['Leadmon DUL']['comment'] =
761 _("FREE - Leadmon DUL - Another list of Dial-up or otherwise dynamically assigned IPs.");
763 $filters['Leadmon SPAM Source']['prefname'] = 'filters_spam_lm_ss';
764 $filters['Leadmon SPAM Source']['name'] = 'Leadmon.net SPAM Source List';
765 $filters['Leadmon SPAM Source']['link'] = 'http://www.leadmon.net/spamguard/';
766 $filters['Leadmon SPAM Source']['dns'] = 'spamguard.leadmon.net';
767 $filters['Leadmon SPAM Source']['result'] = '127.0.0.3';
768 $filters['Leadmon SPAM Source']['comment'] =
769 _("FREE - Leadmon SPAM Source - List of IPs Leadmon.net has received SPAM directly from.");
771 $filters['Leadmon Bulk Mailers']['prefname'] = 'filters_spam_lm_bm';
772 $filters['Leadmon Bulk Mailers']['name'] = 'Leadmon.net Bulk Mailers List';
773 $filters['Leadmon Bulk Mailers']['link'] = 'http://www.leadmon.net/spamguard/';
774 $filters['Leadmon Bulk Mailers']['dns'] = 'spamguard.leadmon.net';
775 $filters['Leadmon Bulk Mailers']['result'] = '127.0.0.4';
776 $filters['Leadmon Bulk Mailers']['comment'] =
777 _("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.");
779 $filters['Leadmon Open Relays']['prefname'] = 'filters_spam_lm_or';
780 $filters['Leadmon Open Relays']['name'] = 'Leadmon.net Open Relays List';
781 $filters['Leadmon Open Relays']['link'] = 'http://www.leadmon.net/spamguard/';
782 $filters['Leadmon Open Relays']['dns'] = 'spamguard.leadmon.net';
783 $filters['Leadmon Open Relays']['result'] = '127.0.0.5';
784 $filters['Leadmon Open Relays']['comment'] =
785 _("FREE - Leadmon Open Relays - Single Stage Open Relays that are not listed on other active RBLs.");
787 $filters['Leadmon Multi-stage']['prefname'] = 'filters_spam_lm_ms';
788 $filters['Leadmon Multi-stage']['name'] = 'Leadmon.net Multi-Stage Relay List';
789 $filters['Leadmon Multi-stage']['link'] = 'http://www.leadmon.net/spamguard/';
790 $filters['Leadmon Multi-stage']['dns'] = 'spamguard.leadmon.net';
791 $filters['Leadmon Multi-stage']['result'] = '127.0.0.6';
792 $filters['Leadmon Multi-stage']['comment'] =
793 _("FREE - Leadmon Multi-stage - Multi-Stage Open Relays that are not listed on other active RBLs and that have sent SPAM to Leadmon.net.");
795 $filters['Leadmon SpamBlock']['prefname'] = 'filters_spam_lm_sb';
796 $filters['Leadmon SpamBlock']['name'] = 'Leadmon.net SpamBlock Sites List';
797 $filters['Leadmon SpamBlock']['link'] = 'http://www.leadmon.net/spamguard/';
798 $filters['Leadmon SpamBlock']['dns'] = 'spamguard.leadmon.net';
799 $filters['Leadmon SpamBlock']['result'] = '127.0.0.7';
800 $filters['Leadmon SpamBlock']['comment'] =
801 _("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.");
803 $filters['NJABL Open Relays']['prefname'] = 'filters_spam_njabl_or';
804 $filters['NJABL Open Relays']['name'] = 'NJABL Open Relay/Direct Spam Source List';
805 $filters['NJABL Open Relays']['link'] = 'http://www.njabl.org/';
806 $filters['NJABL Open Relays']['dns'] = 'dnsbl.njabl.org';
807 $filters['NJABL Open Relays']['result'] = '127.0.0.2';
808 $filters['NJABL Open Relays']['comment'] =
809 _("FREE, for now - Not Just Another Blacklist - Both Open Relays and Direct SPAM Sources.");
811 $filters['NJABL DUL']['prefname'] = 'filters_spam_njabl_dul';
812 $filters['NJABL DUL']['name'] = 'NJABL Dial-ups List';
813 $filters['NJABL DUL']['link'] = 'http://www.njabl.org/';
814 $filters['NJABL DUL']['dns'] = 'dnsbl.njabl.org';
815 $filters['NJABL DUL']['result'] = '127.0.0.3';
816 $filters['NJABL DUL']['comment'] =
817 _("FREE, for now - Not Just Another Blacklist - Dial-up IPs.");
819 $filters['Conf DSBL.ORG Relay']['prefname'] = 'filters_spam_dsbl_conf_ss';
820 $filters['Conf DSBL.ORG Relay']['name'] = 'DSBL.org Confirmed Relay List';
821 $filters['Conf DSBL.ORG Relay']['link'] = 'http://www.dsbl.org/';
822 $filters['Conf DSBL.ORG Relay']['dns'] = 'list.dsbl.org';
823 $filters['Conf DSBL.ORG Relay']['result'] = '127.0.0.2';
824 $filters['Conf DSBL.ORG Relay']['comment'] =
825 _("FREE - Distributed Sender Boycott List - Confirmed Relays");
827 $filters['Conf DSBL.ORG Multi-Stage']['prefname'] = 'filters_spam_dsbl_conf_ms';
828 $filters['Conf DSBL.ORG Multi-Stage']['name'] = 'DSBL.org Confirmed Multi-Stage Relay List';
829 $filters['Conf DSBL.ORG Multi-Stage']['link'] = 'http://www.dsbl.org/';
830 $filters['Conf DSBL.ORG Multi-Stage']['dns'] = 'multihop.dsbl.org';
831 $filters['Conf DSBL.ORG Multi-Stage']['result'] = '127.0.0.2';
832 $filters['Conf DSBL.ORG Multi-Stage']['comment'] =
833 _("FREE - Distributed Sender Boycott List - Confirmed Multi-stage Relays");
835 $filters['UN-Conf DSBL.ORG']['prefname'] = 'filters_spam_dsbl_unc';
836 $filters['UN-Conf DSBL.ORG']['name'] = 'DSBL.org UN-Confirmed Relay List';
837 $filters['UN-Conf DSBL.ORG']['link'] = 'http://www.dsbl.org/';
838 $filters['UN-Conf DSBL.ORG']['dns'] = 'unconfirmed.dsbl.org';
839 $filters['UN-Conf DSBL.ORG']['result'] = '127.0.0.2';
840 $filters['UN-Conf DSBL.ORG']['comment'] =
841 _("FREE - Distributed Sender Boycott List - UN-Confirmed Relays");
843 foreach ($filters as $Key => $Value) {
844 $filters[$Key]['enabled'] = getPref($data_dir, $username, $filters[$Key]['prefname']);
851 * Removes a User filter
852 * @param int $id ID of the filter to remove
855 function remove_filter ($id) {
856 global $data_dir, $username;
858 while ($nextFilter = getPref($data_dir, $username, 'filter' . ($id +
1))) {
859 setPref($data_dir, $username, 'filter' . $id, $nextFilter);
863 removePref($data_dir, $username, 'filter' . $id);
868 * @param int $id1 ID of first filter to swap
869 * @param int $id2 ID of second filter to swap
872 function filter_swap($id1, $id2) {
873 global $data_dir, $username;
875 $FirstFilter = getPref($data_dir, $username, 'filter' . $id1);
876 $SecondFilter = getPref($data_dir, $username, 'filter' . $id2);
878 if ($FirstFilter && $SecondFilter) {
879 setPref($data_dir, $username, 'filter' . $id2, $FirstFilter);
880 setPref($data_dir, $username, 'filter' . $id1, $SecondFilter);
885 * This updates the filter rules when renaming or deleting folders
889 function update_for_folder ($args) {
891 $old_folder = $args[0];
892 $new_folder = $args[2];
894 global $data_dir, $username;
896 $filters = load_filters();
897 $filter_count = count($filters);
899 for ($i = 0; $i < $filter_count; $i++
) {
900 if (!empty($filters)) {
901 if ($old_folder == $filters[$i]['folder']) {
902 if ($action == 'rename') {
903 $filters[$i]['folder'] = $new_folder;
904 setPref($data_dir, $username, 'filter'.$i,
905 $filters[$i]['where'].','.$filters[$i]['what'].','.$new_folder);
907 elseif ($action == 'delete') {
918 * Display formated error message
919 * @param string $string text message
920 * @return string html formated text message
923 function do_error($string) {
925 echo "<p align=\"center\"><font color=\"$color[2]\">";
927 echo "</font></p>\n";