Overview

Packages

  • Horde
    • Icalendar
      • UnitTests
  • Ingo
    • UnitTests
  • None

Classes

  • Ingo_MaildropTest
  • Ingo_ProcmailTest
  • Ingo_ScriptTest
  • Ingo_SieveTest
  • Ingo_TestBase
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Test cases for Ingo_Script_procmail:: class
  4:  *
  5:  * See the enclosed file LICENSE for license information (ASL).  If you
  6:  * did not receive this file, see http://www.horde.org/licenses/apache.
  7:  *
  8:  * @author     Jason M. Felice <jason.m.felice@gmail.com>
  9:  * @package    Ingo
 10:  * @subpackage UnitTests
 11:  */
 12: 
 13: require_once dirname(__FILE__) . '/TestBase.php';
 14: 
 15: class Ingo_ProcmailTest 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:             'procmail',
 33:             array('path_style' => 'mbox',
 34:                   'spam_compare' => 'string',
 35:                   'spam_header' => 'X-Spam-Level',
 36:                   'spam_char' => '*'));
 37:     }
 38: 
 39:     function testForwardKeep()
 40:     {
 41:         $forward = new Ingo_Storage_Forward();
 42:         $forward->setForwardAddresses('joefabetes@example.com');
 43:         $forward->setForwardKeep(true);
 44: 
 45:         $this->store($forward);
 46:         $this->assertScript(':0 c
 47: {
 48: :0
 49: *$ ! ^From *\/[^  ]+
 50: *$ ! ^Sender: *\/[^   ]+
 51: *$ ! ^From: *\/[^     ]+
 52: *$ ! ^Reply-to: *\/[^     ]+
 53: {
 54: OUTPUT = `formail -zxFrom:`
 55: }
 56: :0 E
 57: {
 58: OUTPUT = $MATCH
 59: }
 60: :0 c
 61: * !^FROM_MAILER
 62: * !^X-Loop: to-joefabetes@example.com
 63: | formail -A"X-Loop: to-joefabetes@example.com" | $SENDMAIL -oi -f $OUTPUT joefabetes@example.com
 64: :0 E
 65: $DEFAULT
 66: :0
 67: /dev/null
 68: }');
 69:     }
 70: 
 71:     function testForwardNoKeep()
 72:     {
 73:         $forward = new Ingo_Storage_Forward();
 74:         $forward->setForwardAddresses('joefabetes@example.com');
 75:         $forward->setForwardKeep(false);
 76: 
 77:         $this->store($forward);
 78:         $this->assertScript(':0
 79: {
 80: :0
 81: *$ ! ^From *\/[^  ]+
 82: *$ ! ^Sender: *\/[^   ]+
 83: *$ ! ^From: *\/[^     ]+
 84: *$ ! ^Reply-to: *\/[^     ]+
 85: {
 86: OUTPUT = `formail -zxFrom:`
 87: }
 88: :0 E
 89: {
 90: OUTPUT = $MATCH
 91: }
 92: :0 c
 93: * !^FROM_MAILER
 94: * !^X-Loop: to-joefabetes@example.com
 95: | formail -A"X-Loop: to-joefabetes@example.com" | $SENDMAIL -oi -f $OUTPUT joefabetes@example.com
 96: :0 E
 97: $DEFAULT
 98: :0
 99: /dev/null
100: }');
101:     }
102: 
103:     function testBlacklistWithFolder()
104:     {
105:         $bl = new Ingo_Storage_Blacklist(3);
106:         $bl->setBlacklist(array('spammer@example.com'));
107:         $bl->setBlacklistFolder('Junk');
108: 
109:         $this->store($bl);
110:         $this->assertScript(':0
111: * ^From:(.*\<)?spammer@example\.com
112: Junk');
113:     }
114: 
115:     function testBlacklistMarker()
116:     {
117:         $bl = new Ingo_Storage_Blacklist(3);
118:         $bl->setBlacklist(array('spammer@example.com'));
119:         $bl->setBlacklistFolder(Ingo::BLACKLIST_MARKER);
120: 
121:         $this->store($bl);
122:         $this->assertScript(':0
123: * ^From:(.*\<)?spammer@example\.com
124: ++DELETE++');
125:     }
126: 
127:     function testBlacklistDiscard()
128:     {
129:         $bl = new Ingo_Storage_Blacklist(3);
130:         $bl->setBlacklist(array('spammer@example.com'));
131:         $bl->setBlacklistFolder(null);
132: 
133:         $this->store($bl);
134:         $this->assertScript(':0
135: * ^From:(.*\<)?spammer@example\.com
136: /dev/null');
137:     }
138: 
139:     function testWhitelist()
140:     {
141:         $wl = new Ingo_Storage_Whitelist(3);
142:         $wl->setWhitelist(array('spammer@example.com'));
143: 
144:         $this->store($wl);
145:         $this->assertScript(':0
146: * ^From:(.*\<)?spammer@example\.com
147: $DEFAULT');
148:     }
149: 
150:     function testVacationDisabled()
151:     {
152:         $vacation = new Ingo_Storage_VacationTest();
153:         $vacation->setVacationAddresses(array('from@example.com'));
154:         $vacation->setVacationSubject('Subject');
155:         $vacation->setVacationReason("Because I don't like working!");
156: 
157:         $this->store($vacation);
158:         $this->assertScript('');
159:     }
160: 
161:     function testVacationEnabled()
162:     {
163:         $vacation = new Ingo_Storage_VacationTest();
164:         $vacation->setVacationAddresses(array('from@example.com'));
165:         $vacation->setVacationSubject('Subject');
166:         $vacation->setVacationReason("Because I don't like working!");
167: 
168:         $this->store($vacation);
169:         $this->_enableRule(Ingo_Storage::ACTION_VACATION);
170: 
171:         $this->assertScript(':0
172: {
173: :0
174: * ^TO_from@example.com
175: {
176: FILEDATE=`test -f ${VACATION_DIR:-.}/\'.vacation.from@example.com\' && ls -lcn --time-style=+%s ${VACATION_DIR:-.}/\'.vacation.from@example.com\' | awk \'{ print $6 + (604800) }\'`
177: DATE=`date +%s`
178: DUMMY=`test -f ${VACATION_DIR:-.}/\'.vacation.from@example.com\' && test $FILEDATE -le $DATE && rm ${VACATION_DIR:-.}/\'.vacation.from@example.com\'`
179: :0 h
180: SUBJECT=| formail -xSubject:
181: :0 Whc: ${VACATION_DIR:-.}/vacation.lock
182: * ^TO_from@example.com
183: * !^X-Loop: from@example.com
184: * !^X-Spam-Flag: YES
185: * !^FROM_DAEMON
186: | formail -rD 8192 ${VACATION_DIR:-.}/.vacation.from@example.com
187: :0 eh
188: | (formail -rI"Precedence: junk" \
189: -a"From: <from@example.com>" \
190: -A"X-Loop: from@example.com" \
191: -i"Subject: Subject (Re: $SUBJECT)" ; \
192: echo -e "Because I don\'t like working!" \
193: ) | $SENDMAIL -ffrom@example.com -oi -t
194: }
195: }');
196:     }
197: 
198: }
199: 
API documentation generated by ApiGen