1 <?php
3 /* Sieve else tag */
4 class sieve_elsif extends sieve_if
5 {
6 var $TYPE = "elsif";
7 }
9 class sieve_else
10 {
11 var $object_id = -1;
13 function sieve_else($data,$object_id)
14 {
15 $this->object_id = $object_id;
16 }
18 function save_object()
19 {
20 }
22 function execute()
23 {
24 $smarty = get_smarty();
25 $smarty->assign("ID", $this->object_id);
26 $object_container = $smarty->fetch(get_template_path("templates/object_container_clear.tpl",TRUE,dirname(__FILE__)));
27 $object= $smarty->fetch(get_template_path("templates/element_else.tpl",TRUE,dirname(__FILE__)));
28 $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container);
29 return($str);
30 }
32 function get_sieve_script_part()
33 {
34 return(" else ");
35 }
36 }
39 /* Sieve comment tag */
40 class sieve_comment
41 {
42 var $data = "";
43 var $object_id= -1;
45 function get_sieve_script_part()
46 {
47 return($this->data."\n");
48 }
50 function sieve_comment($data,$object_id)
51 {
52 $this->object_id = $object_id;
53 foreach($data['ELEMENTS'] as $node){
54 $this->data .= $node['text'];
55 }
56 }
58 function save_object()
59 {
60 if(isset($_POST['comment_'.$this->object_id])){
61 $cm = $_POST['comment_'.$this->object_id];
62 $this->data = "/*".$cm."*/";
63 }
64 }
66 function execute()
67 {
68 $smarty = get_smarty();
69 $smarty->assign("ID", $this->object_id);
70 $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__)));
71 $Comment = $this->data;
73 /* Remove comment tags */
74 if(preg_match("/^#/",$Comment)){
75 $Comment = preg_replace("/^#/","",$Comment);
76 }elseif(preg_match("#\/\*#",$Comment)){
77 $Comment = preg_replace("#^\/\*#","",$Comment);
78 $Comment = preg_replace("#\*\/$#","",$Comment);
79 }
81 /* Create html object */
82 $smarty = get_smarty();
83 $smarty->assign("Comment",$Comment);
84 $smarty->assign("ID",$this->object_id);
85 $object = $smarty->fetch(get_template_path("templates/element_comment.tpl",TRUE,dirname(__FILE__)));
86 $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container);
87 return($str);
88 }
89 }
92 class sieve_require
93 {
94 var $data = array();
95 var $object_id = -1;
97 function sieve_require($data,$object_id)
98 {
99 $this->object_id = $object_id;
100 foreach($data['ELEMENTS'] as $node ){
101 if(in_array($node['class'],array("quoted-string","text"))){
102 $this->data[] = preg_replace("/\"/","",$node['text']);
103 }
104 }
105 }
107 function save_object()
108 {
109 /* Get the values should check for, they are seperated by , */
110 if(isset($_POST['require_'.$this->object_id])){
111 $vls = stripslashes($_POST['require_'.$this->object_id]);
112 $tmp = array();
114 $tmp2 = split(",",$vls);
115 foreach($tmp2 as $val){
116 $tmp[] = "\"".trim(preg_replace("/\"/","",$val))."\"";
117 }
118 $this->data = $tmp;
119 }
120 }
122 function get_sieve_script_part()
123 {
124 $tmp = sieve_create_strings($this->data);
125 return("require ".$tmp.";\n");
126 }
128 function execute()
129 {
130 $Require = "";
131 foreach($this->data as $key){
132 $Require .= $key.", ";
133 }
134 $Require = preg_replace("/,$/","",trim($Require));
136 $smarty = get_smarty();
137 $smarty->assign("Require",$Require);
138 $smarty->assign("ID", $this->object_id);
139 $object_container = $smarty->fetch(get_template_path("templates/object_container_clear.tpl",TRUE,dirname(__FILE__)));
140 $object= $smarty->fetch(get_template_path("templates/element_require.tpl",TRUE,dirname(__FILE__)));
141 $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container);
142 return($str);
143 }
144 }
146 class sieve_discard
147 {
148 var $data = array();
149 var $object_id = -1;
151 function sieve_discard($data,$object_id)
152 {
153 $this->object_id = $object_id;
154 }
156 function get_sieve_script_part()
157 {
158 return("discard;\n");
159 }
161 function save_object()
162 {
164 }
166 function execute()
167 {
168 $smarty = get_smarty();
169 $smarty->assign("ID", $this->object_id);
170 $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__)));
171 $object = $smarty->fetch(get_template_path("templates/element_discard.tpl",TRUE,dirname(__FILE__)));
172 $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container);
173 return($str);
174 }
175 }
179 class sieve_reject
180 {
181 var $data = array();
182 var $object_id = -1;
185 function save_object()
186 {
187 if(isset($_POST['reject_message_'.$this->object_id])){
188 $msg = stripslashes($_POST['reject_message_'.$this->object_id]);
190 $this->data = $msg;
191 }
192 }
194 function sieve_reject($data,$object_id)
195 {
196 $this->object_id = $object_id;
197 $str = "";
198 foreach($data['ELEMENTS'] as $node ){
199 if(in_array($node['class'],array("quoted-string","text","multi-line"))){
201 if($node['class'] == "multi-line"){
202 $str .= preg_replace("/^text:[ \n\r]*/","",$node['text']);
203 $str = preg_replace("/[ \n\r]*\.[ \n\r]*$/","",$str);
204 }else{
205 $str .= $node['text'];
206 }
207 }
208 }
209 $this->data = preg_replace("/\"/","",$str);
210 }
212 function get_sieve_script_part()
213 {
214 return("reject ".sieve_create_strings($this->data).";\n");
215 }
217 function execute()
218 {
219 /* check if this will be a
220 * - single string ""
221 * - or a multi line text: ... ;
222 */
223 $Multiline = preg_match("/\n/",$this->data);
225 $smarty = get_smarty();
226 $smarty->assign("ID", $this->object_id);
227 $smarty->assign("Message",$this->data);
228 $smarty->assign("Multiline",$Multiline);
229 $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__)));
230 $object= $smarty->fetch(get_template_path("templates/element_reject.tpl",TRUE,dirname(__FILE__)));
231 $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container);
232 return($str);
233 }
234 }
236 class sieve_redirect
237 {
238 var $data = array();
239 var $object_id = -1;
241 function save_object()
242 {
243 if(isset($_POST['redirect_to_'.$this->object_id])){
244 $rt = stripslashes($_POST['redirect_to_'.$this->object_id]);
246 $tmp = array();
247 $tmp2 = split(",",$rt);
248 foreach($tmp2 as $val){
249 $tmp[] = "\"".trim(preg_replace("/\"/","",$val))."\"";
250 }
251 $this->data = $tmp;
252 }
253 }
256 function sieve_redirect($data,$object_id)
257 {
258 foreach($data['ELEMENTS'] as $node ){
259 if(in_array($node['class'],array("quoted-string","text"))){
260 $this->data[] = $node['text'];
261 }
262 }
263 }
266 function get_sieve_script_part()
267 {
268 $tmp = "";
269 foreach($this->data as $dat){
270 $tmp.= "\"".$dat."\", ";
271 }
272 $tmp = preg_replace("/,$/","",trim($tmp));
273 $tmp = preg_replace ("/\"\"/","\"",$tmp);
274 return("redirect ".$tmp.";\n");
275 }
278 function execute()
279 {
280 $values = "";
281 foreach($this->data as $key){
282 $values .= $key.", ";
283 }
284 $values = preg_replace("/,$/","",trim($values));
286 $smarty = get_smarty();
287 $smarty->assign("ID", $this->object_id);
288 $smarty->assign("Destinations" , $values);
289 $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__)));
290 $object= $smarty->fetch(get_template_path("templates/element_redirect.tpl",TRUE,dirname(__FILE__)));
291 $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container);
292 return($str);
293 }
294 }
296 class sieve_fileinto
297 {
298 var $data = array();
299 var $object_id= -1;
300 var $options = array();
302 function save_object()
303 {
304 $mbs = $this->get_mail_boxes();
306 if(isset($_POST['fileinto_'.$this->object_id])){
307 $mb = $_POST['fileinto_'.$this->object_id];
309 if(isset($mbs[$mb])) {
310 $this->data[0] = $mb;
311 }
312 }
313 }
315 function sieve_fileinto($data,$object_id)
316 {
317 $this->object_id = $object_id;
318 foreach($data['ELEMENTS'] as $node ){
319 if(in_array($node['class'],array("quoted-string","text"))){
320 $this->data[] = preg_replace("/\"/","",$node['text']);
321 }
322 }
323 }
325 function get_sieve_script_part()
326 {
327 $tmp = "";
328 foreach($this->data as $dat){
329 $tmp.= "\"".$dat."\", ";
330 }
331 $tmp = preg_replace("/,$/","",trim($tmp));
332 $tmp = preg_replace ("/\"\"/","\"",$tmp);
333 return("fileinto ".$tmp.";\n");
334 }
336 function execute()
337 {
338 $smarty = get_smarty();
339 $smarty->assign("Selected",$this->data[0]);
340 $smarty->assign("Boxes", $this->get_mail_boxes());
341 $smarty->assign("ID", $this->object_id);
342 $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__)));
343 $object= $smarty->fetch(get_template_path("templates/element_fileinto.tpl",TRUE,dirname(__FILE__)));
344 $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container);
345 return($str);
346 }
348 function get_mail_boxes()
349 {
350 return(array("not"=>"not","impplemented/yet"=>"impplemented/yet"));
351 }
352 }
354 class sieve_vacation
355 {
356 var $days = FALSE;
357 var $subject = FALSE;
358 var $from = "";
359 var $mime = "";
360 var $handle = "";
361 var $reason = "";
362 var $addresses= array();
363 var $object_id= -1;
364 var $Expert = FALSE;
366 function sieve_vacation($data,$object_id)
367 {
368 /* Usage: vacation [":days" number] [":subject" string]
369 [":from" string] [":addresses" string-list]
370 [":mime"] [":handle" string] <reason: string> */
372 /* Not all attribute types are supported by the sieve class right now */
373 $known_attrs = array(":days",":subject",":from",":mime",":handle");
375 /* Walk through elements */
376 for($i = 0 ; $i < count($data['ELEMENTS']) ; $i ++){
378 /* get current element */
379 $node = $data['ELEMENTS'][$i];
381 /* Check if tag is in the specified list of attributes */
382 if($node['class'] == "tag" && in_array($node['text'],$known_attrs)){
384 $var = preg_replace("/\:/","",$node['text']);
385 $this->$var = $data['ELEMENTS'][$i+1]['text'];
386 $i ++;
387 }
389 /* Check for addresses */
390 if($node['class'] == "tag" && $node['text'] == ":addresses") {
391 $this->addresses = array();
392 $i ++;
394 /* Multiple or single address given */
395 if($data['ELEMENTS'][$i]['class'] == "left-bracket"){
396 while($data['ELEMENTS'][$i]['class'] != "right-bracket" && ($i < count($data['ELEMENTS']))){
397 $i ++;
398 if($data['ELEMENTS'][$i]['class'] == "quoted-string"){
399 $this->addresses[] = preg_replace("/\"/i","",$data['ELEMENTS'][$i]['text']);
400 }
401 }
402 }else{
403 $this->addresses[] = $data['ELEMENTS'][$i]['text'] ;
404 }
405 }
407 /* Add the vacation message */
408 if($node['class'] == "quoted-string"){
409 $this->reason = $node['text'];
410 }
411 }
412 }
414 function get_sieve_script_part()
415 {
416 $str = "vacation ";
417 if($this->days){
418 $str.= ":days ".$this->days;
419 }
420 $str .= ":addresses ".sieve_create_strings($this->addresses);
421 if($this->subject){
422 $str.= ":subject ".sieve_create_strings($this->subject);
423 }
424 if($this->mime){
425 $str.= ":mime ".sieve_create_strings($this->mime);
426 }
427 $str .= "\n ".sieve_create_strings($this->reason);
428 return($str." ; \n");
429 }
432 function save_object()
433 {
434 /* Get release date */
435 if(isset($_POST['vacation_release_'.$this->object_id])){
436 $this->days = $_POST['vacation_release_'.$this->object_id];
437 }
439 /* Check if we want to toggle the expert mode */
440 if(isset($_POST['Toggle_Expert_'.$this->object_id])){
441 $this->Expert = !$this->Expert;
442 }
444 /* Get release date */
445 if(isset($_POST['vacation_receiver_'.$this->object_id])){
446 $vr = stripslashes ($_POST['vacation_receiver_'.$this->object_id]);
447 $tmp = array();
448 $tmp2 = split(",",$vr);
449 foreach($tmp2 as $val){
450 $tmp[] = "\"".trim(preg_replace("/\"/","",$val))."\"";
451 }
452 $this->addresses = $tmp;
453 }
455 /* Get reason */
456 if(isset($_POST['vacation_reason_'.$this->object_id])){
457 $vr = stripslashes ($_POST['vacation_reason_'.$this->object_id]);
458 $this->reason = "\"".trim(preg_replace("/\"/","",$vr))."\"";
459 }
460 }
462 function execute()
463 {
464 $Addresses = "";
465 foreach($this->addresses as $key){
466 $Addresses .= $key.", ";
467 }
468 $Addresses = preg_replace("/,$/","",trim($Addresses));
469 $smarty = get_smarty();
470 $smarty->assign("Reason",$this->reason);
471 $smarty->assign("Addresses",$Addresses);
472 $smarty->assign("Subject",$this->subject);
473 $smarty->assign("Days",$this->days);
474 $smarty->assign("ID",$this->object_id);
475 $smarty->assign("Expert",$this->Expert);
476 return($smarty->fetch(get_template_path("templates/element_vacation.tpl",TRUE,dirname(__FILE__))));
477 }
478 }
480 class sieve_block_start
481 {
482 function execute()
483 {
484 $smarty = get_smarty();
485 return($smarty->fetch(get_template_path("templates/element_block_start.tpl",TRUE,dirname(__FILE__))));
486 }
488 function save_object()
489 {
490 }
492 function get_sieve_script_part()
493 {
494 return("{\n");
495 }
496 }
498 class sieve_block_end
499 {
500 function execute()
501 {
502 $smarty = get_smarty();
503 return($smarty->fetch(get_template_path("templates/element_block_end.tpl",TRUE,dirname(__FILE__))));
504 }
505 function get_sieve_script_part()
506 {
507 return("}\n");
508 }
509 function save_object()
510 {
511 }
513 }
515 /* This class handles the keep statement */
516 class sieve_keep
517 {
518 var $object_id = -1;
520 function sieve_keep($data,$object_id)
521 {
522 $this->object_id = $object_id;
523 }
525 function save_object()
526 {
527 }
529 function execute()
530 {
531 $smarty = get_smarty();
532 $smarty->assign("ID", $this->object_id);
533 $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__)));
534 $object = $smarty->fetch(get_template_path("templates/element_keep.tpl",TRUE,dirname(__FILE__)));
535 $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container);
536 return($str);
537 }
538 function get_sieve_script_part()
539 {
540 return("keep;\n");
541 }
543 }
545 /* This class handles the stop statement */
546 class sieve_stop
547 {
548 var $object_id = -1;
550 function sieve_stop($data,$object_id)
551 {
552 $this->object_id = $object_id;
553 }
555 function save_object()
556 {
557 }
559 function execute()
560 {
561 $smarty = get_smarty();
562 $smarty->assign("ID", $this->object_id);
563 $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__)));
564 $object= $smarty->fetch(get_template_path("templates/element_stop.tpl",TRUE,dirname(__FILE__)));
565 $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container);
566 return($str);
567 }
569 function get_sieve_script_part()
570 {
571 return("stop; \n");
572 }
574 }
575 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
576 ?>