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 14840 2020-01-07 07:42:38Z pdontthink $
  22.  * @copyright (c) 1999-2020 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_stream_options,
  183.            $imap_general$filters$imap_stream$imapConnection,
  184.  
  185.     // if there were filtering errors previously during
  186.     // this login session, we won't try again
  187.     //
  188.     // (errors that this plugin was able to catch or a "NO"
  189.     // response/failure from IMAP found in the current session,
  190.     // which could have resulted from an attempted filter copy
  191.     // (over quota), in which case execution halts before this
  192.     // plugin can catch the problem -- note, however, that any
  193.     // other IMAP "NO" failure (caused by unrelated actions) at
  194.     // any time during the current session will cause this plugin
  195.     // to effectively shut down)
  196.     //
  197.     sqgetGlobalVar('filters_error'$filters_errorSQ_SESSIONFALSE);
  198.     sqgetGlobalVar('IMAP_FATAL_ERROR_TYPE'$imap_fatal_errorSQ_SESSION'');
  199.     if ($filters_error || $imap_fatal_error == 'NO')
  200.         return;
  201.  
  202.     sqgetGlobalVar('username'$usernameSQ_SESSION);
  203.     sqgetGlobalVar('key',      $key,      SQ_COOKIE);
  204.  
  205.  
  206.     $filters load_filters();
  207.  
  208.     // No point running spam filters if there aren't any to run //
  209.     if ($AllowSpamFilters{
  210.         $spamfilters load_spam_filters();
  211.  
  212.         $AllowSpamFilters false;
  213.         foreach($spamfilters as $filterkey => $value{
  214.             if ($value['enabled'== SMPREF_ON{
  215.                 $AllowSpamFilters true;
  216.                 break;
  217.             }
  218.         }
  219.     }
  220.  
  221.     // No user filters, and no spam filters, no need to continue //
  222.     if (!$AllowSpamFilters && empty($filters)) {
  223.         return;
  224.     }
  225.  
  226.  
  227.     // Detect if we have already connected to IMAP or not.
  228.     // Also check if we are forced to use a separate IMAP connection
  229.     if ((!isset($imap_stream&& !isset($imapConnection)) ||
  230.         $UseSeparateImapConnection {
  231.             $stream sqimap_login($username$key$imapServerAddress,
  232.                                 $imapPort10$imap_stream_options);
  233.             $previously_connected false;
  234.     else if (isset($imapConnection)) {
  235.         $stream $imapConnection;
  236.         $previously_connected true;
  237.     else {
  238.         $previously_connected true;
  239.         $stream $imap_stream;
  240.     }
  241.     $aStatus sqimap_status_messages ($stream'INBOX'array('MESSAGES'));
  242.  
  243.     if ($aStatus['MESSAGES']{
  244.         sqimap_mailbox_select($stream'INBOX');
  245.         // Filter spam from inbox before we sort them into folders
  246.         if ($AllowSpamFilters{
  247.             spam_filters($stream);
  248.         }
  249.  
  250.         // Sort into folders
  251.         user_filters($stream);
  252.     }
  253.  
  254.     if (!$previously_connected{
  255.         sqimap_logout($stream);
  256.     }
  257. }
  258.  
  259. /**
  260.  * Does the loop through each filter
  261.  * @param stream imap_stream the stream to read from
  262.  * @access private
  263.  */
  264. function user_filters($imap_stream{
  265.     global $data_dir$username;
  266.     $filters load_filters();
  267.     if ($filtersreturn;
  268.     $filters_user_scan getPref($data_dir$username'filters_user_scan');
  269.  
  270.     sqimap_mailbox_select($imap_stream'INBOX');
  271.     $id array();
  272.     // For every rule
  273.     for ($i=0$num count($filters)$i $num$i++{
  274.         // Don't attempt to run filters if folder does not exist //
  275.         if (!sqimap_mailbox_exists($imap_stream$filters[$i]['folder'])) {
  276.             continue;
  277.         }
  278.         
  279.         
  280.         // If it is the "combo" rule
  281.         if ($filters[$i]['where'== 'To or Cc'{
  282.             /*
  283.             *  If it's "TO OR CC", we have to do two searches, one for TO
  284.             *  and the other for CC.
  285.             */
  286.             $id filter_search_and_delete($imap_stream'TO',
  287.                   $filters[$i]['what']$filters[$i]['folder']$filters_user_scan$id);
  288.             $id filter_search_and_delete($imap_stream'CC',
  289.                   $filters[$i]['what']$filters[$i]['folder']$filters_user_scan$id);
  290.         else {
  291.             /*
  292.             *  If it's a normal TO, CC, SUBJECT, or FROM, then handle it
  293.             *  normally.
  294.             */
  295.             $id filter_search_and_delete($imap_stream$filters[$i]['where'],
  296.                  $filters[$i]['what']$filters[$i]['folder']$filters_user_scan$id);
  297.         }
  298.     }
  299.     // Clean out the mailbox whether or not auto_expunge is on
  300.     // That way it looks like it was redirected properly
  301.     if (count($id)) {
  302.         sqimap_mailbox_expunge($imap_stream'INBOX');
  303.     }
  304. }
  305.  
  306. /**
  307.  * Creates and runs the IMAP command to filter messages
  308.  * @param string $imap TODO: Document this parameter
  309.  * @param string $where Which part of the message to search (TO, CC, SUBJECT, etc...)
  310.  * @param string $what String to search for
  311.  * @param string $where_to Folder it will move to
  312.  * @param string $user_scan Whether to search all or just unseen
  313.  * @param string $del_id TODO: Document this parameter
  314.  * @access private
  315.  */
  316. function filter_search_and_delete($imap$where$what$where_to$user_scan,
  317.                                   $del_id{
  318.     global $languages$squirrelmail_language$allow_charset_search,
  319.            $uid_support$imap_server_type;
  320.  
  321.     if (strtolower($where_to== 'inbox'{
  322.         return array();
  323.     }
  324.  
  325.     if ($user_scan == 'new'{
  326.         $category 'UNSEEN';
  327.     else {
  328.         $category 'ALL';
  329.     }
  330.     $category .= ' UNDELETED';
  331.  
  332.     if ($allow_charset_search &&
  333.         isset($languages[$squirrelmail_language]['CHARSET']&&
  334.         $languages[$squirrelmail_language]['CHARSET']{
  335.         $search_str 'SEARCH CHARSET '
  336.                     . strtoupper($languages[$squirrelmail_language]['CHARSET'])
  337.                     . ' ' $category;
  338.     else {
  339.         $search_str 'SEARCH CHARSET US-ASCII ' $category;
  340.     }
  341.     if ($where == 'Header'{
  342.         $what  explode(':'$what);
  343.         $where trim($where ' ' $what[0]);
  344.         $what  addslashes(trim($what[1]));
  345.     }
  346.  
  347.     // see comments in squirrelmail sqimap_search function
  348.     if ($imap_server_type == 'macosx' || $imap_server_type == 'hmailserver'{
  349.         $search_str .= ' ' $where ' ' $what;
  350.         $read sqimap_run_command_list($imap$search_strtrue$response$message$uid_support);        
  351.     else {
  352.         $lit array();
  353.         $lit['commands'][$search_str ' ' $where;
  354.         $lit['literal_args'][$what;
  355.         
  356.         $read sqimap_run_literal_command($imap$littrue$response$message$uid_support );
  357.     }
  358.  
  359.     /* read data back from IMAP */
  360.     
  361.  
  362.     // This may have problems with EIMS due to it being goofy
  363.  
  364.     for ($r=0$num count($read)$r $num &&
  365.                 substr($read[$r]08!= '* SEARCH'$r++{}
  366.     if ($response == 'OK'{
  367.         $ids explode(' '$read[$r]);
  368.         if (sqimap_mailbox_exists($imap$where_to)) {
  369.             /*
  370.              * why we do n calls instead of just one. It is safer to copy
  371.              * messages one by one, but code does not call expunge after
  372.              * message is copied and quota limits are not resolved.
  373.              */
  374.             for ($j=2$num count($ids)$j $num$j++{
  375.                 $id trim($ids[$j]);
  376.                 if (sqimap_msgs_list_move($imap$id$where_to)) {
  377.                     $del_id[$id;
  378.                 else {
  379.                     // if errors occurred, don't try to filter again during this session
  380.                     sqsession_register(TRUE'filters_error');
  381.                     global $color;
  382.                     error_box(_("A problem occurred filtering messages. Check filter settings and account quota if applicable. Filtering is disabled for the remainder of this login session.")$color);
  383.                     // we stil return info about what was successfully
  384.                     // filtered before this error occurred
  385.                     return $del_id;
  386.                 }
  387.             }
  388.         }
  389.     }
  390.     return $del_id;
  391. }
  392.  
  393. /**
  394.  * Loops through all the Received Headers to find IP Addresses
  395.  * @param stream imap_stream the stream to read from
  396.  * @access private
  397.  */
  398. function spam_filters($imap_stream{
  399.     global $data_dir$username$uid_support;
  400.     global $SpamFilters_YourHop;
  401.     global $SpamFilters_DNScache;
  402.     global $SpamFilters_SharedCache;
  403.     global $SpamFilters_BulkQuery;
  404.  
  405.     $filters_spam_scan getPref($data_dir$username'filters_spam_scan');
  406.     $filters_spam_folder getPref($data_dir$username'filters_spam_folder');
  407.     $filters load_spam_filters();
  408.  
  409.     if ($SpamFilters_SharedCache{
  410.        filters_LoadCache();
  411.     }
  412.  
  413.     $run false;
  414.  
  415.     foreach ($filters as $Key => $Value{
  416.         if ($Value['enabled']{
  417.             $run true;
  418.             break;
  419.         }
  420.     }
  421.  
  422.     // short-circuit
  423.     if (!$run{
  424.         return;
  425.     }
  426.  
  427.     sqimap_mailbox_select($imap_stream'INBOX');
  428.  
  429.     $search_array array();
  430.     if ($filters_spam_scan == 'new'{
  431.         $read sqimap_run_command($imap_stream'SEARCH UNSEEN'true$response$message$uid_support);
  432.         if (isset($read[0])) {
  433.             for ($i 0$iCnt count($read)$i $iCnt++$i{
  434.                 if (preg_match("/^\* SEARCH (.+)$/"$read[$i]$regs)) {
  435.                     $search_array explode(' 'trim($regs[1]));
  436.                     break;
  437.                 }
  438.             }
  439.         }
  440.     }
  441.  
  442.     if ($filters_spam_scan == 'new' && count($search_array)) {
  443.         $msg_str sqimap_message_list_squisher($search_array);
  444.         $imap_query 'FETCH ' $msg_str ' (FLAGS BODY.PEEK[HEADER.FIELDS (RECEIVED)])';
  445.     else if ($filters_spam_scan != 'new'{
  446.         $imap_query 'FETCH 1:* (FLAGS BODY.PEEK[HEADER.FIELDS (RECEIVED)])';
  447.     else {
  448.         return;
  449.     }
  450.  
  451.     $read sqimap_run_command_list($imap_stream$imap_querytrue$response$message$uid_support);
  452.  
  453.     if (isset($response&& $response != 'OK'{
  454.         return;
  455.     }
  456.  
  457.     $messages parseFetch($read);
  458.  
  459.     $bulkquery (strlen($SpamFilters_BulkQuerytrue false);
  460.     $aSpamIds array();
  461.     foreach($messages as $id=>$message{
  462.         if (isset($message['UID'])) {
  463.             $MsgNum $message['UID'];
  464.         else {
  465.             $MsgNum $id;
  466.         }
  467.  
  468.         if (isset($message['received'])) {
  469.             foreach($message['received'as $received{
  470.                 if (is_int(strpos($received$SpamFilters_YourHop))) {
  471.                     if (preg_match('/([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/'$received$matches)) {
  472.                         $IsSpam false;
  473.                         if (filters_spam_check_site($matches[1]$matches[2]$matches[3]$matches[4]$filters)) {
  474.                             $aSpamIds[$MsgNum;
  475.                             $IsSpam true;
  476.                         }
  477.  
  478.                         if ($bulkquery{
  479.                             array_shift($matches);
  480.                             $IP explode('.'$matches);
  481.                             foreach ($filters as $key => $value{
  482.                                 if ($filters[$key]['enabled'&& $filters[$key]['dns']{
  483.                                     if (strlen($SpamFilters_DNScache[$IP '.' $filters[$key]['dns']]== 0{
  484.                                         $IPs[$IPtrue;
  485.                                         break;
  486.                                     }
  487.                                 }
  488.                             }
  489.                         }
  490.                         // If we've checked one IP and YourHop is
  491.                         // just a space
  492.                         if ($SpamFilters_YourHop == ' ' || $IsSpam{
  493.                             break;  // don't check any more
  494.                         }
  495.                     }
  496.                 }
  497.             }
  498.         }
  499.     }
  500.     // Lookie!  It's spam!  Yum!
  501.     if (count($aSpamIds&& sqimap_mailbox_exists($imap_stream$filters_spam_folder)) {
  502.         if (!sqimap_msgs_list_move($imap_stream$aSpamIds$filters_spam_folder)) {
  503.             // if errors occurred, don't try to filter again during this session
  504.             sqsession_register(TRUE'filters_error');
  505.             global $color;
  506.             error_box(_("A problem occurred filtering messages. Check filter folders and account quota if applicable. Filtering is disabled for the remainder of this login session.")$color);
  507.             return;
  508.         }
  509.         sqimap_mailbox_expunge($imap_stream'INBOX'true$aSpamIds);
  510.     }
  511.  
  512.     if ($bulkquery && count($IPs)) {
  513.         filters_bulkquery($filters$IPs);
  514.     }
  515.  
  516.     if ($SpamFilters_SharedCache{
  517.        filters_SaveCache();
  518.     else {
  519.        sqsession_register($SpamFilters_DNScache'SpamFilters_DNScache');
  520.     }
  521. }
  522.  
  523. /**
  524.  * Does the loop through each enabled filter for the specified IP address.
  525.  * IP format:  $a.$b.$c.$d
  526.  * @param int $a First subset of IP
  527.  * @param int $b Second subset of IP
  528.  * @param int $c Third subset of IP
  529.  * @param int $d Forth subset of IP
  530.  * @param array $filters The Spam Filters
  531.  * @return boolean Whether the IP is Spam
  532.  * @access private
  533.  */
  534. function filters_spam_check_site($a$b$c$d&$filters{
  535.     foreach ($filters as $key => $value{
  536.         if ($filters[$key]['enabled']{
  537.             if ($filters[$key]['dns']{
  538.  
  539.                 /**
  540.                  * RFC allows . on end of hostname to force domain lookup to
  541.                  * not use search domain from resolv.conf, i.e. to ensure
  542.                  * search domain isn't used if no hostname is found
  543.                  */
  544.                 $filter_revip $d '.' $c '.' $b '.' $a '.' .
  545.                                 $filters[$key]['dns''.';
  546.  
  547.                 if(!isset($SpamFilters_DNScache[$filter_revip]['L']))
  548.                         $SpamFilters_DNScache[$filter_revip]['L''';
  549.  
  550.                 if(!isset($SpamFilters_DNScache[$filter_revip]['T']))
  551.                         $SpamFilters_DNScache[$filter_revip]['T''';
  552.  
  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;
  558.                 }
  559.  
  560.                 /**
  561.                  * gethostbyname returns ip if resolved, or returns original
  562.                  * host supplied to function if there is no resolution
  563.                  */
  564.                 if ($SpamFilters_DNScache[$filter_revip]['L'!= $filter_revip{
  565.                     return 1;
  566.                 }
  567.             }
  568.         }
  569.     }
  570.     return 0;
  571. }
  572.  
  573. /**
  574.  * Loads the filters from the user preferences
  575.  * @return array All the user filters
  576.  * @access private
  577.  */
  578. function load_filters({
  579.     global $data_dir$username;
  580.  
  581.     $filters array();
  582.     for ($i 0$fltr getPref($data_dir$username'filter' $i)$i++{
  583.         $ary explode(','$fltr);
  584.         $filters[$i]['where'$ary[0];
  585.         $filters[$i]['what'str_replace('###COMMA###'','$ary[1]);
  586.         $filters[$i]['folder'$ary[2];
  587.     }
  588.     return $filters;
  589. }
  590.  
  591. /**
  592.  * Loads the Spam Filters and checks the preferences for the enabled status
  593.  * @return array All the spam filters
  594.  * @access private
  595.  */
  596. function load_spam_filters({
  597.     global $data_dir$username$SpamFilters_ShowCommercial;
  598.  
  599.     if ($SpamFilters_ShowCommercial{
  600.         $filters['MAPS RBL']['prefname''filters_spam_maps_rbl';
  601.         $filters['MAPS RBL']['name''MAPS Realtime Blackhole List';
  602.         $filters['MAPS RBL']['link''http://www.mail-abuse.org/rbl/';
  603.         $filters['MAPS RBL']['dns''blackholes.mail-abuse.org';
  604.         $filters['MAPS RBL']['result''127.0.0.2';
  605.         $filters['MAPS RBL']['comment'=
  606.             _("COMMERCIAL - This list contains servers that are verified spam senders. It is a pretty reliable list to scan spam from.");
  607.  
  608.         $filters['MAPS RSS']['prefname''filters_spam_maps_rss';
  609.         $filters['MAPS RSS']['name''MAPS Relay Spam Stopper';
  610.         $filters['MAPS RSS']['link''http://www.mail-abuse.org/rss/';
  611.         $filters['MAPS RSS']['dns''relays.mail-abuse.org';
  612.         $filters['MAPS RSS']['result''127.0.0.2';
  613.         $filters['MAPS RSS']['comment'=
  614.             _("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.");
  615.  
  616.         $filters['MAPS DUL']['prefname''filters_spam_maps_dul';
  617.         $filters['MAPS DUL']['name''MAPS Dial-Up List';
  618.         $filters['MAPS DUL']['link''http://www.mail-abuse.org/dul/';
  619.         $filters['MAPS DUL']['dns''dialups.mail-abuse.org';
  620.         $filters['MAPS DUL']['result''127.0.0.3';
  621.         $filters['MAPS DUL']['comment'=
  622.             _("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.");
  623.  
  624.         $filters['MAPS RBLplus-RBL']['prefname''filters_spam_maps_rblplus_rbl';
  625.         $filters['MAPS RBLplus-RBL']['name''MAPS RBL+ RBL List';
  626.         $filters['MAPS RBLplus-RBL']['link''http://www.mail-abuse.org/';
  627.         $filters['MAPS RBLplus-RBL']['dns''rbl-plus.mail-abuse.org';
  628.         $filters['MAPS RBLplus-RBL']['result''127.0.0.2';
  629.         $filters['MAPS RBLplus-RBL']['comment'=
  630.             _("COMMERCIAL - RBL+ Blackhole entries.");
  631.  
  632.         $filters['MAPS RBLplus-RSS']['prefname''filters_spam_maps_rblplus_rss';
  633.         $filters['MAPS RBLplus-RSS']['name''MAPS RBL+ List RSS entries';
  634.         $filters['MAPS RBLplus-RSS']['link''http://www.mail-abuse.org/';
  635.         $filters['MAPS RBLplus-RSS']['dns''rbl-plus.mail-abuse.org';
  636.         $filters['MAPS RBLplus-RSS']['result''127.0.0.2';
  637.         $filters['MAPS RBLplus-RSS']['comment'=
  638.             _("COMMERCIAL - RBL+ OpenRelay entries.");
  639.  
  640.         $filters['MAPS RBLplus-DUL']['prefname''filters_spam_maps_rblplus_dul';
  641.         $filters['MAPS RBLplus-DUL']['name''MAPS RBL+ List DUL entries';
  642.         $filters['MAPS RBLplus-DUL']['link''http://www.mail-abuse.org/';
  643.         $filters['MAPS RBLplus-DUL']['dns''rbl-plus.mail-abuse.org';
  644.         $filters['MAPS RBLplus-DUL']['result''127.0.0.3';
  645.         $filters['MAPS RBLplus-DUL']['comment'=
  646.             _("COMMERCIAL - RBL+ Dial-up entries.");
  647.     }
  648.  
  649.     $filters['FiveTen Direct']['prefname''filters_spam_fiveten_src';
  650.     $filters['FiveTen Direct']['name''Five-Ten-sg.com Direct SPAM Sources';
  651.     $filters['FiveTen Direct']['link''http://www.five-ten-sg.com/blackhole.php';
  652.     $filters['FiveTen Direct']['dns''blackholes.five-ten-sg.com';
  653.     $filters['FiveTen Direct']['result''127.0.0.2';
  654.     $filters['FiveTen Direct']['comment'=
  655.         _("FREE - Five-Ten-sg.com - Direct SPAM sources.");
  656.  
  657.     $filters['FiveTen DUL']['prefname''filters_spam_fiveten_dul';
  658.     $filters['FiveTen DUL']['name''Five-Ten-sg.com DUL Lists';
  659.     $filters['FiveTen DUL']['link''http://www.five-ten-sg.com/blackhole.php';
  660.     $filters['FiveTen DUL']['dns''blackholes.five-ten-sg.com';
  661.     $filters['FiveTen DUL']['result''127.0.0.3';
  662.     $filters['FiveTen DUL']['comment'=
  663.         _("FREE - Five-Ten-sg.com - Dial-up lists - includes some DSL IPs.");
  664.  
  665.     $filters['FiveTen Unc. OptIn']['prefname''filters_spam_fiveten_oi';
  666.     $filters['FiveTen Unc. OptIn']['name''Five-Ten-sg.com Unconfirmed OptIn Lists';
  667.     $filters['FiveTen Unc. OptIn']['link''http://www.five-ten-sg.com/blackhole.php';
  668.     $filters['FiveTen Unc. OptIn']['dns''blackholes.five-ten-sg.com';
  669.     $filters['FiveTen Unc. OptIn']['result''127.0.0.4';
  670.     $filters['FiveTen Unc. OptIn']['comment'=
  671.         _("FREE - Five-Ten-sg.com - Bulk mailers that do not use confirmed opt-in.");
  672.  
  673.     $filters['FiveTen Others']['prefname''filters_spam_fiveten_oth';
  674.     $filters['FiveTen Others']['name''Five-Ten-sg.com Other Misc. Servers';
  675.     $filters['FiveTen Others']['link''http://www.five-ten-sg.com/blackhole.php';
  676.     $filters['FiveTen Others']['dns''blackholes.five-ten-sg.com';
  677.     $filters['FiveTen Others']['result''127.0.0.5';
  678.     $filters['FiveTen Others']['comment'=
  679.         _("FREE - Five-Ten-sg.com - Other misc. servers.");
  680.  
  681.     $filters['FiveTen Single Stage']['prefname''filters_spam_fiveten_ss';
  682.     $filters['FiveTen Single Stage']['name''Five-Ten-sg.com Single Stage Servers';
  683.     $filters['FiveTen Single Stage']['link''http://www.five-ten-sg.com/blackhole.php';
  684.     $filters['FiveTen Single Stage']['dns''blackholes.five-ten-sg.com';
  685.     $filters['FiveTen Single Stage']['result''127.0.0.6';
  686.     $filters['FiveTen Single Stage']['comment'=
  687.         _("FREE - Five-Ten-sg.com - Single Stage servers.");
  688.  
  689.     $filters['FiveTen SPAM Support']['prefname''filters_spam_fiveten_supp';
  690.     $filters['FiveTen SPAM Support']['name''Five-Ten-sg.com SPAM Support Servers';
  691.     $filters['FiveTen SPAM Support']['link''http://www.five-ten-sg.com/blackhole.php';
  692.     $filters['FiveTen SPAM Support']['dns''blackholes.five-ten-sg.com';
  693.     $filters['FiveTen SPAM Support']['result''127.0.0.7';
  694.     $filters['FiveTen SPAM Support']['comment'=
  695.         _("FREE - Five-Ten-sg.com - SPAM Support servers.");
  696.  
  697.     $filters['FiveTen Web forms']['prefname''filters_spam_fiveten_wf';
  698.     $filters['FiveTen Web forms']['name''Five-Ten-sg.com Web Form IPs';
  699.     $filters['FiveTen Web forms']['link''http://www.five-ten-sg.com/blackhole.php';
  700.     $filters['FiveTen Web forms']['dns''blackholes.five-ten-sg.com';
  701.     $filters['FiveTen Web forms']['result''127.0.0.8';
  702.     $filters['FiveTen Web forms']['comment'=
  703.         _("FREE - Five-Ten-sg.com - Web Form IPs.");
  704.  
  705.     $filters['Dorkslayers']['prefname''filters_spam_dorks';
  706.     $filters['Dorkslayers']['name''Dorkslayers Lists';
  707.     $filters['Dorkslayers']['link''http://www.dorkslayers.com';
  708.     $filters['Dorkslayers']['dns''orbs.dorkslayers.com';
  709.     $filters['Dorkslayers']['result''127.0.0.2';
  710.     $filters['Dorkslayers']['comment'=
  711.         _("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.");
  712.  
  713.     $filters['SPAMhaus']['prefname''filters_spam_spamhaus';
  714.     $filters['SPAMhaus']['name''SPAMhaus Lists';
  715.     $filters['SPAMhaus']['link''http://www.spamhaus.org';
  716.     $filters['SPAMhaus']['dns''sbl.spamhaus.org';
  717.     $filters['SPAMhaus']['result''127.0.0.6';
  718.     $filters['SPAMhaus']['comment'=
  719.         _("FREE - SPAMhaus - A list of well-known SPAM sources.");
  720.  
  721.     $filters['SPAMcop']['prefname''filters_spam_spamcop';
  722.     $filters['SPAMcop']['name''SPAM Cop Lists';
  723.     $filters['SPAMcop']['link''http://spamcop.net/bl.shtml';
  724.     $filters['SPAMcop']['dns''bl.spamcop.net';
  725.     $filters['SPAMcop']['result''127.0.0.2';
  726.     $filters['SPAMcop']['comment'=
  727.         _("FREE, for now - SpamCop - An interesting solution that lists servers that have a very high spam to legit email ratio (85 percent or more).");
  728.  
  729.     $filters['dev.null.dk']['prefname''filters_spam_devnull';
  730.     $filters['dev.null.dk']['name''dev.null.dk Lists';
  731.     $filters['dev.null.dk']['link''http://dev.null.dk/';
  732.     $filters['dev.null.dk']['dns''dev.null.dk';
  733.     $filters['dev.null.dk']['result''127.0.0.2';
  734.     $filters['dev.null.dk']['comment'=
  735.         _("FREE - dev.null.dk - I don't have any detailed info on this list.");
  736.  
  737.     $filters['visi.com']['prefname''filters_spam_visi';
  738.     $filters['visi.com']['name''visi.com Relay Stop List';
  739.     $filters['visi.com']['link''http://relays.visi.com';
  740.     $filters['visi.com']['dns''relays.visi.com';
  741.     $filters['visi.com']['result''127.0.0.2';
  742.     $filters['visi.com']['comment'=
  743.         _("FREE - visi.com - Relay Stop List. Very conservative OpenRelay List.");
  744.  
  745.     $filters['ahbl.org Open Relays']['prefname''filters_spam_2mb_or';
  746.     $filters['ahbl.org Open Relays']['name''ahbl.org Open Relays List';
  747.     $filters['ahbl.org Open Relays']['link''http://www.ahbl.org/';
  748.     $filters['ahbl.org Open Relays']['dns''dnsbl.ahbl.org';
  749.     $filters['ahbl.org Open Relays']['result''127.0.0.2';
  750.     $filters['ahbl.org Open Relays']['comment'=
  751.         _("FREE - ahbl.org Open Relays - Another list of Open Relays.");
  752.  
  753.     $filters['ahbl.org SPAM Source']['prefname''filters_spam_2mb_ss';
  754.     $filters['ahbl.org SPAM Source']['name''ahbl.org SPAM Source List';
  755.     $filters['ahbl.org SPAM Source']['link''http://www.ahbl.org/';
  756.     $filters['ahbl.org SPAM Source']['dns''dnsbl.ahbl.org';
  757.     $filters['ahbl.org SPAM Source']['result''127.0.0.4';
  758.     $filters['ahbl.org SPAM Source']['comment'=
  759.         _("FREE - ahbl.org SPAM Source - List of Direct SPAM Sources.");
  760.  
  761.     $filters['ahbl.org SPAM ISPs']['prefname''filters_spam_2mb_isp';
  762.     $filters['ahbl.org SPAM ISPs']['name''ahbl.org SPAM-friendly ISP List';
  763.     $filters['ahbl.org SPAM ISPs']['link''http://www.ahbl.org/';
  764.     $filters['ahbl.org SPAM ISPs']['dns''dnsbl.ahbl.org';
  765.     $filters['ahbl.org SPAM ISPs']['result''127.0.0.7';
  766.     $filters['ahbl.org SPAM ISPs']['comment'=
  767.         _("FREE - ahbl.org SPAM ISPs - List of SPAM-friendly ISPs.");
  768.  
  769.     $filters['Leadmon DUL']['prefname''filters_spam_lm_dul';
  770.     $filters['Leadmon DUL']['name''Leadmon.net DUL List';
  771.     $filters['Leadmon DUL']['link''http://www.leadmon.net/spamguard/';
  772.     $filters['Leadmon DUL']['dns''spamguard.leadmon.net';
  773.     $filters['Leadmon DUL']['result''127.0.0.2';
  774.     $filters['Leadmon DUL']['comment'=
  775.         _("FREE - Leadmon DUL - Another list of Dial-up or otherwise dynamically assigned IPs.");
  776.  
  777.     $filters['Leadmon SPAM Source']['prefname''filters_spam_lm_ss';
  778.     $filters['Leadmon SPAM Source']['name''Leadmon.net SPAM Source List';
  779.     $filters['Leadmon SPAM Source']['link''http://www.leadmon.net/spamguard/';
  780.     $filters['Leadmon SPAM Source']['dns''spamguard.leadmon.net';
  781.     $filters['Leadmon SPAM Source']['result''127.0.0.3';
  782.     $filters['Leadmon SPAM Source']['comment'=
  783.         _("FREE - Leadmon SPAM Source - List of IPs Leadmon.net has received SPAM directly from.");
  784.  
  785.     $filters['Leadmon Bulk Mailers']['prefname''filters_spam_lm_bm';
  786.     $filters['Leadmon Bulk Mailers']['name''Leadmon.net Bulk Mailers List';
  787.     $filters['Leadmon Bulk Mailers']['link''http://www.leadmon.net/spamguard/';
  788.     $filters['Leadmon Bulk Mailers']['dns''spamguard.leadmon.net';
  789.     $filters['Leadmon Bulk Mailers']['result''127.0.0.4';
  790.     $filters['Leadmon Bulk Mailers']['comment'=
  791.         _("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.");
  792.  
  793.     $filters['Leadmon Open Relays']['prefname''filters_spam_lm_or';
  794.     $filters['Leadmon Open Relays']['name''Leadmon.net Open Relays List';
  795.     $filters['Leadmon Open Relays']['link''http://www.leadmon.net/spamguard/';
  796.     $filters['Leadmon Open Relays']['dns''spamguard.leadmon.net';
  797.     $filters['Leadmon Open Relays']['result''127.0.0.5';
  798.     $filters['Leadmon Open Relays']['comment'=
  799.         _("FREE - Leadmon Open Relays - Single Stage Open Relays that are not listed on other active RBLs.");
  800.  
  801.     $filters['Leadmon Multi-stage']['prefname''filters_spam_lm_ms';
  802.     $filters['Leadmon Multi-stage']['name''Leadmon.net Multi-Stage Relay List';
  803.     $filters['Leadmon Multi-stage']['link''http://www.leadmon.net/spamguard/';
  804.     $filters['Leadmon Multi-stage']['dns''spamguard.leadmon.net';
  805.     $filters['Leadmon Multi-stage']['result''127.0.0.6';
  806.     $filters['Leadmon Multi-stage']['comment'=
  807.         _("FREE - Leadmon Multi-stage - Multi-Stage Open Relays that are not listed on other active RBLs and that have sent SPAM to Leadmon.net.");
  808.  
  809.     $filters['Leadmon SpamBlock']['prefname''filters_spam_lm_sb';
  810.     $filters['Leadmon SpamBlock']['name''Leadmon.net SpamBlock Sites List';
  811.     $filters['Leadmon SpamBlock']['link''http://www.leadmon.net/spamguard/';
  812.     $filters['Leadmon SpamBlock']['dns''spamguard.leadmon.net';
  813.     $filters['Leadmon SpamBlock']['result''127.0.0.7';
  814.     $filters['Leadmon SpamBlock']['comment'=
  815.         _("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.");
  816.  
  817.     $filters['NJABL Open Relays']['prefname''filters_spam_njabl_or';
  818.     $filters['NJABL Open Relays']['name''NJABL Open Relay/Direct Spam Source List';
  819.     $filters['NJABL Open Relays']['link''http://www.njabl.org/';
  820.     $filters['NJABL Open Relays']['dns''dnsbl.njabl.org';
  821.     $filters['NJABL Open Relays']['result''127.0.0.2';
  822.     $filters['NJABL Open Relays']['comment'=
  823.         _("FREE, for now - Not Just Another Blacklist - Both Open Relays and Direct SPAM Sources.");
  824.  
  825.     $filters['NJABL DUL']['prefname''filters_spam_njabl_dul';
  826.     $filters['NJABL DUL']['name''NJABL Dial-ups List';
  827.     $filters['NJABL DUL']['link''http://www.njabl.org/';
  828.     $filters['NJABL DUL']['dns''dnsbl.njabl.org';
  829.     $filters['NJABL DUL']['result''127.0.0.3';
  830.     $filters['NJABL DUL']['comment'=
  831.         _("FREE, for now - Not Just Another Blacklist - Dial-up IPs.");
  832.  
  833.     foreach ($filters as $Key => $Value{
  834.         $filters[$Key]['enabled'= (bool)getPref($data_dir$username$filters[$Key]['prefname']);
  835.     }
  836.  
  837.     return $filters;
  838. }
  839.  
  840. /**
  841.  * Removes a User filter
  842.  * @param int $id ID of the filter to remove
  843.  * @access private
  844.  */
  845. function remove_filter ($id{
  846.     global $data_dir$username;
  847.  
  848.     while ($nextFilter getPref($data_dir$username'filter' ($id 1))) {
  849.         setPref($data_dir$username'filter' $id$nextFilter);
  850.         $id ++;
  851.     }
  852.  
  853.     removePref($data_dir$username'filter' $id);
  854. }
  855.  
  856. /**
  857.  * Swaps two filters
  858.  * @param int $id1 ID of first filter to swap
  859.  * @param int $id2 ID of second filter to swap
  860.  * @access private
  861.  */
  862. function filter_swap($id1$id2{
  863.     global $data_dir$username;
  864.  
  865.     $FirstFilter getPref($data_dir$username'filter' $id1);
  866.     $SecondFilter getPref($data_dir$username'filter' $id2);
  867.  
  868.     if ($FirstFilter && $SecondFilter{
  869.         setPref($data_dir$username'filter' $id2$FirstFilter);
  870.         setPref($data_dir$username'filter' $id1$SecondFilter);
  871.     }
  872. }
  873.  
  874. /**
  875.  * This updates the filter rules when renaming or deleting folders
  876.  * @param array $args 
  877.  * @access private
  878.  */
  879. function update_for_folder ($args{
  880.     $old_folder $args[0];
  881.     $new_folder $args[2];
  882.     $action $args[1];
  883.     global $plugins$data_dir$username;
  884.     $filters array();
  885.     $filters load_filters();
  886.     $filter_count count($filters);
  887.     $p 0;
  888.     for ($i 0$i $filter_count$i++{
  889.         if (!empty($filters)) {
  890.             if ($old_folder == $filters[$i]['folder']{
  891.                 if ($action == 'rename'{
  892.                     $filters[$i]['folder'$new_folder;
  893.                     setPref($data_dir$username'filter'.$i,
  894.                     $filters[$i]['where'].','.$filters[$i]['what'].','.$new_folder);
  895.                 }
  896.                 elseif ($action == 'delete'{
  897.                     remove_filter($p);
  898.                     $p $p-1;
  899.                 }
  900.             }
  901.         $p++;
  902.         }
  903.     }
  904. }
  905.  
  906. /**
  907.  * Display formated error message
  908.  * @param string $string text message
  909.  * @return string html formated text message
  910.  * @access private
  911.  */
  912. function do_error($string{
  913.     global $color;
  914.     echo "<p align=\"center\"><font color=\"$color[2]\">";
  915.     echo $string;
  916.     echo "</font></p>\n";
  917. }

Documentation generated on Mon, 13 Jan 2020 04:24:37 +0100 by phpDocumentor 1.4.3