1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
<?php
/**
* Test cases for Ingo_Script_sieve:: class
*
* $Horde: ingo/lib/tests/SieveTest.php,v 1.1.2.2 2009/12/21 23:19:05 jan Exp $
*
* See the enclosed file LICENSE for license information (ASL). If you
* did not receive this file, see http://www.horde.org/licenses/asl.php.
*
* @author Jason M. Felice <jason.m.felice@gmail.com>
* @package Ingo
* @subpackage UnitTests
*/
require_once dirname(__FILE__) . '/TestBase.php';
class Ingo_SieveTest extends Ingo_TestBase {
function store($ob)
{
return $GLOBALS['ingo_storage']->store($ob);
}
function setUp()
{
require_once INGO_BASE . '/lib/Session.php';
require_once INGO_BASE . '/lib/Script.php';
require_once INGO_BASE . '/lib/Storage.php';
require_once INGO_BASE . '/lib/Ingo.php';
$GLOBALS['conf']['spam'] = array('enabled' => true,
'char' => '*',
'header' => 'X-Spam-Level');
$GLOBALS['ingo_storage'] = Ingo_Storage::factory(
'mock',
array('maxblacklist' => 3,
'maxwhitelist' => 3));
$GLOBALS['ingo_script'] = Ingo_Script::factory(
'sieve',
array('spam_compare' => 'string',
'spam_header' => 'X-Spam-Level',
'spam_char' => '*',
'date_format' => '%x',
'time_format' => '%R'));
}
function testForwardKeep()
{
$forward = new Ingo_Storage_forward();
$forward->setForwardAddresses('joefabetes@example.com');
$forward->setForwardKeep(true);
$this->store($forward);
$this->assertScript('if true {
redirect "joefabetes@example.com";
}
if true {
keep;
stop;
}');
}
function testForwardNoKeep()
{
$forward = new Ingo_Storage_forward();
$forward->setForwardAddresses('joefabetes@example.com');
$forward->setForwardKeep(false);
$this->store($forward);
$this->assertScript('if true {
redirect "joefabetes@example.com";
stop;
}');
}
function testBlacklistMarker()
{
$bl = new Ingo_Storage_blacklist(3);
$bl->setBlacklist(array('spammer@example.com'));
$bl->setBlacklistFolder(INGO_BLACKLIST_MARKER);
$this->store($bl);
$this->assertScript('require "imapflags";
if address :all :comparator "i;ascii-casemap" :is ["From", "Sender", "Resent-From"] "spammer@example.com" {
addflag "\\\\Deleted";
keep;
removeflag "\\\\Deleted";
stop;
}');
}
function testWhitelist()
{
$wl = new Ingo_Storage_whitelist(3);
$wl->setWhitelist(array('spammer@example.com'));
$this->store($wl);
$this->assertScript('if address :all :comparator "i;ascii-casemap" :is ["From", "Sender", "Resent-From"] "spammer@example.com" {
keep;
stop;
}');
}
function testVacationDisabled()
{
$vacation = new Ingo_Storage_vacation();
$vacation->setVacationAddresses(array('from@example.com'));
$vacation->setVacationSubject('Subject');
$vacation->setVacationReason("Because I don't like working!");
$this->store($vacation);
$this->assertScript('');
}
function testVacationEnabled()
{
$vacation = new Ingo_Storage_vacation();
$vacation->setVacationAddresses(array('from@example.com'));
$vacation->setVacationSubject('Subject');
$vacation->setVacationReason("Because I don't like working!");
$this->store($vacation);
$this->_enableRule(INGO_STORAGE_ACTION_VACATION);
$this->assertScript('require ["vacation", "regex"];
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*" ) {
vacation :days 7 :addresses "from@example.com" :subject "Subject" "Because I don\'t like working!";
}');
}
function testSpamDisabled()
{
$spam = new Ingo_Storage_spam();
$spam->setSpamLevel(7);
$spam->setSpamFolder("Junk");
$this->store($spam);
$this->assertScript('');
}
function testSpamEnabled()
{
$spam = new Ingo_Storage_spam();
$spam->setSpamLevel(7);
$spam->setSpamFolder("Junk");
$this->store($spam);
$this->_enableRule(INGO_STORAGE_ACTION_SPAM);
$this->assertScript('require "fileinto";
if header :comparator "i;ascii-casemap" :contains "X-Spam-Level" "*******" {
fileinto "Junk";
stop;
}');
}
}
|