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');
44 * Register option blocks
47 function filters_optpage_register_block() {
48 global $optpage_blocks, $AllowSpamFilters;
50 $optpage_blocks[] = array(
51 'name' => _("Message Filters"),
52 'url' => SM_PATH
. 'plugins/filters/options.php',
53 'desc' => _("Filtering enables messages with different criteria to be automatically filtered into different folders for easier organization."),
57 if ($AllowSpamFilters) {
58 $optpage_blocks[] = array(
59 'name' => _("SPAM Filters"),
60 'url' => SM_PATH
. 'plugins/filters/spamoptions.php',
61 '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)."),
67 /* Receive the status of the folder and do something with it */
68 function filters_folder_status($statusarr) {
70 global $filter_inbox_count;
71 if (empty($filter_inbox_count)) $filter_inbox_count=0;
73 //echo "GOT HOOK<br><pre>";
74 //var_dump($statusarr);
75 //echo "</pre><br>\n";
77 if ($statusarr['MAILBOX'] == 'INBOX')
79 if (!empty($statusarr['MESSAGES'])) $filter_inbox_count=$statusarr['MESSAGES'];
84 * Saves the DNS Cache to disk
87 function filters_SaveCache () {
88 global $data_dir, $SpamFilters_DNScache;
90 if (file_exists($data_dir . '/dnscache')) {
91 $fp = fopen($data_dir . '/dnscache', 'r');
98 $fp = fopen($data_dir . '/dnscache', 'w+');
100 $fp = fopen($data_dir . '/dnscache', 'r');
103 $fp1 = fopen($data_dir . '/dnscache', 'w+');
105 foreach ($SpamFilters_DNScache as $Key=> $Value) {
106 $tstr = $Key . ',' . $Value['L'] . ',' . $Value['T'] . "\n";
115 * Loads the DNS Cache from disk
118 function filters_LoadCache () {
119 global $data_dir, $SpamFilters_DNScache;
121 if (file_exists($data_dir . '/dnscache')) {
122 $SpamFilters_DNScache = array();
123 if ($fp = fopen ($data_dir . '/dnscache', 'r')) {
125 while ($data = fgetcsv($fp,1024)) {
126 if ($data[2] > time()) {
127 $SpamFilters_DNScache[$data[0]]['L'] = $data[1];
128 $SpamFilters_DNScache[$data[0]]['T'] = $data[2];
137 * Uses the BulkQuery executable to query all the RBLs at once
138 * @param array $filters Array of SPAM Fitlers
139 * @param array $IPs Array of IP Addresses
142 function filters_bulkquery($filters, $IPs) {
143 global $attachment_dir, $username,
144 $SpamFilters_DNScache, $SpamFilters_BulkQuery,
145 $SpamFilters_CacheTTL;
147 if (count($IPs) > 0) {
149 foreach ($filters as $key => $value) {
150 if ($filters[$key]['enabled']) {
151 if ($filters[$key]['dns']) {
152 $rbls[$filters[$key]['dns']] = true;
157 $bqfil = $attachment_dir . $username . '-bq.in';
158 $fp = fopen($bqfil, 'w');
159 fputs ($fp, $SpamFilters_CacheTTL . "\n");
160 foreach ($rbls as $key => $value) {
161 fputs ($fp, '.' . $key . "\n");
163 fputs ($fp, "----------\n");
164 foreach ($IPs as $key => $value) {
165 fputs ($fp, $key . "\n");
169 exec ($SpamFilters_BulkQuery . ' < ' . $bqfil, $bqout);
170 foreach ($bqout as $value) {
171 $Chunks = explode(',', $value);
172 $SpamFilters_DNScache[$Chunks[0]]['L'] = $Chunks[1];
173 $SpamFilters_DNScache[$Chunks[0]]['T'] = $Chunks[2] +
time();
180 * Starts the filtering process
181 * @param array $hook_args do hook arguments. Is used to check hook name, array key = 0.
184 function start_filters($hook_args) {
185 global $imapServerAddress, $imapPort, $imap_stream, $imapConnection,
186 $UseSeparateImapConnection, $AllowSpamFilters, $filter_inbox_count;
188 sqgetGlobalVar('username', $username, SQ_SESSION
);
189 sqgetGlobalVar('key', $key, SQ_COOKIE
);
192 * check hook that calls filtering. If filters are called by right_main_after_header,
193 * do filtering only when we are in INBOX folder.
195 if ($hook_args[0]=='right_main_after_header' &&
196 (sqgetGlobalVar('mailbox',$mailbox,SQ_FORM
) && $mailbox!='INBOX')) {
200 $filters = load_filters();
202 // No point running spam filters if there aren't any to run //
203 if ($AllowSpamFilters) {
204 $spamfilters = load_spam_filters();
206 $AllowSpamFilters = false;
207 foreach($spamfilters as $filterskey=>$value) {
208 if ($value['enabled'] == 'yes') {
209 $AllowSpamFilters = true;
215 if (!$AllowSpamFilters && empty($filters)) {
220 // Detect if we have already connected to IMAP or not.
221 // Also check if we are forced to use a separate IMAP connection
222 if ((!isset($imap_stream) && !isset($imapConnection)) ||
223 $UseSeparateImapConnection ) {
224 $stream = sqimap_login($username, $key, $imapServerAddress,
226 $previously_connected = false;
227 } else if (isset($imapConnection)) {
228 $stream = $imapConnection;
229 $previously_connected = true;
231 $previously_connected = true;
232 $stream = $imap_stream;
235 if (!isset($filter_inbox_count)) {
236 $aStatus = sqimap_status_messages ($stream, 'INBOX', array('MESSAGES'));
237 if (!empty($aStatus['MESSAGES'])) {
238 $filter_inbox_count=$aStatus['MESSAGES'];
240 $filter_inbox_count=0;
244 if ($filter_inbox_count > 0) {
245 sqimap_mailbox_select($stream, 'INBOX');
246 // Filter spam from inbox before we sort them into folders
247 if ($AllowSpamFilters) {
248 spam_filters($stream);
252 user_filters($stream);
255 if (!$previously_connected) {
256 sqimap_logout($stream);
261 * Does the loop through each filter
262 * @param stream imap_stream the stream to read from
265 function user_filters($imap_stream) {
266 global $data_dir, $username;
267 $filters = load_filters();
268 if (! $filters) return;
269 $filters_user_scan = getPref($data_dir, $username, 'filters_user_scan');
273 for ($i=0, $num = count($filters); $i < $num; $i++
) {
274 // If it is the "combo" rule
275 if ($filters[$i]['where'] == 'To or Cc') {
277 * If it's "TO OR CC", we have to do two searches, one for TO
278 * and the other for CC.
280 $expunge = filter_search_and_delete($imap_stream, 'TO',
281 $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge);
282 $expunge = filter_search_and_delete($imap_stream, 'CC',
283 $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge);
284 } else if ($filters[$i]['where'] == 'Header and Body') {
285 $expunge = filter_search_and_delete($imap_stream, 'TEXT',
286 $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge);
287 } else if ($filters[$i]['where'] == 'Message Body') {
288 $expunge = filter_search_and_delete($imap_stream, 'BODY',
289 $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge);
292 * If it's a normal TO, CC, SUBJECT, or FROM, then handle it
295 $expunge = filter_search_and_delete($imap_stream, $filters[$i]['where'],
296 $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge);
299 // Clean out the mailbox whether or not auto_expunge is on
300 // That way it looks like it was redirected properly
302 sqimap_mailbox_expunge($imap_stream, 'INBOX');
307 * Creates and runs the IMAP command to filter messages
308 * @param string $where Which part of the message to search (TO, CC, SUBJECT, etc...)
309 * @param string $what String to search for
310 * @param string $where_to Folder it will move to
311 * @param string $user_scan Whether to search all or just unseen
312 * @param string $should_expunge
313 * @param boolean $where Which part of location to search
316 function filter_search_and_delete($imap_stream, $where, $what, $where_to, $user_scan,
318 global $languages, $squirrelmail_language, $allow_charset_search, $imap_server_type;
320 //TODO: make use of new mailbox cache. See mailbox_display.phpinfo
322 if (strtolower($where_to) == 'inbox') {
326 if ($user_scan == 'new') {
327 $category = 'UNSEEN';
331 $category .= ' UNDELETED';
333 if ($allow_charset_search &&
334 isset($languages[$squirrelmail_language]['CHARSET']) &&
335 $languages[$squirrelmail_language]['CHARSET']) {
336 $search_str = 'SEARCH CHARSET '
337 . strtoupper($languages[$squirrelmail_language]['CHARSET'])
340 $search_str = 'SEARCH CHARSET US-ASCII ' . $category;
342 if ($where == 'Header') {
343 $what = explode(':', $what);
344 $where = strtoupper($where);
345 $where = trim($where . ' ' . $what[0]);
346 $what = addslashes(trim($what[1]));
349 // see comments in squirrelmail sqimap_search function
350 if ($imap_server_type == 'macosx' ||
$imap_server_type == 'hmailserver') {
351 $search_str .= ' ' . $where . ' ' . $what;
352 /* read data back from IMAP */
353 $read = sqimap_run_command($imap_stream, $search_str, true, $response, $message, TRUE);
355 $search_str .= ' ' . $where . ' {' . strlen($what) . "}";
356 $sid = sqimap_session_id(true);
357 fputs ($imap_stream, $sid . ' ' . $search_str . "\r\n");
358 $read2 = sqimap_fgets($imap_stream);
359 # server should respond with Ready for argument, then we will send search text
360 #echo "RR2 $read2<br>";
361 fputs ($imap_stream, "$what\r\n");
362 #echo "SS $what<br>";
363 $read2 = sqimap_fgets($imap_stream);
364 #echo "RR2 $read2<br>";
366 $read3 = sqimap_fgets($imap_stream);
367 #echo "RR3 $read3<br>";
368 list($rtag,$response,$message)=explode(' ',$read3,3);
369 ## $read2 = sqimap_retrieve_imap_response($imap_stream, $sid, true,
370 ## $response, $message, $search_str, false, true, false);
371 #echo "RR2 $read2 / RESPONSE $response<br>";
374 if (isset($read[0])) {
376 for ($i = 0, $iCnt = count($read); $i < $iCnt; ++
$i) {
377 if (preg_match("/^\* SEARCH (.+)$/", $read[$i], $regs)) {
378 $ids +
= preg_split("/ /", trim($regs[1]));
381 if ($response == 'OK' && count($ids)) {
382 if (sqimap_mailbox_exists($imap_stream, $where_to)) {
383 $should_expunge = true;
384 sqimap_msgs_list_move ($imap_stream, $ids, $where_to, false);
386 } elseif ($response != 'OK') {
387 if ($response == 'NO') {
388 $query = $search_str . "\r\n".$what ."\r\n";
389 if (strpos($message,'BADCHARSET') !== false ||
390 strpos($message,'character') !== false) {
391 sqm_trigger_imap_error('SQM_IMAP_BADCHARSET',$query, $response, $message);
393 sqm_trigger_imap_error('SQM_IMAP_ERROR',$query, $response, $message);
396 sqm_trigger_imap_error('SQM_IMAP_ERROR',$query, $response, $message);
400 return $should_expunge;
404 * Loops through all the Received Headers to find IP Addresses
405 * @param stream imap_stream the stream to read from
408 function spam_filters($imap_stream) {
409 global $data_dir, $username;
410 global $SpamFilters_YourHop;
411 global $SpamFilters_DNScache;
412 global $SpamFilters_SharedCache;
413 global $SpamFilters_BulkQuery;
414 global $SpamFilters_CacheTTL;
416 $filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan');
417 $filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder');
418 $filters = load_spam_filters();
420 if ($SpamFilters_SharedCache) {
426 foreach ($filters as $Key => $Value) {
427 if ($Value['enabled']) {
438 // Ask for a big list of all "Received" headers in the inbox with
439 // flags for each message. Kinda big.
441 if ($filters_spam_scan == 'new') {
442 $search_array = array();
443 $read = sqimap_run_command($imap_stream, 'SEARCH UNSEEN', true, $response, $message, TRUE);
444 if (isset($read[0])) {
445 for ($i = 0, $iCnt = count($read); $i < $iCnt; ++
$i) {
446 if (preg_match("/^\* SEARCH (.+)$/", $read[$i], $regs)) {
447 $search_array = preg_split("/ /", trim($regs[1]));
453 if ($filters_spam_scan == 'new' && count($search_array)) {
454 $headers = sqimap_get_small_header_list ($imap_stream, $search_array, array('Received'),array());
455 } else if ($filters_spam_scan != 'new') {
456 $headers = sqimap_get_small_header_list ($imap_stream, null , array('Received'),array());
460 if (!count($headers)) {
463 $bulkquery = (strlen($SpamFilters_BulkQuery) > 0 ?
true : false);
466 foreach ($headers as $id => $aValue) {
467 if (isset($aValue['UID'])) {
468 $MsgNum = $aValue['UID'];
472 // Look through all of the Received headers for IP addresses
473 if (isset($aValue['RECEIVED'])) {
474 foreach ($aValue['RECEIVED'] as $received) {
475 // Check to see if this line is the right "Received from" line
478 // $aValue['Received'] is an array with all the received lines.
479 // We should check them from bottom to top and only check the first 2.
480 // Currently we check only the header where $SpamFilters_YourHop in occures
482 if (is_int(strpos($received, $SpamFilters_YourHop))) {
483 if (preg_match('/([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/',$received,$aMatch)) {
485 if (filters_spam_check_site($aMatch[1],$aMatch[2],$aMatch[3],$aMatch[4],$filters)) {
486 $aSpamIds[] = $MsgNum;
490 array_shift($aMatch);
491 $IP = explode('.',$aMatch);
492 foreach ($filters as $key => $value) {
493 if ($filters[$key]['enabled'] && $filters[$key]['dns']) {
494 if (strlen($SpamFilters_DNScache[$IP.'.'.$filters[$key]['dns']]) == 0) {
501 // If we've checked one IP and YourHop is
503 if ($SpamFilters_YourHop == ' ' ||
$isspam) {
504 break; // don't check any more
511 // Lookie! It's spam! Yum!
512 if (count($aSpamIds) && sqimap_mailbox_exists($imap_stream, $filters_spam_folder)) {
513 sqimap_msgs_list_move ($imap_stream, $aSpamIds, $filters_spam_folder);
514 sqimap_mailbox_expunge($imap_stream, 'INBOX');
517 if ($bulkquery && count($IPs)) {
518 filters_bulkquery($filters, $IPs);
521 if ($SpamFilters_SharedCache) {
524 sqsession_register($SpamFilters_DNScache, 'SpamFilters_DNScache');
529 * Does the loop through each enabled filter for the specified IP address.
530 * IP format: $a.$b.$c.$d
531 * @param int $a First subset of IP
532 * @param int $b Second subset of IP
533 * @param int $c Third subset of IP
534 * @param int $d Forth subset of IP
535 * @param array $filters The Spam Filters
536 * @return boolean Whether the IP is Spam
539 function filters_spam_check_site($a, $b, $c, $d, &$filters) {
540 global $SpamFilters_DNScache, $SpamFilters_CacheTTL;
541 foreach ($filters as $key => $value) {
542 if ($filters[$key]['enabled']) {
543 if ($filters[$key]['dns']) {
544 $filter_revip = $d . '.' . $c . '.' . $b . '.' . $a . '.' .
545 $filters[$key]['dns'];
547 if(!isset($SpamFilters_DNScache[$filter_revip]['L']))
548 $SpamFilters_DNScache[$filter_revip]['L'] = '';
550 if(!isset($SpamFilters_DNScache[$filter_revip]['T']))
551 $SpamFilters_DNScache[$filter_revip]['T'] = '';
553 if (strlen($SpamFilters_DNScache[$filter_revip]['L']) == 0) {
554 $SpamFilters_DNScache[$filter_revip]['L'] =
555 gethostbyname($filter_revip);
556 $SpamFilters_DNScache[$filter_revip]['T'] =
557 time() +
$SpamFilters_CacheTTL;
559 if ($SpamFilters_DNScache[$filter_revip]['L'] ==
560 $filters[$key]['result']) {
570 * Loads the filters from the user preferences
571 * @return array All the user filters
574 function load_filters() {
575 global $data_dir, $username;
578 for ($i = 0; $fltr = getPref($data_dir, $username, 'filter' . $i); $i++
) {
579 $ary = explode(',', $fltr);
580 $filters[$i]['where'] = $ary[0];
581 $filters[$i]['what'] = $ary[1];
582 $filters[$i]['folder'] = $ary[2];
588 * Loads the Spam Filters and checks the preferences for the enabled status
589 * @return array All the spam filters
592 function load_spam_filters() {
593 global $data_dir, $username, $SpamFilters_ShowCommercial;
595 if ($SpamFilters_ShowCommercial) {
596 $filters['MAPS RBL']['prefname'] = 'filters_spam_maps_rbl';
597 $filters['MAPS RBL']['name'] = 'MAPS Realtime Blackhole List';
598 $filters['MAPS RBL']['link'] = 'http://www.mail-abuse.org/rbl/';
599 $filters['MAPS RBL']['dns'] = 'blackholes.mail-abuse.org';
600 $filters['MAPS RBL']['result'] = '127.0.0.2';
601 $filters['MAPS RBL']['comment'] =
602 _("COMMERCIAL - This list contains servers that are verified spam senders. It is a pretty reliable list to scan spam from.");
604 $filters['MAPS RSS']['prefname'] = 'filters_spam_maps_rss';
605 $filters['MAPS RSS']['name'] = 'MAPS Relay Spam Stopper';
606 $filters['MAPS RSS']['link'] = 'http://www.mail-abuse.org/rss/';
607 $filters['MAPS RSS']['dns'] = 'relays.mail-abuse.org';
608 $filters['MAPS RSS']['result'] = '127.0.0.2';
609 $filters['MAPS RSS']['comment'] =
610 _("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.");
612 $filters['MAPS DUL']['prefname'] = 'filters_spam_maps_dul';
613 $filters['MAPS DUL']['name'] = 'MAPS Dial-Up List';
614 $filters['MAPS DUL']['link'] = 'http://www.mail-abuse.org/dul/';
615 $filters['MAPS DUL']['dns'] = 'dialups.mail-abuse.org';
616 $filters['MAPS DUL']['result'] = '127.0.0.3';
617 $filters['MAPS DUL']['comment'] =
618 _("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.");
620 $filters['MAPS RBLplus-RBL']['prefname'] = 'filters_spam_maps_rblplus_rbl';
621 $filters['MAPS RBLplus-RBL']['name'] = 'MAPS RBL+ RBL List';
622 $filters['MAPS RBLplus-RBL']['link'] = 'http://www.mail-abuse.org/';
623 $filters['MAPS RBLplus-RBL']['dns'] = 'rbl-plus.mail-abuse.org';
624 $filters['MAPS RBLplus-RBL']['result'] = '127.0.0.2';
625 $filters['MAPS RBLplus-RBL']['comment'] =
626 _("COMMERCIAL - RBL+ Blackhole entries.");
628 $filters['MAPS RBLplus-RSS']['prefname'] = 'filters_spam_maps_rblplus_rss';
629 $filters['MAPS RBLplus-RSS']['name'] = 'MAPS RBL+ List RSS entries';
630 $filters['MAPS RBLplus-RSS']['link'] = 'http://www.mail-abuse.org/';
631 $filters['MAPS RBLplus-RSS']['dns'] = 'rbl-plus.mail-abuse.org';
632 $filters['MAPS RBLplus-RSS']['result'] = '127.0.0.2';
633 $filters['MAPS RBLplus-RSS']['comment'] =
634 _("COMMERCIAL - RBL+ OpenRelay entries.");
636 $filters['MAPS RBLplus-DUL']['prefname'] = 'filters_spam_maps_rblplus_dul';
637 $filters['MAPS RBLplus-DUL']['name'] = 'MAPS RBL+ List DUL entries';
638 $filters['MAPS RBLplus-DUL']['link'] = 'http://www.mail-abuse.org/';
639 $filters['MAPS RBLplus-DUL']['dns'] = 'rbl-plus.mail-abuse.org';
640 $filters['MAPS RBLplus-DUL']['result'] = '127.0.0.3';
641 $filters['MAPS RBLplus-DUL']['comment'] =
642 _("COMMERCIAL - RBL+ Dial-up entries.");
645 $filters['ORDB']['prefname'] = 'filters_spam_ordb';
646 $filters['ORDB']['name'] = 'Open Relay Database List';
647 $filters['ORDB']['link'] = 'http://www.ordb.org/';
648 $filters['ORDB']['dns'] = 'relays.ordb.org';
649 $filters['ORDB']['result'] = '127.0.0.2';
650 $filters['ORDB']['comment'] =
651 _("FREE - ORDB was born when ORBS went off the air. It seems to have fewer false positives than ORBS did though.");
653 $filters['FiveTen Direct']['prefname'] = 'filters_spam_fiveten_src';
654 $filters['FiveTen Direct']['name'] = 'Five-Ten-sg.com Direct SPAM Sources';
655 $filters['FiveTen Direct']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
656 $filters['FiveTen Direct']['dns'] = 'blackholes.five-ten-sg.com';
657 $filters['FiveTen Direct']['result'] = '127.0.0.2';
658 $filters['FiveTen Direct']['comment'] =
659 _("FREE - Five-Ten-sg.com - Direct SPAM sources.");
661 $filters['FiveTen DUL']['prefname'] = 'filters_spam_fiveten_dul';
662 $filters['FiveTen DUL']['name'] = 'Five-Ten-sg.com DUL Lists';
663 $filters['FiveTen DUL']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
664 $filters['FiveTen DUL']['dns'] = 'blackholes.five-ten-sg.com';
665 $filters['FiveTen DUL']['result'] = '127.0.0.3';
666 $filters['FiveTen DUL']['comment'] =
667 _("FREE - Five-Ten-sg.com - Dial-up lists - includes some DSL IPs.");
669 $filters['FiveTen Unc. OptIn']['prefname'] = 'filters_spam_fiveten_oi';
670 $filters['FiveTen Unc. OptIn']['name'] = 'Five-Ten-sg.com Unconfirmed OptIn Lists';
671 $filters['FiveTen Unc. OptIn']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
672 $filters['FiveTen Unc. OptIn']['dns'] = 'blackholes.five-ten-sg.com';
673 $filters['FiveTen Unc. OptIn']['result'] = '127.0.0.4';
674 $filters['FiveTen Unc. OptIn']['comment'] =
675 _("FREE - Five-Ten-sg.com - Bulk mailers that do not use confirmed opt-in.");
677 $filters['FiveTen Others']['prefname'] = 'filters_spam_fiveten_oth';
678 $filters['FiveTen Others']['name'] = 'Five-Ten-sg.com Other Misc. Servers';
679 $filters['FiveTen Others']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
680 $filters['FiveTen Others']['dns'] = 'blackholes.five-ten-sg.com';
681 $filters['FiveTen Others']['result'] = '127.0.0.5';
682 $filters['FiveTen Others']['comment'] =
683 _("FREE - Five-Ten-sg.com - Other misc. servers.");
685 $filters['FiveTen Single Stage']['prefname'] = 'filters_spam_fiveten_ss';
686 $filters['FiveTen Single Stage']['name'] = 'Five-Ten-sg.com Single Stage Servers';
687 $filters['FiveTen Single Stage']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
688 $filters['FiveTen Single Stage']['dns'] = 'blackholes.five-ten-sg.com';
689 $filters['FiveTen Single Stage']['result'] = '127.0.0.6';
690 $filters['FiveTen Single Stage']['comment'] =
691 _("FREE - Five-Ten-sg.com - Single Stage servers.");
693 $filters['FiveTen SPAM Support']['prefname'] = 'filters_spam_fiveten_supp';
694 $filters['FiveTen SPAM Support']['name'] = 'Five-Ten-sg.com SPAM Support Servers';
695 $filters['FiveTen SPAM Support']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
696 $filters['FiveTen SPAM Support']['dns'] = 'blackholes.five-ten-sg.com';
697 $filters['FiveTen SPAM Support']['result'] = '127.0.0.7';
698 $filters['FiveTen SPAM Support']['comment'] =
699 _("FREE - Five-Ten-sg.com - SPAM Support servers.");
701 $filters['FiveTen Web forms']['prefname'] = 'filters_spam_fiveten_wf';
702 $filters['FiveTen Web forms']['name'] = 'Five-Ten-sg.com Web Form IPs';
703 $filters['FiveTen Web forms']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
704 $filters['FiveTen Web forms']['dns'] = 'blackholes.five-ten-sg.com';
705 $filters['FiveTen Web forms']['result'] = '127.0.0.8';
706 $filters['FiveTen Web forms']['comment'] =
707 _("FREE - Five-Ten-sg.com - Web Form IPs.");
709 $filters['Dorkslayers']['prefname'] = 'filters_spam_dorks';
710 $filters['Dorkslayers']['name'] = 'Dorkslayers Lists';
711 $filters['Dorkslayers']['link'] = 'http://www.dorkslayers.com';
712 $filters['Dorkslayers']['dns'] = 'orbs.dorkslayers.com';
713 $filters['Dorkslayers']['result'] = '127.0.0.2';
714 $filters['Dorkslayers']['comment'] =
715 _("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.");
717 $filters['SPAMhaus']['prefname'] = 'filters_spam_spamhaus';
718 $filters['SPAMhaus']['name'] = 'SPAMhaus Lists';
719 $filters['SPAMhaus']['link'] = 'http://www.spamhaus.org';
720 $filters['SPAMhaus']['dns'] = 'sbl.spamhaus.org';
721 $filters['SPAMhaus']['result'] = '127.0.0.6';
722 $filters['SPAMhaus']['comment'] =
723 _("FREE - SPAMhaus - A list of well-known SPAM sources.");
725 $filters['SPAMcop']['prefname'] = 'filters_spam_spamcop';
726 $filters['SPAMcop']['name'] = 'SPAM Cop Lists';
727 $filters['SPAMcop']['link'] = 'http://spamcop.net/bl.shtml';
728 $filters['SPAMcop']['dns'] = 'bl.spamcop.net';
729 $filters['SPAMcop']['result'] = '127.0.0.2';
730 $filters['SPAMcop']['comment'] =
731 _("FREE, for now - SpamCop - An interesting solution that lists servers that have a very high spam to legit email ratio (85 percent or more).");
733 $filters['dev.null.dk']['prefname'] = 'filters_spam_devnull';
734 $filters['dev.null.dk']['name'] = 'dev.null.dk Lists';
735 $filters['dev.null.dk']['link'] = 'http://dev.null.dk/';
736 $filters['dev.null.dk']['dns'] = 'dev.null.dk';
737 $filters['dev.null.dk']['result'] = '127.0.0.2';
738 $filters['dev.null.dk']['comment'] =
739 _("FREE - dev.null.dk - I don't have any detailed info on this list.");
741 $filters['visi.com']['prefname'] = 'filters_spam_visi';
742 $filters['visi.com']['name'] = 'visi.com Relay Stop List';
743 $filters['visi.com']['link'] = 'http://relays.visi.com';
744 $filters['visi.com']['dns'] = 'relays.visi.com';
745 $filters['visi.com']['result'] = '127.0.0.2';
746 $filters['visi.com']['comment'] =
747 _("FREE - visi.com - Relay Stop List. Very conservative OpenRelay List.");
749 $filters['ahbl.org Open Relays']['prefname'] = 'filters_spam_2mb_or';
750 $filters['ahbl.org Open Relays']['name'] = 'ahbl.org Open Relays List';
751 $filters['ahbl.org Open Relays']['link'] = 'http://www.ahbl.org/';
752 $filters['ahbl.org Open Relays']['dns'] = 'dnsbl.ahbl.org';
753 $filters['ahbl.org Open Relays']['result'] = '127.0.0.2';
754 $filters['ahbl.org Open Relays']['comment'] =
755 _("FREE - ahbl.org Open Relays - Another list of Open Relays.");
757 $filters['ahbl.org SPAM Source']['prefname'] = 'filters_spam_2mb_ss';
758 $filters['ahbl.org SPAM Source']['name'] = 'ahbl.org SPAM Source List';
759 $filters['ahbl.org SPAM Source']['link'] = 'http://www.ahbl.org/';
760 $filters['ahbl.org SPAM Source']['dns'] = 'dnsbl.ahbl.org';
761 $filters['ahbl.org SPAM Source']['result'] = '127.0.0.4';
762 $filters['ahbl.org SPAM Source']['comment'] =
763 _("FREE - ahbl.org SPAM Source - List of Direct SPAM Sources.");
765 $filters['ahbl.org SPAM ISPs']['prefname'] = 'filters_spam_2mb_isp';
766 $filters['ahbl.org SPAM ISPs']['name'] = 'ahbl.org SPAM-friendly ISP List';
767 $filters['ahbl.org SPAM ISPs']['link'] = 'http://www.ahbl.org/';
768 $filters['ahbl.org SPAM ISPs']['dns'] = 'dnsbl.ahbl.org';
769 $filters['ahbl.org SPAM ISPs']['result'] = '127.0.0.7';
770 $filters['ahbl.org SPAM ISPs']['comment'] =
771 _("FREE - ahbl.org SPAM ISPs - List of SPAM-friendly ISPs.");
773 $filters['Leadmon DUL']['prefname'] = 'filters_spam_lm_dul';
774 $filters['Leadmon DUL']['name'] = 'Leadmon.net DUL List';
775 $filters['Leadmon DUL']['link'] = 'http://www.leadmon.net/spamguard/';
776 $filters['Leadmon DUL']['dns'] = 'spamguard.leadmon.net';
777 $filters['Leadmon DUL']['result'] = '127.0.0.2';
778 $filters['Leadmon DUL']['comment'] =
779 _("FREE - Leadmon DUL - Another list of Dial-up or otherwise dynamically assigned IPs.");
781 $filters['Leadmon SPAM Source']['prefname'] = 'filters_spam_lm_ss';
782 $filters['Leadmon SPAM Source']['name'] = 'Leadmon.net SPAM Source List';
783 $filters['Leadmon SPAM Source']['link'] = 'http://www.leadmon.net/spamguard/';
784 $filters['Leadmon SPAM Source']['dns'] = 'spamguard.leadmon.net';
785 $filters['Leadmon SPAM Source']['result'] = '127.0.0.3';
786 $filters['Leadmon SPAM Source']['comment'] =
787 _("FREE - Leadmon SPAM Source - List of IPs Leadmon.net has received SPAM directly from.");
789 $filters['Leadmon Bulk Mailers']['prefname'] = 'filters_spam_lm_bm';
790 $filters['Leadmon Bulk Mailers']['name'] = 'Leadmon.net Bulk Mailers List';
791 $filters['Leadmon Bulk Mailers']['link'] = 'http://www.leadmon.net/spamguard/';
792 $filters['Leadmon Bulk Mailers']['dns'] = 'spamguard.leadmon.net';
793 $filters['Leadmon Bulk Mailers']['result'] = '127.0.0.4';
794 $filters['Leadmon Bulk Mailers']['comment'] =
795 _("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.");
797 $filters['Leadmon Open Relays']['prefname'] = 'filters_spam_lm_or';
798 $filters['Leadmon Open Relays']['name'] = 'Leadmon.net Open Relays List';
799 $filters['Leadmon Open Relays']['link'] = 'http://www.leadmon.net/spamguard/';
800 $filters['Leadmon Open Relays']['dns'] = 'spamguard.leadmon.net';
801 $filters['Leadmon Open Relays']['result'] = '127.0.0.5';
802 $filters['Leadmon Open Relays']['comment'] =
803 _("FREE - Leadmon Open Relays - Single Stage Open Relays that are not listed on other active RBLs.");
805 $filters['Leadmon Multi-stage']['prefname'] = 'filters_spam_lm_ms';
806 $filters['Leadmon Multi-stage']['name'] = 'Leadmon.net Multi-Stage Relay List';
807 $filters['Leadmon Multi-stage']['link'] = 'http://www.leadmon.net/spamguard/';
808 $filters['Leadmon Multi-stage']['dns'] = 'spamguard.leadmon.net';
809 $filters['Leadmon Multi-stage']['result'] = '127.0.0.6';
810 $filters['Leadmon Multi-stage']['comment'] =
811 _("FREE - Leadmon Multi-stage - Multi-Stage Open Relays that are not listed on other active RBLs and that have sent SPAM to Leadmon.net.");
813 $filters['Leadmon SpamBlock']['prefname'] = 'filters_spam_lm_sb';
814 $filters['Leadmon SpamBlock']['name'] = 'Leadmon.net SpamBlock Sites List';
815 $filters['Leadmon SpamBlock']['link'] = 'http://www.leadmon.net/spamguard/';
816 $filters['Leadmon SpamBlock']['dns'] = 'spamguard.leadmon.net';
817 $filters['Leadmon SpamBlock']['result'] = '127.0.0.7';
818 $filters['Leadmon SpamBlock']['comment'] =
819 _("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.");
821 $filters['NJABL Open Relays']['prefname'] = 'filters_spam_njabl_or';
822 $filters['NJABL Open Relays']['name'] = 'NJABL Open Relay/Direct Spam Source List';
823 $filters['NJABL Open Relays']['link'] = 'http://www.njabl.org/';
824 $filters['NJABL Open Relays']['dns'] = 'dnsbl.njabl.org';
825 $filters['NJABL Open Relays']['result'] = '127.0.0.2';
826 $filters['NJABL Open Relays']['comment'] =
827 _("FREE, for now - Not Just Another Blacklist - Both Open Relays and Direct SPAM Sources.");
829 $filters['NJABL DUL']['prefname'] = 'filters_spam_njabl_dul';
830 $filters['NJABL DUL']['name'] = 'NJABL Dial-ups List';
831 $filters['NJABL DUL']['link'] = 'http://www.njabl.org/';
832 $filters['NJABL DUL']['dns'] = 'dnsbl.njabl.org';
833 $filters['NJABL DUL']['result'] = '127.0.0.3';
834 $filters['NJABL DUL']['comment'] =
835 _("FREE, for now - Not Just Another Blacklist - Dial-up IPs.");
837 $filters['Conf DSBL.ORG Relay']['prefname'] = 'filters_spam_dsbl_conf_ss';
838 $filters['Conf DSBL.ORG Relay']['name'] = 'DSBL.org Confirmed Relay List';
839 $filters['Conf DSBL.ORG Relay']['link'] = 'http://www.dsbl.org/';
840 $filters['Conf DSBL.ORG Relay']['dns'] = 'list.dsbl.org';
841 $filters['Conf DSBL.ORG Relay']['result'] = '127.0.0.2';
842 $filters['Conf DSBL.ORG Relay']['comment'] =
843 _("FREE - Distributed Sender Boycott List - Confirmed Relays");
845 $filters['Conf DSBL.ORG Multi-Stage']['prefname'] = 'filters_spam_dsbl_conf_ms';
846 $filters['Conf DSBL.ORG Multi-Stage']['name'] = 'DSBL.org Confirmed Multi-Stage Relay List';
847 $filters['Conf DSBL.ORG Multi-Stage']['link'] = 'http://www.dsbl.org/';
848 $filters['Conf DSBL.ORG Multi-Stage']['dns'] = 'multihop.dsbl.org';
849 $filters['Conf DSBL.ORG Multi-Stage']['result'] = '127.0.0.2';
850 $filters['Conf DSBL.ORG Multi-Stage']['comment'] =
851 _("FREE - Distributed Sender Boycott List - Confirmed Multi-stage Relays");
853 $filters['UN-Conf DSBL.ORG']['prefname'] = 'filters_spam_dsbl_unc';
854 $filters['UN-Conf DSBL.ORG']['name'] = 'DSBL.org UN-Confirmed Relay List';
855 $filters['UN-Conf DSBL.ORG']['link'] = 'http://www.dsbl.org/';
856 $filters['UN-Conf DSBL.ORG']['dns'] = 'unconfirmed.dsbl.org';
857 $filters['UN-Conf DSBL.ORG']['result'] = '127.0.0.2';
858 $filters['UN-Conf DSBL.ORG']['comment'] =
859 _("FREE - Distributed Sender Boycott List - UN-Confirmed Relays");
861 foreach ($filters as $Key => $Value) {
862 $filters[$Key]['enabled'] = getPref($data_dir, $username, $filters[$Key]['prefname']);
869 * Removes a User filter
870 * @param int $id ID of the filter to remove
873 function remove_filter ($id) {
874 global $data_dir, $username;
876 while ($nextFilter = getPref($data_dir, $username, 'filter' . ($id +
1))) {
877 setPref($data_dir, $username, 'filter' . $id, $nextFilter);
881 removePref($data_dir, $username, 'filter' . $id);
886 * @param int $id1 ID of first filter to swap
887 * @param int $id2 ID of second filter to swap
890 function filter_swap($id1, $id2) {
891 global $data_dir, $username;
893 $FirstFilter = getPref($data_dir, $username, 'filter' . $id1);
894 $SecondFilter = getPref($data_dir, $username, 'filter' . $id2);
896 if ($FirstFilter && $SecondFilter) {
897 setPref($data_dir, $username, 'filter' . $id2, $FirstFilter);
898 setPref($data_dir, $username, 'filter' . $id1, $SecondFilter);
903 * This updates the filter rules when renaming or deleting folders
907 function update_for_folder ($args) {
909 $old_folder = $args[0];
910 $new_folder = $args[2];
912 global $data_dir, $username;
914 $filters = load_filters();
915 $filter_count = count($filters);
917 for ($i = 0; $i < $filter_count; $i++
) {
918 if (!empty($filters)) {
919 if ($old_folder == $filters[$i]['folder']) {
920 if ($action == 'rename') {
921 $filters[$i]['folder'] = $new_folder;
922 setPref($data_dir, $username, 'filter'.$i,
923 $filters[$i]['where'].','.$filters[$i]['what'].','.$new_folder);
925 elseif ($action == 'delete') {
936 * Display formated error message
937 * @param string $string text message
938 * @return string html formated text message
941 function do_error($string) {
943 echo "<p align=\"center\"><font color=\"$color[2]\">";
945 echo "</font></p>\n";