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 */
22 /* The sieve management class displays a list of sieve
23 * scripts for the given mail account.
24 * The account is identified by the parents uid attribute.
25 *
26 * $config The config object
27 * $dn The object edited
28 * $parent The parent object that provides the uid attribute
29 */
30 class sieveManagement extends plugin
31 {
32 var $parent = NULL;
33 var $scripts= array();
36 /* Initialize the class and load all sieve scripts
37 * try to parse them and display errors
38 */
39 function sieveManagement($config,$dn,$parent)
40 {
41 $this->parent = $parent;
42 plugin::plugin($config,$dn);
45 /* Connect to sieve class and try to get all available sieve scripts */
46 $cfg= $this->config->data['SERVERS']['IMAP'][$this->parent->gosaMailServer];
48 /* Log into the mail server */
49 $sieve= new sieve($cfg["sieve_server"], $cfg["sieve_port"], $this->parent->uid,
50 $cfg["password"], $cfg["admin"]);
52 /* Try to login */
53 if (!$sieve->sieve_login()){
54 print_red(sprintf(_("Can't log into SIEVE server. Server says '%s'."),
55 to_string($sieve->error_raw)));
56 return;
57 }
59 /* Get all sieve scripts names */
60 if($sieve->sieve_listscripts()){
61 if (is_array($sieve->response)){
62 foreach($sieve->response as $key => $name){
63 $this->scripts[$key]['NAME'] = $name;
64 }
65 }
66 }
68 /* Get script contents */
69 foreach($this->scripts as $key => $script){
70 $p = new My_Parser;
71 $sieve->sieve_getscript($script['NAME']);
73 $script = "";
74 foreach($sieve->response as $line){
75 $script.=$line;
76 }
78 $this->scripts[$key]['SCRIPT'] = $script;
79 $this->scripts[$key]['MSG'] = "";
80 $ret = $p->parse($script);
81 if(!$ret){
82 $this->scripts[$key]['MSG'] = "<font color='red'>".$p->status_text."</font>";
83 $this->scripts[$key]['STATUS'] = FALSE;
84 }else{
85 $this->scripts[$key]['STATUS'] = TRUE;
86 }
87 $this->scripts[$key]['PARSER'] = $p;
88 }
89 }
92 /* Handle sieve list
93 */
94 function execute()
95 {
96 $once = TRUE;
97 foreach($_POST as $name => $value){
98 if(preg_match("/^editscript_/",$name) && $once){
99 $script = preg_replace("/^editscript_/","",$name);
100 $script = preg_replace("/_(x|y)/","",$script);
101 $once = FALSE;
103 $obj_handler = new sieveElement;
104 $data = $this->scripts[$script]['PARSER'];
105 $obj_handler->resolve_to_object($data);
106 return($obj_handler->execute());
107 }
108 }
111 /* Create list of available sieve scripts
112 */
113 $List = new divSelectBox("sieveManagement");
114 foreach($this->scripts as $key => $script){
115 $field1 = array("string" => $script['NAME']);
116 if($script['STATUS']){
117 $field2 = array("string" => _("Parse successful"));
118 }else{
119 $field2 = array("string" => _("Parse failed") .$script['MSG']);
120 }
121 $field3 = array("string" => _("Script length")." : ".strlen($script['SCRIPT']));
122 $field4 = array("string" => "<input type='image' name='editscript_".$key."' src='images/edit.png'>");
123 $List ->AddEntry(array($field1,$field2,$field3,$field4));
124 }
126 return($List->DrawList());
127 }
129 function save_object()
130 {
132 }
133 }
135 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
136 ?>