Source for file filters.php

Documentation is available at filters.php

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

Documentation generated on Thu, 23 May 2013 04:22:00 +0200 by phpDocumentor 1.4.3