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";
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;
493 $data = $this->current_handler->tree_->pap;
495 /* Get index of the element identified by object_id == $this->add_new_id; */
496 $index = -1;
497 foreach($data as $key => $obj){
498 if($obj->object_id == $this->add_new_id && $index==-1){
499 $index = $key;
500 }
501 }
503 /* We have found the specified object_id
504 * and want to detect the next free position
505 * to insert the new element.
506 */
507 if($index != -1){
508 if($this->add_above_below == "above"){
509 $direction ="up";
510 $next_free = $this->current_handler->tree_->_get_next_free_move_slot($index,$direction);
511 $next_free ++;
512 }else{
513 $direction = "down";
514 $next_free = $this->current_handler->tree_->_get_next_free_move_slot($index,$direction);
515 }
516 $this->add_new_id = $this->current_handler->tree_->pap[$next_free]->object_id;
517 }
519 /* Create elements we should add */
520 $ele[] = new $this->add_element_type(NULL, preg_replace("/[^0-9]/","",microtime()));
521 if($this->add_element_type == "sieve_if"){
522 $ele[] = new sieve_block_start(NULL,preg_replace("/[^0-9]/","",microtime()));
523 $ele[] = new sieve_block_end(NULL,preg_replace("/[^0-9]/","",microtime()));
524 }
525 $start = $end = array();
526 $found = false;
528 /* Add above current element*/
529 if($this->add_above_below == "above"){
530 foreach($data as $key => $obj){
531 if($obj->object_id == $this->add_new_id){
532 $found = true;
533 }
534 if(!$found){
535 $start[] = $obj;
536 }else{
537 $end[] = $obj;
538 }
539 }
540 }else{
541 /* Add below current element */
542 foreach($data as $key => $obj){
543 if(!$found){
544 $start[] = $obj;
545 }else{
546 $end[] = $obj;
547 }
548 if($obj->object_id == $this->add_new_id){
549 $found = true;
550 }
551 }
552 }
555 /* Only add, if current element could be located */
556 if($found){
557 $new = array();
558 foreach($start as $obj){
559 $new[] = $obj;
560 }
561 foreach($ele as $el){
562 $new[] = $el;
563 }
564 foreach($end as $obj){
565 $new[] = $obj;
566 }
567 $data= $new;
568 $this->current_handler->tree_->pap = $data;
569 $this->add_new_element = FALSE;
570 }else{
571 print_red(_("Something went wrong while adding a new entry."));
572 }
573 }
574 }
576 /* Only display select dialog if it is necessary */
577 if($this->add_new_element){
578 $smarty = get_smarty();
579 $smarty->assign("element_types",$element_types );
580 $smarty->assign("element_type",$this->add_element_type);
581 $str = $smarty->fetch(get_template_path("templates/add_element.tpl",TRUE,dirname(__FILE__)));
582 return($str);
583 }
587 /****************
588 * Handle test posts
589 ****************/
591 /* handle some special posts from test elements
592 */
593 foreach($_POST as $name => $value){
594 if(preg_match("/^Add_Test_Object_/",$name)) {
595 $name = preg_replace("/^Add_Test_Object_/","",$name);
596 $name = preg_replace("/_(x|y)$/","",$name);
598 $test_types_to_add = array(
599 "address" =>_("Address"),
600 "header" =>_("Header"),
601 "envelope"=>_("Envelope"),
602 "size" =>_("Size"),
603 "exists" =>_("Exists"),
604 "allof" =>_("All of"),
605 "anyof" =>_("Any of"),
606 "true" =>_("True"),
607 "false" =>_("False"));
609 $smarty = get_smarty();
610 $smarty->assign("ID",$name);
611 $smarty->assign("test_types_to_add",$test_types_to_add);
612 $ret = $smarty->fetch(get_template_path("templates/select_test_type.tpl",TRUE,dirname(__FILE__)));
613 return($ret);
614 }
615 }
617 $current = $this->scripts[$this->current_script];
619 /* Create html results */
620 $smarty = get_smarty();
621 $smarty->assign("Mode",$current['MODE']);
622 if($current['MODE'] == "Structured"){
623 $smarty->assign("Contents",$this->current_handler->tree_->execute());
624 }else{
625 $smarty->assign("Contents",$current['SCRIPT']);
626 }
627 $smarty->assign("Script_Error",$this->Script_Error);
628 $ret = $smarty->fetch(get_template_path("templates/edit_frame_base.tpl",TRUE,dirname(__FILE__)));
629 return($ret);
630 }
633 /* Create list of available sieve scripts
634 */
635 $List = new divSelectBox("sieveManagement");
636 foreach($this->scripts as $key => $script){
638 $edited = $script['EDITED'];
639 $active = $script['ACTIVE'];
641 $field1 = array("string" => " ",
642 "attach" => "style='width:20px;'");
643 if($active){
644 $field1 = array("string" => "<img src='images/true.png' alt='"._("Active")."'>",
645 "attach" => "style='width:20px;'");
646 }
647 $field2 = array("string" => $script['NAME']);
648 $field3 = array("string" => $script['MSG']);
649 $field4 = array("string" => _("Script length")." : ".strlen($script['SCRIPT']));
651 if($edited){
652 $field5 = array("string" => "<img src='images/fai_new_hook.png' alt='"._("Edited")."'>",
653 "attach" => "style='width:30px;'");
654 }else{
655 $field5 = array("string" => "",
656 "attach" => "style='width:30px;'");
657 }
659 if($active){
660 $field6 = array("string" => "<img src='images/empty.png' alt=' '>".
661 "<input type='image' name='editscript_".$key."' src='images/edit.png'>".
662 "<input type='image' name='delscript_".$key."' src='images/edittrash.png'>");
663 }else{
664 $field6 = array("string" => "<input type='image' name='active_script_".$key."' src='images/true.png'>".
665 "<input type='image' name='editscript_".$key."' src='images/edit.png'>".
666 "<input type='image' name='delscript_".$key."' src='images/edittrash.png'>");
667 }
668 $List ->AddEntry(array($field1,$field2,$field3,$field4,$field5,$field6));
669 }
671 $display ="<h2>Sieve script management</h2>";
672 $display .= _("Be careful. All your changes will be saved directly to sieve, if you use the save button below.");
673 $display .= "<br><input type='submit' name='create_new_script' value='"._("Create new script")."'>";
674 $display .= $List->DrawList();
676 $display .= "<p style=\"text-align:right\">\n";
677 $display .= "<input type=submit name=\"sieve_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
678 $display .= " \n";
679 $display .= "<input type=submit name=\"sieve_cancel\" value=\""._("Cancel")."\">\n";
680 $display .= "</p>";
681 return($display);;
682 }
684 function save_object()
685 {
686 if($this->current_handler){
688 /* Check if there is an add object requested
689 */
690 $data = $this->current_handler->tree_->pap;
691 $once = TRUE;
692 foreach($_POST as $name => $value){
693 foreach($data as $key => $obj){
694 if(isset($obj->object_id) && preg_match("/^Add_Object_Top_".$obj->object_id."_/",$name) && $once){
695 $once = FALSE;
696 $this->add_new_element = TRUE;
697 $this->add_new_id = $obj->object_id;
698 $this->add_above_below = "above";
699 }
700 if(isset($obj->object_id) && preg_match("/^Add_Object_Bottom_".$obj->object_id."_/",$name) && $once){
701 $once = FALSE;
702 $this->add_new_element = TRUE;
703 $this->add_new_id = $obj->object_id;
704 $this->add_above_below = "below";
705 }
707 if(isset($obj->object_id) && preg_match("/^Remove_Object_".$obj->object_id."_/",$name) && $once){
708 $once = FALSE;
709 $this->current_handler->tree_->remove_object($key);
710 }
711 if(isset($obj->object_id) && preg_match("/^Move_Up_Object_".$obj->object_id."_/",$name) && $once){
712 $this->current_handler->tree_->move_up_down($key,"up");
713 $once = FALSE;
714 }
715 if(isset($obj->object_id) && preg_match("/^Move_Down_Object_".$obj->object_id."_/",$name) && $once){
716 $this->current_handler->tree_->move_up_down($key,"down");
717 $once = FALSE;
718 }
719 }
720 }
722 /* Skip Mode changes and Parse tests
723 * if we are currently in a subdialog
724 */
726 $this->current_handler->save_object();
727 $Mode = $this->scripts[$this->current_script]['MODE'];
728 $skip_mode_change = false;
729 if(in_array($Mode,array("Source-Only","Source"))){
730 if(isset($_POST['script_contents'])){
731 $sc = stripslashes($_POST['script_contents']);
732 $this->scripts[$this->current_script]['SCRIPT'] = $sc;
733 $p = new My_Parser;
734 if($p -> parse($sc)){
735 $this->Script_Error = "";
736 } else {
737 $this->Script_Error = $p->status_text;
738 $skip_mode_change = TRUE;
739 }
740 }
741 }
742 if(in_array($Mode,array("Structured"))){
743 $sc = $this->current_handler->get_sieve_script();
744 $this->scripts[$this->current_script]['SCRIPT'] = $sc;
745 $p = new My_Parser;
746 if($p -> parse($sc)){
747 $this->Script_Error = "";
748 } else {
749 $this->Script_Error = $p->status_text;
750 $skip_mode_change = TRUE;
751 }
752 }
753 if(!$skip_mode_change){
754 if($this->scripts[$this->current_script]['MODE'] != "Source-Only"){
755 $old_mode = $this->scripts[$this->current_script]['MODE'];
756 if(isset($_POST['View_Source'])){
757 $this->scripts[$this->current_script]['MODE'] = "Source";
758 }
759 if(isset($_POST['View_Structured'])){
760 $this->scripts[$this->current_script]['MODE'] = "Structured";
761 }
762 $new_mode = $this->scripts[$this->current_script]['MODE'];
764 if($old_mode != $new_mode){
766 $sc = $this->scripts[$this->current_script]['SCRIPT'];
767 $p = new My_Parser;
769 if($p -> parse($sc)){
770 $this->current_handler->parse($sc);
771 $this->Script_Error = "";
772 } else {
773 $this->Script_Error = $p->status_text;
774 }
775 }
776 }
777 }
778 }
779 }
782 function save()
783 {
784 /* Connect to sieve class and try to get all available sieve scripts */
785 $cfg= $this->config->data['SERVERS']['IMAP'][$this->parent->gosaMailServer];
787 $this->sieve_handle=
788 new sieve( $cfg["sieve_server"],
789 $cfg["sieve_port"],
790 $this->parent->mail,
791 $cfg["password"],
792 $cfg["admin"]);
794 if (!$this->sieve_handle->sieve_login()){
795 print_red(sprintf(_("Can't log into SIEVE server. Server says '%s'."),to_string($this->sieve_handle->error_raw)));
796 return;
797 }
799 $everything_went_fine = TRUE;
801 foreach($this->scripts as $key => $script){
802 if($script['EDITED']){
803 $data = $this->scripts[$key]['SCRIPT'];
804 if(!$this->sieve_handle->sieve_sendscript($script['NAME'], $data)){
805 gosa_log("Failed to save sieve script named '".$script['NAME']."': ".to_string($this->sieve_handle->error_raw));
806 $everything_went_fine = FALSE;
807 print_red(to_string($this->sieve_handle->error_raw));
808 $this->scripts[$key]['MSG'] = "<font color='red'>".
809 _("Failed to save sieve script").": ".
810 to_string($this->sieve_handle->error_raw).
811 "</font>";
812 }
813 }
814 }
815 return($everything_went_fine);
816 }
817 }
818 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
819 ?>