4
if (-e 't/test_dir') { # if we are running "t/rule_tests.t", kluge around ...
8
if (-e 'test_dir') { # running from test directory, not ..
9
unshift(@INC, '../blib/lib');
10
unshift(@INC, '../lib');
15
if (-e 'test_dir') { # running from test directory, not ..
19
use lib '.'; use lib 't';
20
use SATest; sa_t_init("spamd_client");
22
use constant TEST_ENABLED => conf_bool('run_long_tests');
23
use constant HAS_SDBM_FILE => eval { require SDBM_File; };
25
our $DO_RUN = !$SKIP_SPAMD_TESTS && TEST_ENABLED;
30
if (!$RUNNING_ON_WINDOWS) {
39
use Test; plan tests => ($DO_RUN ? $num_tests : 0);
43
# ---------------------------------------------------------------------------
45
my $testmsg = getmessage("data/spam/gtube.eml");
50
q{ X-Spam-Flag: YES}, 'flag',
51
q{ BODY: Generic Test for Unsolicited Bulk Email }, 'gtube',
52
q{ XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X }, 'gtube string',
55
ok(start_spamd("-L"));
57
my $client = create_clientobj({
66
my $result = $client->check($testmsg);
70
ok($result->{isspam} eq 'True');
71
ok(!$result->{message});
73
$result = $client->process($testmsg);
77
ok($result->{isspam} eq 'True');
78
ok($result->{message});
80
patterns_run_cb($result->{message});
83
clear_pattern_counters();
85
q{ X-Spam-Flag: YES}, 'flag',
89
q{ XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X }, 'gtube string',
92
$result = $client->headers($testmsg);
96
ok($result->{message});
98
patterns_run_cb($result->{message});
103
if (!$RUNNING_ON_WINDOWS) {
105
clear_pattern_counters();
106
$spamd_already_killed = undef;
109
q{ X-Spam-Flag: YES}, 'flag',
110
q{ BODY: Generic Test for Unsolicited Bulk Email }, 'gtube',
111
q{ XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X }, 'gtube string',
116
my $sockpath = mk_safe_tmpdir()."/spamd.sock";
117
ok(start_spamd("-L --socketpath=$sockpath"));
119
$client = create_clientobj({
120
socketpath => $sockpath,
127
$result = $client->check($testmsg);
131
ok($result->{isspam} eq 'True');
132
ok(!$result->{message});
134
$result = $client->process($testmsg);
138
ok($result->{isspam} eq 'True');
139
ok($result->{message});
141
patterns_run_cb($result->{message});
145
cleanup_safe_tmpdir();
150
clear_pattern_counters();
151
$spamd_already_killed = undef;
153
bayes_store_module Mail::SpamAssassin::BayesStore::SDBM
156
ok(start_spamd("-L --allow-tell"));
158
my $client = create_clientobj({
165
my $spammsg = getmessage("data/spam/001");
168
ok($client->learn($spammsg, 0));
170
ok(!$client->learn($spammsg, 0));
172
%patterns = ( '1 0 non-token data: nspam' => 'spam in database' );
173
ok(salearnrun("--dump magic", \&patterns_run_cb));
175
clear_pattern_counters();
177
ok($client->learn($spammsg, 2));
179
%patterns = ( '0 0 non-token data: nspam' => 'spam in database',
180
'0 0 non-token data: nham' => 'ham in database' );
181
ok(salearnrun("--dump magic", \&patterns_run_cb));
183
clear_pattern_counters();
185
my $hammsg = getmessage("data/nice/001");
188
ok($client->learn($spammsg, 1));
190
ok(!$client->learn($spammsg, 1));
192
%patterns = ( '1 0 non-token data: nham' => 'ham in database' );
193
ok(salearnrun("--dump magic", \&patterns_run_cb));
195
clear_pattern_counters();
197
ok($client->learn($spammsg, 2));
199
%patterns = ( '0 0 non-token data: nspam' => 'spam in database',
200
'0 0 non-token data: nham' => 'ham in database' );
201
ok(salearnrun("--dump magic", \&patterns_run_cb));
203
clear_pattern_counters();
212
open(MSG, $msgpath) || return undef;
215
my $msg = join('', @file);