-
Notifications
You must be signed in to change notification settings - Fork 70
/
missing_hb_separator.t
executable file
·150 lines (105 loc) · 3.17 KB
/
missing_hb_separator.t
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
#!/usr/bin/perl -w
BEGIN {
if (-e 't/test_dir') { # if we are running "t/rule_tests.t", kluge around ...
chdir 't';
}
if (-e 'test_dir') { # running from test directory, not ..
unshift(@INC, '../blib/lib');
}
}
my $prefix = '.';
if (-e 'test_dir') { # running from test directory, not ..
$prefix = '..';
}
use strict;
use Test;
use SATest; sa_t_init("missing_hb_separator");
use Mail::SpamAssassin;
plan tests => 12;
# initialize SpamAssassin
my $sa = create_saobj({'dont_copy_prefs' => 1});
$sa->init(0); # parse rules
my @msg;
my $mail;
my $status;
my $result;
#####
# make sure we catch w/out body, and that we catch the last header
@msg = ("Content-Type: text/plain; boundary=foo\n","X-Message-Info: foo\n");
$mail = $sa->parse(\@msg, 1);
$status = $sa->check($mail);
$result = 0;
foreach (@{$status->{test_names_hit}}) {
$result++ if ($_ eq 'MISSING_HB_SEP' || $_ eq 'X_MESSAGE_INFO');
}
ok ( $result == 2 );
ok ( $mail->{pristine_body} eq "" );
$status->finish();
$mail->finish();
#####
# we should also catch no separator before the mime part boundary, and the
# last header
@msg = ("Content-Type: text/plain;\n"," boundary=foo\n","X-Message-Info: foo\n","--foo\n");
$mail = $sa->parse(\@msg, 1);
$status = $sa->check($mail);
$result = 0;
foreach (@{$status->{test_names_hit}}) {
$result++ if ($_ eq 'MISSING_HB_SEP' || $_ eq 'X_MESSAGE_INFO');
}
ok ( $result == 2 );
ok ( $mail->{pristine_body} eq "--foo\n" );
$status->finish();
$mail->finish();
#####
@msg = ("X-Message-Info: foo\n", "Content-Type: text/plain; boundary=foo\n","--foo\n");
$mail = $sa->parse(\@msg, 1);
$status = $sa->check($mail);
$result = 0;
foreach (@{$status->{test_names_hit}}) {
$result++ if ($_ eq 'MISSING_HB_SEP' || $_ eq 'X_MESSAGE_INFO');
}
ok ( $result == 2 );
ok ( $mail->{pristine_body} eq "--foo\n" );
$status->finish();
$mail->finish();
#####
@msg = ("X-Message-Info: foo\n", "This is a test\n");
$mail = $sa->parse(\@msg, 1);
$status = $sa->check($mail);
$result = 0;
foreach (@{$status->{test_names_hit}}) {
$result++ if ($_ eq 'MISSING_HB_SEP' || $_ eq 'X_MESSAGE_INFO');
}
ok ( $result == 2 );
ok ( $mail->{pristine_body} eq "This is a test\n" );
$status->finish();
$mail->finish();
#####
@msg = ('Content-Type: multipart/related; boundary="foobar:"'."\n",
"--foobar:\n",
"Content-Type: text/plain\n",
"XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X\n",
"--foobar:--\n");
$mail = $sa->parse(\@msg, 1);
$status = $sa->check($mail);
$result = 0;
foreach (@{$status->{test_names_hit}}) {
$result++ if ($_ eq 'MISSING_HB_SEP' || $_ eq 'GTUBE');
}
ok ( $result == 2 );
ok ( $mail->{body_parts}->[0]->{rendered} eq "XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X" );
$status->finish();
$mail->finish();
#####
# A normal message, should not trigger
@msg = ("Content-Type: text/plain;\n", " boundary=foo\n","\n","--foo\n");
$mail = $sa->parse(\@msg, 1);
$status = $sa->check($mail);
$result = 1;
foreach (@{$status->{test_names_hit}}) {
$result = 0 if ($_ eq 'MISSING_HB_SEP');
}
ok ( $result && $mail->{pristine_body} eq "--foo\n" );
ok ( $mail->{pristine_body} eq "--foo\n" );
$status->finish();
$mail->finish();