1 <?php
3 class sieve_fileinto
4 {
5 var $data = array();
6 var $object_id= -1;
7 var $options = array();
8 var $parent = NULL;
9 var $user_mode= FALSE;
11 function save_object()
12 {
13 $mbs = $this->get_mail_boxes();
15 if(isset($_POST['fileinto_'.$this->object_id])){
16 $mb = $_POST['fileinto_'.$this->object_id];
19 /* Depending on the user mode we only accept
20 * existing mailboxes
21 */
22 if($this->user_mode){
23 $this->data = $mb;
24 }else{
25 if(in_array_ics($mb,$mbs)){
26 $this->data = $mb;
27 }
28 }
30 /* Check Mode */
31 if(isset($_POST['user_mode_'.$this->object_id])){
32 $this->user_mode = !$this->user_mode;
33 }
34 }
35 }
37 function sieve_fileinto($data,$object_id,$parent)
38 {
39 $this->object_id = $object_id;
40 $this->parent = $parent;
41 $this->parent->add_require("fileinto");
43 $mbs = $this->get_mail_boxes();
45 /* Set the default mailbox */
46 if($data == NULL){
47 $data = array('ELEMENTS' => array(array('class' => "quoted-string" ,"text" => $mbs[key($mbs)])));
48 }
50 /* Set mailbox */
51 foreach($data['ELEMENTS'] as $node ){
52 if(in_array($node['class'],array("quoted-string","text"))){
53 $this->data = preg_replace("/\"/","",$node['text']);
54 }
55 }
57 /* Set user mode to active, so we are able to insert
58 * the destination mail folder manually
59 */
60 if(!in_array_ics($this->data,$mbs)){
61 $this->user_mode = TRUE;
62 }
63 }
65 function get_sieve_script_part()
66 {
67 $tmp = "";
68 $tmp.= "\"".$this->data."\", ";
69 $tmp = preg_replace("/,$/","",trim($tmp));
70 $tmp = preg_replace ("/\"\"/","\"",$tmp);
71 return("fileinto ".$tmp.";");
72 }
74 function execute()
75 {
76 $smarty = get_smarty();
77 $smarty->assign("Selected",$this->data);
78 $smarty->assign("Boxes", $this->get_mail_boxes());
79 $smarty->assign("User_Mode", $this->user_mode);
80 $smarty->assign("ID", $this->object_id);
81 $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__)));
82 $object= $smarty->fetch(get_template_path("templates/element_fileinto.tpl",TRUE,dirname(__FILE__)));
83 $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container);
85 return($str);
86 }
88 function check()
89 {
90 return(array());
91 }
93 function get_mail_boxes()
94 {
95 $list = $this->parent->parent->parent->parent->mailboxList;
96 return($list);
97 }
98 }
100 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
101 ?>