Salsa/Action/Post.pm

filter: Statementstmt 12.0% 31 / 258 Branchbran 0.0% 0 / 186 Conditioncond 0.0% 0 / 68 MC/DCmcdc 0.0% 0 / 43 Subroutinesub 38.1% 8 / 21 Podpod 0.0% 0 / 12 totaltotal 6.6% 39 / 588 CC 118 SCAR 64.3
CC
118
Cov
6%
setup_msg
1560.0
check_restrict
650.0
process_msg
306.0
CRAP 618.8
↑ Summary Salsa/Action/Admin.pm »
1 #
2 # Mail/Salsa/Action/Post.pm
3 # Last Modification: Wed Mar 17 19:11:38 WET 2010
4 #
5 # Copyright (c) 2010 Henrique Dias <henrique.ribeiro.dias@gmail.com>.
6 # All rights reserved.
7 # This module is free software; you can redistribute it and/or modify
8 # it under the same terms as Perl itself.
9 #
10 package Mail::Salsa::Action::Post;
11  
12 2 ▶use 5.008000;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 require Exporter;
17 #use AutoLoader qw(AUTOLOAD);
18 2 ▶use SelfLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use Mail::Salsa::Utils qw(file_path create_file generate_id);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use Mail::Salsa::Logs qw(logs debug);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶use Mail::Salsa::Archive qw(archive_msg);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 ▶use MIME::QuotedPrint qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 # Items to export into callers namespace by default. Note: do not export
25 # names by default without a very good reason. Use EXPORT_OK instead.
26 # Do not simply export all your public functions/methods/constants.
27  
28 # This allows declaration use Mail::Salsa ':all';
29 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
30 # will save memory.
31  
32 2 our %EXPORT_TAGS = ( 'all' => [ qw() ] );
33 2 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
34 2 our @EXPORT = qw();
35 2 our $VERSION = '0.05';
36  
37 2 SelfLoader->load_stubs();
38  
39 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
40 0 my $proto = shift;
41 0 ▶ my $class = ref($proto) || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
42 0 my $self = {@_};
43 0 bless ($self, $class);
44 0 $self->process_msg();
45 0 return($self);
46 }
47  
48 0 ▶sub process_msg {
Subroutine process_msg: not called CC=17 SCAR=57.2
Pod undocumented
49 0 my $self = shift;
50  
51 0 my ($name, $domain) = split(/\@/, $self->{'list'});
52 0 ▶ unless($self->check_restrict('restrict.txt', $self->{'headers'}->{'0.0'}->{'received'}, [])) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->check_restrict("restrict.txt", $self->{"headers"}{"0.0"}{"received"}, [])) 0 0 0
53 Mail::Salsa::Utils::tplsendmail(
54 smtp_server => $self->{'smtp_server'},
55 timeout => $self->{'timeout'},
56 label => "PERMISSION_DENY",
57 lang => $self->{'config'}->{'language'},
58 vars => {
59 from => "$name\-owner\@$domain",
60 to => $self->{'from'},
61 0 list => $self->{'list'},
62 }
63 );
64 0 $self->logs(join("", "[permission deny] from: ", $self->{'from'}), "list");
65 0 return();
66 }
67 0 ▶ if($self->{'config'}->{'max_message_size'} && (((-s $self->{'message'})/1024) > $self->{'config'}->{'max_message_size'})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"config"}{"max_message_size"} and (-s $self->{"message"}) / 1024 > $self->{"config"}{"max_message_size"}) 0 0 0
Condition0%0/3
$self->{"config"}{"max_message_size"} and (-s $self->{"message"}) / 1024 > $self->{"config"}{"max_message_size"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"config"}{"max_message_size"} and (-s $self->{"message"}) / 1024 > $self->{"config"}{"max_message_size"}
$self->{"config"}{"max_message_size"} (-s $self->{"message"}) / 1024 > $self->{"config"}{"max_message_size"}
Truth table0%0/3
A and B
A= $self->{"config"}{"max_message_size"}B= (-s $self->{"message"}) / 1024 > $self->{"config"}{"max_message_size"}
ABresult
0X0
100
111
68 Mail::Salsa::Utils::tplsendmail(
69 smtp_server => $self->{'smtp_server'},
70 timeout => $self->{'timeout'},
71 label => "MAX_MESSAGE_SIZE",
72 lang => $self->{'config'}->{'language'},
73 vars => {
74 from => "$name\-owner\@$domain",
75 to => $self->{'from'},
76 list => $self->{'list'},
77 0 size => $self->{'config'}->{'max_message_size'},
78 }
79 );
80 0 $self->logs(join("", "[max message size exceed] from: ", $self->{'from'}), "list");
81 0 return();
82 }
83 0 ▶ if(scalar(keys(%{$self->{'headers'}})) > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %{$$self{"headers"};} > 1) 0 0 0
84 0 my $attachfile = file_path($self->{'list'}, $self->{'list_dir'}, "attachments.txt");
85 0 my $listfile = file_path($self->{'list'}, $self->{'list_dir'}, "list.txt");
86 0 my ($code, $access, $mime_type) = ("", "allow", "");
87 0 ▶ if(my $error = &generate_code($listfile, $attachfile, $self->{'from'}, $code)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = &generate_code($listfile, $attachfile, $self->{"from"}, $code)) 0 0 0
88 0 $self->logs("[file] $error", "errors");
89 0 return();
90 }
91 0 eval($code);
92 0 ▶ if($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
93 0 $self->logs("[eval] $@", "errors");
94 0 return();
95 }
96 0 ▶ if($access eq "deny") {
Branch: 1 branch
BranchTrueFalseTotal
if ($access eq "deny") 0 0 0
97 Mail::Salsa::Utils::tplsendmail(
98 smtp_server => $self->{'smtp_server'},
99 timeout => $self->{'timeout'},
100 label => "NO_ATTACHMENTS",
101 lang => $self->{'config'}->{'language'},
102 vars => {
103 from => "$name\-owner\@$domain",
104 to => $self->{'from'},
105 0 list => $self->{'list'},
106 mime_type => $mime_type,
107 }
108 );
109 0 $self->logs(join("", "[deny attachment] mime-type: $mime_type from: ", $self->{'from'}), "list");
110 0 return();
111 }
112 }
113  
114 0 ▶ $self->setup_stamp() if($self->{'config'}->{'stamp'} eq "y");
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"config"}{"stamp"} eq "y" 0 0 0
115 0 ▶ my $reply = ($self->{'headers'}->{'0.0'}->{'subject'}->{'value'} =~ /^Re: /i) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'headers'}{'0.0'}{'subject'}{'value'} =~ /^Re: /i ? : 0 0 0
116 0 my $bounce = $self->check4bounces();
117 0 my $human = $self->setup_msg();
118 0 ▶ $human = 0 unless($self->{'stamp'});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"stamp"} 0 0 0
119  
120 0 ▶ if($bounce == 2) {
Branch: 3 branches
BranchTrueFalseTotal
if ($bounce == 2) { } 0 0 0
elsif ($bounce and $self->{'config'}{'accept_bounces'} eq 'n') { } 0 0 0
elsif ($self->{'stamp'} and not $human) { } 0 0 0
121 # debug and test
122 0 $self->logs(join("", "[been-there] from: ", $self->{'from'}), "list");
123 ▶ } elsif($bounce && $self->{'config'}->{'accept_bounces'} eq "n") {
Condition0%0/3
$bounce and $self->{"config"}{"accept_bounces"} eq "n"
!ll&&!rl&&r
000
MC/DC0%0/2
$bounce and $self->{"config"}{"accept_bounces"} eq "n"
$bounce $self->{"config"}{"accept_bounces"} eq "n"
Truth table0%0/3
A and B
A= $bounceB= $self->{"config"}{"accept_bounces"} eq "n"
ABresult
0X0
100
111
124 Mail::Salsa::Utils::tplsendmail(
125 smtp_server => $self->{'smtp_server'},
126 timeout => $self->{'timeout'},
127 label => "DONT_BOUNCE",
128 lang => $self->{'config'}->{'language'},
129 vars => {
130 from => "$name\-owner\@$domain",
131 to => $self->{'from'},
132 0 list => $self->{'list'},
133 }
134 );
135 0 $self->logs(join("", "[bounce] from: ", $self->{'from'}), "list");
136 ▶ } elsif($self->{'stamp'} && !$human) {
Condition0%0/3
$self->{"stamp"} and not $human
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"stamp"} and not $human
$self->{"stamp"} not $human
Truth table0%0/3
A and not(B)
A= $self->{"stamp"}B= not $human
ABresult
0X0
100
111
137 Mail::Salsa::Utils::tplsendmail(
138 smtp_server => $self->{'smtp_server'},
139 timeout => $self->{'timeout'},
140 label => "MAILSTAMP",
141 lang => $self->{'config'}->{'language'},
142 vars => {
143 from => "$name\-owner\@$domain",
144 to => $self->{'from'},
145 list => $self->{'list'},
146 0 stamp => $self->{'stamp'}
147 }
148 );
149 0 $self->logs(join("", "[sent stamp] to: ", $self->{'from'}), "list");
150 } else {
151 0 $self->sendmail4all();
152 0 $self->logs(join("", "[post message] from: ", $self->{'from'}), "list");
153 0 ▶ $self->archive_msg() if($self->{'config'}->{'archive'} eq "y");
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"config"}{"archive"} eq "y" 0 0 0
154 }
155 0 unlink($self->{'message'});
156 0 return();
157 }
158  
159 0 ▶sub check4bounces {
Subroutine check4bounces: not called CC=6 SCAR=37.4
Pod undocumented
160 0 my $self = shift;
161  
162 0 my $bounce = 1;
163 0 my $list = $self->{'list'};
164 0 ▶ $bounce = 0 if(lc($self->{'headers'}->{'0.0'}->{'to'}) =~ /\b$list\b/);
Branch: 1 branch
BranchTrueFalseTotal
if lc($self->{"headers"}{"0.0"}{"to"}) =~ /\b$list\b/ 0 0 0
165 0 ▶ $bounce = 0 if(exists($self->{'headers'}->{'0.0'}->{'cc'}) && lc($self->{'headers'}->{'0.0'}->{'cc'}) =~ /\b$list\b/);
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"headers"}{"0.0"}{"cc"} and lc($self->{"headers"}{"0.0"}{"cc"}) =~ /\b$list\b/ 0 0 0
Condition0%0/3
exists $self->{"headers"}{"0.0"}{"cc"} and lc($self->{"headers"}{"0.0"}{"cc"}) =~ /\b$list\b/
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"headers"}{"0.0"}{"cc"} and lc($self->{"headers"}{"0.0"}{"cc"}) =~ /\b$list\b/
exists $self->{"headers"}{"0.0"}{"cc"} lc($self->{"headers"}{"0.0"}{"cc"}) =~ /\b$list\b/
Truth table0%0/3
A and B
A= exists $self->{"headers"}{"0.0"}{"cc"}B= lc($self->{"headers"}{"0.0"}{"cc"}) =~ /\b$list\b/
ABresult
0X0
100
111
166 0 ▶ $bounce = 2 if(exists($self->{'headers'}->{'0.0'}->{'x-been-there'}) && $self->{'headers'}->{'0.0'}->{'x-been-there'} eq $self->{'list'});
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"headers"}{"0.0"}{"x-been-there"} and $self->{"headers"}{"0.0"}{"x-been-there"} eq $self->{"list"} 0 0 0
Condition0%0/3
exists $self->{"headers"}{"0.0"}{"x-been-there"} and $self->{"headers"}{"0.0"}{"x-been-there"} eq $self->{"list"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"headers"}{"0.0"}{"x-been-there"} and $self->{"headers"}{"0.0"}{"x-been-there"} eq $self->{"list"}
exists $self->{"headers"}{"0.0"}{"x-been-there"} $self->{"headers"}{"0.0"}{"x-been-there"} eq $self->{"list"}
Truth table0%0/3
A and B
A= exists $self->{"headers"}{"0.0"}{"x-been-there"}B= $self->{"headers"}{"0.0"}{"x-been-there"} eq $self->{"list"}
ABresult
0X0
100
111
167  
168 0 return($bounce);
169 }
170  
171 0 ▶sub setup_stamp {
Subroutine setup_stamp: not called CC=10 SCAR=47.0
Pod undocumented
172 0 my $self = shift;
173  
174 0 my $sfile = file_path($self->{'list'}, $self->{'list_dir'}, 'stamp.txt');
175 0 my ($number, $letter) = ($self->{'config'}->{'stamp_life'} =~ /^(\d+)([dwmy])$/);
176  
177 0 my $days = int(-M $sfile);
178 0 my $newstamp = 0;
179  
180 0 ▶ if($letter eq "d") {
Branch: 4 branches
BranchTrueFalseTotal
if ($letter eq 'd') { } 0 0 0
elsif ($letter eq 'w') { } 0 0 0
elsif ($letter eq 'm') { } 0 0 0
elsif ($letter eq 'y') { } 0 0 0
181 0 ▶ $newstamp = 1 if($days > $number);
Branch: 1 branch
BranchTrueFalseTotal
if $days > $number 0 0 0
182 } elsif($letter eq "w") {
183 0 ▶ $newstamp = 1 if(int($days/7) > $number);
Branch: 1 branch
BranchTrueFalseTotal
if int $days / 7 > $number 0 0 0
184 } elsif($letter eq "m") {
185 0 ▶ $newstamp = 1 if(int($days/30) > $number);
Branch: 1 branch
BranchTrueFalseTotal
if int $days / 30 > $number 0 0 0
186 } elsif($letter eq "y") {
187 0 ▶ $newstamp = 1 if(int($days/365) > $number);
Branch: 1 branch
BranchTrueFalseTotal
if int $days / 365 > $number 0 0 0
188 }
189 0 ▶ if($newstamp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newstamp) { } 0 0 0
190 0 $self->{'stamp'} = uc(generate_id(32));
191 0 create_file($sfile, join("", $self->{'stamp'}, "\n"), 0600);
192 0 } else { $self->{'stamp'} = Mail::Salsa::Utils::get_key($sfile); }
193  
194 0 return();
195 }
196  
197 0 ▶sub exist_subscriber {
Subroutine exist_subscriber: not called CC=6 SCAR=37.4
Pod undocumented
198 0 my $file = shift;
199 0 ▶ my $string = shift || return(0);
Condition0%0/2
shift() || (return 0)
l!l
00
MC/DC0%0/1
shift() || (return 0)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
200  
201 0 my $exist = 0;
202 0 ▶ open(MLIST, "<", $file) or return("$!");
Branch: 1 branch
BranchTrueFalseTotal
open MLIST, "<", $file or return "$!" 0 0 0
203 0 ▶ while(<MLIST>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline MLIST)) 0 0 0
204 0 ▶ next if(/^[\#\x0d\x0a]/);
Branch: 1 branch
BranchTrueFalseTotal
if /^[\#\x0d\x0a]/ 0 0 0
205 0 ▶ if(/\b$string\b/) { $exist = 1; last; }
Branch: 1 branch
BranchTrueFalseTotal
if (/\b$string\b/) 0 0 0
206 }
207 0 close(MLIST);
208 0 return($exist);
209 }
210  
211 0 ▶sub generate_code {
Subroutine generate_code: not called CC=10 SCAR=47.0
Pod undocumented
212 0 my $listfile = shift;
213 0 my $attachfile = shift;
214 0 my $from_addr = shift;
215  
216 0 $_[0] .= <<ENDCODE;
217 for my \$part (keys(\%{\$self->{'headers'}})) {
218 \$mime_type = \$self->{'headers'}->{\$part}->{'content-type'}->{'value'};
219 local \$_ = \$mime_type;
220 next if(index(\$_, \"multipart\/\") > -1);
221 ENDCODE
222 0 my $subscriber = 0;
223 0 ▶ open(ATTACHMENT, "<", $attachfile) or return("$!");
Branch: 1 branch
BranchTrueFalseTotal
open ATTACHMENT, "<", $attachfile or return "$!" 0 0 0
224 0 ▶ while(<ATTACHMENT>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline ATTACHMENT)) 0 0 0
225 0 ▶ next if(/^[\#\x0d\x0a]/);
Branch: 1 branch
BranchTrueFalseTotal
if /^[\#\x0d\x0a]/ 0 0 0
226 0 my ($policy, $mime, $addr) = /^(\w+) +(\w+\/[\w\.\-\+]+) +from +(\S+)[\x0d\x0a]+/;
227 0 ▶ if($addr eq "subscribers") {
Branch: 1 branch
BranchTrueFalseTotal
if ($addr eq "subscribers") 0 0 0
228 0 ▶ unless($subscriber) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($subscriber) 0 0 0
229 0 $subscriber = &exist_subscriber($listfile, $from_addr);
230 0 ▶ $subscriber = -1 unless($subscriber);
Branch: 1 branch
BranchTrueFalseTotal
unless $subscriber 0 0 0
231 }
232 0 ▶ if($subscriber > 0) { $addr = $from_addr; }
Branch: 1 branch
BranchTrueFalseTotal
if ($subscriber > 0) { } 0 0 0
233 0 else { next; }
234 }
235 0 $mime =~ s{any(?=\/)}{\[\\w\\+\\-\\.\]\+}g;
236 0 $mime =~ s{(?<=\/)any}{\[\\w\\+\\-\\.\]\+}g;
237 0 $mime =~ s{\/}{\\\/};
238 0 $addr =~ s/\@/\\\@/g;
239 0 $addr =~ s/\./\\\./g;
240 0 ▶ my $part = ($addr eq "any") ? "" : " (\$self-\>{\'from\'} =~ /$addr\$/) and";
Branch: 1 branch
BranchTrueFalseTotal
$addr eq 'any' ? : 0 0 0
241 0 ▶ my $keyword = $policy eq "deny" ? "last" : "next";
Branch: 1 branch
BranchTrueFalseTotal
$policy eq 'deny' ? : 0 0 0
242 0 $_[0] .= "\t/\^$mime\$/ and$part \$access = \"$policy\", $keyword;\n";
243 }
244 0 close(ATTACHMENT);
245 0 $_[0] .= "}\n";
246 0 return();
247 }
248  
249 0 ▶sub sendmail4all {
Subroutine sendmail4all: not called CC=1 SCAR=6.9
Pod undocumented
250 0 my $self = shift;
251  
252 0 my ($name, $domain) = split(/\@/, $self->{'list'});
253 0 my $listfile = file_path($self->{'list'}, $self->{'list_dir'}, "list.txt");
254 0 (my $outfile = $self->{'message'}) =~ s/\.msg$/\.out/;
255  
256 0 ▶ my $refsub = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
257 0 my $handle = shift;
258 0 ▶ open(FILE, "<", $outfile) or die("$!");
Branch: 1 branch
BranchTrueFalseTotal
open FILE, "<", $outfile or die "$!" 0 0 0
259 0 ▶ while(<FILE>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline FILE)) 0 0 0
260 0 s{^\.}{\.\.};
261 0 print $handle $_;
262 }
263 0 close(FILE);
264 0 };
265 my $sm = Mail::Salsa::Sendmail->new(
266 smtp_server => $self->{'smtp_server'},
267 0 timeout => $self->{'timeout'},
268 smtp_port => 25,
269 );
270 0 $sm->everything(
271 mail_from => "$name\-return\@$domain",
272 list_file => $listfile,
273 data => $refsub
274 );
275 0 unlink($outfile);
276  
277 0 return();
278 }
279  
280 0 ▶sub set_headers {
Subroutine set_headers: not called CC=1 SCAR=6.9
Pod undocumented
281 0 my $list = shift;
282  
283 0 my ($name, $domain) = split(/\@/, $list);
284 0 my $headers = <<"EOF";
285 X-Salsa-Version: 0.01
286 X-Been-There: $name\@$domain
287 Precedence: bulk
288 List-Help: <mailto:$name-help\@$domain?subject=help\>
289 List-Unsubscribe: <mailto:$name-unsubscribe\@$domain?subject=unsubscribe\>
290 List-Subscribe: <mailto:$name-subscribe\@$domain?subject=subscribe\>
291 List-Admin: <mailto:$name-admin\@$domain\>
292 List-Post: \<mailto:$name\@$domain\>
293 EOF
294 0 return($headers);
295 }
296  
297 0 ▶sub insert_text {
Subroutine insert_text: not called CC=4 SCAR=30.0
Pod undocumented
298 0 my $handle = shift;
299 0 my $file = shift;
300 0 my $encoding = shift;
301  
302 0 ▶ open(BANNER, "<", $file) or die("$!");
Branch: 1 branch
BranchTrueFalseTotal
open BANNER, "<", $file or die "$!" 0 0 0
303 0 ▶ while(local $_ = <BANNER>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(local $_ = readline BANNER)) 0 0 0
304 0 ▶ my $line = ($encoding eq "quoted-printable") ? MIME::QuotedPrint::encode($_) : $_;
Branch: 1 branch
BranchTrueFalseTotal
$encoding eq 'quoted-printable' ? : 0 0 0
305 0 print $handle $line;
306 }
307 0 close(BANNER);
308 0 print $handle "\n";
309  
310 0 return();
311 }
312  
313 0 ▶sub check_encoding {
Subroutine check_encoding: not called CC=6 SCAR=37.4
Pod undocumented
314 0 ▶ my $encoding = shift || return(1);
Condition0%0/2
shift() || (return 1)
l!l
00
MC/DC0%0/1
shift() || (return 1)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
315  
316 0 ▶ return(length($encoding) == 0 ? 1 :
Branch: 4 branches
BranchTrueFalseTotal
length $encoding == 0 ? : 0 0 0
$encoding eq 'quoted-printable' ? : 0 0 0
$encoding eq '7bit' ? : 0 0 0
$encoding eq '8bit' ? : 0 0 0
317 $encoding eq "quoted-printable" ? 1 :
318 $encoding eq "7bit" ? 1 :
319 $encoding eq "8bit" ? 1 : 0);
320 }
321  
322 0 ▶sub setup_msg {
Subroutine setup_msg: not called CC=39 SCAR=73.5
Pod undocumented
323 0 my $self = shift;
324
325 0 my ($name, $domain) = split(/\@/, $self->{'list'});
326 0 (my $outfile = $self->{'message'}) =~ s/\.msg$/\.out/;
327  
328 0 my ($headerfile, $footerfile, $encoding) = ("", "", "");
329 0 ▶ if($self->{'config'}->{'header'} eq "y") {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"config"}{"header"} eq "y") 0 0 0
330 0 $headerfile = file_path($self->{'list'}, $self->{'list_dir'}, "header.txt");
331 0 ▶ (-e $headerfile && -s $headerfile) or $headerfile = "";
Branch: 1 branch
BranchTrueFalseTotal
-e $headerfile and -s $headerfile or $headerfile = "" 0 0 0
Condition0%0/3
-e $headerfile and -s $headerfile
!ll&&!rl&&r
000
MC/DC0%0/2
-e $headerfile and -s $headerfile
-e $headerfile -s $headerfile
Truth table0%0/3
A and B
A= -e $headerfileB= -s $headerfile
ABresult
0X0
100
111
332 }
333 0 ▶ if($self->{'config'}->{'footer'} eq "y") {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"config"}{"footer"} eq "y") 0 0 0
334 0 $footerfile = file_path($self->{'list'}, $self->{'list_dir'}, "footer.txt");
335 0 ▶ (-e $footerfile && -s $footerfile) or $footerfile = "";
Branch: 1 branch
BranchTrueFalseTotal
-e $footerfile and -s $footerfile or $footerfile = "" 0 0 0
Condition0%0/3
-e $footerfile and -s $footerfile
!ll&&!rl&&r
000
MC/DC0%0/2
-e $footerfile and -s $footerfile
-e $footerfile -s $footerfile
Truth table0%0/3
A and B
A= -e $footerfileB= -s $footerfile
ABresult
0X0
100
111
336 }
337 0 ▶ my $boundary = exists($self->{'headers'}->{'0.0'}->{'content-type'}->{'boundary'}) ? $self->{'headers'}->{'0.0'}->{'content-type'}->{'boundary'} : "";
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'headers'}{'0.0'}{'content-type'}{'boundary'} ? : 0 0 0
338 0 ▶ my ($tree, $count) = $boundary ? ("0.0.0", 0) : ("0.0", 1);
Branch: 1 branch
BranchTrueFalseTotal
$boundary ? : 0 0 0
339  
340 0 ▶ if($headerfile || $footerfile) {
Branch: 1 branch
BranchTrueFalseTotal
if ($headerfile or $footerfile) 0 0 0
Condition0%0/3
$headerfile or $footerfile
l!l&&r!l&&!r
000
MC/DC0%0/2
$headerfile or $footerfile
$headerfile $footerfile
Truth table0%0/3
A or B
A= $headerfileB= $footerfile
ABresult
1X1
011
000
341 0 ▶ if(exists($self->{'headers'}->{$tree}->{'content-type'}->{'value'}) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'headers'}{$tree}{'content-type'}{'value'} and $self->{'headers'}{$tree}{'content-type'}{'value'} eq 'text/plain') { } 0 0 0
Condition0%0/3
exists $self->{"headers"}{$tree}{"content-type"}{"value"} and $self->{"headers"}{$tree}{"content-type"}{"value"} eq "text/plain"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"headers"}{$tree}{"content-type"}{"value"} and $self->{"headers"}{$tree}{"content-type"}{"value"} eq "text/plain"
exists $self->{"headers"}{$tree}{"content-type"}{"value"} $self->{"headers"}{$tree}{"content-type"}{"value"} eq "text/plain"
Truth table0%0/3
A and B
A= exists $self->{"headers"}{$tree}{"content-type"}{"value"}B= $self->{"headers"}{$tree}{"content-type"}{"value"} eq "text/plain"
ABresult
0X0
100
111
342 $self->{'headers'}->{$tree}->{'content-type'}->{'value'} eq "text/plain") {
343 0 ▶ if(exists($self->{'headers'}->{$tree}->{'content-transfer-encoding'}->{'value'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"headers"}{$tree}{"content-transfer-encoding"}{"value"}) 0 0 0
344 0 $encoding = $self->{'headers'}->{$tree}->{'content-transfer-encoding'}->{'value'};
345 0 ▶ $encoding = $footerfile = $headerfile = "" unless(&check_encoding($encoding));
Branch: 1 branch
BranchTrueFalseTotal
unless &check_encoding($encoding) 0 0 0
346 }
347 0 } else { $footerfile = $headerfile = ""; }
348 }
349  
350 0 ▶ my $stamp = $self->{'stamp'} || "";
Condition0%0/2
$self->{'stamp'} || ''
l!l
00
MC/DC0%0/1
$self->{'stamp'} || ''
$self->{'stamp'}
Truth table0%0/2
A
A= $self->{'stamp'}
Aresult
11
00
351 0 my $prefix = $self->{'config'}->{'prefix'};
352 0 my ($exist, $received, $headers, $topheaders) = (0, 1, 1, 1);
353 0 ▶ open(INFILE, "<", $self->{'message'}) or die("$!");
Branch: 1 branch
BranchTrueFalseTotal
open INFILE, "<", $self->{"message"} or die "$!" 0 0 0
354 0 ▶ open(OUTFILE, ">", $outfile) or die("$!");
Branch: 1 branch
BranchTrueFalseTotal
open OUTFILE, ">", $outfile or die "$!" 0 0 0
355 0 select(OUTFILE);
356 0 ▶ while(<INFILE>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline INFILE)) 0 0 0
357 0 ▶ if($headers) {
Branch: 1 branch
BranchTrueFalseTotal
if ($headers) { } 0 0 0
358 0 ▶ if($topheaders) {
Branch: 1 branch
BranchTrueFalseTotal
if ($topheaders) 0 0 0
359 0 ▶ next if(&check_headers($_));
Branch: 1 branch
BranchTrueFalseTotal
if &check_headers($_) 0 0 0
360 0 ▶ s/^Subject: (.+)/Subject: $prefix $1/o if($prefix && index($_, $prefix, 0) == -1);
Branch: 1 branch
BranchTrueFalseTotal
if $prefix and index($_, $prefix, 0) == -1 0 0 0
Condition0%0/3
$prefix and index($_, $prefix, 0) == -1
!ll&&!rl&&r
000
MC/DC0%0/2
$prefix and index($_, $prefix, 0) == -1
$prefix index($_, $prefix, 0) == -1
Truth table0%0/3
A and B
A= $prefixB= index($_, $prefix, 0) == -1
ABresult
0X0
100
111
361 0 ▶ $received = 0 if($received == 1 && !(/^(X-)?Received: / || /^[ \t]+/));
Branch: 1 branch
BranchTrueFalseTotal
if $received == 1 and not /^(X-)?Received: / || /^[ \t]+/ 0 0 0
Condition0%0/6
$received == 1 and not /^(X-)?Received: / || /^[ \t]+/
!ll&&!rl&&r
000
/^(X-)?Received: / || /^[ \t]+/
l!l&&r!l&&!r
000
MC/DC0%0/3
$received == 1 and not /^(X-)?Received: / || /^[ \t]+/
$received == 1 /^(X-)?Received: / /^[ \t]+/
Truth table0%0/4
A and not(B || C)
A= $received == 1B= /^(X-)?Received: /C= /^[ \t]+/
ABCresult
0XX0
11X0
1010
1001
362 0 ▶ if($received == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($received == 0) 0 0 0
363 0 print OUTFILE &set_headers($self->{'list'});
364 0 $received = -1;
365 }
366 }
367 0 ▶ $headers = 0 if(/^[\n\r]$/o);
Branch: 1 branch
BranchTrueFalseTotal
if /^[\n\r]$/o 0 0 0
368 } else {
369 0 $topheaders = 0;
370 0 ▶ $exist = 1 if(s/\b$stamp\b//og);
Branch: 1 branch
BranchTrueFalseTotal
if s/\b$stamp\b//go 0 0 0
371 0 ▶ if($headerfile || $footerfile) {
Branch: 1 branch
BranchTrueFalseTotal
if ($headerfile or $footerfile) 0 0 0
Condition0%0/3
$headerfile or $footerfile
l!l&&r!l&&!r
000
MC/DC0%0/2
$headerfile or $footerfile
$headerfile $footerfile
Truth table0%0/3
A or B
A= $headerfileB= $footerfile
ABresult
1X1
011
000
372 0 ▶ if($headerfile && $count == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($headerfile and $count == 1) 0 0 0
Condition0%0/3
$headerfile and $count == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$headerfile and $count == 1
$headerfile $count == 1
Truth table0%0/3
A and B
A= $headerfileB= $count == 1
ABresult
0X0
100
111
373 0 &insert_text(\*OUTFILE, $headerfile, $encoding);
374 0 $headerfile = "";
375 }
376 0 ▶ if($boundary && /^--$boundary/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($boundary and /^--$boundary/) 0 0 0
Condition0%0/3
$boundary and /^--$boundary/
!ll&&!rl&&r
000
MC/DC0%0/2
$boundary and /^--$boundary/
$boundary /^--$boundary/
Truth table0%0/3
A and B
A= $boundaryB= /^--$boundary/
ABresult
0X0
100
111
377 0 $headers = 1;
378 0 $count++;
379 }
380 0 ▶ if($footerfile && $count == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($footerfile and $count == 2) 0 0 0
Condition0%0/3
$footerfile and $count == 2
!ll&&!rl&&r
000
MC/DC0%0/2
$footerfile and $count == 2
$footerfile $count == 2
Truth table0%0/3
A and B
A= $footerfileB= $count == 2
ABresult
0X0
100
111
381 0 &insert_text(\*OUTFILE, $footerfile, $encoding);
382 0 $footerfile = "";
383 }
384 }
385 }
386 0 print OUTFILE $_;
387 }
388 0 ▶ &insert_text(\*OUTFILE, $footerfile, $encoding) if($footerfile);
Branch: 1 branch
BranchTrueFalseTotal
if $footerfile 0 0 0
389 0 close(OUTFILE);
390 0 close(INFILE);
391  
392 0 select(STDOUT);
393 0 return($exist);
394 }
395  
396 0 ▶sub check_restrict {
Subroutine check_restrict: not called CC=25 SCAR=64.8
Pod undocumented
397 0 my $self = shift;
398 0 my $thisfile = shift;
399 0 my $receiveds = shift;
400 0 ▶ my $array = shift || [];
Condition0%0/2
shift() || []
l!l
00
MC/DC0%0/1
shift() || []
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
401  
402 0 my $file = file_path($self->{'list'}, $self->{'list_dir'}, $thisfile);
403 0 ▶ (-s $file) or return(1);
Branch: 1 branch
BranchTrueFalseTotal
-s $file or return 1 0 0 0
404 0 my $count = scalar(@{$array});
405 ### ["policy", "address", "action", "network", "stamp"] ###
406 0 ▶ $array = ["", "", "", "", ""] unless($count);
Branch: 1 branch
BranchTrueFalseTotal
unless $count 0 0 0
407 0 my $netok = 0;
408  
409 0 ▶ open(FILE, "<", $file) or return(1);
Branch: 1 branch
BranchTrueFalseTotal
open FILE, "<", $file or return 1 0 0 0
410 0 ▶ while(<FILE>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline FILE)) 0 0 0
411 0 ▶ next if(/^[\#\n\r]+/);
Branch: 1 branch
BranchTrueFalseTotal
if /^[\#\n\r]+/ 0 0 0
412 0 chomp;
413 0 ▶ if($count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count) { } 0 0 0
414 0 my ($addr) = (/\<?([^\@\<\>]+\@[^\@\<\>]+)\>?/);
415 0 $array->[1] = $addr;
416 } else {
417 0 (@{$array}) = (/^(allow|deny) +(\S+) +to +(post|bounce|proceed) +from +(localnet|anywhere)( +with(out)? +stamp)?/);
418 }
419 0 ▶ if($array->[1] eq "subscribers") {
Branch: 1 branch
BranchTrueFalseTotal
if ($array->[1] eq 'subscribers') { } 0 0 0
420 0 $array->[1] = "";
421 0 $netok = $self->check_restrict('list.txt', $receiveds, $array);
422 } else {
423 0 $self->{'config'}->{'accept_bounces'} = ($self->{'config'}->{'stamp'} = "n");
424 0 my $address = $array->[1];
425 0 ▶ if($address eq "any") {
Branch: 1 branch
BranchTrueFalseTotal
if ($address eq "any") 0 0 0
426 0 ▶ last if($array->[0] eq "deny" and $array->[3] eq "anywhere");
Branch: 1 branch
BranchTrueFalseTotal
if $array->[0] eq "deny" and $array->[3] eq "anywhere" 0 0 0
Condition0%0/3
$array->[0] eq "deny" and $array->[3] eq "anywhere"
!ll&&!rl&&r
000
MC/DC0%0/2
$array->[0] eq "deny" and $array->[3] eq "anywhere"
$array->[0] eq "deny" $array->[3] eq "anywhere"
Truth table0%0/3
A and B
A= $array->[0] eq "deny"B= $array->[3] eq "anywhere"
ABresult
0X0
100
111
427 0 $address = "\.+";
428 }
429 0 ▶ if($self->{'from'} =~ /$address$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"from"} =~ /$address$/) 0 0 0
430 $netok = ($array->[3] eq "anywhere") ? 1 :
431 0 ▶ ($array->[3] eq "localnet") ? &check_network($receiveds, $self->{'config'}->{'localnet'}) : 0;
Branch: 2 branches
BranchTrueFalseTotal
$array->[3] eq 'anywhere' ? : 0 0 0
$array->[3] eq 'localnet' ? : 0 0 0
432 }
433 0 ▶ if(defined($array->[4]) && $array->[4]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $array->[4] and $array->[4]) 0 0 0
Condition0%0/3
defined $array->[4] and $array->[4]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $array->[4] and $array->[4]
defined $array->[4] $array->[4]
Truth table0%0/3
A and B
A= defined $array->[4]B= $array->[4]
ABresult
0X0
100
111
434 0 ▶ $self->{'config'}->{'stamp'} = ($array->[0] eq "allow") ?
Branch: 3 branches
BranchTrueFalseTotal
$array->[0] eq 'allow' ? : 0 0 0
$array->[4] =~ /^ +without +stamp/ ? : 0 0 0
$array->[4] =~ /^ +without +stamp/ ? : 0 0 0
435 (($array->[4] =~ /^ +without +stamp/) ? "n" : "y") :
436 (($array->[4] =~ /^ +without +stamp/) ? "y" : "n");
437 }
438 0 ▶ if($array->[2] eq "bounce" or $array->[2] eq "proceed") {
Branch: 1 branch
BranchTrueFalseTotal
if ($array->[2] eq "bounce" or $array->[2] eq "proceed") 0 0 0
Condition0%0/3
$array->[2] eq "bounce" or $array->[2] eq "proceed"
l!l&&r!l&&!r
000
MC/DC0%0/2
$array->[2] eq "bounce" or $array->[2] eq "proceed"
$array->[2] eq "bounce" $array->[2] eq "proceed"
Truth table0%0/3
A or B
A= $array->[2] eq "bounce"B= $array->[2] eq "proceed"
ABresult
1X1
011
000
439 0 ▶ $self->{'config'}->{'accept_bounces'} = ($array->[0] eq "allow") ? "y" : ($self->{'config'}->{'stamp'} eq "y") ? "y" : "n";
Branch: 2 branches
BranchTrueFalseTotal
$array->[0] eq 'allow' ? : 0 0 0
$self->{'config'}{'stamp'} eq 'y' ? : 0 0 0
440 }
441 }
442 0 ▶ last if($netok);
Branch: 1 branch
BranchTrueFalseTotal
if $netok 0 0 0
443 }
444 0 close(FILE);
445 0 return($netok);
446 }
447  
448 # Autoload methods go after =cut, and are processed by the autosplit program.
449  
450 2 1;
451 __DATA__
↑ Summary Salsa/Action/Admin.pm »