Code

945a6d2843a634e74cf56d986b59e4605dafc088
[gosa.git] / include / sieve / class_sieveManagement.inc
1 <?php
2 /*
3    This code is part of GOsa (https://gosa.gonicus.de)
4    Copyright (C) 2003-2007 - Fabian Hickert <hickert@gonicus.de>
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
21 class sieveManagement extends plugin
22 {
23   var $parent = NULL;
24   var $scripts= array();  
26   
27   function sieveManagement($config,$dn,$parent)
28   {
29     $this->parent = $parent;
30     plugin::plugin($config,$dn);
33     /* Connect to sieve class and try to get all available sieve scripts */
34     $cfg=  $this->config->data['SERVERS']['IMAP'][$this->parent->gosaMailServer];
35     
36     /* Log into the mail server */
37     $sieve= new sieve($cfg["sieve_server"], $cfg["sieve_port"], $this->parent->uid,
38         $cfg["password"], $cfg["admin"]);
40     /* Try to login */
41     if (!$sieve->sieve_login()){
42       print_red(sprintf(_("Can't log into SIEVE server. Server says '%s'."),
43             to_string($sieve->error_raw)));
44       return;
45     }
47     /* Get all sieve scripts names */
48     if($sieve->sieve_listscripts()){
49       if (is_array($sieve->response)){
50         foreach($sieve->response as $key => $name){
51           $this->scripts[$key]['NAME'] = $name;
52         }
53       } 
54     }
56     /* Get script contents */
57     foreach($this->scripts as $key => $script){
58       $p = new My_Parser;
59       $sieve->sieve_getscript($script['NAME']);
61       $script = "";
62       foreach($sieve->response as $line){
63         $script.=$line;
64       }
66       $this->scripts[$key]['SCRIPT'] = $script;
67       $this->scripts[$key]['MSG']   = "";
68       $ret = $p->parse($script);
69       if(!$ret){
70         $this->scripts[$key]['MSG']   = "<font color='red'>".$p->status_text."</font>";
71         $this->scripts[$key]['STATUS'] = FALSE;
72       }else{
73         $this->scripts[$key]['STATUS'] = TRUE;
74       }
75       $this->scripts[$key]['PARSER'] = $p;
76     }
77   }
79   function execute()
80   {
81     $once = TRUE;
82     foreach($_POST as $name => $value){
83       if(preg_match("/^editscript_/",$name) && $once){
84         $script = preg_replace("/^editscript_/","",$name);
85         $script = preg_replace("/_(x|y)/","",$script);
86         $once = FALSE;
88         $obj_handler = new sieveElement;
89         $data = $this->scripts[$script]['PARSER'];
90         $obj_handler->resolve_to_object($data);
91         return($obj_handler->execute());
92       }
93     }
96     $List = new divSelectBox("sieveManagement");
98     foreach($this->scripts as $key => $script){
99   
100       $field1 = array("string" => $script['NAME']);  
102       if($script['STATUS']){
103         $field2 = array("string" => _("Parse successful"));
104       }else{
105         $field2 = array("string" => _("Parse failed") .$script['MSG']);
106       }
108       $field3 = array("string" => _("Script length")."&nbsp;:&nbsp;".strlen($script['SCRIPT']));
109       $field4 = array("string" => "<input type='image' name='editscript_".$key."' src='images/edit.png'>");
111       $List ->AddEntry(array($field1,$field2,$field3,$field4)); 
112     }
114     return($List->DrawList());
115   }
117   function save_object()
118   {
119     
120   }
123 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
124 ?>