Call me anal
[squirrelmail.git] / plugins / filters / filters.php
index 09df3f7fbc210ad9c50556e85cccb3781f6b3ad8..dc53c9abfb0d534ecb9c89c49fa73632233df4e0 100644 (file)
@@ -3,7 +3,7 @@
 /**
  * Message and Spam Filter Plugin - Filtering Functions
  *
- * @copyright © 1999-2006 The SquirrelMail Project Team
+ * @copyright © 1999-2007 The SquirrelMail Project Team
  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @package plugins
@@ -13,8 +13,7 @@
 /**
  * do not allow to call this file directly
  */
-if ((isset($_SERVER['SCRIPT_FILENAME']) && $_SERVER['SCRIPT_FILENAME'] == __FILE__) ||
-     (isset($HTTP_SERVER_SERVER['SCRIPT_FILENAME']) && $HTTP_SERVER_SERVER['SCRIPT_FILENAME'] == __FILE__) ) {
+if (isset($_SERVER['SCRIPT_FILENAME']) && $_SERVER['SCRIPT_FILENAME'] == __FILE__) {
     header("Location: ../../src/login.php");
     die();
 }
@@ -26,7 +25,7 @@ global $UseSeparateImapConnection,
     $SpamFilters_CacheTTL;
 
 /**
- * load required functions. Plugin depends on IMAP functions and they are not 
+ * load required functions. Plugin depends on IMAP functions and they are not
  * loaded in src/webmail.php
  */
 include_once (SM_PATH . 'functions/imap.php');
@@ -192,10 +191,8 @@ function filters_bulkquery($filters, $IPs) {
  */
 function start_filters($hook_args) {
     global $imapServerAddress, $imapPort, $imap_stream, $imapConnection,
-           $UseSeparateImapConnection, $AllowSpamFilters, $filter_inbox_count;
-
-    sqgetGlobalVar('username', $username, SQ_SESSION);
-    sqgetGlobalVar('key',      $key,      SQ_COOKIE);
+           $UseSeparateImapConnection, $AllowSpamFilters, $filter_inbox_count,
+           $username;
 
     /**
      * check hook that calls filtering. If filters are called by right_main_after_header,
@@ -213,8 +210,8 @@ function start_filters($hook_args) {
         $spamfilters = load_spam_filters();
 
         $AllowSpamFilters = false;
-        foreach($spamfilters as $filterskey=>$value) {
-            if ($value['enabled'] == 'yes') {
+        foreach($spamfilters as $value) {
+            if ($value['enabled'] == SMPREF_ON) {
                 $AllowSpamFilters = true;
                 break;
             }
@@ -230,7 +227,7 @@ function start_filters($hook_args) {
     // Also check if we are forced to use a separate IMAP connection
     if ((!isset($imap_stream) && !isset($imapConnection)) ||
         $UseSeparateImapConnection ) {
-            $stream = sqimap_login($username, $key, $imapServerAddress,
+            $stream = sqimap_login($username, false, $imapServerAddress,
                                 $imapPort, 10);
             $previously_connected = false;
     } else if (isset($imapConnection)) {
@@ -384,7 +381,7 @@ function filter_search_and_delete($imap_stream, $where, $what, $where_to, $user_
         $ids = array();
         for ($i = 0, $iCnt = count($read); $i < $iCnt; ++$i) {
             if (preg_match("/^\* SEARCH (.+)$/", $read[$i], $regs)) {
-                $ids += preg_split("/ /", trim($regs[1]));
+                $ids += explode(' ', trim($regs[1]));
             }
         }
         if ($response == 'OK' && count($ids)) {
@@ -432,7 +429,7 @@ function spam_filters($imap_stream) {
 
     $run = false;
 
-    foreach ($filters as $Key => $Value) {
+    foreach ($filters as $Value) {
         if ($Value['enabled']) {
             $run = true;
             break;
@@ -453,7 +450,7 @@ function spam_filters($imap_stream) {
         if (isset($read[0])) {
             for ($i = 0, $iCnt = count($read); $i < $iCnt; ++$i) {
                 if (preg_match("/^\* SEARCH (.+)$/", $read[$i], $regs)) {
-                    $search_array = preg_split("/ /", trim($regs[1]));
+                    $search_array = explode(' ', trim($regs[1]));
                 break;
                 }
             }
@@ -550,8 +547,12 @@ function filters_spam_check_site($a, $b, $c, $d, &$filters) {
     foreach ($filters as $key => $value) {
         if ($filters[$key]['enabled']) {
             if ($filters[$key]['dns']) {
+                /**
+                 * RFC allows . on end of hostname to force domain lookup
+                 * to not use search domain from resolv.conf
+                 */
                 $filter_revip = $d . '.' . $c . '.' . $b . '.' . $a . '.' .
-                                $filters[$key]['dns'];
+                                $filters[$key]['dns'] . '.';
 
                 if(!isset($SpamFilters_DNScache[$filter_revip]['L']))
                         $SpamFilters_DNScache[$filter_revip]['L'] = '';
@@ -565,8 +566,12 @@ function filters_spam_check_site($a, $b, $c, $d, &$filters) {
                     $SpamFilters_DNScache[$filter_revip]['T'] =
                                        time() + $SpamFilters_CacheTTL;
                 }
-                if ($SpamFilters_DNScache[$filter_revip]['L'] ==
-                    $filters[$key]['result']) {
+
+                /**
+                 * gethostbyname returns ip if resolved, or returns original
+                 * host query if no resolution
+                 */
+                if ($SpamFilters_DNScache[$filter_revip]['L'] != $filter_revip) {
                     return 1;
                 }
             }
@@ -651,14 +656,6 @@ function load_spam_filters() {
             _("COMMERCIAL - RBL+ Dial-up entries.");
     }
 
-    $filters['ORDB']['prefname'] = 'filters_spam_ordb';
-    $filters['ORDB']['name'] = 'Open Relay Database List';
-    $filters['ORDB']['link'] = 'http://www.ordb.org/';
-    $filters['ORDB']['dns'] = 'relays.ordb.org';
-    $filters['ORDB']['result'] = '127.0.0.2';
-    $filters['ORDB']['comment'] =
-        _("FREE - ORDB was born when ORBS went off the air. It seems to have fewer false positives than ORBS did though.");
-
     $filters['FiveTen Direct']['prefname'] = 'filters_spam_fiveten_src';
     $filters['FiveTen Direct']['name'] = 'Five-Ten-sg.com Direct SPAM Sources';
     $filters['FiveTen Direct']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
@@ -727,7 +724,7 @@ function load_spam_filters() {
     $filters['SPAMhaus']['name'] = 'SPAMhaus Lists';
     $filters['SPAMhaus']['link'] = 'http://www.spamhaus.org';
     $filters['SPAMhaus']['dns'] = 'sbl.spamhaus.org';
-    $filters['SPAMhaus']['result'] = '127.0.0.6';
+    $filters['SPAMhaus']['result'] = '127.0.0.2';
     $filters['SPAMhaus']['comment'] =
         _("FREE - SPAMhaus - A list of well-known SPAM sources.");
 
@@ -868,7 +865,7 @@ function load_spam_filters() {
         _("FREE - Distributed Sender Boycott List - UN-Confirmed Relays");
 
     foreach ($filters as $Key => $Value) {
-        $filters[$Key]['enabled'] = getPref($data_dir, $username, $filters[$Key]['prefname']);
+        $filters[$Key]['enabled'] = (bool)getPref($data_dir, $username, $filters[$Key]['prefname']);
     }
 
     return $filters;