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 = stripslashes($_POST['fileinto_'.$this->object_id]);
18 /* Depending on the user mode we only accept
19 * existing mailboxes
20 */
21 if($this->user_mode){
22 $this->data = $mb;
23 }else{
24 if(in_array_ics($mb,$mbs)){
25 $this->data = $mb;
26 }
27 }
29 /* Check Mode */
30 if(isset($_POST['user_mode_'.$this->object_id])){
31 $this->user_mode = !$this->user_mode;
32 }
33 }
34 }
36 function sieve_fileinto($data,$object_id,$parent)
37 {
38 $this->object_id = $object_id;
39 $this->parent = $parent;
40 $this->parent->add_require("fileinto");
42 $mbs = $this->get_mail_boxes();
44 /* Set the default mailbox */
45 if($data == NULL){
46 $data = array('ELEMENTS' => array(array('class' => "quoted-string" ,"text" => $mbs[key($mbs)])));
47 }
49 /* Set mailbox */
50 foreach($data['ELEMENTS'] as $node ){
51 if(in_array($node['class'],array("quoted-string","text"))){
52 $this->data = preg_replace("/\"/","",$node['text']);
53 }
54 }
56 /* Set user mode to active, so we are able to insert
57 * the destination mail folder manually
58 */
59 if(!in_array_ics($this->data,$mbs)){
60 $this->user_mode = TRUE;
61 }
62 }
64 function get_sieve_script_part()
65 {
66 $tmp = "";
67 $tmp.= "\"".$this->data."\", ";
68 $tmp = preg_replace("/,$/","",trim($tmp));
69 $tmp = preg_replace ("/\"\"/","\"",$tmp);
70 return("fileinto ".$tmp.";");
71 }
73 function execute()
74 {
75 $smarty = get_smarty();
76 $smarty->assign("Selected",htmlentities($this->data));
77 $smarty->assign("Boxes", $this->get_mail_boxes());
78 $smarty->assign("User_Mode", $this->user_mode);
79 $smarty->assign("ID", $this->object_id);
80 $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__)));
81 $object= $smarty->fetch(get_template_path("templates/element_fileinto.tpl",TRUE,dirname(__FILE__)));
82 $str = preg_replace("/%%OBJECT_CONTENT%%/",addcslashes($object,"\\"),$object_container);
84 return($str);
85 }
87 function check()
88 {
89 return(array());
90 }
92 function get_mail_boxes()
93 {
94 $list = $this->parent->parent->parent->parent->mailboxList;
95 return($list);
96 }
97 }
99 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
100 ?>