b436808a41a8c2d4552db4c1977efc18987b7bfc
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();
35 var $current_script = -1;
36 var $current_handler = NULL;
37 var $script_to_delete =-1;
38 var $sieve_handle = NULL;
39 var $Script_Error = "";
40 var $Sieve_Error = "";
41 var $create_script = FALSE;
43 /* To add new elements we need to know
44 * Where to the element -> add_new_id
45 * Whould we add above or below this id -> add_above_below
46 * What kind of element should we add -> add_element_type
47 */
48 var $add_new_element = FALSE;
49 var $add_new_id = -1;
50 var $add_above_below = "below";
51 var $add_element_type = "sieve_comment";
53 /* If this variable is TRUE, this indicates that we have the
54 * import dialog opened.
55 */
56 var $Import_Script = FALSE;
58 /* Initialize the class and load all sieve scripts
59 * try to parse them and display errors
60 */
61 function sieveManagement($config,$dn,$parent)
62 {
63 $this->parent = $parent;
64 plugin::plugin($config,$dn);
66 /* Get sieve */
67 if(!$sieve = $this->get_sieve()){
68 print_red(
69 sprintf(
70 _("Can't log into SIEVE server. Server says '%s'."),
71 to_string($this->Sieve_Error)));
72 return;
73 }
76 /* Get all sieve scripts names */
77 if($sieve->sieve_listscripts()){
78 if (is_array($sieve->response)){
79 foreach($sieve->response as $key => $name){
81 $data = array();
82 $data['NAME'] = $name;
84 if($key == "ACTIVE" && $key === "ACTIVE"){
85 $data['ACTIVE'] = TRUE;
86 }else{
87 $data['ACTIVE'] = FALSE;
88 }
89 $this->scripts[] = $data;
90 }
91 }
92 }
94 /* Get script contents */
95 foreach($this->scripts as $key => $script){
96 $p = new My_Parser;
97 $sieve->sieve_getscript($script['NAME']);
99 $script = "";
100 foreach($sieve->response as $line){
101 $script.=$line;
102 }
104 $this->scripts[$key]['IS_NEW'] = FALSE;;
105 $this->scripts[$key]['SCRIPT'] = $script;
106 $this->scripts[$key]['ORIG_SCRIPT'] = $script;
107 $this->scripts[$key]['MSG'] = "";
108 $ret = $p->parse($script);
109 if(!$ret){
110 $this->scripts[$key]['STATUS'] = FALSE;
111 $this->scripts[$key]['MODE'] = "Source-Only";
112 $this->scripts[$key]['MSG'] = _("Parse failed")."<font color='red'>".$p->status_text."</font>";
113 }else{
114 $this->scripts[$key]['STATUS'] = TRUE;
115 $this->scripts[$key]['MODE'] = "Structured";
116 $this->scripts[$key]['MSG'] = _("Parse successful");
117 }
118 $this->scripts[$key]['PARSER'] = $p;
119 $this->scripts[$key]['EDITED'] = FALSE;
120 }
121 $this->sieve_handle = $sieve;
122 }
125 /* Return a sieve class hanlde,
126 * false if login fails
127 */
128 function get_sieve()
129 {
130 /* Connect to sieve class and try to get all available sieve scripts */
131 $cfg= $this->config->data['SERVERS']['IMAP'][$this->parent->gosaMailServer];
132 $this->Sieve_Error = "";
134 /* Log into the mail server */
135 $sieve= new sieve(
136 $cfg["sieve_server"],
137 $cfg["sieve_port"],
138 $this->parent->uid,
139 $cfg["password"],
140 $cfg["admin"]);
142 /* Try to login */
143 if (!$sieve->sieve_login()){
144 $this->Sieve_Error = $sieve->error_raw;
145 return(FALSE);
146 }
147 return($sieve);
148 }
151 /* Handle sieve list
152 */
153 function execute()
154 {
155 /***************
156 * Create a new Script
157 ***************/
159 /* Force opening the add script dialog */
160 if(isset($_POST['create_new_script'])){
161 $this->create_script = TRUE;
162 }
164 /* Close add script dialog, without adding a new one */
165 if(isset($_POST['create_script_cancel'])){
166 $this->create_script = FALSE;
167 }
169 /* Display create script dialog
170 * handle posts, display warnings if specified
171 * name is not useable.
172 * Create a new script with given name
173 */
174 if($this->create_script){
176 /* Set initial name or used posted name if available */
177 $name = "";
178 if(isset($_POST['NewScriptName'])){
179 $name = trim($_POST['NewScriptName']);
180 }
182 /* Check given name */
183 $err = "";
185 /* Is given name in lower case characters ? */
186 if(isset($_POST['create_script_save'])){
187 if(!strlen($name)){
188 $err = _("You should specify a name for your new script.");
189 }
190 /* Is given name in lower case characters ? */
191 if($name != strtolower($name)){
192 $err = _("Only lower case names are allowed here.");
193 }
195 /* Only chars are allowed here */
196 if(preg_match("/[^a-z]/i",$name)){
197 $err = _("Only a-z are allowed in script names.");
198 }
199 }
201 /* Create script if everything is ok */
202 if($this->create_script && isset($_POST['create_script_save']) && $err == "" ){
204 /* Close dialog */
205 $this->create_script = FALSE;
207 /* Script contents to use */
208 $script = "/*New script */".
209 "stop;";
211 /* Create a new parser and initialize default values */
212 $p = new My_Parser;
213 $ret = $p->parse($script);
214 $sc['SCRIPT'] = $script;
215 $sc['ORIG_SCRIPT'] = $script;
216 $sc['IS_NEW'] = TRUE;
217 $sc['MSG'] = "";
218 if(!$ret){
219 $sc['STATUS'] = FALSE;
220 $sc['MODE'] = "Source-Only";
221 $sc['MSG'] = _("Parse failed")."<font color='red'>".$p->status_text."</font>";
222 }else{
223 $sc['STATUS'] = TRUE;
224 $sc['MODE'] = "Strucktured";
225 $sc['MSG'] = _("Parse successful");
226 }
227 $sc['PARSER'] = $p;
228 $sc['EDITED'] = TRUE;
229 $sc['ACTIVE'] = FALSE;
230 $sc['NAME'] = $name;
232 /* Add script */
233 $this->scripts[$name] = $sc;
234 }else{
236 /* Display dialog to enter new script name */
237 $smarty = get_smarty();
238 $smarty->assign("NewScriptName",$name);
239 $smarty->assign("Error",$err);
240 return($smarty->fetch(get_template_path("templates/create_script.tpl",TRUE,dirname(__FILE__))));
241 }
242 }
245 /*************
246 * Handle several posts
247 *************/
249 $once = TRUE;
250 foreach($_POST as $name => $value){
252 /* Edit script requested */
253 if(preg_match("/^editscript_/",$name) && $once && !$this->current_handler){
254 $script = preg_replace("/^editscript_/","",$name);
255 $script = preg_replace("/_(x|y)/","",$script);
256 $once = FALSE;
258 $this->current_script = $script;
259 $this->current_handler = $this->scripts[$script]['PARSER'];
260 }
262 /* remove script requested */
263 if(preg_match("/^delscript_/",$name) && $once && !$this->current_handler){
264 $script = preg_replace("/^delscript_/","",$name);
265 $script = preg_replace("/_(x|y)/","",$script);
266 $once = FALSE;
268 $this->script_to_delete = $script;
269 }
271 /* Activate script */
272 if(preg_match("/^active_script_/",$name) && $once && !$this->current_handler){
273 $script = preg_replace("/^active_script_/","",$name);
274 $script = preg_replace("/_(x|y)/","",$script);
275 $once = FALSE;
277 /* Get sieve */
278 if(!$sieve = $this->get_sieve()){
279 print_red(
280 sprintf(
281 _("Can't log into SIEVE server. Server says '%s'."),
282 to_string($this->Sieve_Error)));
283 }
285 /* Try to activate the given script and update
286 * class script array.
287 */
288 if(!$this->sieve_handle->sieve_setactivescript($this->scripts[$script]['NAME'])){
289 print_red(sprintf(_("Can't activate sieve script on server. Server says '%s'."),to_string($this->sieve_handle->error_raw)));
290 }else{
291 foreach($this->scripts as $key => $data){
292 if($key == $script){
293 $this->scripts[$key]['ACTIVE'] = TRUE;
294 }else{
295 $this->scripts[$key]['ACTIVE'] = FALSE;
296 }
297 }
298 }
299 }
300 }
303 /*************
304 * Remove script handling
305 *************/
307 /* Remove aborted */
308 if(isset($_POST['delete_cancel'])){
309 $this->script_to_delete = -1;
310 }
312 /* Remove confirmed */
313 if(isset($_POST['delete_script_confirm'])){
315 $script = $this->scripts[$this->script_to_delete];
317 /* Just remove from array if it is a new script */
318 if($script['IS_NEW']){
319 unset($this->scripts[$this->script_to_delete]);
320 }else{
322 /* Get sieve */
323 if(!$sieve = $this->get_sieve()){
324 print_red(
325 sprintf(
326 _("Can't log into SIEVE server. Server says '%s'."),
327 to_string($this->Sieve_Error)));
328 }
330 if(!$sieve->sieve_deletescript($this->scripts[$this->script_to_delete]['NAME'])){
331 print_red(sprintf(_("Can't remove sieve script from server. Server says '%s'."),to_string($this->sieve_handle->error_raw)));
332 }else{
333 unset($this->scripts[$this->script_to_delete]);
334 }
335 }
336 $this->script_to_delete = -1;
337 }
339 /* Display confirm dialog */
340 if($this->script_to_delete != -1){
341 $smarty = get_smarty();
342 $smarty->assign("Warning",
343 sprintf(_("You are going to remove the sieve script '%s' from your mail server."),
344 $this->scripts[$this->script_to_delete]['NAME']));
345 return($smarty->fetch(get_template_path("templates/remove_script.tpl",TRUE,dirname(__FILE__))));
346 }
349 /**************
350 * Save script changes
351 **************/
353 /* Abort saving */
354 if(isset($_POST['cancel_sieve_changes'])){
355 $this->current_handler = NULL;
356 }
358 /* Save currently edited sieve script. */
359 if(isset($_POST['save_sieve_changes'])){
360 $chk = $this->current_handler->check();
361 if(!count($chk)){
363 $sc = $this->scripts[$this->current_script]['SCRIPT'];
364 $p = new My_Parser;
365 if($p -> parse($sc)){
367 if($this->scripts[$this->current_script]['MODE'] == "Source-Only"){
368 $this->scripts[$this->current_script]['MODE'] = "Source";
369 }
371 $this->scripts[$this->current_script]['PARSER'] = $p;
372 $this->scripts[$this->current_script]['EDITED'] = TRUE;
373 $this->scripts[$this->current_script]['STATUS'] = TRUE;
374 $this->scripts[$this->current_script]['MSG'] = _("Edited");
375 $this->current_handler = NULL;
376 }else{
377 print_red($p->status_text);;
378 }
379 }else{
380 print_red(_("Please fix all errors before saving."));
381 }
382 }
385 /*************
386 * Display edit dialog
387 *************/
389 /* Display edit dialog, depending on Mode display different uis
390 */
391 if($this->current_handler){
393 if(isset($_POST['Import_Script'])){
394 $this->Import_Script = TRUE;
395 }
397 if(isset($_POST['Import_Script_Cancel'])){
398 $this->Import_Script = FALSE;
399 }
401 if(isset($_POST['Import_Script_Save']) && isset($_FILES['Script_To_Import'])){
403 $file = $_FILES['Script_To_Import'];
405 if($file['size'] == 0){
406 print_red(_("Specified file seams to empty."));
407 }elseif(!file_exists($file['tmp_name'])){
408 print_red(_("Upload failed, somehow nothing was uploaded or the temporary file can't be accessed."));
409 }elseif(!is_readable ($file['tmp_name'])){
410 print_red(sprintf(_("Can't open file '%s' to read uploaded file contents."),$file['tmp_name']));
411 }else{
415 $contents = file_get_contents($file['tmp_name']);
417 $this->scripts[$this->current_script]['SCRIPT'] = $contents;
418 if(!$this->current_handler->parse($contents)){
419 $this->scripts[$this->current_script]['MODE'] = "Source";
420 }else{
421 $this->scripts[$this->current_script]['MODE'] = "Structured";
422 }
423 $this->Import_Script = FALSE;
424 }
425 }
427 if($this->Import_Script){
428 $smarty = get_smarty();
429 $str = $smarty->fetch(get_template_path("templates/import_script.tpl",TRUE,dirname(__FILE__)));
430 return($str);
431 }
434 /* Create dump of current sieve script */
435 if(isset($_POST['Save_Copy'])){
437 /* force download dialog */
438 header("Content-type: application/tiff\n");
439 if (preg_match('/MSIE 5.5/', $HTTP_USER_AGENT) ||
440 preg_match('/MSIE 6.0/', $HTTP_USER_AGENT)) {
441 header('Content-Disposition: filename="dump.script"');
442 } else {
443 header('Content-Disposition: attachment; filename="dump.script"');
444 }
445 header("Content-transfer-encoding: binary\n");
446 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
447 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
448 header("Cache-Control: no-cache");
449 header("Pragma: no-cache");
450 header("Cache-Control: post-check=0, pre-check=0");
451 echo $this->scripts[$this->current_script]['SCRIPT'];
452 exit();
453 }
456 /****
457 * Add new element to ui
458 ****/
460 /* Abort add dialog */
461 if(isset($_POST['select_new_element_type_cancel'])){
462 $this->add_new_element = FALSE;
463 }
465 /* Add a new element */
466 if($this->add_new_element){
468 $element_types= array(
469 "sieve_keep" => _("Keep"),
470 "sieve_comment" => _("Comment"),
471 "sieve_fileinto" => _("File into"),
472 "sieve_keep" => _("Keep"),
473 "sieve_discard" => _("Discard"),
474 "sieve_redirect" => _("Redirect"),
475 "sieve_reject" => _("Reject"),
476 "sieve_require" => _("Require"),
477 "sieve_stop" => _("Stop"),
478 "sieve_vacation" => _("Vacation message"),
479 "sieve_if" => _("If"));
482 /* Element selected */
483 if(isset($_POST['element_type']) && isset($element_types[$_POST['element_type']])){
484 $this->add_element_type = $_POST['element_type'];
485 }
487 /* Create new element and add it to
488 * the selected position
489 */
490 if(isset($_POST['select_new_element_type'])){
492 $this->add_new_id;
494 $data = $this->current_handler->tree_->pap;
496 /* Get index of the element identified by object_id == $this->add_new_id; */
497 $index = -1;
498 foreach($data as $key => $obj){
499 if($obj->object_id == $this->add_new_id && $index==-1){
500 $index = $key;
501 }
502 }
504 /* We have found the specified object_id
505 * and want to detect the next free position
506 * to insert the new element.
507 */
508 if($index != -1){
509 if($this->add_above_below == "above"){
510 $direction ="up";
511 $next_free = $this->current_handler->tree_->_get_next_free_move_slot($index,$direction);
512 $next_free ++;
513 }else{
514 $direction = "down";
515 $next_free = $this->current_handler->tree_->_get_next_free_move_slot($index,$direction);
516 }
517 $this->add_new_id = $this->current_handler->tree_->pap[$next_free]->object_id;
518 }
520 /* Create elements we should add */
521 $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime()));
522 if($this->add_element_type == "sieve_if"){
523 $ele[] = new sieve_block_start(NULL,preg_replace("/[^0-9]/","",microtime()));
524 $ele[] = new sieve_block_end(NULL,preg_replace("/[^0-9]/","",microtime()));
525 }
526 $start = $end = array();
527 $found = false;
529 /* Add above current element*/
530 if($this->add_above_below == "above"){
531 foreach($data as $key => $obj){
532 if($obj->object_id == $this->add_new_id){
533 $found = true;
534 }
535 if(!$found){
536 $start[] = $obj;
537 }else{
538 $end[] = $obj;
539 }
540 }
541 }else{
542 /* Add below current element */
543 foreach($data as $key => $obj){
544 if(!$found){
545 $start[] = $obj;
546 }else{
547 $end[] = $obj;
548 }
549 echo $obj->object_id." --> ".$this->add_new_id."<br>";
550 if($obj->object_id == $this->add_new_id){
551 $found = true;
552 echo "Jop";
553 }
554 }
555 }
558 /* Only add, if current element could be located */
559 if($found){
560 $new = array();
561 foreach($start as $obj){
562 $new[] = $obj;
563 }
564 foreach($ele as $el){
565 $new[] = $el;
566 }
567 foreach($end as $obj){
568 $new[] = $obj;
569 }
570 $data= $new;
571 $this->current_handler->tree_->pap = $data;
572 $this->add_new_element = FALSE;
573 }else{
574 print_red(_("Something went wrong while adding a new entry."));
575 }
576 }
577 }
579 /* Only display select dialog if it is necessary */
580 if($this->add_new_element){
581 $smarty = get_smarty();
582 $smarty->assign("element_types",$element_types );
583 $smarty->assign("element_type",$this->add_element_type);
584 $str = $smarty->fetch(get_template_path("templates/add_element.tpl",TRUE,dirname(__FILE__)));
585 return($str);
586 }
590 /****************
591 * Handle test posts
592 ****************/
594 /* handle some special posts from test elements
595 */
596 foreach($_POST as $name => $value){
597 if(preg_match("/^Add_Test_Object_/",$name)) {
598 $name = preg_replace("/^Add_Test_Object_/","",$name);
599 $name = preg_replace("/_(x|y)$/","",$name);
601 $test_types_to_add = array(
602 "address" =>_("Address"),
603 "header" =>_("Header"),
604 "envelope"=>_("Envelope"),
605 "size" =>_("Size"),
606 "exists" =>_("Exists"),
607 "allof" =>_("All of"),
608 "anyof" =>_("Any of"),
609 "true" =>_("True"),
610 "false" =>_("False"));
612 $smarty = get_smarty();
613 $smarty->assign("ID",$name);
614 $smarty->assign("test_types_to_add",$test_types_to_add);
615 $ret = $smarty->fetch(get_template_path("templates/select_test_type.tpl",TRUE,dirname(__FILE__)));
616 return($ret);
617 }
618 }
620 $current = $this->scripts[$this->current_script];
622 /* Create html results */
623 $smarty = get_smarty();
624 $smarty->assign("Mode",$current['MODE']);
625 if($current['MODE'] == "Structured"){
626 $smarty->assign("Contents",$this->current_handler->tree_->execute());
627 }else{
628 $smarty->assign("Contents",$current['SCRIPT']);
629 }
630 $smarty->assign("Script_Error",$this->Script_Error);
631 $ret = $smarty->fetch(get_template_path("templates/edit_frame_base.tpl",TRUE,dirname(__FILE__)));
632 return($ret);
633 }
636 /* Create list of available sieve scripts
637 */
638 $List = new divSelectBox("sieveManagement");
639 foreach($this->scripts as $key => $script){
641 $edited = $script['EDITED'];
642 $active = $script['ACTIVE'];
644 $field1 = array("string" => " ",
645 "attach" => "style='width:20px;'");
646 if($active){
647 $field1 = array("string" => "<img src='images/true.png' alt='"._("Active")."'>",
648 "attach" => "style='width:20px;'");
649 }
650 $field2 = array("string" => $script['NAME']);
651 $field3 = array("string" => $script['MSG']);
652 $field4 = array("string" => _("Script length")." : ".strlen($script['SCRIPT']));
654 if($edited){
655 $field5 = array("string" => "<img src='images/fai_new_hook.png' alt='"._("Edited")."'>",
656 "attach" => "style='width:30px;'");
657 }else{
658 $field5 = array("string" => "",
659 "attach" => "style='width:30px;'");
660 }
662 if($active){
663 $field6 = array("string" => "<img src='images/empty.png' alt=' '>".
664 "<input type='image' name='editscript_".$key."' src='images/edit.png'>".
665 "<input type='image' name='delscript_".$key."' src='images/edittrash.png'>");
666 }else{
667 $field6 = array("string" => "<input type='image' name='active_script_".$key."' src='images/true.png'>".
668 "<input type='image' name='editscript_".$key."' src='images/edit.png'>".
669 "<input type='image' name='delscript_".$key."' src='images/edittrash.png'>");
670 }
671 $List ->AddEntry(array($field1,$field2,$field3,$field4,$field5,$field6));
672 }
674 $display ="<h2>Sieve script management</h2>";
675 $display .= _("Be careful. All your changes will be saved directly to sieve, if you use the save button below.");
676 $display .= "<br><input type='submit' name='create_new_script' value='"._("Create new script")."'>";
677 $display .= $List->DrawList();
679 $display .= "<p style=\"text-align:right\">\n";
680 $display .= "<input type=submit name=\"sieve_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
681 $display .= " \n";
682 $display .= "<input type=submit name=\"sieve_cancel\" value=\""._("Cancel")."\">\n";
683 $display .= "</p>";
684 return($display);;
685 }
687 function save_object()
688 {
689 if($this->current_handler){
691 /* Check if there is an add object requested
692 */
693 $data = $this->current_handler->tree_->pap;
694 $once = TRUE;
695 foreach($_POST as $name => $value){
696 foreach($data as $key => $obj){
697 if(isset($obj->object_id) && preg_match("/^Add_Object_Top_".$obj->object_id."_/",$name) && $once){
698 $once = FALSE;
699 $this->add_new_element = TRUE;
700 $this->add_new_id = $obj->object_id;
701 $this->add_above_below = "above";
702 }
703 if(isset($obj->object_id) && preg_match("/^Add_Object_Bottom_".$obj->object_id."_/",$name) && $once){
704 $once = FALSE;
705 $this->add_new_element = TRUE;
706 $this->add_new_id = $obj->object_id;
707 $this->add_above_below = "below";
708 }
710 if(isset($obj->object_id) && preg_match("/^Remove_Object_".$obj->object_id."_/",$name) && $once){
711 $once = FALSE;
712 $this->current_handler->tree_->remove_object($key);
713 }
714 if(isset($obj->object_id) && preg_match("/^Move_Up_Object_".$obj->object_id."_/",$name) && $once){
715 $this->current_handler->tree_->move_up_down($key,"up");
716 $once = FALSE;
717 }
718 if(isset($obj->object_id) && preg_match("/^Move_Down_Object_".$obj->object_id."_/",$name) && $once){
719 $this->current_handler->tree_->move_up_down($key,"down");
720 $once = FALSE;
721 }
722 }
723 }
725 /* Skip Mode changes and Parse tests
726 * if we are currently in a subdialog
727 */
729 $Mode = $this->scripts[$this->current_script]['MODE'];
730 $skip_mode_change = false;
731 if(in_array($Mode,array("Source-Only","Source"))){
732 if(isset($_POST['script_contents'])){
733 $sc = stripslashes($_POST['script_contents']);
734 $this->scripts[$this->current_script]['SCRIPT'] = $sc;
735 $p = new My_Parser;
736 if($p -> parse($sc)){
737 $this->Script_Error = "";
738 } else {
739 $this->Script_Error = $p->status_text;
740 $skip_mode_change = TRUE;
741 }
742 }
743 }
744 if(in_array($Mode,array("Structured"))){
745 $sc = $this->current_handler->get_sieve_script();
746 $this->scripts[$this->current_script]['SCRIPT'] = $sc;
747 $p = new My_Parser;
748 if($p -> parse($sc)){
749 $this->Script_Error = "";
750 } else {
751 $this->Script_Error = $p->status_text;
752 $skip_mode_change = TRUE;
753 }
754 }
755 if(!$skip_mode_change){
756 if($this->scripts[$this->current_script]['MODE'] != "Source-Only"){
757 $old_mode = $this->scripts[$this->current_script]['MODE'];
758 if(isset($_POST['View_Source'])){
759 $this->scripts[$this->current_script]['MODE'] = "Source";
760 }
761 if(isset($_POST['View_Structured'])){
762 $this->scripts[$this->current_script]['MODE'] = "Structured";
763 }
764 $new_mode = $this->scripts[$this->current_script]['MODE'];
766 if($old_mode != $new_mode){
768 $sc = $this->scripts[$this->current_script]['SCRIPT'];
769 $p = new My_Parser;
771 if($p -> parse($sc)){
772 $this->current_handler->parse($sc);
773 $this->Script_Error = "";
774 } else {
775 $this->Script_Error = $p->status_text;
776 }
777 }
778 }
779 }
780 $this->current_handler->save_object();
781 }
782 }
785 function save()
786 {
787 /* Connect to sieve class and try to get all available sieve scripts */
788 $cfg= $this->config->data['SERVERS']['IMAP'][$this->parent->gosaMailServer];
790 $this->sieve_handle=
791 new sieve( $cfg["sieve_server"],
792 $cfg["sieve_port"],
793 $this->parent->mail,
794 $cfg["password"],
795 $cfg["admin"]);
797 if (!$this->sieve_handle->sieve_login()){
798 print_red(sprintf(_("Can't log into SIEVE server. Server says '%s'."),to_string($this->sieve_handle->error_raw)));
799 return;
800 }
802 $everything_went_fine = TRUE;
804 foreach($this->scripts as $key => $script){
805 if($script['EDITED']){
806 $data = $this->scripts[$key]['SCRIPT'];
807 if(!$this->sieve_handle->sieve_sendscript($script['NAME'], $data)){
808 gosa_log("Failed to save sieve script named '".$script['NAME']."': ".to_string($this->sieve_handle->error_raw));
809 $everything_went_fine = FALSE;
810 print_red(to_string($this->sieve_handle->error_raw));
811 $this->scripts[$key]['MSG'] = "<font color='red'>".
812 _("Failed to save sieve script").": ".
813 to_string($this->sieve_handle->error_raw).
814 "</font>";
815 }
816 }
817 }
818 return($everything_went_fine);
819 }
820 }
821 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
822 ?>