| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# -*- perl -*- |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Mail::IspMailGate::Filter::Packer; |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
require 5.004; |
|
7
|
3
|
|
|
3
|
|
2057
|
use strict; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
2944
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
require Mail::IspMailGate::Filter; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
@Mail::IspMailGate::Filter::Packer::ISA = qw(Mail::IspMailGate::Filter::InOut); |
|
12
|
|
|
|
|
|
|
|
|
13
|
12
|
|
|
12
|
1
|
113
|
sub getSign { "X-ispMailGate-Packer"; }; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
##################################################################### |
|
16
|
|
|
|
|
|
|
# |
|
17
|
|
|
|
|
|
|
# Name: mustFilter |
|
18
|
|
|
|
|
|
|
# |
|
19
|
|
|
|
|
|
|
# Purpose: determines wether this message must be filtered and |
|
20
|
|
|
|
|
|
|
# allowed to modify $self the message and so on |
|
21
|
|
|
|
|
|
|
# |
|
22
|
|
|
|
|
|
|
# Inputs: $self - This class |
|
23
|
|
|
|
|
|
|
# $entity - the whole message |
|
24
|
|
|
|
|
|
|
# |
|
25
|
|
|
|
|
|
|
# Returns: 1 if it must be, else 0 |
|
26
|
|
|
|
|
|
|
# |
|
27
|
|
|
|
|
|
|
##################################################################### |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub mustFilter ($$) { |
|
30
|
4
|
|
|
4
|
1
|
9
|
my($self, $entity) = @_; |
|
31
|
4
|
|
|
|
|
6
|
my $cfg = $Mail::IspMailGate::Config::config; |
|
32
|
|
|
|
|
|
|
|
|
33
|
4
|
100
|
|
|
|
37
|
if (!$self->SUPER::mustFilter($entity)) { |
|
34
|
2
|
|
|
|
|
10
|
return 0; |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
2
|
|
|
|
|
7
|
my($packer) = $self->{'packer'}; |
|
38
|
2
|
|
|
|
|
4
|
my($direction) = $self->{'recDirection'}; |
|
39
|
2
|
|
|
|
|
7
|
my($head) = $entity->head(); |
|
40
|
2
|
50
|
|
|
|
17
|
if ($direction eq 'neg') { |
|
41
|
0
|
|
|
|
|
0
|
my $prevPack = $head->mime_attr('X-IspMailGate-Packer-Type'); |
|
42
|
0
|
0
|
|
|
|
0
|
$prevPack = '' unless defined $prevPack; |
|
43
|
0
|
0
|
|
|
|
0
|
if(exists($cfg->{'packer'}->{$prevPack})) { |
|
44
|
0
|
|
|
|
|
0
|
$packer=$prevPack; |
|
45
|
|
|
|
|
|
|
} else { |
|
46
|
0
|
|
|
|
|
0
|
return 0; |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
} else { |
|
49
|
2
|
|
|
|
|
10
|
$head->mime_attr('X-IspMailGate-Packer-Type', $packer); |
|
50
|
|
|
|
|
|
|
} |
|
51
|
2
|
|
|
|
|
515
|
$self->{'recPacker'} = $packer; |
|
52
|
|
|
|
|
|
|
|
|
53
|
2
|
|
|
|
|
12
|
return 1; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
##################################################################### |
|
58
|
|
|
|
|
|
|
# |
|
59
|
|
|
|
|
|
|
# Name: hookFilter |
|
60
|
|
|
|
|
|
|
# |
|
61
|
|
|
|
|
|
|
# Purpse: a function which is called after the filtering process |
|
62
|
|
|
|
|
|
|
# |
|
63
|
|
|
|
|
|
|
# Inputs: $self - This class |
|
64
|
|
|
|
|
|
|
# $entity - the whole message |
|
65
|
|
|
|
|
|
|
# |
|
66
|
|
|
|
|
|
|
# Returns: errormessage if any |
|
67
|
|
|
|
|
|
|
# |
|
68
|
|
|
|
|
|
|
##################################################################### |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub hookFilter ($$) { |
|
71
|
2
|
|
|
2
|
1
|
20
|
my($self, $entity) = @_; |
|
72
|
2
|
|
|
|
|
19
|
my($direction) = $self->{'recDirection'}; |
|
73
|
2
|
|
|
|
|
92
|
$self->SUPER::hookFilter($entity); |
|
74
|
2
|
50
|
|
|
|
25
|
if ($direction eq 'neg') { |
|
75
|
0
|
|
|
|
|
0
|
$entity->head()->delete('X-Ispmailgate-Packer-Type'); |
|
76
|
0
|
|
|
|
|
0
|
$entity->head()->delete('X-Ispmailgate-Packer'); |
|
77
|
|
|
|
|
|
|
} |
|
78
|
2
|
|
|
|
|
24
|
delete $self->{'recPacker'}; |
|
79
|
2
|
|
|
|
|
44
|
''; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
##################################################################### |
|
85
|
|
|
|
|
|
|
# |
|
86
|
|
|
|
|
|
|
# Name: filterFile |
|
87
|
|
|
|
|
|
|
# |
|
88
|
|
|
|
|
|
|
# Purpse: do the filter process for one file. Compress it or |
|
89
|
|
|
|
|
|
|
# uncompress it. the direction will be guessed, if this |
|
90
|
|
|
|
|
|
|
# fails the initial one will be used |
|
91
|
|
|
|
|
|
|
# If the direction is 'neg' the packer will |
|
92
|
|
|
|
|
|
|
# be guessed. Only if this fails the 'packer' attribute will |
|
93
|
|
|
|
|
|
|
# be tried |
|
94
|
|
|
|
|
|
|
# |
|
95
|
|
|
|
|
|
|
# Inputs: $self - This class |
|
96
|
|
|
|
|
|
|
# $attr - hash-ref to filter attribute |
|
97
|
|
|
|
|
|
|
# 1. 'body' |
|
98
|
|
|
|
|
|
|
# 2. 'parser' |
|
99
|
|
|
|
|
|
|
# 3. 'head' |
|
100
|
|
|
|
|
|
|
# 4. 'globHead' |
|
101
|
|
|
|
|
|
|
# |
|
102
|
|
|
|
|
|
|
# Returns: error message, if any |
|
103
|
|
|
|
|
|
|
# |
|
104
|
|
|
|
|
|
|
##################################################################### |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub filterFile ($$$) { |
|
107
|
6
|
|
|
6
|
1
|
16
|
my ($self, $attr) = @_; |
|
108
|
6
|
|
|
|
|
11
|
my $cfg = $Mail::IspMailGate::Config::config; |
|
109
|
|
|
|
|
|
|
|
|
110
|
6
|
|
|
|
|
15
|
my ($ret) = 0; |
|
111
|
6
|
50
|
|
|
|
70
|
if($ret = $self->SUPER::filterFile($attr)) { |
|
112
|
0
|
|
|
|
|
0
|
return $ret; |
|
113
|
|
|
|
|
|
|
} |
|
114
|
6
|
|
|
|
|
15
|
my $head = $attr->{'head'}; |
|
115
|
6
|
|
|
|
|
12
|
my $body = $attr->{'body'}; |
|
116
|
6
|
|
|
|
|
16
|
my $parser = $attr->{'parser'}; |
|
117
|
6
|
|
|
|
|
12
|
my $globHead = $attr->{'globHead'}; |
|
118
|
6
|
|
|
|
|
24
|
my $ifile = $body->path(); |
|
119
|
6
|
|
|
|
|
452
|
my $ofile = $parser->output_path($head); |
|
120
|
6
|
|
|
|
|
24
|
my $packer = $self->{'recPacker'}; |
|
121
|
6
|
|
|
|
|
19
|
my $direction = $self->{'recDirection'}; |
|
122
|
6
|
|
|
|
|
12
|
my $sign = ''; |
|
123
|
|
|
|
|
|
|
|
|
124
|
6
|
50
|
33
|
|
|
65
|
if((!defined($packer)) || (!defined($direction))) { |
|
125
|
0
|
|
|
|
|
0
|
return "Invalid invoke"; |
|
126
|
|
|
|
|
|
|
} |
|
127
|
6
|
50
|
|
|
|
40
|
return "Unknown packer: $packer" |
|
128
|
|
|
|
|
|
|
unless exists($cfg->{'packer'}->{$packer}); |
|
129
|
6
|
|
|
|
|
29
|
my $cmd = $cfg->{'packer'}->{$packer}->{$direction}; |
|
130
|
6
|
|
|
|
|
296
|
$cmd =~ s/\$(\w+)/$cfg->{$1}/g; |
|
131
|
|
|
|
|
|
|
|
|
132
|
6
|
50
|
|
|
|
87574
|
if ($ret=system("$cmd " . quotemeta($ifile) . " >" . quotemeta($ofile))) { |
|
133
|
0
|
|
|
|
|
0
|
return $ret; |
|
134
|
|
|
|
|
|
|
} else { |
|
135
|
6
|
|
|
|
|
557
|
$body->path($ofile); |
|
136
|
|
|
|
|
|
|
} |
|
137
|
6
|
|
|
|
|
643
|
$self->setEncoding({('head' => $head, 'direction' => $direction)}); |
|
138
|
6
|
|
|
|
|
449
|
''; |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
##################################################################### |
|
142
|
|
|
|
|
|
|
# |
|
143
|
|
|
|
|
|
|
# Name: setEncoding |
|
144
|
|
|
|
|
|
|
# |
|
145
|
|
|
|
|
|
|
# Purpse: set a reasonable encoding type, for the filtered mail |
|
146
|
|
|
|
|
|
|
# |
|
147
|
|
|
|
|
|
|
# Inputs: $self - This class |
|
148
|
|
|
|
|
|
|
# $attr - the attributes |
|
149
|
|
|
|
|
|
|
# 'head' |
|
150
|
|
|
|
|
|
|
# 'direction' |
|
151
|
|
|
|
|
|
|
# |
|
152
|
|
|
|
|
|
|
# Returns: error message, if any |
|
153
|
|
|
|
|
|
|
# |
|
154
|
|
|
|
|
|
|
##################################################################### |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub setEncoding ($$$) { |
|
157
|
6
|
|
|
6
|
1
|
49
|
my ($self, $attr) = @_; |
|
158
|
6
|
|
|
|
|
25
|
my ($head) = $attr->{'head'}; |
|
159
|
6
|
|
|
|
|
31
|
my ($direction) = $attr->{'direction'}; |
|
160
|
6
|
|
|
|
|
160
|
my ($actuEnc) = $head->mime_attr('Content-Transfer-Encoding'); |
|
161
|
6
|
50
|
|
|
|
3620
|
if (!defined($actuEnc)) { |
|
162
|
0
|
|
|
|
|
0
|
$actuEnc = ''; |
|
163
|
|
|
|
|
|
|
} |
|
164
|
6
|
|
|
|
|
40
|
my ($prevEnc) = $head->mime_attr('X-ispMailGate-Packer-PEncoding'); |
|
165
|
6
|
50
|
|
|
|
1232
|
if (!defined($prevEnc)) { |
|
166
|
0
|
|
|
|
|
0
|
$prevEnc = ''; |
|
167
|
|
|
|
|
|
|
} |
|
168
|
6
|
|
|
|
|
34
|
my ($newEnc) = ''; |
|
169
|
|
|
|
|
|
|
|
|
170
|
6
|
50
|
|
|
|
35
|
if ($direction eq 'neg') { |
|
171
|
0
|
0
|
|
|
|
0
|
if ($prevEnc) { |
|
172
|
0
|
|
|
|
|
0
|
$newEnc = $prevEnc; |
|
173
|
|
|
|
|
|
|
} else { |
|
174
|
|
|
|
|
|
|
# Assume base64 to go the sure way |
|
175
|
0
|
|
|
|
|
0
|
$newEnc = "base64"; |
|
176
|
|
|
|
|
|
|
} |
|
177
|
0
|
|
|
|
|
0
|
$head->delete('X-IspMailgate-Packer-PEncoding'); |
|
178
|
|
|
|
|
|
|
} else { |
|
179
|
6
|
|
|
|
|
21
|
$newEnc = "base64"; |
|
180
|
6
|
50
|
|
|
|
20
|
if ($actuEnc) { |
|
181
|
6
|
|
|
|
|
277
|
$head->replace("X-ispMailGate-Packer-PEncoding", $actuEnc); |
|
182
|
|
|
|
|
|
|
} else { |
|
183
|
|
|
|
|
|
|
# Assume base64 as encoding if not clear |
|
184
|
0
|
|
|
|
|
0
|
$head->replace("X-ispMailGate-Packer-PEncoding", "base64"); |
|
185
|
|
|
|
|
|
|
} |
|
186
|
|
|
|
|
|
|
} |
|
187
|
6
|
|
|
|
|
3077
|
$head->replace("Content-Transfer-Encoding", $newEnc); |
|
188
|
|
|
|
|
|
|
|
|
189
|
6
|
|
|
|
|
1649
|
''; |
|
190
|
|
|
|
|
|
|
} |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub IsEq ($$) { |
|
194
|
2
|
|
|
2
|
1
|
4
|
my($self, $cmp) = @_; |
|
195
|
2
|
50
|
|
|
|
93
|
$cmp->isa('Mail::IspMailGate::Filter::Packer') && |
|
196
|
|
|
|
|
|
|
$self->{'packer'} eq $cmp->{'packer'}; |
|
197
|
|
|
|
|
|
|
} |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
$Mail::IspMailGate::Filter::VERSION = "1.000"; |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
1; |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
__END__ |