writing the procmail rcfile
authorPierre Habouzit <madcoder@debian.org>
Mon, 13 Oct 2003 09:22:35 +0000 (09:22 +0000)
committerPierre Habouzit <madcoder@debian.org>
Mon, 13 Oct 2003 09:22:35 +0000 (09:22 +0000)
philter/philter/include/philter.inc.php
philter/philter/include/rule.inc.php
philter/philter/index.php
philter/philter/install.d/header.inc.php

index 3b89bff..4d3c4f9 100644 (file)
@@ -83,10 +83,16 @@ class Philter {
     }
 
     /** function that writes the procmailrc.
+     * @param   &$procmail  the string containing the procmail filter
+     * @param   $filename   the base filename of the procmailrc filter
      * @return  true if all is ok
      */
-    function write_procmailrc() {
-        // TODO
+    function write_procmailrc(&$procmail, $filename) {
+        $file = $philter->config['path']['spool']."/".$filename;
+        $f = fopen($file.".tmp", "w");
+        fwrite($f, $procmail, strlen($procmail));
+        fclose($f);
+        rename($file.".tmp", $file);
         return true;
     }
 
index 6bb70f4..5f1736d 100644 (file)
@@ -91,10 +91,10 @@ class Rule {
         
         $res = ($this->block ? ":0\n" : ":0 c\n");
         foreach($this->matches as $match)
-            $res .= $philter->['config']['match_plugins'][$match[0]]->to_string($match);
+            $res .= $philter->config['match_plugins'][$match[0]]->to_string($match);
         $res.= "{\n";
         foreach($this->actions as $action)
-            $res .= $philter->['config']['actioh_plugins'][$action[0]]->to_string($action);
+            $res .= $philter->config['actioh_plugins'][$action[0]]->to_string($action);
         $res.= "}\n\n";
 
         return $res;
index 8c0cf61..b99f3a9 100644 (file)
@@ -42,6 +42,7 @@ if(isset($_POST['set_adv']) && !$philter->is_advanced()) {
 if(isset($_POST['filter_valid']) && $philter->is_advanced()) {
     $philter->del_advanced();
     to_main(get_user_id());
+    $PHILTER_HAS_TO_BE_WRITTEN=true;
 }
 
 if(isset($_POST['filter_cancel']) && $philter->is_advanced()) {
@@ -52,6 +53,11 @@ if(isset($_POST['filter_cancel']) && $philter->is_advanced()) {
 $mail_pool = new EmailPool(get_user_id());
 $filter = new Filter(get_user_id());
 
+if(isset($PHILTER_HAS_TO_BE_WRITTEN) && $PHILTER_HAS_TO_BE_WRITTEN) {
+    unset($PHILTER_HAS_TO_BE_WRITTEN);
+    $philter->write_procmailrc($filter->to_string(), get_filename());
+}
+
 if($philter->is_advanced())
     require("include/form_filter.inc.php");
 else
index b810861..352ac56 100644 (file)
@@ -16,6 +16,8 @@ function is_auth() {
     return false;
 }
 
+function get_filename() { return get_user_id(); };
+
 session_start();
 
 ?>