Code

New sieve filter, not yet finished.
[gosa.git] / include / sieve / class_sieveElements.inc
1 <?php
4 class sieve_element
5 {
7   function execute()
8   {
9     return("NIY<br>");
10   }
11 }
13 class sieve_elsif extends sieve_if {}
14 class sieve_if extends sieve_element
15 {
17   /* Contains all tests with an uniqe id */
18   var $test_list = array();
19       
20   /* Available test types */
21   var $TESTS = array("address","allof","anyof","exists","false","header","not","size","true","envelope");
22   
23   var $elements = array();
26   function sieve_if($elements)
27   {
28     $this->elements = $elements;
29     $this->_parse($elements);
30   }
32   function execute()
33   {
34     return("-> "._("Condition"));
35   }
38   function _parse($data,$id = 0)
39   {
40     /* Objects that could be tested */
41     $av_methods   = array("address","allof","anyof","exists","false","header","not","size","true","envelope");
43     /* Tests that could be used */
44     $av_match_type= array(":is",":contains",":matches",":over",":count",":value");
46     /* Variable initialization */
47     $test_method    = ""; // The object that we want to test, like 'header'
48     $match_type     = ""; // The operator like :contains
49     $obj_attribute  = ""; // The attribute we want to check, like 'from'
50     $obj_match_value= ""; // The value that we want to match for.
51     $comparator     = ""; // The comperator specifies the type of values that should be matched.
53     $node = $data['ELEMENTS'][$id];
55     /* Skip the if / else identifier */
56     if($node ['class'] == "identifier" && in_array($node['text'],array("if","elsif"))){
57       $id ++;
58       $node = $data['ELEMENTS'][$id];
59     }
61     /* Get current command like "allof" or "header" */
62     if($node ['class'] == "identifier" && in_array($node['text'],$av_methods)){
63       $test_method = $node['text'];
64     }
66     echo $id;
68     /* switch different types */
69     switch($test_method)
70     {
71       case "allof"  : $this->_parse($elements,$id);
72       case "anyof"  : $this->_parse($elements,$id);
74       case "address" : 
75       {
76         /* header :comparator <string> :optional-operator :operator attribute match-value */
77         $tmp = array();
78         $tmp['OPTIONAL_OP']     ="";
79         $tmp['COMPARATOR']      ="";
80         $tmp['OPERATOR']        ="";
81         $tmp['ATTRIBUTE']       ="";
82         $tmp['MATCH-VALUE']     ="";
83         
85       }
86       default : echo $test_method."<br>" ;
87     }
88   }
89 };
92 class sieve_comment extends sieve_element
93 {
94   var $data = "";
95  
96     
97   function sieve_comment($data)
98   {
99     foreach($data['ELEMENTS'] as $node){
100        $this->data .= $node['text'];
101     }
102   }
104   function execute()
105   {
106     return(_("Comment")."&nbsp;<input type='text' name='comment_' value='".$this->data."'>");
107   }
111 class sieve_require extends sieve_element
113   var $data = array();
115   function sieve_require($data)
116   {
117     foreach($data['ELEMENTS'] as $node ){
118       if(in_array($node['class'],array("quoted-string","text"))){
119         $this->data[] = preg_replace("/\"/","",$node['text']);
120       }
121     }
122   }
124   function execute()
125   {
126     $str = _("Sieve includes");
127     foreach($this->data as $req){
128       $str .= "&nbsp;<i>".$req."</i>";
129     }
130     return($str);
131   }
134 class sieve_discard extends sieve_element
136   var $data = array();
138   function sieve_discard($data)
139   {
140   }
142   function execute()
143   {
144     $str = _("Discard mail");
145     return($str);
146   }
151 class sieve_reject extends sieve_element
153   var $data = array();
155   function sieve_reject($data)
156   {
157     $str = "";
158     foreach($data['ELEMENTS'] as $node ){
159       if(in_array($node['class'],array("quoted-string","text"))){
160         $str .= $node['text'];
161       }
162     }
163     $this->data = preg_replace("/\"/","",$str);
164   }
166   function execute()
167   {
168     $str = _("Reject mail");
169     $str .= "&nbsp;<textarea name='test' style='width:90%'>".$this->data."</textarea>";
170     return($str);
171   }
174 class sieve_redirect extends sieve_element
176   var $data = array();
178   function sieve_redirect($data)
179   {
180     foreach($data['ELEMENTS'] as $node ){
181       if(in_array($node['class'],array("quoted-string","text"))){
182         $this->data[] = $node['text'];
183       }
184     }
185   }
187   function execute()
188   {
189     $str = _("Redirect to");
190     foreach($this->data as $dest){
191       $str .= "<input type='text' name='bal' value='".$dest."'><br> ";
192     }
193     return($str);
194   }
197 class sieve_fileinto extends sieve_element
199   var $data = array();
201   function sieve_fileinto($data)
202   {
203     foreach($data['ELEMENTS'] as $node ){
204       if(in_array($node['class'],array("quoted-string","text"))){
205         $this->data[] = preg_replace("/\"/","",$node['text']);
206       }
207     }
208   }
210   function execute()
211   {
212     $str = _("File into");
214     $str .= "<select name='test'>";
215     foreach($this->data as $folder){
216       $str .= "<option>".$folder."</option>";
217     }
218     $str .= "</select>";
220     return($str);
221   }
224 class sieve_vacation extends sieve_element 
226   var $days     = FALSE;
227   var $subject  = FALSE;
228   var $from     = "";
229   var $mime     = "";
230   var $hanlde   = "";
231   var $reason   = "";
232   var $addresses= array();
234   function sieve_vacation($data)
235   {
236     /* Usage:   vacation [":days" number] [":subject" string]
237        [":from" string] [":addresses" string-list]
238        [":mime"] [":handle" string] <reason: string> */
240     /* Not all attribute types are supported by the sieve class right now */
241     $known_attrs = array(":days",":subject",":from",":mime",":handle");
243     /* Walk through elements */
244     for($i = 0 ; $i < count($data['ELEMENTS']) ; $i ++){
246       /* get current element */
247       $node = $data['ELEMENTS'][$i];
249       /* Check if tag is in the specified list of attributes */
250       if($node['class'] == "tag" && in_array($node['text'],$known_attrs)){
252         $var = preg_replace("/\:/","",$node['text']);
253         $this->$var = $data['ELEMENTS'][$i+1]['text'];
254         $i ++;
255       }
257       /* Check for addresses */
258       if($node['class'] == "tag" && $node['text'] == ":addresses") {
259         $this->addresses = array();
260         $i ++;
262         /* Multiple or single address given */
263         if($data['ELEMENTS'][$i]['class'] == "left-bracket"){
264           while($data['ELEMENTS'][$i]['class'] != "right-bracket" && ($i < count($data['ELEMENTS']))){
265             $i ++;
266             if($data['ELEMENTS'][$i]['class'] == "quoted-string"){
267               $this->addresses[] = preg_replace("/\"/i","",$data['ELEMENTS'][$i]['text']);
268             }
269           }
270         }else{
271           $this->addresses[] = $data['ELEMENTS'][$i]['text'] ;
272         }
273       }
275       /* Add the vacation message */
276       if($node['class'] == "quoted-string"){
277         $this->reason = $node['text'];
278       }
279     }
280   }
283   function execute()
284   {
285     $str ="";
286     $str .="<b>"._("Vacation message")."</b>";
287     foreach($this->addresses as $addr){ 
288       $str .="<br><input type='text' value='".$addr."' style='width:50%;'>";
289     }
290     $str .="<br><textarea style='width:100%;height:60px;'>".$this->reason."</textarea>";
291     
292     return($str);
293   }
296 class sieve_block_start extends sieve_element 
298   function execute()
299   {
300     return("<table width='100%'> <tr><td style='background-color:#BBBBBB;border: solid 2px #FFFFFF;padding-left:20px;'>");
301   }
304 class sieve_block_end extends sieve_element 
306   function execute()
307   {
308     return("</td></tr></table>");
309   }
312 /* This class handles the keep statement */
313 class sieve_keep extends sieve_element 
315   function execute()
316   {
317     return("->  "._("Keep message"));
318   }
320 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
321 ?>