3 * Message and Spam Filter Plugin - Filtering Functions
6 * @copyright (c) 1999-2005 The SquirrelMail Project Team
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
13 if (file_exists(SM_PATH
. 'plugins/filters/config.php'))
14 include_once (SM_PATH
. 'plugins/filters/config.php');
20 function filters_init_hooks () {
21 global $squirrelmail_plugin_hooks;
22 if (!file_exists(SM_PATH
. 'plugins/filters/config.php')) return;
23 if (sqgetGlobalVar('mailbox',$mailbox,SQ_FORM
)) {
24 sqgetGlobalVar('mailbox',$mailbox,SQ_FORM
);
29 $squirrelmail_plugin_hooks['left_main_before']['filters'] = 'start_filters_hook';
30 if (isset($mailbox) && $mailbox == 'INBOX') {
31 $squirrelmail_plugin_hooks['right_main_after_header']['filters'] = 'start_filters_hook';
33 $squirrelmail_plugin_hooks['optpage_register_block']['filters'] = 'filters_optpage_register_block_hook';
34 $squirrelmail_plugin_hooks['special_mailbox']['filters'] = 'filters_special_mailbox';
35 $squirrelmail_plugin_hooks['rename_or_delete_folder']['filters'] = 'update_for_folder_hook';
36 $squirrelmail_plugin_hooks['webmail_bottom']['filters'] = 'start_filters_hook';
40 * Register option blocks
43 function filters_optpage_register_block() {
44 global $optpage_blocks, $AllowSpamFilters;
45 if (!file_exists(SM_PATH
. 'plugins/filters/config.php')) return;
47 $optpage_blocks[] = array(
48 'name' => _("Message Filters"),
49 'url' => SM_PATH
. 'plugins/filters/options.php',
50 'desc' => _("Filtering enables messages with different criteria to be automatically filtered into different folders for easier organization."),
54 if ($AllowSpamFilters) {
55 $optpage_blocks[] = array(
56 'name' => _("SPAM Filters"),
57 'url' => SM_PATH
. 'plugins/filters/spamoptions.php',
58 '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)."),
65 * Saves the DNS Cache to disk
68 function filters_SaveCache () {
69 global $data_dir, $SpamFilters_DNScache;
71 if (file_exists($data_dir . '/dnscache')) {
72 $fp = fopen($data_dir . '/dnscache', 'r');
79 $fp = fopen($data_dir . '/dnscache', 'w+');
81 $fp = fopen($data_dir . '/dnscache', 'r');
84 $fp1 = fopen($data_dir . '/dnscache', 'w+');
86 foreach ($SpamFilters_DNScache as $Key=> $Value) {
87 $tstr = $Key . ',' . $Value['L'] . ',' . $Value['T'] . "\n";
96 * Loads the DNS Cache from disk
99 function filters_LoadCache () {
100 global $data_dir, $SpamFilters_DNScache;
102 if (file_exists($data_dir . '/dnscache')) {
103 $SpamFilters_DNScache = array();
104 if ($fp = fopen ($data_dir . '/dnscache', 'r')) {
106 while ($data = fgetcsv($fp,1024)) {
107 if ($data[2] > time()) {
108 $SpamFilters_DNScache[$data[0]]['L'] = $data[1];
109 $SpamFilters_DNScache[$data[0]]['T'] = $data[2];
118 * Uses the BulkQuery executable to query all the RBLs at once
119 * @param array $filters Array of SPAM Fitlers
120 * @param array $IPs Array of IP Addresses
123 function filters_bulkquery($filters, $IPs) {
124 global $attachment_dir, $username,
125 $SpamFilters_DNScache, $SpamFilters_BulkQuery,
126 $SpamFilters_CacheTTL;
128 if (count($IPs) > 0) {
130 foreach ($filters as $key => $value) {
131 if ($filters[$key]['enabled']) {
132 if ($filters[$key]['dns']) {
133 $rbls[$filters[$key]['dns']] = true
;
138 $bqfil = $attachment_dir . $username . '-bq.in';
139 $fp = fopen($bqfil, 'w');
140 fputs ($fp, $SpamFilters_CacheTTL . "\n");
141 foreach ($rbls as $key => $value) {
142 fputs ($fp, '.' . $key . "\n");
144 fputs ($fp, "----------\n");
145 foreach ($IPs as $key => $value) {
146 fputs ($fp, $key . "\n");
150 exec ($SpamFilters_BulkQuery . ' < ' . $bqfil, $bqout);
151 foreach ($bqout as $value) {
152 $Chunks = explode(',', $value);
153 $SpamFilters_DNScache[$Chunks[0]]['L'] = $Chunks[1];
154 $SpamFilters_DNScache[$Chunks[0]]['T'] = $Chunks[2] +
time();
161 * Starts the filtering process
164 function start_filters() {
165 global $imapServerAddress, $imapPort, $imap_stream, $imapConnection,
166 $UseSeparateImapConnection, $AllowSpamFilters;
168 if (!file_exists(SM_PATH
. 'plugins/filters/config.php')) return;
170 sqgetGlobalVar('username', $username, SQ_SESSION
);
171 sqgetGlobalVar('key', $key, SQ_COOKIE
);
173 // Detect if we have already connected to IMAP or not.
174 // Also check if we are forced to use a separate IMAP connection
175 if ((!isset($imap_stream) && !isset($imapConnection)) ||
176 $UseSeparateImapConnection ) {
177 $stream = sqimap_login($username, $key, $imapServerAddress,
179 $previously_connected = false
;
180 } else if (isset($imapConnection)) {
181 $stream = $imapConnection;
182 $previously_connected = true
;
184 $previously_connected = true
;
185 $stream = $imap_stream;
187 $aStatus = sqimap_status_messages ($stream, 'INBOX', array('MESSAGES'));
189 if ($aStatus['MESSAGES']) {
190 sqimap_mailbox_select($stream, 'INBOX');
191 // Filter spam from inbox before we sort them into folders
192 if ($AllowSpamFilters) {
193 spam_filters($stream);
197 user_filters($stream);
200 if (!$previously_connected) {
201 sqimap_logout($stream);
206 * Does the loop through each filter
207 * @param stream imap_stream the stream to read from
210 function user_filters($imap_stream) {
211 global $data_dir, $username;
212 $filters = load_filters();
213 if (! $filters) return;
214 $filters_user_scan = getPref($data_dir, $username, 'filters_user_scan');
218 for ($i=0, $num = count($filters); $i < $num; $i++
) {
219 // If it is the "combo" rule
220 if ($filters[$i]['where'] == 'To or Cc') {
222 * If it's "TO OR CC", we have to do two searches, one for TO
223 * and the other for CC.
225 $expunge = filter_search_and_delete($imap_stream, 'TO',
226 $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge);
227 $expunge = filter_search_and_delete($imap_stream, 'CC',
228 $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge);
229 } else if ($filters[$i]['where'] == 'Header and Body') {
230 $expunge = filter_search_and_delete($imap_stream, 'TEXT',
231 $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge);
232 } else if ($filters[$i]['where'] == 'Message Body') {
233 $expunge = filter_search_and_delete($imap_stream, 'BODY',
234 $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge);
237 * If it's a normal TO, CC, SUBJECT, or FROM, then handle it
240 $expunge = filter_search_and_delete($imap_stream, $filters[$i]['where'],
241 $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge);
244 // Clean out the mailbox whether or not auto_expunge is on
245 // That way it looks like it was redirected properly
247 sqimap_mailbox_expunge($imap_stream, 'INBOX');
252 * Creates and runs the IMAP command to filter messages
253 * @param string $where Which part of the message to search (TO, CC, SUBJECT, etc...)
254 * @param string $what String to search for
255 * @param string $where_to Folder it will move to
256 * @param string $user_scan Whether to search all or just unseen
257 * @param string $should_expunge
258 * @param boolean $where Which part of location to search
261 function filter_search_and_delete($imap_stream, $where, $what, $where_to, $user_scan,
263 global $languages, $squirrelmail_language, $allow_charset_search, $imap_server_type;
265 if (strtolower($where_to) == 'inbox') {
269 if ($user_scan == 'new') {
270 $category = 'UNSEEN';
274 $category .= ' UNDELETED';
276 if ($allow_charset_search &&
277 isset($languages[$squirrelmail_language]['CHARSET']) &&
278 $languages[$squirrelmail_language]['CHARSET']) {
279 $search_str = 'SEARCH CHARSET '
280 . strtoupper($languages[$squirrelmail_language]['CHARSET'])
283 $search_str = 'SEARCH CHARSET US-ASCII ' . $category;
285 if ($where == 'Header') {
286 $what = explode(':', $what);
287 $where = trim($where . ' ' . $what[0]);
288 $what = addslashes(trim($what[1]));
291 // see comments in squirrelmail sqimap_search function
292 if ($imap_server_type == 'macosx' ||
$imap_server_type == 'hmailserver') {
293 $search_str .= ' ' . $where . ' ' . $what;
295 $search_str .= ' ' . $where . ' {' . strlen($what) . "}\r\n"
299 /* read data back from IMAP */
300 $read = sqimap_run_command($imap_stream, $search_str, true
, $response, $message, TRUE
);
301 if (isset($read[0])) {
303 for ($i = 0, $iCnt = count($read); $i < $iCnt; ++
$i) {
304 if (preg_match("/^\* SEARCH (.+)$/", $read[$i], $regs)) {
305 $ids = preg_split("/ /", trim($regs[1]));
309 if ($response == 'OK' && count($ids)) {
310 if (sqimap_mailbox_exists($imap_stream, $where_to)) {
311 $should_expunge = true
;
312 sqimap_msgs_list_move ($imap_stream, $ids, $where_to, false
);
316 return $should_expunge;
320 * Loops through all the Received Headers to find IP Addresses
321 * @param stream imap_stream the stream to read from
324 function spam_filters($imap_stream) {
325 global $data_dir, $username;
326 global $SpamFilters_YourHop;
327 global $SpamFilters_DNScache;
328 global $SpamFilters_SharedCache;
329 global $SpamFilters_BulkQuery;
330 global $SpamFilters_CacheTTL;
332 $filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan');
333 $filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder');
334 $filters = load_spam_filters();
336 if ($SpamFilters_SharedCache) {
342 foreach ($filters as $Key => $Value) {
343 if ($Value['enabled']) {
354 // Ask for a big list of all "Received" headers in the inbox with
355 // flags for each message. Kinda big.
357 if ($filters_spam_scan == 'new') {
358 $search_array = array();
359 $read = sqimap_run_command($imap_stream, 'SEARCH UNSEEN', true
, $response, $message, TRUE
);
360 if (isset($read[0])) {
361 for ($i = 0, $iCnt = count($read); $i < $iCnt; ++
$i) {
362 if (preg_match("/^\* SEARCH (.+)$/", $read[$i], $regs)) {
363 $search_array = preg_split("/ /", trim($regs[1]));
369 if ($filters_spam_scan == 'new' && count($search_array)) {
370 $headers = sqimap_get_small_header_list ($imap_stream, $search_array, array('Received'),array());
371 } else if ($filters_spam_scan != 'new') {
372 $headers = sqimap_get_small_header_list ($imap_stream, null
, array('Received'),array());
376 if (!count($headers)) {
379 $bulkquery = (strlen($SpamFilters_BulkQuery) > 0 ? true
: false
);
382 foreach ($headers as $id => $aValue) {
383 if (isset($aValue['UID'])) {
384 $MsgNum = $aValue['UID'];
388 // Look through all of the Received headers for IP addresses
389 if (isset($aValue['RECEIVED'])) {
390 foreach ($aValue['RECEIVED'] as $received) {
391 // Check to see if this line is the right "Received from" line
394 // $aValue['Received'] is an array with all the received lines.
395 // We should check them from bottom to top and only check the first 2.
396 // Currently we check only the header where $SpamFilters_YourHop in occures
398 if (is_int(strpos($received, $SpamFilters_YourHop))) {
399 if (preg_match('/([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/',$received,$aMatch)) {
401 if (filters_spam_check_site($aMatch[1],$aMatch[2],$aMatch[3],$aMatch[4],$filters)) {
402 $aSpamIds[] = $MsgNum;
406 array_shift($aMatch);
407 $IP = explode('.',$aMatch);
408 foreach ($filters as $key => $value) {
409 if ($filters[$key]['enabled'] && $filters[$key]['dns']) {
410 if (strlen($SpamFilters_DNScache[$IP.'.'.$filters[$key]['dns']]) == 0) {
417 // If we've checked one IP and YourHop is
419 if ($SpamFilters_YourHop == ' ' ||
$isspam) {
420 break; // don't check any more
427 // Lookie! It's spam! Yum!
428 if (count($aSpamIds) && sqimap_mailbox_exists($imap_stream, $filters_spam_folder)) {
429 sqimap_msgs_list_move ($imap_stream, $aSpamIds, $filters_spam_folder);
430 sqimap_mailbox_expunge($imap_stream, 'INBOX');
433 if ($bulkquery && count($IPs)) {
434 filters_bulkquery($filters, $IPs);
437 if ($SpamFilters_SharedCache) {
440 sqsession_register($SpamFilters_DNScache, 'SpamFilters_DNScache');
445 * Does the loop through each enabled filter for the specified IP address.
446 * IP format: $a.$b.$c.$d
447 * @param int $a First subset of IP
448 * @param int $b Second subset of IP
449 * @param int $c Third subset of IP
450 * @param int $d Forth subset of IP
451 * @param array $filters The Spam Filters
452 * @return boolean Whether the IP is Spam
455 function filters_spam_check_site($a, $b, $c, $d, &$filters) {
456 global $SpamFilters_DNScache, $SpamFilters_CacheTTL;
457 foreach ($filters as $key => $value) {
458 if ($filters[$key]['enabled']) {
459 if ($filters[$key]['dns']) {
460 $filter_revip = $d . '.' . $c . '.' . $b . '.' . $a . '.' .
461 $filters[$key]['dns'];
463 if(!isset($SpamFilters_DNScache[$filter_revip]['L']))
464 $SpamFilters_DNScache[$filter_revip]['L'] = '';
466 if(!isset($SpamFilters_DNScache[$filter_revip]['T']))
467 $SpamFilters_DNScache[$filter_revip]['T'] = '';
469 if (strlen($SpamFilters_DNScache[$filter_revip]['L']) == 0) {
470 $SpamFilters_DNScache[$filter_revip]['L'] =
471 gethostbyname($filter_revip);
472 $SpamFilters_DNScache[$filter_revip]['T'] =
473 time() +
$SpamFilters_CacheTTL;
475 if ($SpamFilters_DNScache[$filter_revip]['L'] ==
476 $filters[$key]['result']) {
486 * Loads the filters from the user preferences
487 * @return array All the user filters
490 function load_filters() {
491 global $data_dir, $username;
494 for ($i = 0; $fltr = getPref($data_dir, $username, 'filter' . $i); $i++
) {
495 $ary = explode(',', $fltr);
496 $filters[$i]['where'] = $ary[0];
497 $filters[$i]['what'] = $ary[1];
498 $filters[$i]['folder'] = $ary[2];
504 * Loads the Spam Filters and checks the preferences for the enabled status
505 * @return array All the spam filters
508 function load_spam_filters() {
509 global $data_dir, $username, $SpamFilters_ShowCommercial;
511 if ($SpamFilters_ShowCommercial) {
512 $filters['MAPS RBL']['prefname'] = 'filters_spam_maps_rbl';
513 $filters['MAPS RBL']['name'] = 'MAPS Realtime Blackhole List';
514 $filters['MAPS RBL']['link'] = 'http://www.mail-abuse.org/rbl/';
515 $filters['MAPS RBL']['dns'] = 'blackholes.mail-abuse.org';
516 $filters['MAPS RBL']['result'] = '127.0.0.2';
517 $filters['MAPS RBL']['comment'] =
518 _("COMMERCIAL - This list contains servers that are verified spam senders. It is a pretty reliable list to scan spam from.");
520 $filters['MAPS RSS']['prefname'] = 'filters_spam_maps_rss';
521 $filters['MAPS RSS']['name'] = 'MAPS Relay Spam Stopper';
522 $filters['MAPS RSS']['link'] = 'http://www.mail-abuse.org/rss/';
523 $filters['MAPS RSS']['dns'] = 'relays.mail-abuse.org';
524 $filters['MAPS RSS']['result'] = '127.0.0.2';
525 $filters['MAPS RSS']['comment'] =
526 _("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.");
528 $filters['MAPS DUL']['prefname'] = 'filters_spam_maps_dul';
529 $filters['MAPS DUL']['name'] = 'MAPS Dial-Up List';
530 $filters['MAPS DUL']['link'] = 'http://www.mail-abuse.org/dul/';
531 $filters['MAPS DUL']['dns'] = 'dialups.mail-abuse.org';
532 $filters['MAPS DUL']['result'] = '127.0.0.3';
533 $filters['MAPS DUL']['comment'] =
534 _("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.");
536 $filters['MAPS RBLplus-RBL']['prefname'] = 'filters_spam_maps_rblplus_rbl';
537 $filters['MAPS RBLplus-RBL']['name'] = 'MAPS RBL+ RBL List';
538 $filters['MAPS RBLplus-RBL']['link'] = 'http://www.mail-abuse.org/';
539 $filters['MAPS RBLplus-RBL']['dns'] = 'rbl-plus.mail-abuse.org';
540 $filters['MAPS RBLplus-RBL']['result'] = '127.0.0.2';
541 $filters['MAPS RBLplus-RBL']['comment'] =
542 _("COMMERCIAL - RBL+ Blackhole entries.");
544 $filters['MAPS RBLplus-RSS']['prefname'] = 'filters_spam_maps_rblplus_rss';
545 $filters['MAPS RBLplus-RSS']['name'] = 'MAPS RBL+ List RSS entries';
546 $filters['MAPS RBLplus-RSS']['link'] = 'http://www.mail-abuse.org/';
547 $filters['MAPS RBLplus-RSS']['dns'] = 'rbl-plus.mail-abuse.org';
548 $filters['MAPS RBLplus-RSS']['result'] = '127.0.0.2';
549 $filters['MAPS RBLplus-RSS']['comment'] =
550 _("COMMERCIAL - RBL+ OpenRelay entries.");
552 $filters['MAPS RBLplus-DUL']['prefname'] = 'filters_spam_maps_rblplus_dul';
553 $filters['MAPS RBLplus-DUL']['name'] = 'MAPS RBL+ List DUL entries';
554 $filters['MAPS RBLplus-DUL']['link'] = 'http://www.mail-abuse.org/';
555 $filters['MAPS RBLplus-DUL']['dns'] = 'rbl-plus.mail-abuse.org';
556 $filters['MAPS RBLplus-DUL']['result'] = '127.0.0.3';
557 $filters['MAPS RBLplus-DUL']['comment'] =
558 _("COMMERCIAL - RBL+ Dial-up entries.");
561 $filters['ORDB']['prefname'] = 'filters_spam_ordb';
562 $filters['ORDB']['name'] = 'Open Relay Database List';
563 $filters['ORDB']['link'] = 'http://www.ordb.org/';
564 $filters['ORDB']['dns'] = 'relays.ordb.org';
565 $filters['ORDB']['result'] = '127.0.0.2';
566 $filters['ORDB']['comment'] =
567 _("FREE - ORDB was born when ORBS went off the air. It seems to have fewer false positives than ORBS did though.");
569 $filters['FiveTen Direct']['prefname'] = 'filters_spam_fiveten_src';
570 $filters['FiveTen Direct']['name'] = 'Five-Ten-sg.com Direct SPAM Sources';
571 $filters['FiveTen Direct']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
572 $filters['FiveTen Direct']['dns'] = 'blackholes.five-ten-sg.com';
573 $filters['FiveTen Direct']['result'] = '127.0.0.2';
574 $filters['FiveTen Direct']['comment'] =
575 _("FREE - Five-Ten-sg.com - Direct SPAM sources.");
577 $filters['FiveTen DUL']['prefname'] = 'filters_spam_fiveten_dul';
578 $filters['FiveTen DUL']['name'] = 'Five-Ten-sg.com DUL Lists';
579 $filters['FiveTen DUL']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
580 $filters['FiveTen DUL']['dns'] = 'blackholes.five-ten-sg.com';
581 $filters['FiveTen DUL']['result'] = '127.0.0.3';
582 $filters['FiveTen DUL']['comment'] =
583 _("FREE - Five-Ten-sg.com - Dial-up lists - includes some DSL IPs.");
585 $filters['FiveTen Unc. OptIn']['prefname'] = 'filters_spam_fiveten_oi';
586 $filters['FiveTen Unc. OptIn']['name'] = 'Five-Ten-sg.com Unconfirmed OptIn Lists';
587 $filters['FiveTen Unc. OptIn']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
588 $filters['FiveTen Unc. OptIn']['dns'] = 'blackholes.five-ten-sg.com';
589 $filters['FiveTen Unc. OptIn']['result'] = '127.0.0.4';
590 $filters['FiveTen Unc. OptIn']['comment'] =
591 _("FREE - Five-Ten-sg.com - Bulk mailers that do not use confirmed opt-in.");
593 $filters['FiveTen Others']['prefname'] = 'filters_spam_fiveten_oth';
594 $filters['FiveTen Others']['name'] = 'Five-Ten-sg.com Other Misc. Servers';
595 $filters['FiveTen Others']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
596 $filters['FiveTen Others']['dns'] = 'blackholes.five-ten-sg.com';
597 $filters['FiveTen Others']['result'] = '127.0.0.5';
598 $filters['FiveTen Others']['comment'] =
599 _("FREE - Five-Ten-sg.com - Other misc. servers.");
601 $filters['FiveTen Single Stage']['prefname'] = 'filters_spam_fiveten_ss';
602 $filters['FiveTen Single Stage']['name'] = 'Five-Ten-sg.com Single Stage Servers';
603 $filters['FiveTen Single Stage']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
604 $filters['FiveTen Single Stage']['dns'] = 'blackholes.five-ten-sg.com';
605 $filters['FiveTen Single Stage']['result'] = '127.0.0.6';
606 $filters['FiveTen Single Stage']['comment'] =
607 _("FREE - Five-Ten-sg.com - Single Stage servers.");
609 $filters['FiveTen SPAM Support']['prefname'] = 'filters_spam_fiveten_supp';
610 $filters['FiveTen SPAM Support']['name'] = 'Five-Ten-sg.com SPAM Support Servers';
611 $filters['FiveTen SPAM Support']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
612 $filters['FiveTen SPAM Support']['dns'] = 'blackholes.five-ten-sg.com';
613 $filters['FiveTen SPAM Support']['result'] = '127.0.0.7';
614 $filters['FiveTen SPAM Support']['comment'] =
615 _("FREE - Five-Ten-sg.com - SPAM Support servers.");
617 $filters['FiveTen Web forms']['prefname'] = 'filters_spam_fiveten_wf';
618 $filters['FiveTen Web forms']['name'] = 'Five-Ten-sg.com Web Form IPs';
619 $filters['FiveTen Web forms']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
620 $filters['FiveTen Web forms']['dns'] = 'blackholes.five-ten-sg.com';
621 $filters['FiveTen Web forms']['result'] = '127.0.0.8';
622 $filters['FiveTen Web forms']['comment'] =
623 _("FREE - Five-Ten-sg.com - Web Form IPs.");
625 $filters['Dorkslayers']['prefname'] = 'filters_spam_dorks';
626 $filters['Dorkslayers']['name'] = 'Dorkslayers Lists';
627 $filters['Dorkslayers']['link'] = 'http://www.dorkslayers.com';
628 $filters['Dorkslayers']['dns'] = 'orbs.dorkslayers.com';
629 $filters['Dorkslayers']['result'] = '127.0.0.2';
630 $filters['Dorkslayers']['comment'] =
631 _("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.");
633 $filters['SPAMhaus']['prefname'] = 'filters_spam_spamhaus';
634 $filters['SPAMhaus']['name'] = 'SPAMhaus Lists';
635 $filters['SPAMhaus']['link'] = 'http://www.spamhaus.org';
636 $filters['SPAMhaus']['dns'] = 'sbl.spamhaus.org';
637 $filters['SPAMhaus']['result'] = '127.0.0.6';
638 $filters['SPAMhaus']['comment'] =
639 _("FREE - SPAMhaus - A list of well-known SPAM sources.");
641 $filters['SPAMcop']['prefname'] = 'filters_spam_spamcop';
642 $filters['SPAMcop']['name'] = 'SPAM Cop Lists';
643 $filters['SPAMcop']['link'] = 'http://spamcop.net/bl.shtml';
644 $filters['SPAMcop']['dns'] = 'bl.spamcop.net';
645 $filters['SPAMcop']['result'] = '127.0.0.2';
646 $filters['SPAMcop']['comment'] =
647 _("FREE, for now - SpamCop - An interesting solution that lists servers that have a very high spam to legit email ratio (85 percent or more).");
649 $filters['dev.null.dk']['prefname'] = 'filters_spam_devnull';
650 $filters['dev.null.dk']['name'] = 'dev.null.dk Lists';
651 $filters['dev.null.dk']['link'] = 'http://dev.null.dk/';
652 $filters['dev.null.dk']['dns'] = 'dev.null.dk';
653 $filters['dev.null.dk']['result'] = '127.0.0.2';
654 $filters['dev.null.dk']['comment'] =
655 _("FREE - dev.null.dk - I don't have any detailed info on this list.");
657 $filters['visi.com']['prefname'] = 'filters_spam_visi';
658 $filters['visi.com']['name'] = 'visi.com Relay Stop List';
659 $filters['visi.com']['link'] = 'http://relays.visi.com';
660 $filters['visi.com']['dns'] = 'relays.visi.com';
661 $filters['visi.com']['result'] = '127.0.0.2';
662 $filters['visi.com']['comment'] =
663 _("FREE - visi.com - Relay Stop List. Very conservative OpenRelay List.");
665 $filters['ahbl.org Open Relays']['prefname'] = 'filters_spam_2mb_or';
666 $filters['ahbl.org Open Relays']['name'] = 'ahbl.org Open Relays List';
667 $filters['ahbl.org Open Relays']['link'] = 'http://www.ahbl.org/';
668 $filters['ahbl.org Open Relays']['dns'] = 'dnsbl.ahbl.org';
669 $filters['ahbl.org Open Relays']['result'] = '127.0.0.2';
670 $filters['ahbl.org Open Relays']['comment'] =
671 _("FREE - ahbl.org Open Relays - Another list of Open Relays.");
673 $filters['ahbl.org SPAM Source']['prefname'] = 'filters_spam_2mb_ss';
674 $filters['ahbl.org SPAM Source']['name'] = 'ahbl.org SPAM Source List';
675 $filters['ahbl.org SPAM Source']['link'] = 'http://www.ahbl.org/';
676 $filters['ahbl.org SPAM Source']['dns'] = 'dnsbl.ahbl.org';
677 $filters['ahbl.org SPAM Source']['result'] = '127.0.0.4';
678 $filters['ahbl.org SPAM Source']['comment'] =
679 _("FREE - ahbl.org SPAM Source - List of Direct SPAM Sources.");
681 $filters['ahbl.org SPAM ISPs']['prefname'] = 'filters_spam_2mb_isp';
682 $filters['ahbl.org SPAM ISPs']['name'] = 'ahbl.org SPAM-friendly ISP List';
683 $filters['ahbl.org SPAM ISPs']['link'] = 'http://www.ahbl.org/';
684 $filters['ahbl.org SPAM ISPs']['dns'] = 'dnsbl.ahbl.org';
685 $filters['ahbl.org SPAM ISPs']['result'] = '127.0.0.7';
686 $filters['ahbl.org SPAM ISPs']['comment'] =
687 _("FREE - ahbl.org SPAM ISPs - List of SPAM-friendly ISPs.");
689 $filters['Leadmon DUL']['prefname'] = 'filters_spam_lm_dul';
690 $filters['Leadmon DUL']['name'] = 'Leadmon.net DUL List';
691 $filters['Leadmon DUL']['link'] = 'http://www.leadmon.net/spamguard/';
692 $filters['Leadmon DUL']['dns'] = 'spamguard.leadmon.net';
693 $filters['Leadmon DUL']['result'] = '127.0.0.2';
694 $filters['Leadmon DUL']['comment'] =
695 _("FREE - Leadmon DUL - Another list of Dial-up or otherwise dynamically assigned IPs.");
697 $filters['Leadmon SPAM Source']['prefname'] = 'filters_spam_lm_ss';
698 $filters['Leadmon SPAM Source']['name'] = 'Leadmon.net SPAM Source List';
699 $filters['Leadmon SPAM Source']['link'] = 'http://www.leadmon.net/spamguard/';
700 $filters['Leadmon SPAM Source']['dns'] = 'spamguard.leadmon.net';
701 $filters['Leadmon SPAM Source']['result'] = '127.0.0.3';
702 $filters['Leadmon SPAM Source']['comment'] =
703 _("FREE - Leadmon SPAM Source - List of IPs Leadmon.net has received SPAM directly from.");
705 $filters['Leadmon Bulk Mailers']['prefname'] = 'filters_spam_lm_bm';
706 $filters['Leadmon Bulk Mailers']['name'] = 'Leadmon.net Bulk Mailers List';
707 $filters['Leadmon Bulk Mailers']['link'] = 'http://www.leadmon.net/spamguard/';
708 $filters['Leadmon Bulk Mailers']['dns'] = 'spamguard.leadmon.net';
709 $filters['Leadmon Bulk Mailers']['result'] = '127.0.0.4';
710 $filters['Leadmon Bulk Mailers']['comment'] =
711 _("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.");
713 $filters['Leadmon Open Relays']['prefname'] = 'filters_spam_lm_or';
714 $filters['Leadmon Open Relays']['name'] = 'Leadmon.net Open Relays List';
715 $filters['Leadmon Open Relays']['link'] = 'http://www.leadmon.net/spamguard/';
716 $filters['Leadmon Open Relays']['dns'] = 'spamguard.leadmon.net';
717 $filters['Leadmon Open Relays']['result'] = '127.0.0.5';
718 $filters['Leadmon Open Relays']['comment'] =
719 _("FREE - Leadmon Open Relays - Single Stage Open Relays that are not listed on other active RBLs.");
721 $filters['Leadmon Multi-stage']['prefname'] = 'filters_spam_lm_ms';
722 $filters['Leadmon Multi-stage']['name'] = 'Leadmon.net Multi-Stage Relay List';
723 $filters['Leadmon Multi-stage']['link'] = 'http://www.leadmon.net/spamguard/';
724 $filters['Leadmon Multi-stage']['dns'] = 'spamguard.leadmon.net';
725 $filters['Leadmon Multi-stage']['result'] = '127.0.0.6';
726 $filters['Leadmon Multi-stage']['comment'] =
727 _("FREE - Leadmon Multi-stage - Multi-Stage Open Relays that are not listed on other active RBLs and that have sent SPAM to Leadmon.net.");
729 $filters['Leadmon SpamBlock']['prefname'] = 'filters_spam_lm_sb';
730 $filters['Leadmon SpamBlock']['name'] = 'Leadmon.net SpamBlock Sites List';
731 $filters['Leadmon SpamBlock']['link'] = 'http://www.leadmon.net/spamguard/';
732 $filters['Leadmon SpamBlock']['dns'] = 'spamguard.leadmon.net';
733 $filters['Leadmon SpamBlock']['result'] = '127.0.0.7';
734 $filters['Leadmon SpamBlock']['comment'] =
735 _("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.");
737 $filters['NJABL Open Relays']['prefname'] = 'filters_spam_njabl_or';
738 $filters['NJABL Open Relays']['name'] = 'NJABL Open Relay/Direct Spam Source List';
739 $filters['NJABL Open Relays']['link'] = 'http://www.njabl.org/';
740 $filters['NJABL Open Relays']['dns'] = 'dnsbl.njabl.org';
741 $filters['NJABL Open Relays']['result'] = '127.0.0.2';
742 $filters['NJABL Open Relays']['comment'] =
743 _("FREE, for now - Not Just Another Blacklist - Both Open Relays and Direct SPAM Sources.");
745 $filters['NJABL DUL']['prefname'] = 'filters_spam_njabl_dul';
746 $filters['NJABL DUL']['name'] = 'NJABL Dial-ups List';
747 $filters['NJABL DUL']['link'] = 'http://www.njabl.org/';
748 $filters['NJABL DUL']['dns'] = 'dnsbl.njabl.org';
749 $filters['NJABL DUL']['result'] = '127.0.0.3';
750 $filters['NJABL DUL']['comment'] =
751 _("FREE, for now - Not Just Another Blacklist - Dial-up IPs.");
753 $filters['Conf DSBL.ORG Relay']['prefname'] = 'filters_spam_dsbl_conf_ss';
754 $filters['Conf DSBL.ORG Relay']['name'] = 'DSBL.org Confirmed Relay List';
755 $filters['Conf DSBL.ORG Relay']['link'] = 'http://www.dsbl.org/';
756 $filters['Conf DSBL.ORG Relay']['dns'] = 'list.dsbl.org';
757 $filters['Conf DSBL.ORG Relay']['result'] = '127.0.0.2';
758 $filters['Conf DSBL.ORG Relay']['comment'] =
759 _("FREE - Distributed Sender Boycott List - Confirmed Relays");
761 $filters['Conf DSBL.ORG Multi-Stage']['prefname'] = 'filters_spam_dsbl_conf_ms';
762 $filters['Conf DSBL.ORG Multi-Stage']['name'] = 'DSBL.org Confirmed Multi-Stage Relay List';
763 $filters['Conf DSBL.ORG Multi-Stage']['link'] = 'http://www.dsbl.org/';
764 $filters['Conf DSBL.ORG Multi-Stage']['dns'] = 'multihop.dsbl.org';
765 $filters['Conf DSBL.ORG Multi-Stage']['result'] = '127.0.0.2';
766 $filters['Conf DSBL.ORG Multi-Stage']['comment'] =
767 _("FREE - Distributed Sender Boycott List - Confirmed Multi-stage Relays");
769 $filters['UN-Conf DSBL.ORG']['prefname'] = 'filters_spam_dsbl_unc';
770 $filters['UN-Conf DSBL.ORG']['name'] = 'DSBL.org UN-Confirmed Relay List';
771 $filters['UN-Conf DSBL.ORG']['link'] = 'http://www.dsbl.org/';
772 $filters['UN-Conf DSBL.ORG']['dns'] = 'unconfirmed.dsbl.org';
773 $filters['UN-Conf DSBL.ORG']['result'] = '127.0.0.2';
774 $filters['UN-Conf DSBL.ORG']['comment'] =
775 _("FREE - Distributed Sender Boycott List - UN-Confirmed Relays");
777 foreach ($filters as $Key => $Value) {
778 $filters[$Key]['enabled'] = getPref($data_dir, $username, $filters[$Key]['prefname']);
785 * Removes a User filter
786 * @param int $id ID of the filter to remove
789 function remove_filter ($id) {
790 global $data_dir, $username;
792 while ($nextFilter = getPref($data_dir, $username, 'filter' . ($id +
1))) {
793 setPref($data_dir, $username, 'filter' . $id, $nextFilter);
797 removePref($data_dir, $username, 'filter' . $id);
802 * @param int $id1 ID of first filter to swap
803 * @param int $id2 ID of second filter to swap
806 function filter_swap($id1, $id2) {
807 global $data_dir, $username;
809 $FirstFilter = getPref($data_dir, $username, 'filter' . $id1);
810 $SecondFilter = getPref($data_dir, $username, 'filter' . $id2);
812 if ($FirstFilter && $SecondFilter) {
813 setPref($data_dir, $username, 'filter' . $id2, $FirstFilter);
814 setPref($data_dir, $username, 'filter' . $id1, $SecondFilter);
819 * This updates the filter rules when renaming or deleting folders
823 function update_for_folder ($args) {
825 if (!file_exists(SM_PATH
. 'plugins/filters/config.php')) return;
827 $old_folder = $args[0];
828 $new_folder = $args[2];
830 global $data_dir, $username;
832 $filters = load_filters();
833 $filter_count = count($filters);
835 for ($i = 0; $i < $filter_count; $i++
) {
836 if (!empty($filters)) {
837 if ($old_folder == $filters[$i]['folder']) {
838 if ($action == 'rename') {
839 $filters[$i]['folder'] = $new_folder;
840 setPref($data_dir, $username, 'filter'.$i,
841 $filters[$i]['where'].','.$filters[$i]['what'].','.$new_folder);
843 elseif ($action == 'delete') {
854 * Display formated error message
855 * @param string $string text message
856 * @return string html formated text message
859 function do_error($string) {
861 echo "<p align=\"center\"><font color=\"$color[2]\">";
863 echo "</font></p>\n";