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 $next_free = $this->current_handler->tree_->_get_next_free_move_slot($index,$direction);
515 $direction = "down";
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 if($obj->object_id == $this->add_new_id){
550 $found = true;
551 }
552 }
553 }
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 print_red(_("Something went wrong while adding a new entry."));
571 }
572 }
573 }
575 /* Only display select dialog if it is necessary */
576 if($this->add_new_element){
577 $smarty = get_smarty();
578 $smarty->assign("element_types",$element_types );
579 $smarty->assign("element_type",$this->add_element_type);
580 $str = $smarty->fetch(get_template_path("templates/add_element.tpl",TRUE,dirname(__FILE__)));
581 return($str);
582 }
586 /****************
587 * Handle test posts
588 ****************/
590 /* handle some special posts from test elements
591 */
592 foreach($_POST as $name => $value){
593 if(preg_match("/^Add_Test_Object_/",$name)) {
594 $name = preg_replace("/^Add_Test_Object_/","",$name);
595 $name = preg_replace("/_(x|y)$/","",$name);
597 $test_types_to_add = array(
598 "address" =>_("Address"),
599 "header" =>_("Header"),
600 "envelope"=>_("Envelope"),
601 "size" =>_("Size"),
602 "exists" =>_("Exists"),
603 "allof" =>_("All of"),
604 "anyof" =>_("Any of"),
605 "true" =>_("True"),
606 "false" =>_("False"));
608 $smarty = get_smarty();
609 $smarty->assign("ID",$name);
610 $smarty->assign("test_types_to_add",$test_types_to_add);
611 $ret = $smarty->fetch(get_template_path("templates/select_test_type.tpl",TRUE,dirname(__FILE__)));
612 return($ret);
613 }
614 }
616 $current = $this->scripts[$this->current_script];
618 /* Create html results */
619 $smarty = get_smarty();
620 $smarty->assign("Mode",$current['MODE']);
621 if($current['MODE'] == "Structured"){
622 $smarty->assign("Contents",$this->current_handler->tree_->execute());
623 }else{
624 $smarty->assign("Contents",$current['SCRIPT']);
625 }
626 $smarty->assign("Script_Error",$this->Script_Error);
627 $ret = $smarty->fetch(get_template_path("templates/edit_frame_base.tpl",TRUE,dirname(__FILE__)));
628 return($ret);
629 }
632 /* Create list of available sieve scripts
633 */
634 $List = new divSelectBox("sieveManagement");
635 foreach($this->scripts as $key => $script){
637 $edited = $script['EDITED'];
638 $active = $script['ACTIVE'];
640 $field1 = array("string" => " ",
641 "attach" => "style='width:20px;'");
642 if($active){
643 $field1 = array("string" => "<img src='images/true.png' alt='"._("Active")."'>",
644 "attach" => "style='width:20px;'");
645 }
646 $field2 = array("string" => $script['NAME']);
647 $field3 = array("string" => $script['MSG']);
648 $field4 = array("string" => _("Script length")." : ".strlen($script['SCRIPT']));
650 if($edited){
651 $field5 = array("string" => "<img src='images/fai_new_hook.png' alt='"._("Edited")."'>",
652 "attach" => "style='width:30px;'");
653 }else{
654 $field5 = array("string" => "",
655 "attach" => "style='width:30px;'");
656 }
658 if($active){
659 $field6 = array("string" => "<img src='images/empty.png' alt=' '>".
660 "<input type='image' name='editscript_".$key."' src='images/edit.png'>".
661 "<input type='image' name='delscript_".$key."' src='images/edittrash.png'>");
662 }else{
663 $field6 = array("string" => "<input type='image' name='active_script_".$key."' src='images/true.png'>".
664 "<input type='image' name='editscript_".$key."' src='images/edit.png'>".
665 "<input type='image' name='delscript_".$key."' src='images/edittrash.png'>");
666 }
667 $List ->AddEntry(array($field1,$field2,$field3,$field4,$field5,$field6));
668 }
670 $display ="<h2>Sieve script management</h2>";
671 $display .= _("Be careful. All your changes will be saved directly to sieve, if you use the save button below.");
672 $display .= "<br><input type='submit' name='create_new_script' value='"._("Create new script")."'>";
673 $display .= $List->DrawList();
675 $display .= "<p style=\"text-align:right\">\n";
676 $display .= "<input type=submit name=\"sieve_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
677 $display .= " \n";
678 $display .= "<input type=submit name=\"sieve_cancel\" value=\""._("Cancel")."\">\n";
679 $display .= "</p>";
680 return($display);;
681 }
683 function save_object()
684 {
685 if($this->current_handler){
687 /* Check if there is an add object requested
688 */
689 $data = $this->current_handler->tree_->pap;
690 $once = TRUE;
691 foreach($_POST as $name => $value){
692 foreach($data as $key => $obj){
693 if(isset($obj->object_id) && preg_match("/^Add_Object_Top_".$obj->object_id."_/",$name) && $once){
694 $once = FALSE;
695 $this->add_new_element = TRUE;
696 $this->add_new_id = $obj->object_id;
697 $this->add_above_below = "above";
698 }
699 if(isset($obj->object_id) && preg_match("/^Add_Object_Bottom_".$obj->object_id."_/",$name) && $once){
700 $once = FALSE;
701 $this->add_new_element = TRUE;
702 $this->add_new_id = $obj->object_id;
703 $this->add_above_below = "below";
704 }
706 if(isset($obj->object_id) && preg_match("/^Remove_Object_".$obj->object_id."_/",$name) && $once){
707 $once = FALSE;
708 $this->current_handler->tree_->remove_object($key);
709 }
710 if(isset($obj->object_id) && preg_match("/^Move_Up_Object_".$obj->object_id."_/",$name) && $once){
711 $this->current_handler->tree_->move_up_down($key,"up");
712 $once = FALSE;
713 }
714 if(isset($obj->object_id) && preg_match("/^Move_Down_Object_".$obj->object_id."_/",$name) && $once){
715 $this->current_handler->tree_->move_up_down($key,"down");
716 $once = FALSE;
717 }
718 }
719 }
721 /* Skip Mode changes and Parse tests
722 * if we are currently in a subdialog
723 */
724 if(1==1 || !$this->add_new_element && !isset($_POST['Save_Copy']) && !$this->Import_Script &&!isset($_POST['add_type'])) {
728 $Mode = $this->scripts[$this->current_script]['MODE'];
729 $skip_mode_change = false;
730 if(in_array($Mode,array("Source-Only","Source"))){
731 if(isset($_POST['script_contents'])){
732 $sc = stripslashes($_POST['script_contents']);
733 $this->scripts[$this->current_script]['SCRIPT'] = $sc;
734 $p = new My_Parser;
735 if($p -> parse($sc)){
736 # $this->current_handler = $p;
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 $this->current_handler->save_object();
746 $sc = $this->current_handler->get_sieve_script();
747 $this->scripts[$this->current_script]['SCRIPT'] = $sc;
748 $p = new My_Parser;
749 if($p -> parse($sc)){
750 # $this->current_handler = $p;
751 $this->Script_Error = "";
752 } else {
753 $this->Script_Error = $p->status_text;
754 $skip_mode_change = TRUE;
755 }
756 }
757 if(!$skip_mode_change){
758 if($this->scripts[$this->current_script]['MODE'] != "Source-Only"){
759 if(isset($_POST['View_Source'])){
760 $this->scripts[$this->current_script]['MODE'] = "Source";
761 }
762 if(isset($_POST['View_Structured'])){
763 $this->scripts[$this->current_script]['MODE'] = "Structured";
764 }
765 }
766 }
767 }
768 $this->current_handler->save_object();
769 }
770 }
773 function save()
774 {
775 /* Connect to sieve class and try to get all available sieve scripts */
776 $cfg= $this->config->data['SERVERS']['IMAP'][$this->parent->gosaMailServer];
778 $this->sieve_handle=
779 new sieve( $cfg["sieve_server"],
780 $cfg["sieve_port"],
781 $this->parent->mail,
782 $cfg["password"],
783 $cfg["admin"]);
785 if (!$this->sieve_handle->sieve_login()){
786 print_red(sprintf(_("Can't log into SIEVE server. Server says '%s'."),to_string($this->sieve_handle->error_raw)));
787 return;
788 }
790 $everything_went_fine = TRUE;
792 foreach($this->scripts as $key => $script){
793 if($script['EDITED']){
794 $data = $this->scripts[$key]['SCRIPT'];
795 if(!$this->sieve_handle->sieve_sendscript($script['NAME'], $data)){
796 gosa_log("Failed to save sieve script named '".$script['NAME']."': ".to_string($this->sieve_handle->error_raw));
797 $everything_went_fine = FALSE;
798 print_red(to_string($this->sieve_handle->error_raw));
799 $this->scripts[$key]['MSG'] = "<font color='red'>".
800 _("Failed to save sieve script").": ".
801 to_string($this->sieve_handle->error_raw).
802 "</font>";
803 }
804 }
805 }
806 return($everything_went_fine);
807 }
808 }
809 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
810 ?>