| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# -*- perl -*- |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# Base class for running tests. |
|
4
|
|
|
|
|
|
|
# |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require 5.004; |
|
8
|
4
|
|
|
4
|
|
13751
|
use strict; |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
321
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require Mail::IspMailGate; |
|
11
|
|
|
|
|
|
|
require Mail::IspMailGate::Config; |
|
12
|
|
|
|
|
|
|
require Mail::IspMailGate::Parser; |
|
13
|
|
|
|
|
|
|
require Exporter; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
package Mail::IspMailGate::Test; |
|
17
|
|
|
|
|
|
|
|
|
18
|
4
|
|
|
|
|
27982
|
use vars qw($VERSION @ISA @EXPORT $numTests $outputDir $outputToCore $parser |
|
19
|
4
|
|
|
4
|
|
23
|
$mailOutput); |
|
|
4
|
|
|
|
|
6
|
|
|
20
|
|
|
|
|
|
|
$VERSION = '0.10'; |
|
21
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
|
22
|
|
|
|
|
|
|
@EXPORT = qw(MiInit MiTest MiParser MiParse MiMail MiMailParse MiSearch); |
|
23
|
|
|
|
|
|
|
$numTests = 0; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $outputDir; |
|
26
|
|
|
|
|
|
|
my $outputToCore; |
|
27
|
|
|
|
|
|
|
my $parser; |
|
28
|
|
|
|
|
|
|
my $mailOutput; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub MiInit (@) { |
|
31
|
4
|
|
|
4
|
0
|
18
|
my %opts = @_; |
|
32
|
4
|
|
100
|
|
|
39
|
$outputDir = $opts{'output_dir'} || 'output'; |
|
33
|
4
|
50
|
|
|
|
123
|
if (!-d $outputDir) { |
|
34
|
0
|
|
|
|
|
0
|
mkdir $outputDir, 0755; |
|
35
|
|
|
|
|
|
|
} |
|
36
|
4
|
50
|
|
|
|
32
|
if (!defined($outputToCore = $opts{'output_to_core'})) { |
|
37
|
4
|
|
|
|
|
9
|
$outputToCore = 0; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
4
|
|
|
|
|
12
|
\%opts; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub MiTest ($;$$@) { |
|
43
|
18
|
|
|
18
|
0
|
527628
|
my $result = shift; |
|
44
|
18
|
|
|
|
|
42
|
my $smsg = shift; |
|
45
|
18
|
100
|
|
|
|
79
|
if (defined(my $msg = shift)) { printf($msg, @_) } |
|
|
12
|
|
|
|
|
1353
|
|
|
46
|
18
|
|
|
|
|
51
|
++$numTests; |
|
47
|
18
|
50
|
|
|
|
56
|
if (!defined($smsg)) { $smsg = '' } else { $smsg = " $smsg" } |
|
|
18
|
|
|
|
|
35
|
|
|
|
0
|
|
|
|
|
0
|
|
|
48
|
18
|
50
|
|
|
|
82
|
if (!$result) { print "not " } |
|
|
0
|
|
|
|
|
0
|
|
|
49
|
18
|
|
|
|
|
2618
|
print "ok $numTests$smsg\n"; |
|
50
|
18
|
|
|
|
|
962
|
$result; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub MiParser(@) { |
|
54
|
3
|
|
|
3
|
0
|
18263
|
MiInit(@_); |
|
55
|
3
|
|
|
|
|
58
|
$parser = Mail::IspMailGate::Parser->new |
|
56
|
|
|
|
|
|
|
('output_dir' => $outputDir, |
|
57
|
|
|
|
|
|
|
'output_to_core' => $outputToCore); |
|
58
|
3
|
|
|
|
|
3153
|
MiTest($parser, undef, "Creating the Parser\n"); |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub MiParse ($$$;$$) { |
|
62
|
3
|
|
|
3
|
0
|
23
|
my $parser = shift; my $filter = shift; my $inputEntity = shift; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
6
|
|
|
63
|
3
|
100
|
|
|
|
14
|
if (defined(my $inputFile = shift)) { |
|
64
|
2
|
|
|
|
|
7
|
$inputFile = "$outputDir/$inputFile"; |
|
65
|
2
|
|
|
|
|
11
|
my $fh = Symbol::gensym(); |
|
66
|
2
|
50
|
33
|
|
|
445
|
if (!open($fh, ">$inputFile") || |
|
|
|
|
33
|
|
|
|
|
|
67
|
|
|
|
|
|
|
!(print $fh $inputEntity->as_string()) || |
|
68
|
|
|
|
|
|
|
!close($fh)) { |
|
69
|
0
|
|
|
|
|
0
|
die "Cannot create input file $inputFile: $!"; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
} |
|
72
|
3
|
|
|
|
|
643377
|
my $outputEntity = $inputEntity->dup(); |
|
73
|
3
|
|
|
|
|
3822
|
my $result = $filter->doFilter({'entity' => $outputEntity, |
|
74
|
|
|
|
|
|
|
'parser' => $parser}); |
|
75
|
3
|
50
|
|
|
|
47
|
if (defined(my $outputFile = shift)) { |
|
76
|
3
|
|
|
|
|
16
|
$outputFile = "$outputDir/$outputFile"; |
|
77
|
3
|
|
|
|
|
35
|
my $fh = Symbol::gensym(); |
|
78
|
3
|
50
|
33
|
|
|
850
|
if (!open($fh, ">$outputFile") || |
|
|
|
|
33
|
|
|
|
|
|
79
|
|
|
|
|
|
|
!(print $fh $outputEntity->as_string()) || |
|
80
|
|
|
|
|
|
|
!close($fh)) { |
|
81
|
0
|
|
|
|
|
0
|
die "Cannot create input file $outputFile: $!"; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
} |
|
84
|
3
|
|
|
|
|
226306
|
($result, $outputEntity); |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub MiMail ($@) { |
|
89
|
1
|
|
|
1
|
0
|
10
|
my $name = shift; |
|
90
|
1
|
|
|
|
|
5
|
my $opts = MiInit(@_); |
|
91
|
1
|
|
|
|
|
2
|
my $cfg = $Mail::IspMailGate::Config::config; |
|
92
|
1
|
|
50
|
|
|
5
|
my $tmpdir = $opts->{'tmp_dir'} || 'output/tmp'; |
|
93
|
1
|
50
|
|
|
|
12
|
if ($tmpdir) { |
|
94
|
1
|
|
|
|
|
4
|
$cfg->{'tmp_dir'} = $tmpdir; |
|
95
|
1
|
50
|
|
|
|
37
|
if (!-d $tmpdir) { |
|
96
|
1
|
|
|
|
|
6
|
require File::Path; |
|
97
|
1
|
|
|
|
|
211
|
File::Path::mkpath($tmpdir, 0, 0755) |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
} |
|
100
|
1
|
50
|
|
|
|
4
|
if ($opts->{'recipients'}) { |
|
101
|
1
|
|
|
|
|
1
|
$cfg->{'recipients'} = [@{$opts->{'recipients'}}]; |
|
|
1
|
|
|
|
|
4
|
|
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
1
|
|
|
|
|
7
|
require Sys::Syslog; |
|
105
|
1
|
|
|
|
|
7
|
Sys::Syslog::openlog($name, 'pid,cons', 'daemon'); |
|
106
|
1
|
50
|
33
|
|
|
33
|
if (defined(&Sys::Syslog::setlogsock) && |
|
107
|
|
|
|
|
|
|
defined(&Sys::Syslog::_PATH_LOG)) { |
|
108
|
1
|
|
|
|
|
5
|
Sys::Syslog::setlogsock('unix'); |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
1
|
|
|
|
|
295
|
$parser = Mail::IspMailGate->new({'debug' => 1, |
|
112
|
|
|
|
|
|
|
'tmpDir' => $tmpdir, |
|
113
|
|
|
|
|
|
|
'noMails' => \$mailOutput}); |
|
114
|
1
|
|
|
|
|
4
|
MiTest($parser, undef, "Creating the parser\n"); |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub MiMailParse ($$$$$$;$) { |
|
119
|
1
|
|
|
1
|
0
|
1565534
|
my($parser, $filter, $input, $sender, $recipients, $inputFile, |
|
120
|
|
|
|
|
|
|
$outputFile) = @_; |
|
121
|
|
|
|
|
|
|
|
|
122
|
1
|
|
|
|
|
6
|
$inputFile = "$outputDir/$inputFile"; |
|
123
|
1
|
|
|
|
|
6
|
my $fh = Symbol::gensym(); |
|
124
|
1
|
50
|
33
|
|
|
597
|
if (!open($fh, ">$inputFile") || |
|
|
|
|
33
|
|
|
|
|
|
125
|
|
|
|
|
|
|
!(print $fh $input) || !close($fh)) { |
|
126
|
0
|
|
|
|
|
0
|
die "Error while creating input file $inputFile: $!"; |
|
127
|
|
|
|
|
|
|
} |
|
128
|
1
|
50
|
|
|
|
37
|
if (!open($fh, "<$inputFile")) { |
|
129
|
0
|
|
|
|
|
0
|
die "Error while opening input file $inputFile: $!"; |
|
130
|
|
|
|
|
|
|
} |
|
131
|
1
|
|
|
|
|
4
|
$mailOutput = ''; |
|
132
|
1
|
|
|
|
|
11
|
$parser->Main($fh, $sender, $recipients); |
|
133
|
1
|
50
|
|
|
|
7
|
if (defined($outputFile)) { |
|
134
|
1
|
|
|
|
|
5
|
$outputFile = "$outputDir/$outputFile"; |
|
135
|
1
|
50
|
33
|
|
|
377154
|
if (!open($fh, ">$outputFile") || |
|
|
|
|
33
|
|
|
|
|
|
136
|
|
|
|
|
|
|
!(print $fh $mailOutput) || !close($fh)) { |
|
137
|
0
|
|
|
|
|
0
|
die "Error while creating output file $outputFile: $!"; |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
} |
|
140
|
1
|
|
|
|
|
20
|
$mailOutput; |
|
141
|
|
|
|
|
|
|
} |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub MiSearch ($) { |
|
145
|
0
|
|
|
0
|
0
|
|
my $prog = shift; |
|
146
|
0
|
0
|
|
|
|
|
my $pathsep = ($^O =~ /win32/i) ? ';' : ':'; |
|
147
|
0
|
|
|
|
|
|
foreach my $dir (split(/$pathsep/, $ENV{'PATH'})) { |
|
148
|
0
|
0
|
|
|
|
|
if (-x "$dir/$prog") { return "$dir/$prog" } |
|
|
0
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
} |
|
150
|
0
|
|
|
|
|
|
undef; |
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
1; |