1use Test;
2BEGIN { $| = 1; plan(tests => 24); chdir 't' if -d 't'; }
3use blib;
4
5use Mail::Procmailrc;
6
7my $r1;
8my $recipe;
9
10$recipe =<<'_RECIPE_';
11:0B:
12## block indecent emails
13* 1^0 people talking dirty
14* 1^0 dirty persian poetry
15* 1^0 dirty pictures
16* 1^0 xxx
17/dev/null
18_RECIPE_
19
20my @recipe = split(/\n/, $recipe);
21
22## array constructor
23ok( $r1 = new Mail::Procmailrc::Recipe(\@recipe) );
24
25## test flags
26ok( $r1->flags(), ':0B:' );
27
28## test info
29ok( join("\n", @{$r1->info()}), '## block indecent emails' );
30
31## test conditions
32ok( join("\n", @{$r1->conditions()}), "* 1^0 people talking dirty\
33* 1^0 dirty persian poetry\
34* 1^0 dirty pictures\
35* 1^0 xxx" );
36
37## test action
38ok( $r1->action(), "/dev/null" );
39
40## test whole recipe dump
41ok( $r1->dump(), $recipe );
42
43## test multiline action
44$recipe =<<'_RECIPE_';
45:0: bouncetemp.${BOUNCEPID}.lock
46| (${FORMAIL} -rt \
47  -I"From: MAILER-DAEMON@$RHOST (Mail Delivery Subsystem)" \
48  -I"Subject: Returned mail: User unknown" \
49  -I"Auto-Submitted: auto-generated (failure)" \
50  -I"Bcc: ${SPAMERROR}" \
51  -I"X-Loop: MAILER-DAEMON@${RHOST}";\
52   echo "The original message was received at ${SPAMDATE}";\
53   echo "from ${SPAMFROM}";\
54   echo " ";\
55   echo "   ----- The following addresses had permanent fatal errors -----";\
56   echo "<${RECIPIENT}>";\
57   echo " ";\
58   echo "   ----- Transcript of session follows -----";\
59   echo "... while talking to ${RHOST}.:";\
60   echo ">>> RCPT To:<${RECIPIENT}>";\
61   echo "<<< 550 5.1.1 <${RECIPIENT}>... User unknown";\
62   echo "550 ${RECIPIENT}... User unknown";\
63   echo " ";\
64   echo "   ----- Original messages follows ----";\
65   echo " ";\
66   cat bouncetemp.${BOUNCEPID};\
67   ${RM} -f bouncetemp.${BOUNCEPID}) \
68   | ${SENDMAIL} -oi -t -fMAILER-DAEMON@${RHOST}
69_RECIPE_
70
71ok( $r1->init([split(/\n/, $recipe)]));
72ok( $r1->flags(), ':0: bouncetemp.${BOUNCEPID}.lock' );
73ok( $r1->dump(), $recipe );
74
75undef $r1;
76$recipe =<<'_RECIPE_';
77:0B:
78## block evil emails
79* 1^0 people talking dirty
80* 1^0 dirty persian poetry
81* 1^0 dirty pictures
82* 1^0 xxx
83* 1^0 evil bad things
84/dev/foo
85_RECIPE_
86
87## scalar constructor
88ok( $r1 = new Mail::Procmailrc::Recipe($recipe) );
89ok( $r1->flags(), ':0B:' );
90ok( join("\n", @{$r1->info()}), '## block evil emails' );
91ok( join("\n", @{$r1->conditions()}), "* 1^0 people talking dirty\
92* 1^0 dirty persian poetry\
93* 1^0 dirty pictures\
94* 1^0 xxx\
95* 1^0 evil bad things" );
96
97ok( $r1->action(), "/dev/foo" );
98ok( $r1->dump(), $recipe );
99
100## bogus constructor (scalar ref?)
101undef $r1;
102ok( $r1 = new Mail::Procmailrc::Recipe(\$recipe) );
103ok( $r1->flags(), '' );
104ok( join("\n", @{$r1->info()}), '' );
105ok( join("\n", @{$r1->conditions()}), '' );
106ok( $r1->action(), '' );
107ok( $r1->dump(), "\n" );
108
109## piece by piece construction
110undef $r1;
111$r1 = new Mail::Procmailrc::Recipe;
112$r1->flags(':0B:');
113$r1->info(['## junk recipes']);
114$r1->conditions(['* ^My name is not Larry', '* jumpin jehosephat!']);
115$r1->action('/dev/null');
116
117ok( $r1->dump, <<_MORE_ );
118:0B:
119## junk recipes
120* ^My name is not Larry
121* jumpin jehosephat!
122/dev/null
123_MORE_
124
125## check to see if info converts non-array refs
126undef $r1;
127$r1 = new Mail::Procmailrc::Recipe;
128$r1->flags(':0B:');
129$r1->info("## junk recipes
130## here's looking at you, kid");
131$r1->conditions(['* ^My name is not Larry', '* jumpin jehosephat!']);
132$r1->action('/dev/null');
133
134ok( $r1->dump, <<_MORE_ );
135:0B:
136## junk recipes
137## here's looking at you, kid
138* ^My name is not Larry
139* jumpin jehosephat!
140/dev/null
141_MORE_
142
143ok( $r1->info->[1], "## here's looking at you, kid" );
144
145exit;
146