to_string basis
authorPierre Habouzit <madcoder@debian.org>
Tue, 21 Oct 2003 20:06:29 +0000 (20:06 +0000)
committerPierre Habouzit <madcoder@debian.org>
Tue, 21 Oct 2003 20:06:29 +0000 (20:06 +0000)
philter/philter/include/filter.inc.php
philter/philter/include/plugin_custheader.inc.php
philter/philter/include/plugin_forward.inc.php
philter/philter/include/plugin_header.inc.php
philter/philter/include/rule.inc.php

index 4e362f4..b46a255 100644 (file)
@@ -48,7 +48,15 @@ class Filter {
     }
     
     function to_string() {
-        return "";
+        $res = ":0 f\n"
+            .  "|formail -I'X-Philter-Or'\n"
+            .  "\n";
+
+        foreach($this->rules as $id=>$rule)
+            if($id)
+                $res .= $rule->to_string();
+
+        return $res;
     }
 
     function delete_rule($_rid) {
index ca179ba..014be81 100644 (file)
@@ -34,10 +34,6 @@ class CustHdrPlugin extends MatchPlugin {
     op_s.options[1] = new Option('"._i18n('3_not_contains')."',1,false,data[2]==1);
     op_s.options[2] = new Option(' = ',2,false,data[2]==2);
     op_s.options[3] = new Option(' != ',3,false,data[2]==3);
-    op_s.options[4] = new Option(' >= ',4,false,data[2]==4);
-    op_s.options[5] = new Option(' > ',5,false,data[2]==5);
-    op_s.options[6] = new Option(' <= ',6,false,data[2]==6);
-    op_s.options[7] = new Option(' < ',7,false,data[2]==7);
     op_s.selectIndex = data[2];
 
     Node.appendChild(document.createTextNode(' '));
@@ -48,6 +44,17 @@ class CustHdrPlugin extends MatchPlugin {
     Node.appendChild(txt_i);
 }";
     }
+    
+    function to_string($_data) {
+        $res = trim($_data[1]).':';
+        switch($_data[2]) {
+            case 0: $res = "* ^$res.*{$_data[3]}\n";   break;
+            case 1: $res = "* !$res.*{$_data[3]}\n";   break;
+            case 2: $res = "* $res {$_data[3]}$\n";    break;
+            case 3: $res = "* !$res {$_data[3]}$\n";   break;
+        }
+        return $res;
+    }
 }
 
 /********************************************************************************
index fb1d0d4..fc3ac95 100644 (file)
@@ -36,7 +36,8 @@ EOF;
 
     function to_string($_data) {
         global $mail_pool;
-        return "! ".$mail_pool->emails[$_data[1]]->email."\n";
+        return "    :0 c\n"
+            .  "    ! ".$mail_pool->emails[$_data[1]]->email."\n\n";
     }
 }
 
index e4294e1..5112b9e 100644 (file)
@@ -47,10 +47,6 @@ function(Node, data) {
     op_s.options[1] = new Option('$_2_not_contains',1,false,data[2]==1);
     op_s.options[2] = new Option(' = ',2,false,data[2]==2);
     op_s.options[3] = new Option(' != ',3,false,data[2]==3);
-    op_s.options[4] = new Option(' >= ',4,false,data[2]==4);
-    op_s.options[5] = new Option(' > ',5,false,data[2]==5);
-    op_s.options[6] = new Option(' <= ',6,false,data[2]==6);
-    op_s.options[7] = new Option(' < ',7,false,data[2]==7);
     op_s.selectIndex = data[2];
 
     Node.appendChild(document.createTextNode(' '));
@@ -62,6 +58,27 @@ function(Node, data) {
 }
 EOF;
     }
+    
+    function to_string($_data) {
+        switch($_data[1]) {
+            case 0: $res = '^TO';                 break;
+            case 1: $res = '^Subject:';           break;
+            case 2: $res = '^From:';              break;
+            case 3: $res = '^To:';                break;
+            case 4: $res = '^Cc:';                break;
+            case 5: $res = '^Reply-To:';          break;
+            case 6: $res = '^Organization:';      break;
+            case 7: $res = '^List-Id:';           break;
+            case 8: $res = '^X-Mailing-List:';    break;
+        }
+        switch($_data[2]) {
+            case 0: $res = "* $res.*{$_data[3]}\n";    break;
+            case 1: $res = "* !$res.*{$_data[3]}\n";   break;
+            case 2: $res = "* $res {$_data[3]}$\n";    break;
+            case 3: $res = "* !$res {$_data[3]}$\n";   break;
+        }
+        return $res;
+    }
 }
 
 /********************************************************************************
index 5f1736d..dbb7b26 100644 (file)
@@ -89,13 +89,34 @@ class Rule {
     function to_string() {
         global $philter;
         
-        $res = ($this->block ? ":0\n" : ":0 c\n");
-        foreach($this->matches as $match)
-            $res .= $philter->config['match_plugins'][$match[0]]->to_string($match);
+        $res = $this->block  ? ":0\n" : ":0 c\n";
+
+        if($this->all) {
+            foreach($this->matches as $match)
+                $res .= $philter->config['match_plugins'][$match[0]]->to_string($match);
+        } else {
+            $i = 0; $res = '';
+            foreach($this->matches as $match) {
+                $res .= (empty($i) ? ":0 f\n" : ":0 fE");
+                $res .= $philter->config['match_plugins'][$match[0]]->to_string($match);
+                $res .= "| formail -I'X-Philter-Or: yes'\n";
+                $i++;
+            }
+
+            $res.= "\n"
+                .  ":0 f\n"
+                .  "* ^X-Philter-Or: yes\n"
+                .  "| formail -I'X-Philter-Or'\n"
+                .  "\n"
+                .  ($this->block ? ":0\n" : ":0 c\n");
+        }
+        
         $res.= "{\n";
         foreach($this->actions as $action)
-            $res .= $philter->config['actioh_plugins'][$action[0]]->to_string($action);
-        $res.= "}\n\n";
+            $res .= $philter->config['action_plugins'][$action[0]]->to_string($action);
+        $res.= "    :0\n"
+            .  "    /dev/null\n"
+            .  "}\n\n";
 
         return $res;
     }