missing_hb_separator.t [plain text]
BEGIN {
if (-e 't/test_dir') { chdir 't';
}
if (-e 'test_dir') { unshift(@INC, '../blib/lib');
}
}
my $prefix = '.';
if (-e 'test_dir') { $prefix = '..';
}
use strict;
use Test;
use SATest; sa_t_init("missing_hb_separator");
use Mail::SpamAssassin;
plan tests => 12;
my $sa = create_saobj({'dont_copy_prefs' => 1});
$sa->init(0);
my @msg;
my $mail;
my $status;
my $result;
@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}}) {
print "test hit: $_\n";
$result++ if ($_ eq 'MISSING_HB_SEP' || $_ eq 'X_MESSAGE_INFO');
}
ok ( $result == 2 );
ok ( $mail->{pristine_body} eq "" );
$status->finish();
$mail->finish();
@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();
@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();