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 return($smarty->fetch(get_template_path("templates/element_require.tpl",TRUE,dirname(__FILE__))));
140 }
141 }
143 class sieve_discard
144 {
145 var $data = array();
146 var $object_id = -1;
148 function sieve_discard($data,$object_id)
149 {
150 $this->object_id = $object_id;
151 }
153 function get_sieve_script_part()
154 {
155 return("discard;\n");
156 }
158 function save_object()
159 {
161 }
163 function execute()
164 {
165 $smarty = get_smarty();
166 $smarty->assign("ID", $this->object_id);
167 $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__)));
168 $object = $smarty->fetch(get_template_path("templates/element_discard.tpl",TRUE,dirname(__FILE__)));
169 $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container);
170 return($str);
171 }
172 }
176 class sieve_reject
177 {
178 var $data = array();
179 var $object_id = -1;
182 function save_object()
183 {
184 if(isset($_POST['reject_message_'.$this->object_id])){
185 $msg = stripslashes($_POST['reject_message_'.$this->object_id]);
187 $this->data = $msg;
188 }
189 }
191 function sieve_reject($data,$object_id)
192 {
193 $this->object_id = $object_id;
194 $str = "";
195 foreach($data['ELEMENTS'] as $node ){
196 if(in_array($node['class'],array("quoted-string","text","multi-line"))){
198 if($node['class'] == "multi-line"){
199 $str .= preg_replace("/^text:[ \n\r]*/","",$node['text']);
200 $str = preg_replace("/[ \n\r]*\.[ \n\r]*$/","",$str);
201 }else{
202 $str .= $node['text'];
203 }
204 }
205 }
206 $this->data = preg_replace("/\"/","",$str);
207 }
209 function get_sieve_script_part()
210 {
211 return("reject ".sieve_create_strings($this->data).";\n");
212 }
214 function execute()
215 {
216 /* check if this will be a
217 * - single string ""
218 * - or a multi line text: ... ;
219 */
220 $Multiline = preg_match("/\n/",$this->data);
222 $smarty = get_smarty();
223 $smarty->assign("ID",$this->object_id);
224 $smarty->assign("Multiline",$Multiline);
225 $smarty->assign("Message",$this->data);
226 return($smarty->fetch(get_template_path("templates/element_reject.tpl",TRUE,dirname(__FILE__))));
227 }
228 }
230 class sieve_redirect
231 {
232 var $data = array();
233 var $object_id = -1;
235 function save_object()
236 {
237 if(isset($_POST['redirect_to_'.$this->object_id])){
238 $rt = stripslashes($_POST['redirect_to_'.$this->object_id]);
240 $tmp = array();
241 $tmp2 = split(",",$rt);
242 foreach($tmp2 as $val){
243 $tmp[] = "\"".trim(preg_replace("/\"/","",$val))."\"";
244 }
245 $this->data = $tmp;
246 }
247 }
250 function sieve_redirect($data,$object_id)
251 {
252 foreach($data['ELEMENTS'] as $node ){
253 if(in_array($node['class'],array("quoted-string","text"))){
254 $this->data[] = $node['text'];
255 }
256 }
257 }
260 function get_sieve_script_part()
261 {
262 $tmp = "";
263 foreach($this->data as $dat){
264 $tmp.= "\"".$dat."\", ";
265 }
266 $tmp = preg_replace("/,$/","",trim($tmp));
267 $tmp = preg_replace ("/\"\"/","\"",$tmp);
268 return("redirect ".$tmp.";\n");
269 }
272 function execute()
273 {
274 $values = "";
275 foreach($this->data as $key){
276 $values .= $key.", ";
277 }
278 $values = preg_replace("/,$/","",trim($values));
280 $smarty = get_smarty();
281 $smarty->assign("Destinations" , $values);
282 $smarty->assign("ID" , $this->object_id);
283 return($smarty->fetch(get_template_path("templates/element_redirect.tpl",TRUE,dirname(__FILE__))));
284 }
285 }
287 class sieve_fileinto
288 {
289 var $data = array();
290 var $object_id= -1;
291 var $options = array();
293 function save_object()
294 {
295 $mbs = $this->get_mail_boxes();
297 if(isset($_POST['fileinto_'.$this->object_id])){
298 $mb = $_POST['fileinto_'.$this->object_id];
300 if(isset($mbs[$mb])) {
301 $this->data[0] = $mb;
302 }
303 }
304 }
306 function sieve_fileinto($data,$object_id)
307 {
308 $this->object_id = $object_id;
309 foreach($data['ELEMENTS'] as $node ){
310 if(in_array($node['class'],array("quoted-string","text"))){
311 $this->data[] = preg_replace("/\"/","",$node['text']);
312 }
313 }
314 }
316 function get_sieve_script_part()
317 {
318 $tmp = "";
319 foreach($this->data as $dat){
320 $tmp.= "\"".$dat."\", ";
321 }
322 $tmp = preg_replace("/,$/","",trim($tmp));
323 $tmp = preg_replace ("/\"\"/","\"",$tmp);
324 return("fileinto ".$tmp.";\n");
325 }
327 function execute()
328 {
329 $smarty = get_smarty();
330 $smarty->assign("Selected",$this->data[0]);
331 $smarty->assign("Boxes", $this->get_mail_boxes());
332 $smarty->assign("ID", $this->object_id);
333 return($smarty->fetch(get_template_path("templates/element_fileinto.tpl",TRUE,dirname(__FILE__))));
334 }
336 function get_mail_boxes()
337 {
338 return(array("not","impplemented/yet"));
339 }
340 }
342 class sieve_vacation
343 {
344 var $days = FALSE;
345 var $subject = FALSE;
346 var $from = "";
347 var $mime = "";
348 var $handle = "";
349 var $reason = "";
350 var $addresses= array();
351 var $object_id= -1;
352 var $Expert = FALSE;
354 function sieve_vacation($data,$object_id)
355 {
356 /* Usage: vacation [":days" number] [":subject" string]
357 [":from" string] [":addresses" string-list]
358 [":mime"] [":handle" string] <reason: string> */
360 /* Not all attribute types are supported by the sieve class right now */
361 $known_attrs = array(":days",":subject",":from",":mime",":handle");
363 /* Walk through elements */
364 for($i = 0 ; $i < count($data['ELEMENTS']) ; $i ++){
366 /* get current element */
367 $node = $data['ELEMENTS'][$i];
369 /* Check if tag is in the specified list of attributes */
370 if($node['class'] == "tag" && in_array($node['text'],$known_attrs)){
372 $var = preg_replace("/\:/","",$node['text']);
373 $this->$var = $data['ELEMENTS'][$i+1]['text'];
374 $i ++;
375 }
377 /* Check for addresses */
378 if($node['class'] == "tag" && $node['text'] == ":addresses") {
379 $this->addresses = array();
380 $i ++;
382 /* Multiple or single address given */
383 if($data['ELEMENTS'][$i]['class'] == "left-bracket"){
384 while($data['ELEMENTS'][$i]['class'] != "right-bracket" && ($i < count($data['ELEMENTS']))){
385 $i ++;
386 if($data['ELEMENTS'][$i]['class'] == "quoted-string"){
387 $this->addresses[] = preg_replace("/\"/i","",$data['ELEMENTS'][$i]['text']);
388 }
389 }
390 }else{
391 $this->addresses[] = $data['ELEMENTS'][$i]['text'] ;
392 }
393 }
395 /* Add the vacation message */
396 if($node['class'] == "quoted-string"){
397 $this->reason = $node['text'];
398 }
399 }
400 }
402 function get_sieve_script_part()
403 {
404 $str = "vacation ";
405 if($this->days){
406 $str.= ":days ".$this->days;
407 }
408 $str .= ":addresses ".sieve_create_strings($this->addresses);
409 if($this->subject){
410 $str.= ":subject ".sieve_create_strings($this->subject);
411 }
412 if($this->mime){
413 $str.= ":mime ".sieve_create_strings($this->mime);
414 }
415 $str .= "\n ".sieve_create_strings($this->reason);
416 return($str." ; \n");
417 }
420 function save_object()
421 {
422 /* Get release date */
423 if(isset($_POST['vacation_release_'.$this->object_id])){
424 $this->days = $_POST['vacation_release_'.$this->object_id];
425 }
427 /* Check if we want to toggle the expert mode */
428 if(isset($_POST['Toggle_Expert_'.$this->object_id])){
429 $this->Expert = !$this->Expert;
430 }
432 /* Get release date */
433 if(isset($_POST['vacation_receiver_'.$this->object_id])){
434 $vr = stripslashes ($_POST['vacation_receiver_'.$this->object_id]);
435 $tmp = array();
436 $tmp2 = split(",",$vr);
437 foreach($tmp2 as $val){
438 $tmp[] = "\"".trim(preg_replace("/\"/","",$val))."\"";
439 }
440 $this->addresses = $tmp;
441 }
443 /* Get reason */
444 if(isset($_POST['vacation_reason_'.$this->object_id])){
445 $vr = stripslashes ($_POST['vacation_reason_'.$this->object_id]);
446 $this->reason = "\"".trim(preg_replace("/\"/","",$vr))."\"";
447 }
448 }
450 function execute()
451 {
452 $Addresses = "";
453 foreach($this->addresses as $key){
454 $Addresses .= $key.", ";
455 }
456 $Addresses = preg_replace("/,$/","",trim($Addresses));
457 $smarty = get_smarty();
458 $smarty->assign("Reason",$this->reason);
459 $smarty->assign("Addresses",$Addresses);
460 $smarty->assign("Subject",$this->subject);
461 $smarty->assign("Days",$this->days);
462 $smarty->assign("ID",$this->object_id);
463 $smarty->assign("Expert",$this->Expert);
464 return($smarty->fetch(get_template_path("templates/element_vacation.tpl",TRUE,dirname(__FILE__))));
465 }
466 }
468 class sieve_block_start
469 {
470 function execute()
471 {
472 $smarty = get_smarty();
473 return($smarty->fetch(get_template_path("templates/element_block_start.tpl",TRUE,dirname(__FILE__))));
474 }
476 function save_object()
477 {
478 }
480 function get_sieve_script_part()
481 {
482 return("{\n");
483 }
484 }
486 class sieve_block_end
487 {
488 function execute()
489 {
490 $smarty = get_smarty();
491 return($smarty->fetch(get_template_path("templates/element_block_end.tpl",TRUE,dirname(__FILE__))));
492 }
493 function get_sieve_script_part()
494 {
495 return("}\n");
496 }
497 function save_object()
498 {
499 }
501 }
503 /* This class handles the keep statement */
504 class sieve_keep
505 {
506 var $object_id = -1;
508 function sieve_keep($data,$object_id)
509 {
510 $this->object_id = $object_id;
511 }
513 function save_object()
514 {
515 }
517 function execute()
518 {
519 $smarty = get_smarty();
520 $smarty->assign("ID", $this->object_id);
521 $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__)));
522 $object = $smarty->fetch(get_template_path("templates/element_keep.tpl",TRUE,dirname(__FILE__)));
523 $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container);
524 return($str);
525 }
526 function get_sieve_script_part()
527 {
528 return("keep;\n");
529 }
531 }
533 /* This class handles the stop statement */
534 class sieve_stop
535 {
536 var $object_id = -1;
538 function sieve_stop($data,$object_id)
539 {
540 $this->object_id = $object_id;
541 }
543 function save_object()
544 {
545 }
547 function execute()
548 {
549 $smarty = get_smarty();
550 $smarty->assign("ID", $this->object_id);
551 $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__)));
552 $object= $smarty->fetch(get_template_path("templates/element_stop.tpl",TRUE,dirname(__FILE__)));
553 $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container);
554 return($str);
555 }
557 function get_sieve_script_part()
558 {
559 return("stop; \n");
560 }
562 }
563 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
564 ?>