1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
12:
13: require_once dirname(__FILE__) . '/TestBase.php';
14:
15: class Ingo_SieveTest extends Ingo_TestBase {
16:
17: function store($ob)
18: {
19: $GLOBALS['ingo_storage']->store($ob);
20: }
21:
22: function setUp()
23: {
24: $GLOBALS['conf']['spam'] = array('enabled' => true,
25: 'char' => '*',
26: 'header' => 'X-Spam-Level');
27: $GLOBALS['ingo_storage'] = Ingo_Storage::factory(
28: 'mock',
29: array('maxblacklist' => 3,
30: 'maxwhitelist' => 3));
31: $GLOBALS['ingo_script'] = Ingo_Script::factory(
32: 'sieve',
33: array('spam_compare' => 'string',
34: 'spam_header' => 'X-Spam-Level',
35: 'spam_char' => '*',
36: 'date_format' => '%x',
37: 'time_format' => '%R'));
38: }
39:
40: function testForwardKeep()
41: {
42: $forward = new Ingo_Storage_Forward();
43: $forward->setForwardAddresses('joefabetes@example.com');
44: $forward->setForwardKeep(true);
45:
46: $this->store($forward);
47: $this->assertScript('if true {
48: redirect "joefabetes@example.com";
49: }
50: if true {
51: keep;
52: stop;
53: }');
54: }
55:
56: function testForwardNoKeep()
57: {
58: $forward = new Ingo_Storage_Forward();
59: $forward->setForwardAddresses('joefabetes@example.com');
60: $forward->setForwardKeep(false);
61:
62: $this->store($forward);
63: $this->assertScript('if true {
64: redirect "joefabetes@example.com";
65: stop;
66: }');
67: }
68:
69: function testBlacklistMarker()
70: {
71: $bl = new Ingo_Storage_Blacklist(3);
72: $bl->setBlacklist(array('spammer@example.com'));
73: $bl->setBlacklistFolder(Ingo::BLACKLIST_MARKER);
74:
75: $this->store($bl);
76: $this->assertScript('require "imapflags";
77: if address :all :comparator "i;ascii-casemap" :is ["From", "Sender", "Resent-From"] "spammer@example.com" {
78: addflag "\\\\Deleted";
79: keep;
80: removeflag "\\\\Deleted";
81: stop;
82: }');
83: }
84:
85: function testWhitelist()
86: {
87: $wl = new Ingo_Storage_Whitelist(3);
88: $wl->setWhitelist(array('spammer@example.com'));
89:
90: $this->store($wl);
91: $this->assertScript('if address :all :comparator "i;ascii-casemap" :is ["From", "Sender", "Resent-From"] "spammer@example.com" {
92: keep;
93: stop;
94: }');
95: }
96:
97: function testVacationDisabled()
98: {
99: $vacation = new Ingo_Storage_VacationTest();
100: $vacation->setVacationAddresses(array('from@example.com'));
101: $vacation->setVacationSubject('Subject');
102: $vacation->setVacationReason("Because I don't like working!");
103:
104: $this->store($vacation);
105: $this->assertScript('');
106: }
107:
108: function testVacationEnabled()
109: {
110: $vacation = new Ingo_Storage_VacationTest();
111: $vacation->setVacationAddresses(array('from@example.com'));
112: $vacation->setVacationSubject('Subject');
113: $vacation->setVacationReason("Because I don't like working!");
114:
115: $this->store($vacation);
116: $this->_enableRule(Ingo_Storage::ACTION_VACATION);
117:
118: $this->assertScript('require ["vacation", "regex"];
119: if allof ( not exists ["list-help", "list-unsubscribe", "list-subscribe", "list-owner", "list-post", "list-archive", "list-id", "Mailing-List"], not header :comparator "i;ascii-casemap" :is "Precedence" ["list", "bulk", "junk"], not header :comparator "i;ascii-casemap" :matches "To" "Multiple recipients of*" ) {
120: vacation :days 7 :addresses "from@example.com" :subject "Subject" "Because I don\'t like working!";
121: }');
122: }
123:
124: function testSpamDisabled()
125: {
126: $spam = new Ingo_Storage_Spam();
127: $spam->setSpamLevel(7);
128: $spam->setSpamFolder("Junk");
129:
130: $this->store($spam);
131: $this->assertScript('');
132: }
133:
134: function testSpamEnabled()
135: {
136: $spam = new Ingo_Storage_Spam();
137: $spam->setSpamLevel(7);
138: $spam->setSpamFolder("Junk");
139:
140: $this->store($spam);
141: $this->_enableRule(Ingo_Storage::ACTION_SPAM);
142: $this->assertScript('require "fileinto";
143: if header :comparator "i;ascii-casemap" :contains "X-Spam-Level" "*******" {
144: fileinto "Junk";
145: stop;
146: }');
147: }
148:
149: }
150: