]> git.donarmstrong.com Git - roundcube.git/blob - plugins/managesieve/tests/parser.phpt
d703534599fef9e1fa32eabdaa7da09c7b9f9e02
[roundcube.git] / plugins / managesieve / tests / parser.phpt
1 --TEST--
2 Main test of script parser
3 --SKIPIF--
4 --FILE--
5 <?php
6 include '../lib/rcube_sieve_script.php';
7
8 $txt = '
9 require ["fileinto","vacation","reject","relational","comparator-i;ascii-numeric","imapflags"];
10 # rule:[spam]
11 if anyof (header :contains "X-DSPAM-Result" "Spam")
12 {
13         fileinto "Spam";
14         stop;
15 }
16 # rule:[test1]
17 if anyof (header :contains ["From","To"] "test@domain.tld")
18 {
19         discard;
20         stop;
21 }
22 # rule:[test2]
23 if anyof (not header :contains ["Subject"] "[test]", header :contains "Subject" "[test2]")
24 {
25         fileinto "test";
26         stop;
27 }
28 # rule:[test-vacation]
29 if anyof (header :contains "Subject" "vacation")
30 {
31         vacation :days 1 text:
32 # test
33 test test /* test */
34 test
35 .
36 ;
37         stop;
38 }
39 # rule:[comments]
40 if anyof (true) /* comment
41  * "comment" #comment */ {
42     /* comment */ stop;
43 # comment
44 }
45 # rule:[reject]
46 if size :over 5000K {
47     reject "Message over 5MB size limit. Please contact me before sending this.";
48 }
49 # rule:[redirect]
50 if header :value "ge" :comparator "i;ascii-numeric"
51     ["X-Spam-score"] ["14"] {redirect "test@test.tld";}
52 # rule:[imapflags]
53 if header :matches "Subject" "^Test$" {
54     setflag "\\\\Seen";
55     addflag ["\\\\Answered","\\\\Deleted"];
56 }
57 ';
58
59 $s = new rcube_sieve_script($txt);
60 echo $s->as_text();
61
62 ?>
63 --EXPECT--
64 require ["fileinto","vacation","reject","relational","comparator-i;ascii-numeric","imapflags"];
65 # rule:[spam]
66 if header :contains "X-DSPAM-Result" "Spam"
67 {
68         fileinto "Spam";
69         stop;
70 }
71 # rule:[test1]
72 if header :contains ["From","To"] "test@domain.tld"
73 {
74         discard;
75         stop;
76 }
77 # rule:[test2]
78 if anyof (not header :contains "Subject" "[test]", header :contains "Subject" "[test2]")
79 {
80         fileinto "test";
81         stop;
82 }
83 # rule:[test-vacation]
84 if header :contains "Subject" "vacation"
85 {
86         vacation :days 1 text:
87 # test
88 test test /* test */
89 test
90 .
91 ;
92         stop;
93 }
94 # rule:[comments]
95 if true
96 {
97         stop;
98 }
99 # rule:[reject]
100 if size :over 5000K
101 {
102         reject "Message over 5MB size limit. Please contact me before sending this.";
103 }
104 # rule:[redirect]
105 if header :value "ge" :comparator "i;ascii-numeric" "X-Spam-score" "14"
106 {
107         redirect "test@test.tld";
108 }
109 # rule:[imapflags]
110 if header :matches "Subject" "^Test$"
111 {
112         setflag "\\Seen";
113         addflag ["\\Answered","\\Deleted"];
114 }