File: 30spam.t

package info (click to toggle)
libmail-box-perl 2.055-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,348 kB
  • ctags: 1,393
  • sloc: perl: 20,386; makefile: 43
file content (127 lines) | stat: -rw-r--r-- 3,509 bytes parent folder | download
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
#!/usr/bin/perl -T
#
# Test the processing of spam groups.
#

use strict;
use warnings;

use lib qw(. .. tests);
use Tools;

use File::Spec;
use Test::More tests => 75;

use Mail::Message::Head::Complete;
use Mail::Message::Head::SpamGroup;
use Mail::Box::Mbox;

#
# Creation of a group
#

my $sg = Mail::Message::Head::SpamGroup->new;

ok(defined $sg,                           'simple construction');
isa_ok($sg, 'Mail::Message::Head::SpamGroup');

#
# Extraction of a group
#

my $h = Mail::Message::Head::Complete->new;
ok(defined $h);

my @sgs = Mail::Message::Head::SpamGroup->from($h);
ok(!@sgs,                                 "no spamgroups in empty header");

#
# Open folder with example messages
#

my $fn = 'sgfolder';
$fn = File::Spec->catfile('31fgroups', $fn) unless -f $fn;
$fn = File::Spec->catfile('tests', $fn)  unless -f $fn;
die "Cannot find file with spam filter examples ($fn)" unless -f $fn;

my $folder = Mail::Box::Mbox->new(folder => $fn, extract => 'ALWAYS');
ok(defined $folder,                   "open example folder");
die unless defined $folder;

my @msgs   = $folder->messages;
cmp_ok(scalar(@msgs), '==', 11,        "all expected messages present");

for(my $nr=0; $nr<5; $nr++)
{  my $msg = $folder->message($nr);
   my @sgs = $msg->head->spamGroups;

   cmp_ok(scalar(@sgs), '==', 1,      "spam group at $nr");
   
   my $sg = $sgs[0];
   is($sg->type, "SpamAssassin");

   $sg->delete;

   @sgs   = $msg->head->spamGroups;
   cmp_ok(scalar(@sgs), '==', 0,      "spam group $nr removed");
}

for(my $nr=5; $nr<10; $nr++)
{   my $msg  = $folder->message($nr);
    my $head = $msg->head;

    my @sgs = $head->spamGroups;
    cmp_ok(scalar(@sgs), '==', 1,      "spam group at $nr");
    my $sg0 = $sgs[0];
    is($sg0->type, "Habeas-SWE");

    my $sg  = $msg->head->spamGroups('Habeas-SWE');
    ok(defined $sg);
    is($sg->type, "Habeas-SWE");

    my $is_correct = ($nr==5 || $nr==6) ? 1 : undef;
    cmp_ok($sg->habeasSweFieldsCorrect, '==', $is_correct, "spam in $nr");

    cmp_ok( Mail::Message::Head::SpamGroup->habeasSweFieldsCorrect($msg)
          , '==', $is_correct,          "spam in message $nr");

    cmp_ok(Mail::Message::Head::SpamGroup->habeasSweFieldsCorrect($head)
          , '==', $is_correct,          "spam in head of message $nr");

    $sg->delete;

    @sgs   = $msg->head->spamGroups;
    cmp_ok(scalar(@sgs), '==', 0,       "spam group $nr removed");
}

my $msg  = $folder->message(10);
my $head = $msg->head;
ok(Mail::Message::Head::SpamGroup->habeasSweFieldsCorrect($msg));
ok(Mail::Message::Head::SpamGroup->habeasSweFieldsCorrect($head));

@sgs     = sort {$a->type cmp $b->type} $head->spamGroups;
cmp_ok(scalar(@sgs), '==', 2,           "message 11 with 2 groups");

is($sgs[0]->type, 'Habeas-SWE');
ok($sgs[0]->habeasSweFieldsCorrect);
is($sgs[1]->type, 'SpamAssassin');

my $sgs  = $head->spamGroups;
cmp_ok($sgs, '==', 2,                   "scalar context = amount");

my $sa   = $head->spamGroups('SpamAssassin');
ok(defined $sa,                         "found spam assassin group");

my $swe  = $head->spamGroups('Habeas-SWE');
ok($swe->habeasSweFieldsCorrect);
ok(defined $swe,                        "found habeas-swe group");

$sa->delete;
@sgs     = $head->spamGroups;
cmp_ok(scalar(@sgs), '==', 1,           "message 11 still 1 group");
is($sgs[0]->type, 'Habeas-SWE');
ok($sgs[0]->habeasSweFieldsCorrect);

$swe->delete;
@sgs     = $head->spamGroups;
cmp_ok(scalar(@sgs), '==', 0,           "message 11 without spam group");