Salsa/Action/Personalize.pm

filter: Statementstmt 25.7% 27 / 105 Branchbran 0.0% 0 / 36 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 58.3% 7 / 12 Podpod 0.0% 0 / 4 totaltotal 19.2% 34 / 177 CC 23 SCAR 50.6
CC
23
Cov
18%
process_msg
306.0
sendmail4all
20.0
__ANON__
12.0
CRAP 157.0
« Salsa/Action/Admin.pm ↑ Summary Salsa/Action/Unsubscribe.pm »
1 #
2 # Mail/Salsa/Action/Personalize
3 # Last Modification: Wed Apr 6 16:09:58 WEST 2005
4 #
5 # Copyright (c) 2005 Henrique Dias <hdias@aesbuc.pt>. All rights reserved.
6 # This module is free software; you can redistribute it and/or modify
7 # it under the same terms as Perl itself.
8 #
9 package Mail::Salsa::Action::Personalize;
10  
11 1 ▶use 5.008000;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 require Exporter;
16 1 ▶use Mail::Salsa::Utils qw(file_path create_file generate_id email_components);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Mail::Salsa::Logs qw(logs debug);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Mail::Salsa::Archive qw(archive_msg);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Mail::Salsa::Action::Post;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 # Items to export into callers namespace by default. Note: do not export
22 # names by default without a very good reason. Use EXPORT_OK instead.
23 # Do not simply export all your public functions/methods/constants.
24  
25 # This allows declaration use Mail::Salsa ':all';
26 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
27 # will save memory.
28  
29 1 our %EXPORT_TAGS = ( 'all' => [ qw() ] );
30 1 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
31 1 our @EXPORT = qw();
32 1 our $VERSION = '0.02';
33  
34 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
35 0 my $proto = shift;
36 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
37 0 my $self = {@_};
38 0 bless ($self, $class);
39 0 $self->process_msg();
40 0 return($self);
41 }
42  
43 0 ▶sub check_restrict {
Subroutine check_restrict: not called CC=1 SCAR=6.9
Pod undocumented
44 0 my $self = shift;
45 0 $self->Mail::Salsa::Action::Post::check_restrict(@_);
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->Mail::Salsa::Action::Post::check_restrict('restrict.txt', $self->{'headers'}->{'0.0'}->{'received'}, [])) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->Mail::Salsa::Action::Post::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  
68 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
69 Mail::Salsa::Utils::tplsendmail(
70 smtp_server => $self->{'smtp_server'},
71 timeout => $self->{'timeout'},
72 label => "MAX_MESSAGE_SIZE",
73 lang => $self->{'config'}->{'language'},
74 vars => {
75 from => "$name\-owner\@$domain",
76 to => $self->{'from'},
77 list => $self->{'list'},
78 0 size => $self->{'config'}->{'max_message_size'},
79 }
80 );
81 0 $self->logs(join("", "[max message size exceed] from: ", $self->{'from'}), "list");
82 0 return();
83 }
84 0 ▶ if(scalar(keys(%{$self->{'headers'}})) > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %{$$self{"headers"};} > 1) 0 0 0
85 0 my $attachfile = file_path($self->{'list'}, $self->{'list_dir'}, "attachments.txt");
86 0 my $listfile = file_path($self->{'list'}, $self->{'list_dir'}, "list.txt");
87 0 my ($code, $access, $mime_type) = ("", "allow", "");
88 0 ▶ if(my $error = Mail::Salsa::Action::Post::generate_code($listfile, $attachfile, $self->{'from'}, $code)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = Mail::Salsa::Action::Post::generate_code($listfile, $attachfile, $self->{"from"}, $code)) 0 0 0
89 0 $self->logs("[file] $error", "errors");
90 0 return();
91 }
92 0 eval($code);
93 0 ▶ if($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
94 0 $self->logs("[eval] $@", "errors");
95 0 return();
96 }
97 0 ▶ if($access eq "deny") {
Branch: 1 branch
BranchTrueFalseTotal
if ($access eq "deny") 0 0 0
98 Mail::Salsa::Utils::tplsendmail(
99 smtp_server => $self->{'smtp_server'},
100 timeout => $self->{'timeout'},
101 label => "NO_ATTACHMENTS",
102 lang => $self->{'config'}->{'language'},
103 vars => {
104 from => "$name\-owner\@$domain",
105 to => $self->{'from'},
106 0 list => $self->{'list'},
107 mime_type => $mime_type,
108 }
109 );
110 0 $self->logs(join("", "[deny attachment] mime-type: $mime_type from: ", $self->{'from'}), "list");
111 0 return();
112 }
113 }
114 0 $self->{'headers'}->{'0.0'}->{'to'} =~ s/\-personalize(?=\@)//;
115 0 ▶ $self->Mail::Salsa::Action::Post::setup_stamp() if($self->{'config'}->{'stamp'} eq "y");
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"config"}{"stamp"} eq "y" 0 0 0
116 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
117 0 my $bounce = $self->Mail::Salsa::Action::Post::check4bounces();
118 0 my $human = $self->Mail::Salsa::Action::Post::setup_msg();
119 0 ▶ $human = 0 unless($self->{'stamp'});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"stamp"} 0 0 0
120  
121 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
122 # debug and test
123 0 $self->logs(join("", "[been-there] from: ", $self->{'from'}), "list");
124 ▶ } 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
125 Mail::Salsa::Utils::tplsendmail(
126 smtp_server => $self->{'smtp_server'},
127 timeout => $self->{'timeout'},
128 label => "DONT_BOUNCE",
129 lang => $self->{'config'}->{'language'},
130 vars => {
131 from => "$name\-owner\@$domain",
132 to => $self->{'from'},
133 0 list => $self->{'list'},
134 }
135 );
136 0 $self->logs(join("", "[bounce] from: ", $self->{'from'}), "list");
137 ▶ } 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
138 Mail::Salsa::Utils::tplsendmail(
139 smtp_server => $self->{'smtp_server'},
140 timeout => $self->{'timeout'},
141 label => "MAILSTAMP",
142 lang => $self->{'config'}->{'language'},
143 vars => {
144 from => "$name\-owner\@$domain",
145 to => $self->{'from'},
146 list => $self->{'list'},
147 0 stamp => $self->{'stamp'}
148 }
149 );
150 0 $self->logs(join("", "[sent stamp] to: ", $self->{'from'}), "list");
151 } else {
152 0 $self->sendmail4all();
153 0 $self->logs(join("", "[personalize message] from: ", $self->{'from'}), "list");
154 0 ▶ $self->archive_msg() if($self->{'config'}->{'archive'} eq "y");
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"config"}{"archive"} eq "y" 0 0 0
155 }
156 0 unlink($self->{'message'});
157 0 return();
158 }
159  
160 0 ▶sub sendmail4all {
Subroutine sendmail4all: not called CC=4 SCAR=30.0
Pod undocumented
161 0 my $self = shift;
162  
163 0 my ($name, $domain) = split(/\@/, $self->{'list'});
164 0 my $listfile = file_path($self->{'list'}, $self->{'list_dir'}, "list.txt");
165  
166 0 (my $outfile = $self->{'message'}) =~ s/\.msg$/\.out/;
167 0 open(LIST, "<", $listfile);
168 0 ▶ while(<LIST>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline LIST)) 0 0 0
169 0 my $fullemail = email_components($_);
170 0 ▶ exists($fullemail->{'address'}) or next;
Branch: 1 branch
BranchTrueFalseTotal
exists $fullemail->{"address"} or next 0 0 0
171 0 ▶ $fullemail->{'username'} = "Mailing List Subscriber" unless(exists($fullemail->{'username'}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $fullemail->{"username"} 0 0 0
172 0 my ($username, $email) = ($fullemail->{'username'}, $fullemail->{'address'});
173  
174 my $sm = Mail::Salsa::Sendmail->new(
175 'smtp_server' => $self->{'smtp_server'},
176 'smtp_port' => 25,
177 0 'timeout' => $self->{'timeout'},
178 );
179 0 $sm->helo();
180 0 $sm->mail_from("$name\-return\@$domain");
181 0 $sm->rcpt_to('addresses' => [$email]);
182 0 ▶ $sm->data(sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
183 0 my $handle = shift;
184 0 ▶ open(SENDFILE, "<", $outfile) or die("$!");
Branch: 1 branch
BranchTrueFalseTotal
open SENDFILE, "<", $outfile or die "$!" 0 0 0
185 0 ▶ while(<SENDFILE>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline SENDFILE)) 0 0 0
186 0 s/^To: +[^\n\r]+/To: $username \<$email\>/io;
187 0 s/\$FULLNAME\b/$username/o;
188 0 s/\$EMAIL\b/$email/o;
189 0 print $handle $_;
190 }
191 0 close(SENDFILE);
192 0 });
193 0 $sm->quit();
194 }
195 0 close(LIST);
196 0 unlink($outfile);
197  
198 0 return();
199 }
200  
201 # Autoload methods go after =cut, and are processed by the autosplit program.
202  
203 1 1;
204  
205 __END__
« Salsa/Action/Admin.pm ↑ Summary Salsa/Action/Unsubscribe.pm »