Make the filters plugin more efficient and remove two E_ALL warnings
authorkink <kink@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Fri, 18 Oct 2002 14:31:42 +0000 (14:31 +0000)
committerkink <kink@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Fri, 18 Oct 2002 14:31:42 +0000 (14:31 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@3915 7612ce4b-ef26-0410-bec9-ea0150e637f0

plugins/filters/filters.php
plugins/filters/options.php
plugins/filters/setup.php
plugins/filters/spamoptions.php

index 54a00f3deaaa9c033b0d49c33c68f876caa607ac..4cbf7b414802d21003887f03347742dfb3244ac7 100644 (file)
 function filters_SaveCache () {
     global $data_dir, $SpamFilters_DNScache;
 
-    if (file_exists($data_dir . "/dnscache")) {
-        $fp = fopen($data_dir . "/dnscache", "r");
+    if (file_exists($data_dir . '/dnscache')) {
+        $fp = fopen($data_dir . '/dnscache', 'r');
     } else {
         $fp = false;
     }
     if ($fp) {
         flock($fp,LOCK_EX);
     } else {
-       $fp = fopen($data_dir . "/dnscache", "w+");
+       $fp = fopen($data_dir . '/dnscache', 'w+');
        fclose($fp);
-       $fp = fopen($data_dir . "/dnscache", "r");
+       $fp = fopen($data_dir . '/dnscache', 'r');
        flock($fp,LOCK_EX);
     }
-    $fp1=fopen($data_dir . "/dnscache", "w+");
+    $fp1=fopen($data_dir . '/dnscache', 'w+');
 
     foreach ($SpamFilters_DNScache as $Key=> $Value) {
        $tstr = $Key . ',' . $Value['L'] . ',' . $Value['T'] . "\n";
@@ -55,9 +55,9 @@ function filters_SaveCache () {
 function filters_LoadCache () {
     global $data_dir, $SpamFilters_DNScache;
 
-    if (file_exists($data_dir . "/dnscache")) {
+    if (file_exists($data_dir . '/dnscache')) {
         $SpamFilters_DNScache = array();
-        if ($fp = fopen ($data_dir . "/dnscache", "r")) {
+        if ($fp = fopen ($data_dir . '/dnscache', 'r')) {
             flock($fp,LOCK_SH);
             while ($data=fgetcsv($fp,1024)) {
                if ($data[2] > time()) {
@@ -139,11 +139,11 @@ function filters_bulkquery($filters_spam_scan, $filters, $read) {
             }
         }
 
-        $bqfil = $attachment_dir . $username . "-bq.in";
-        $fp = fopen($bqfil, "w");
+        $bqfil = $attachment_dir . $username . '-bq.in';
+        $fp = fopen($bqfil, 'w');
         fputs ($fp, $SpamFilters_CacheTTL . "\n");
         foreach ($rbls as $key => $value) {
-            fputs ($fp, "." . $key . "\n");
+            fputs ($fp, '.' . $key . "\n");
         }
         fputs ($fp, "----------\n");
         foreach ($IPs as $key => $value) {
@@ -151,7 +151,7 @@ function filters_bulkquery($filters_spam_scan, $filters, $read) {
         }
         fclose ($fp);
         $bqout = array();
-        exec ($SpamFilters_BulkQuery . " < " . $bqfil, $bqout);
+        exec ($SpamFilters_BulkQuery . ' < ' . $bqfil, $bqout);
         foreach ($bqout as $value) {
             $Chunks = explode(',', $value);
             $SpamFilters_DNScache[$Chunks[0]]['L'] = $Chunks[1];
@@ -210,7 +210,7 @@ function user_filters($imap_stream) {
     sqimap_mailbox_select($imap_stream, 'INBOX');
     $id = array();
     // For every rule
-    for ($i=0; $i < count($filters); $i++) {
+    for ($i=0, $num = count($filters); $i < $num; $i++) {
         // If it is the "combo" rule
         if ($filters[$i]['where'] == 'To or Cc') {
             /*
@@ -256,7 +256,7 @@ function filter_search_and_delete($imap, $where, $what, $where_to, $user_scan,
     } else {
         $search_str = 'SEARCH CHARSET US-ASCII ' . $category;
     }
-    if ($where == "Header") {
+    if ($where == 'Header') {
         $what  = explode(':', $what);
         $where = trim($where . ' ' . $what[0]);
         $what  = addslashes(trim($what[1]));
@@ -274,12 +274,12 @@ function filter_search_and_delete($imap, $where, $what, $where_to, $user_scan,
 
     // This may have problems with EIMS due to it being goofy
 
-    for ($r=0; $r < count($read) &&
+    for ($r=0, $num = count($read); $r < $num &&
                 substr($read[$r], 0, 8) != '* SEARCH'; $r++) {}
     if ($response == 'OK') {
         $ids = explode(' ', $read[$r]);
         if (sqimap_mailbox_exists($imap, $where_to)) {
-            for ($j=2; $j < count($ids); $j++) {
+            for ($j=2, $num = count($ids); $j < $num; $j++) {
                 $id = trim($ids[$j]);
                 $del_id[] = $id;
                 sqimap_messages_copy ($imap, $id, $id, $where_to);
@@ -435,6 +435,13 @@ function filters_spam_check_site($a, $b, $c, $d, &$filters) {
             if ($filters[$key]['dns']) {
                 $filter_revip = $d . '.' . $c . '.' . $b . '.' . $a . '.' .
                                 $filters[$key]['dns'];
+
+                if(!isset($SpamFilters_DNScache[$filter_revip]['L']))
+                        $SpamFilters_DNScache[$filter_revip]['L'] = '';
+
+                if(!isset($SpamFilters_DNScache[$filter_revip]['T']))
+                        $SpamFilters_DNScache[$filter_revip]['T'] = '';
+
                 if (strlen($SpamFilters_DNScache[$filter_revip]['L']) == 0) {
                     $SpamFilters_DNScache[$filter_revip]['L'] =
                                     gethostbyname($filter_revip);
index f402a1f1eeae142bf9564ebabe78e2d677c82359..b5e0bd59f55e90fc4499e1c6578d6532cb54fdcc 100644 (file)
@@ -65,19 +65,19 @@ require_once(SM_PATH . 'plugins/filters/filters.php');
       $filter_where  = $_POST['filter_where'];
       $filter_folder = $_POST['filter_folder'];
 
-      $filter_what = ereg_replace(",", " ", $filter_what);
+      $filter_what = str_replace(',', ' ', $filter_what);
       $filter_what = str_replace("\\\\", "\\", $filter_what);
-      $filter_what = str_replace("\\\"", "\"", $filter_what);
-      $filter_what = str_replace("\"", "&quot;", $filter_what);
+      $filter_what = str_replace("\\\"", '"', $filter_what);
+      $filter_what = str_replace('"', '&quot;', $filter_what);
 
       if (($filter_where == 'Header') && (strchr($filter_what,':') == '')) {
          print ('WARNING! Header filters should be of the format "Header: value"<BR>');
         $action = 'edit';
       }
-      setPref($data_dir, $username, "filter".$theid, $filter_where.",".$filter_what.",".$filter_folder);
-      $filters[$theid]["where"] = $filter_where;
-      $filters[$theid]["what"] = $filter_what;
-      $filters[$theid]["folder"] = $filter_folder;
+      setPref($data_dir, $username, 'filter'.$theid, $filter_where.','.$filter_what.','.$filter_folder);
+      $filters[$theid]['where'] = $filter_where;
+      $filters[$theid]['what'] = $filter_what;
+      $filters[$theid]['folder'] = $filter_folder;
    } elseif (isset($action) && $action == 'delete') {
       remove_filter($theid);
    } elseif (isset($action) && $action == 'move_up') {
@@ -185,7 +185,7 @@ require_once(SM_PATH . 'plugins/filters/filters.php');
                     '<tt>'.
                     '<select name=filter_folder>';
 
-        for ($i = 0; $i < count($boxes); $i++) {
+        for ($i = 0, $num = count($boxes); $i < $num; $i++) {
             if (! in_array('noselect', $boxes[$i]['flags'])) {
                 $box = $boxes[$i]['unformatted'];
                 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['formatted']);
@@ -210,7 +210,7 @@ require_once(SM_PATH . 'plugins/filters/filters.php');
 
        echo html_tag( 'table', '', 'center', '', 'border="0" cellpadding="3" cellspacing="0"' );
 
-    for ($i=0; $i < count($filters); $i++) {
+    for ($i=0, $num = count($filters); $i < $num; $i++) {
 
         $clr = (($i % 2)?$color[0]:$color[9]);
         $fdr = ($folder_prefix)?str_replace($folder_prefix, "", $filters[$i]["folder"]):$filters[$i]["folder"];
index b93ac70414ebdcd2946a62a29d22a1ba76089434..6f1eca8b5d823d78ad5cfecee5283116eba29ad6 100644 (file)
@@ -85,7 +85,7 @@ global $SpamFilters_DNScache;
  * in the bulkquery directory for more information on using bulkquery.
  */
 global $SpamFilters_BulkQuery;
-$SpamFilters_BulkQuery = "";
+$SpamFilters_BulkQuery = '';
 
 /*
  * Do you want to use a shared file for the DNS cache or a session variable?
index 2cc694b44a36175c600c71532d1bbeb29f199cbf..e4769cae0751f9059d801027ccdc727a0f15ee9e 100644 (file)
@@ -86,7 +86,9 @@ if (isset($action) && $action == 'spam') {
     $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
     $boxes = sqimap_mailbox_list($imapConnection);
     sqimap_logout($imapConnection);
-    for ($i = 0; $i < count($boxes) && $filters_spam_folder == ''; $i++) {
+    $numboxes = count($boxes);
+
+    for ($i = 0; $i < $numboxes && $filters_spam_folder == ''; $i++) {
         if ((isset($boxes[$i]['flags'][0]) && $boxes[$i]['flags'][0] != 'noselect') &&
             (isset($boxes[$i]['flags'][1]) && $boxes[$i]['flags'][1] != 'noselect') &&
             (isset($boxes[$i]['flags'][2]) && $boxes[$i]['flags'][2] != 'noselect')) {
@@ -102,7 +104,7 @@ if (isset($action) && $action == 'spam') {
                 html_tag( 'td', '', 'left' ) .
                     '<select name="filters_spam_folder_set">';
 
-    for ($i = 0; $i < count($boxes); $i++) {
+    for ($i = 0; $i < $numboxes; $i++) {
         if (! in_array('noselect', $boxes[$i]['flags'])) {
             $box = $boxes[$i]['unformatted'];
             $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['formatted']);