Code

Udpated tree class
[gosa.git] / include / sieve / class_sieveManagement.inc
index dca53556f94dfa001ca95b5163e617976b77ab15..dff33d0fe73af84007ef550afc1acd4feb39caf9 100644 (file)
@@ -37,6 +37,7 @@ class sieveManagement extends plugin
   var $script_to_delete =-1;
   var $sieve_handle = NULL; 
   var $Script_Error = "";
+  var $Sieve_Error = "";
   var $create_script = FALSE;
 
   /* To add new elements we need to know 
@@ -49,6 +50,10 @@ class sieveManagement extends plugin
   var $add_above_below    = "below";
   var $add_element_type   = "sieve_comment";
 
+  /* If this variable is TRUE, this indicates that we have the 
+   *  import dialog opened. 
+   */
+  var $Import_Script = FALSE;
 
   /* Initialize the class and load all sieve scripts 
    *  try to parse them and display errors 
@@ -58,25 +63,20 @@ class sieveManagement extends plugin
     $this->parent = $parent;
     plugin::plugin($config,$dn);
 
-
-    /* Connect to sieve class and try to get all available sieve scripts */
-    $cfg=  $this->config->data['SERVERS']['IMAP'][$this->parent->gosaMailServer];
-    
-    /* Log into the mail server */
-    $sieve= new sieve($cfg["sieve_server"], $cfg["sieve_port"], $this->parent->uid,
-        $cfg["password"], $cfg["admin"]);
-
-    /* Try to login */
-    if (!$sieve->sieve_login()){
-      print_red(sprintf(_("Can't log into SIEVE server. Server says '%s'."),
-            to_string($sieve->error_raw)));
+    /* Get sieve */
+    if(!$this->sieve_handle = $this->get_sieve()){
+      print_red(
+        sprintf(
+          _("Can't log into SIEVE server. Server says '%s'."),
+          to_string($this->Sieve_Error)));
       return;
     }
 
+
     /* Get all sieve scripts names */
-    if($sieve->sieve_listscripts()){
-      if (is_array($sieve->response)){
-        foreach($sieve->response as $key => $name){
+    if($this->sieve_handle->sieve_listscripts()){
+      if (is_array($this->sieve_handle->response)){
+        foreach($this->sieve_handle->response as $key => $name){
 
           $data = array();
           $data['NAME'] = $name;
@@ -93,11 +93,11 @@ class sieveManagement extends plugin
 
     /* Get script contents */
     foreach($this->scripts as $key => $script){
-      $p = new My_Parser;
-      $sieve->sieve_getscript($script['NAME']);
+      $p = new My_Parser($this);
+      $this->sieve_handle->sieve_getscript($script['NAME']);
 
       $script = "";
-      foreach($sieve->response as $line){
+      foreach($this->sieve_handle->response as $line){
         $script.=$line;
       }
 
@@ -108,7 +108,7 @@ class sieveManagement extends plugin
       $ret = $p->parse($script);
       if(!$ret){
         $this->scripts[$key]['STATUS']   = FALSE;
-        $this->scripts[$key]['MODE']    = "Source-Only";
+        $this->scripts[$key]['MODE']    = "Source";
         $this->scripts[$key]['MSG'] = _("Parse failed")."<font color='red'>".$p->status_text."</font>";
       }else{
         $this->scripts[$key]['STATUS']   = TRUE;
@@ -118,7 +118,33 @@ class sieveManagement extends plugin
       $this->scripts[$key]['PARSER'] = $p;
       $this->scripts[$key]['EDITED'] = FALSE;
     }
-    $this->sieve_handle = $sieve;
+    $this->sieve_handle = $this->sieve_handle;
+  }
+
+
+  /* Return a sieve class hanlde,
+   *  false if login fails
+   */
+  function get_sieve()
+  {
+    /* Connect to sieve class and try to get all available sieve scripts */
+    $cfg=  $this->config->data['SERVERS']['IMAP'][$this->parent->gosaMailServer];
+    $this->Sieve_Error = "";
+  
+    /* Log into the mail server */
+    $this->sieve_handle= new sieve(
+        $cfg["sieve_server"], 
+        $cfg["sieve_port"], 
+        $this->parent->uid, 
+        $cfg["password"], 
+        $cfg["admin"]);
+
+    /* Try to login */
+    if (!$this->sieve_handle->sieve_login()){
+      $this->Sieve_Error = $this->sieve_handle->error_raw;
+      return(FALSE);
+    }
+    return($this->sieve_handle);
   }
 
 
@@ -170,6 +196,11 @@ class sieveManagement extends plugin
         if(preg_match("/[^a-z]/i",$name)){
           $err = _("Only a-z are allowed in script names.");
         }
+
+        $tmp = $this->get_used_script_names();
+        if(in_array_ics($name,$tmp)){
+          $err =_("The specified name is already in use.");
+        }
       }
 
       /* Create script if everything is ok */
@@ -183,7 +214,7 @@ class sieveManagement extends plugin
                   "stop;";
 
         /* Create a new parser and initialize default values */
-        $p = new My_Parser;
+        $p = new My_Parser($this);
         $ret = $p->parse($script);
         $sc['SCRIPT'] = $script;
         $sc['ORIG_SCRIPT'] = $script;
@@ -191,11 +222,11 @@ class sieveManagement extends plugin
         $sc['MSG']   = "";
         if(!$ret){
           $sc['STATUS']   = FALSE;
-          $sc['MODE']    = "Source-Only";
+          $sc['MODE']    = "Source";
           $sc['MSG'] = _("Parse failed")."<font color='red'>".$p->status_text."</font>";
         }else{
           $sc['STATUS']   = TRUE;
-          $sc['MODE']    = "Strucktured";
+          $sc['MODE']    = "Structured";
           $sc['MSG'] = _("Parse successful");
         }
         $sc['PARSER'] = $p;
@@ -231,6 +262,7 @@ class sieveManagement extends plugin
 
         $this->current_script = $script;
         $this->current_handler = $this->scripts[$script]['PARSER'];
+        $this->scripts[$script]['SCRIPT_BACKUP'] = $this->scripts[$script]['SCRIPT'];
       }
 
       /* remove script requested */
@@ -247,32 +279,30 @@ class sieveManagement extends plugin
         $script = preg_replace("/^active_script_/","",$name);
         $script = preg_replace("/_(x|y)/","",$script);
         $once = FALSE;
-        /* Connect to sieve class and try to get all available sieve scripts */
-        $cfg=  $this->config->data['SERVERS']['IMAP'][$this->parent->gosaMailServer];
-        $this->sieve_handle=
-          new sieve(  $cfg["sieve_server"],
-              $cfg["sieve_port"],
-              $this->parent->mail,
-              $cfg["password"],
-              $cfg["admin"]);
-
-        if (!$this->sieve_handle->sieve_login()){
-          print_red(sprintf(_("Can't log into SIEVE server. Server says '%s'."),to_string($this->sieve_handle->error_raw)));
-          return;
-        }
 
-        /* Try to activate the given script and update 
-         *  class script array. 
-         */
-        if(!$this->sieve_handle->sieve_setactivescript($this->scripts[$script]['NAME'])){
-          print_red(sprintf(_("Can't activate sieve script on server. Server says '%s'."),to_string($this->sieve_handle->error_raw)));
-        }else{
-          foreach($this->scripts as $key => $data){
-            if($key == $script){
-              $this->scripts[$key]['ACTIVE'] = TRUE;
-            }else{
-              $this->scripts[$key]['ACTIVE'] = FALSE;
+        /* We can only activate existing scripts */
+        if(!$this->scripts[$script]['IS_NEW']){
+
+          /* Get sieve */
+          if(!$this->sieve_handle = $this->get_sieve()){
+            print_red(
+                sprintf(
+                  _("Can't log into SIEVE server. Server says '%s'."),
+                  to_string($this->Sieve_Error)));
+          }
+
+          /* Try to activate the given script and update 
+           *  class script array. 
+           */
+          if(!$this->sieve_handle->sieve_setactivescript($this->scripts[$script]['NAME'])){
+            print_red(sprintf(_("Can't activate sieve script on server. Server says '%s'."),to_string($this->sieve_handle->error_raw)));
+          }else{
+            foreach($this->scripts as $key => $data){
+              if($key == $script){
+                $this->scripts[$key]['ACTIVE'] = TRUE;
+              }else{
+                $this->scripts[$key]['ACTIVE'] = FALSE;
+              }
             }
           }
         }
@@ -299,17 +329,12 @@ class sieveManagement extends plugin
         unset($this->scripts[$this->script_to_delete]);
       }else{
 
-        /* Connect to sieve class and try to get all available sieve scripts */
-        $cfg=  $this->config->data['SERVERS']['IMAP'][$this->parent->gosaMailServer];
-        $this->sieve_handle=
-          new sieve(  $cfg["sieve_server"],
-              $cfg["sieve_port"],
-              $this->parent->mail,
-              $cfg["password"],
-              $cfg["admin"]);
-        if (!$this->sieve_handle->sieve_login()){
-          print_red(sprintf(_("Can't log into SIEVE server. Server says '%s'."),to_string($this->sieve_handle->error_raw)));
-          return;
+        /* Get sieve */
+        if(!$this->sieve_handle = $this->get_sieve()){
+          print_red(
+              sprintf(
+                _("Can't log into SIEVE server. Server says '%s'."),
+                to_string($this->Sieve_Error)));
         }
 
         if(!$this->sieve_handle->sieve_deletescript($this->scripts[$this->script_to_delete]['NAME'])){
@@ -337,6 +362,9 @@ class sieveManagement extends plugin
 
     /* Abort saving */
     if(isset($_POST['cancel_sieve_changes'])){
+      $tmp = $this->scripts[$this->current_script]['SCRIPT_BACKUP'];
+      $this->scripts[$this->current_script]['SCRIPT'] = $tmp;
+      $this->scripts[$this->current_script]['PARSER']->parse($tmp);
       $this->current_handler = NULL;
     }
 
@@ -346,7 +374,7 @@ class sieveManagement extends plugin
       if(!count($chk)){
 
         $sc = $this->scripts[$this->current_script]['SCRIPT'];
-        $p = new My_Parser;
+        $p = new My_Parser($this);
         if($p -> parse($sc)){
 
           if($this->scripts[$this->current_script]['MODE'] == "Source-Only"){
@@ -375,6 +403,69 @@ class sieveManagement extends plugin
      */
     if($this->current_handler){
 
+        if(isset($_POST['Import_Script'])){
+          $this->Import_Script = TRUE;
+        }
+
+        if(isset($_POST['Import_Script_Cancel'])){
+          $this->Import_Script = FALSE;
+        }
+
+        if(isset($_POST['Import_Script_Save']) && isset($_FILES['Script_To_Import'])){
+
+          $file     = $_FILES['Script_To_Import'];
+
+          if($file['size'] == 0){
+            print_red(_("Specified file seams to empty."));
+          }elseif(!file_exists($file['tmp_name'])){
+            print_red(_("Upload failed, somehow nothing was uploaded or the temporary file can't be accessed."));
+          }elseif(!is_readable ($file['tmp_name'])){
+            print_red(sprintf(_("Can't open file '%s' to read uploaded file contents."),$file['tmp_name']));
+          }else{
+            
+            
+            $contents = file_get_contents($file['tmp_name']);
+           
+            $this->scripts[$this->current_script]['SCRIPT'] = $contents;
+            if(!$this->current_handler->parse($contents)){
+              $this->scripts[$this->current_script]['MODE'] = "Source";
+            }else{
+              $this->scripts[$this->current_script]['MODE'] = "Structured";
+            }
+            $this->Import_Script = FALSE;
+          }
+        }
+
+        if($this->Import_Script){
+          $smarty = get_smarty();
+          $str = $smarty->fetch(get_template_path("templates/import_script.tpl",TRUE,dirname(__FILE__)));
+          return($str);
+        }
+  
+
+        /* Create dump of current sieve script */
+        if(isset($_POST['Save_Copy'])){
+
+            /* force download dialog */
+            header("Content-type: application/tiff\n");
+            if (preg_match('/MSIE 5.5/', $HTTP_USER_AGENT) ||
+                    preg_match('/MSIE 6.0/', $HTTP_USER_AGENT)) {
+                header('Content-Disposition: filename="dump.script"');
+            } else {
+                header('Content-Disposition: attachment; filename="dump.script"');
+            }
+            header("Content-transfer-encoding: binary\n");
+            header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
+            header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
+            header("Cache-Control: no-cache");
+            header("Pragma: no-cache");
+            header("Cache-Control: post-check=0, pre-check=0");
+            echo $this->scripts[$this->current_script]['SCRIPT'];
+            exit();
+        }
+
+
       /****
        * Add new element to ui
        ****/
@@ -402,7 +493,8 @@ class sieveManagement extends plugin
 
 
         /* Element selected */
-        if(isset($_POST['element_type']) && isset($element_types[$_POST['element_type']])){
+        if(isset($_POST['element_type']) && isset($element_types[$_POST['element_type']]) 
+           || isset($_POST['element_type']) &&in_array($_POST['element_type'],array("sieve_else","sieve_elsif"))){
           $this->add_element_type = $_POST['element_type'];
         }
 
@@ -410,60 +502,10 @@ class sieveManagement extends plugin
          *  the selected position 
          */
         if(isset($_POST['select_new_element_type'])){
-
-          /* Create elements we should add */
-          $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime()));
-          if($this->add_element_type == "sieve_if"){
-            $ele[] = new sieve_block_start(NULL,preg_replace("/[^0-9]/","",microtime()));
-            $ele[] = new sieve_block_end(NULL,preg_replace("/[^0-9]/","",microtime()));
-          }
-          $start = $end = array();
-          $found = false;
-          $data = $this->current_handler->tree_->pap;
-
-          /* Add above current element*/
-          if($this->add_above_below == "above"){
-            foreach($data as $key => $obj){
-              if($obj->object_id == $this->add_new_id){
-                $found = true;
-              }
-              if(!$found){
-                $start[] = $obj;
-              }else{
-                $end[] = $obj;
-              }
-            }
-          }else{
-            /* Add below current element */
-            foreach($data as $key => $obj){
-              if(!$found){
-                $start[] = $obj;
-              }else{
-                $end[] = $obj;
-              }
-              if($obj->object_id == $this->add_new_id){
-                $found = true;
-              }
-            }
-          }
-
-          /* Only add, if current element could be located */
-          if($found){
-            $new = array();
-            foreach($start as $obj){
-              $new[] = $obj;
-            }
-            foreach($ele as $el){
-              $new[] = $el;
-            }
-            foreach($end as $obj){
-              $new[] = $obj;
-            }
-            $data= $new;
-            $this->current_handler->tree_->pap = $data;
+          if($this->add_new_element_to_current_script($this->add_element_type,$this->add_new_id,$this->add_above_below)){
             $this->add_new_element = FALSE;
           }else{
-            print_red(_("Something went wrong while adding a new entry."));
+            print_red(_("Failed to add new element."));
           }
         }
       }
@@ -471,6 +513,48 @@ class sieveManagement extends plugin
       /* Only display select dialog if it is necessary */
       if($this->add_new_element){
         $smarty = get_smarty();
+    
+        $add_else_elsif = FALSE;
+
+        /* Check if we should add else/elsif to the select box 
+         *  or not. We can't add else twice!.
+         */
+        if($this->add_above_below == "below"){
+
+          /* Get posistion of the current element 
+           */
+          foreach($this->current_handler->tree_->pap as $key => $obj){
+        
+            if($obj->object_id == $this->add_new_id && in_array(get_class($obj),array("sieve_if","sieve_elsif"))){
+  
+              /* Get block start/end */
+              $end_id = $this->current_handler->tree_->get_block_end($key);
+              $else_found = FALSE;
+              $elsif_found = FALSE;
+          
+              /* Check if there is already an else in this block 
+               */
+              for($i =  $key ; $i < $end_id ; $i ++){
+                if(get_class($this->current_handler->tree_->pap[$i]) == "sieve_else"){
+                  $else_found = TRUE;
+                }
+                if(get_class($this->current_handler->tree_->pap[$i]) == "sieve_elsif"){
+                  $elsif_found = TRUE;
+                }
+              }
+  
+              /* Only allow adding 'else' if there is currently 
+               *  no 'else' statement. And don't allow adding 
+               *  'else' before 'elseif'
+               */ 
+              if(!$else_found && (!(get_class($obj) == "sieve_if" && $elsif_found))){
+                $element_types['sieve_else'] = _("Else");
+              }
+              $element_types['sieve_elsif'] = _("Else if");
+            }
+          }
+        }
+
         $smarty->assign("element_types",$element_types );
         $smarty->assign("element_type",$this->add_element_type);
         $str = $smarty->fetch(get_template_path("templates/add_element.tpl",TRUE,dirname(__FILE__)));
@@ -551,7 +635,7 @@ class sieveManagement extends plugin
                         "attach" => "style='width:30px;'");
       }
 
-      if($active){
+      if($active || $script['IS_NEW']){
         $field6 = array("string" => "<img src='images/empty.png' alt=' '>".
                                     "<input type='image' name='editscript_".$key."' src='images/edit.png'>".
                                     "<input type='image' name='delscript_".$key."' src='images/edittrash.png'>");
@@ -576,6 +660,111 @@ class sieveManagement extends plugin
     return($display);;
   }
 
+
+  /* Add a new element to the currently opened script editor.
+   * The insert position is specified by 
+   */
+  function add_new_element_to_current_script($type,$id,$position)
+  {
+    /* Test given data */
+    if(!in_array_ics($position,array("above","below"))){
+      trigger_error("Can't add new element with \$position=".$position.". Only 'above','below' are allowed here.");
+      return(FALSE);
+    }
+    if(!is_numeric($id)){
+      trigger_error("Can't add new element, given id is not numeric.");
+      return(FALSE);
+    }
+    $tmp = get_declared_classes();  
+    if(!in_array($type,$tmp)){
+      trigger_error("Can't add new element, given \$class=".$class." does not exists.");
+      return(FALSE);
+    }
+    if(!is_object($this->current_handler) || get_class($this->current_handler) != "My_Parser"){
+      trigger_error("Can't add new element, there is no valid script editor opened.");
+      return(FALSE);
+    }
+
+    /* Create elements we should add 
+     * -Some element require also surrounding block elements
+     */
+    $parent = $this->current_handler->tree_;
+    if($this->add_element_type == "sieve_if"){
+      $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime()),$parent);
+      $ele[] = new sieve_block_start(NULL,preg_replace("/[^0-9]/","",microtime()),$parent);
+      $ele[] = new sieve_block_end(NULL,preg_replace("/[^0-9]/","",microtime()),$parent);
+    }elseif($this->add_element_type == "sieve_else"){
+      $ele[] = new sieve_block_end(NULL,preg_replace("/[^0-9]/","",microtime()),$parent);
+      $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime()),$parent);
+      $ele[] = new sieve_block_start(NULL,preg_replace("/[^0-9]/","",microtime()),$parent);
+    }elseif($this->add_element_type == "sieve_elsif"){
+      $ele[] = new sieve_block_end(NULL,preg_replace("/[^0-9]/","",microtime()),$parent);
+      $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime()),$parent);
+      $ele[] = new sieve_block_start(NULL,preg_replace("/[^0-9]/","",microtime()),$parent);
+    }else{
+      $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime()),$parent);
+    }
+
+    /* Get index of the element identified by object_id == $id; 
+     */
+    $index = -1;
+    $data = $this->current_handler->tree_->pap;
+    foreach($data as $key => $obj){
+      if($obj->object_id == $id && $index==-1){
+        $index = $key;
+      }
+    }
+
+    /* Tell to user that we couldn't find the given object 
+     *  so we can't add an element. 
+     */
+    if($index == -1 ){
+      trigger_error("Can't add new element, specified \$id=".$id." could not be found in object tree.");
+      return(FALSE);
+    }
+
+    /* We have found the specified object_id 
+     *  and want to detect the next free position 
+     *  to insert the new element.
+     */
+    if($position == "above"){
+      $direction ="up";
+      $next_free = $this->current_handler->tree_->_get_next_free_move_slot($index,$direction,TRUE);
+    }else{
+      $direction = "down";
+      $next_free = $this->current_handler->tree_->_get_next_free_move_slot($index,$direction,TRUE);
+    }
+    /* This is extremly necessary, cause some objects 
+     *  updates the tree objects ... Somehow i should change this ... 
+     */
+    $data = $this->current_handler->tree_->pap;
+    $start = $end = array();
+
+    if($position == "above"){
+      $start = array_slice($data,0,$next_free);
+      $end   = array_slice($data,$next_free);
+    }else{
+      $start = array_slice($data,0,$next_free+1);
+      $end   = array_slice($data,$next_free+1);
+    }
+
+    $new = array();
+    foreach($start as $obj){
+      $new[] = $obj;
+    }
+    foreach($ele as $el){
+      $new[] = $el;
+    }
+    foreach($end as $obj){
+      $new[] = $obj;
+    }
+    $data= $new;
+    $this->current_handler->tree_->pap = $data;
+    return(TRUE);
+  }
+
+
+
   function save_object()
   {
     if($this->current_handler){
@@ -613,72 +802,86 @@ class sieveManagement extends plugin
           }
         }
       }
-      
+
       /* Skip Mode changes and Parse tests 
        *  if we are currently in a subdialog 
        */
-      if(!$this->add_new_element) {
-
-        $Mode = $this->scripts[$this->current_script]['MODE'];
-        $skip_mode_change = false;
-        if(in_array($Mode,array("Source-Only","Source"))){
-          if(isset($_POST['script_contents'])){
-            $sc = stripslashes($_POST['script_contents']);
-            $this->scripts[$this->current_script]['SCRIPT'] = $sc;
-            $p = new My_Parser;
-            if($p -> parse($sc)){
-              $this->current_handler = $p;
-              $this->Script_Error = "";
-            } else {
-              $this->Script_Error = $p->status_text;
-              $skip_mode_change = TRUE;
-            }
-          }
-        }
-        if(in_array($Mode,array("Structured"))){
-          $this->current_handler->save_object();
-          $sc = $this->current_handler->get_sieve_script();
+
+      $this->current_handler->save_object();
+      $Mode = $this->scripts[$this->current_script]['MODE'];
+      $skip_mode_change = false;
+      if(in_array($Mode,array("Source-Only","Source"))){
+        if(isset($_POST['script_contents'])){
+          $sc = stripslashes($_POST['script_contents']);
           $this->scripts[$this->current_script]['SCRIPT'] = $sc;
-          $p = new My_Parser;
+          $p = new My_Parser($this);
           if($p -> parse($sc)){
-            $this->current_handler = $p;
             $this->Script_Error = "";
           } else {
             $this->Script_Error = $p->status_text;
             $skip_mode_change = TRUE;
           }
         }
-        if(!$skip_mode_change){
-          if($this->scripts[$this->current_script]['MODE'] != "Source-Only"){
-            if(isset($_POST['View_Source'])){
-              $this->scripts[$this->current_script]['MODE'] = "Source";
-            }
-            if(isset($_POST['View_Structured'])){
-              $this->scripts[$this->current_script]['MODE'] = "Structured";
-            }
+      }
+      if(in_array($Mode,array("Structured"))){
+        $sc = $this->current_handler->get_sieve_script();
+        $this->scripts[$this->current_script]['SCRIPT'] = $sc;
+        $p = new My_Parser($this);
+        if($p -> parse($sc)){
+          $this->Script_Error = "";
+        } else {
+          $this->Script_Error = $p->status_text;
+          $skip_mode_change = TRUE;
+        }
+      }
+      if(!$skip_mode_change){
+        if($this->scripts[$this->current_script]['MODE'] != "Source-Only"){
+          $old_mode = $this->scripts[$this->current_script]['MODE'];
+          if(isset($_POST['View_Source'])){
+            $this->scripts[$this->current_script]['MODE'] = "Source";
           }
+          if(isset($_POST['View_Structured'])){
+            $this->scripts[$this->current_script]['MODE'] = "Structured";
+          }
+          $new_mode = $this->scripts[$this->current_script]['MODE'];
+
+          if($old_mode != $new_mode){
+
+            $sc = $this->scripts[$this->current_script]['SCRIPT'];
+            $p = new My_Parser($this);
+
+            if($p -> parse($sc)){
+              $this->current_handler->parse($sc);
+              $this->Script_Error = "";
+            } else {
+              $this->Script_Error = $p->status_text;
+            }
+          } 
         }
       }
-      $this->current_handler->save_object();
     }
   }
 
-
-  function save()
+  
+  function get_used_script_names()
   {
-    /* Connect to sieve class and try to get all available sieve scripts */
-    $cfg=  $this->config->data['SERVERS']['IMAP'][$this->parent->gosaMailServer];
+    $ret = array();
+    foreach($this->scripts as $script){
+      $ret[] = $script['NAME'];
+    }
+    return($ret);
+  }
 
-    $this->sieve_handle= 
-        new sieve(  $cfg["sieve_server"], 
-                    $cfg["sieve_port"], 
-                    $this->parent->mail,
-                    $cfg["password"], 
-                    $cfg["admin"]);
 
-    if (!$this->sieve_handle->sieve_login()){
-      print_red(sprintf(_("Can't log into SIEVE server. Server says '%s'."),to_string($this->sieve_handle->error_raw)));
-      return;
+
+  function save()
+  {
+    /* Get sieve */
+    if(!$this->sieve_handle = $this->get_sieve()){
+      print_red(
+          sprintf(
+            _("Can't log into SIEVE server. Server says '%s'."),
+            to_string($this->Sieve_Error)));
     }
 
     $everything_went_fine = TRUE;