6ac66371ca6fca283c5b7971a0a38611744dcbb1
1 <?php
3 class sieve_fileinto
4 {
5 var $data = "";
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 /* Load element contents, should normaly be only one string
50 * but if we found more than one, just append the following strings.
51 */
52 foreach($data['ELEMENTS'] as $key => $node ){
53 if(in_array($node['class'],array("quoted-string","text"))){
54 $tmp = sieve_get_strings($data['ELEMENTS'],$key);
55 if(count($tmp['STRINGS'])){
56 foreach($tmp['STRINGS'] as $str){
57 $this->data.= $str;
58 }
59 }
60 }
61 }
63 /* Set user mode to active, so we are able to insert
64 * the destination mail folder manually
65 */
66 if(!in_array_ics($this->data,$mbs)){
67 $this->user_mode = TRUE;
68 }
69 }
71 function get_sieve_script_part()
72 {
73 $tmp = "";
74 $tmp.= "\"".$this->data."\", ";
75 $tmp = preg_replace("/,$/","",trim($tmp));
76 $tmp = preg_replace ("/\"\"/","\"",$tmp);
77 return("fileinto ".$tmp.";");
78 }
80 function execute()
81 {
82 $smarty = get_smarty();
83 $smarty->assign("Selected",htmlentities($this->data));
84 $smarty->assign("Boxes", $this->get_mail_boxes());
85 $smarty->assign("User_Mode", $this->user_mode);
86 $smarty->assign("ID", $this->object_id);
87 $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__)));
88 $object= $smarty->fetch(get_template_path("templates/element_fileinto.tpl",TRUE,dirname(__FILE__)));
89 $str = preg_replace("/%%OBJECT_CONTENT%%/",addcslashes($object,"\\"),$object_container);
91 return($str);
92 }
94 function check()
95 {
96 return(array());
97 }
99 function get_mail_boxes()
100 {
101 $list = $this->parent->parent->parent->parent->mailboxList;
102 return($list);
103 }
104 }
106 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
107 ?>